App.vue 1.5 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 timer = ref(null)
  7. const autoCloseTime = 30000
  8. onMounted(() => {
  9. nextTick(() => {
  10. console.log('baseurl', import.meta.env?.VITE_BASE_URL, 'version', import.meta.env?.VITE_VERSION)
  11. //
  12. const process_ENV = process?.env?.NODE_ENV || ''
  13. if (process_ENV === 'production') { // development production
  14. if (timer.value) clearInterval(timer.value)
  15. timer.value = setInterval(() => { checkVersion() }, autoCloseTime)
  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. const option = {
  34. autoCloseTime: autoCloseTime > 3000 ? (autoCloseTime-3000) : autoCloseTime
  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>