12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <script setup>
- import { RouterView } from 'vue-router'
- import { ref, onMounted, onUnmounted, nextTick } from 'vue'
- import Confirm from '@/plugins/confirm'
- import axios from 'axios'
- const timer = ref(null)
- const autoCloseTime = 30000
- onMounted(() => {
- nextTick(() => {
- console.log('baseurl', import.meta.env?.VITE_BASE_URL, 'version', import.meta.env?.VITE_VERSION)
- //
- const process_ENV = process?.env?.NODE_ENV || ''
- if (process_ENV === 'production') { // development production
- if (timer.value) clearInterval(timer.value)
- timer.value = setInterval(() => { checkVersion() }, autoCloseTime)
- }
- })
- })
- onUnmounted(() => {
- if (timer.value) clearInterval(timer.value)
- })
- // 检查版本号
- const checkVersion = () => {
- const baseUrl = import.meta.env.VITE_BASE_URL || 'https://www.menduner.com'
- const version = import.meta.env?.VITE_VERSION || ''
- axios.get(`${baseUrl}/app-api/menduner/system/get/version`, {
- headers: {
- ['tenant-id']: import.meta.env.VITE_TENANTCODE
- },
- // cache: 'no-store' // 禁用缓存
- }).then((res) => {
- if (res?.data?.data !== version) {
- const option = {
- autoCloseTime: autoCloseTime > 3000 ? (autoCloseTime-3000) : autoCloseTime
- }
- Confirm('系统提示', '发现新版本,是否立即刷新页面', option).then(() => {
- window.location.reload()
- })
- }
- }).catch(err => {
- console.log('checkVersion-err', err)
- })
- }
- </script>
- <template>
- <v-app>
- <RouterView />
- </v-app>
- </template>
- <style scoped>
- </style>
|