App.vue 1.4 KB

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