App.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <script setup>
  2. import { RouterView } from 'vue-router'
  3. import { ref, onMounted, onUnmounted, nextTick } from 'vue'
  4. import Confirm from '@/plugins/confirm'
  5. import axios from 'axios'
  6. const testOpen = true // 开启测试环境测试 默认关闭
  7. const timer = ref(null)
  8. const setIntervalTime = 30000 //
  9. onMounted(() => {
  10. nextTick(() => {
  11. console.log('baseurl', import.meta.env?.VITE_BASE_URL, 'version', import.meta.env?.VITE_VERSION, process?.env?.NODE_ENV)
  12. //
  13. const process_ENV = process?.env?.NODE_ENV || ''
  14. if (process_ENV === 'production' || testOpen) { // development production
  15. if (timer.value) clearInterval(timer.value)
  16. timer.value = setInterval(() => { checkVersion() }, setIntervalTime)
  17. }
  18. })
  19. })
  20. onUnmounted(() => {
  21. if (timer.value) clearInterval(timer.value)
  22. })
  23. // 检查版本号
  24. const checkVersion = () => {
  25. const baseUrl = import.meta.env.VITE_BASE_URL || ''
  26. const version = import.meta.env?.VITE_VERSION || ''
  27. const tenantId = import.meta.env?.VITE_TENANTCODE || ''
  28. if (!baseUrl || !version) return
  29. axios.get(`${baseUrl}/app-api/menduner/system/get/version`, {
  30. headers: { ['tenant-id']: tenantId }
  31. }).then((res) => {
  32. if (res?.data?.data !== version) {
  33. const option = {
  34. autoCloseTime: setIntervalTime > 30000 ? setIntervalTime/2 : setIntervalTime > 10000 ? setIntervalTime - 3000 : setIntervalTime
  35. }
  36. Confirm('系统提示', '发现新版本,是否立即刷新页面', option).then(() => {
  37. window.location.reload()
  38. })
  39. }
  40. }).catch(err => {
  41. console.log('checkVersion-err', err)
  42. })
  43. }
  44. </script>
  45. <template>
  46. <v-app>
  47. <RouterView />
  48. </v-app>
  49. </template>
  50. <style scoped>
  51. </style>