App.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 timer = ref(null)
  7. onMounted(() => {
  8. nextTick(() => {
  9. console.log(1, 'NODE_ENV', import.meta.env?.NODE_ENV); console.log(1, 'process_ENV', process.env.NODE_ENV)
  10. //
  11. const open = true // 是否开启
  12. const process_ENV = process?.env?.NODE_ENV || ''
  13. if (process_ENV === 'production' || open) { // development production
  14. if (timer.value) clearInterval(timer.value)
  15. timer.value = setInterval(() => { checkVersion() }, 5000)
  16. }
  17. })
  18. })
  19. onUnmounted(() => {
  20. if (timer.value) clearInterval(timer.value)
  21. })
  22. // 检查版本号
  23. const checkVersion = () => {
  24. const baseUrl = import.meta.env.VITE_BASE_URL || 'https://www.menduner.com'
  25. const version = import.meta.env?.VITE_VERSION || ''
  26. axios.get(`${baseUrl}/app-api/menduner/system/get/version`, {
  27. headers: {
  28. ['tenant-id']: import.meta.env.VITE_TENANTCODE
  29. },
  30. // cache: 'no-store' // 禁用缓存
  31. }).then((res) => {
  32. if (res?.data?.data !== version) {
  33. Confirm('系统提示', '发现新版本,是否立即刷新页面').then(() => {
  34. window.location.reload()
  35. })
  36. }
  37. }).catch(err => {
  38. console.log('checkVersion-err', err)
  39. })
  40. }
  41. </script>
  42. <template>
  43. <v-app>
  44. <RouterView />
  45. </v-app>
  46. </template>
  47. <style scoped>
  48. </style>