|
@@ -1,36 +1,48 @@
|
|
|
<script setup>
|
|
|
import { RouterView } from 'vue-router'
|
|
|
-// import { ref, onMounted, onUnmounted } from 'vue'
|
|
|
+import { ref, onMounted, onUnmounted, nextTick } from 'vue'
|
|
|
+import Confirm from '@/plugins/confirm'
|
|
|
+import axios from 'axios'
|
|
|
|
|
|
-// const checkVersion = () => {
|
|
|
-// const oldVersion = localStorage.getItem('version')
|
|
|
-// axios.get('/version.json', {
|
|
|
-// cache: 'no-store' // 禁用缓存
|
|
|
-// }).then(({ data }) => {
|
|
|
-// const res = data
|
|
|
-// if (+oldVersion !== +res.version) {
|
|
|
-// alert('页面已经更新,请点击 “确认” 按钮继续使用')
|
|
|
-// // 如果有更新,保存最新版本
|
|
|
-// localStorage.setItem('version', res.version)
|
|
|
-// // 帮用户刷新页面
|
|
|
-// setTimeout(() => {
|
|
|
-// window.location.reload()
|
|
|
-// }, 0)
|
|
|
-// }
|
|
|
-// })
|
|
|
-// }
|
|
|
+const testVersion = '' // 开启测试环境测试 (默认为空关闭测试,v24.11.07.1936测试使用)
|
|
|
+const timer = ref(null)
|
|
|
+const setIntervalTime = 10000
|
|
|
+onMounted(() => {
|
|
|
+ nextTick(() => {
|
|
|
+ console.log('baseurl:', import.meta.env?.VITE_BASE_URL, 'version:', import.meta.env?.VITE_VERSION || testVersion)
|
|
|
+ //
|
|
|
+ const process_ENV = process?.env?.NODE_ENV || ''
|
|
|
+ if (process_ENV === 'production' || testVersion) { // development production
|
|
|
+ if (timer.value) clearInterval(timer.value)
|
|
|
+ // timer.value = setInterval(() => { checkVersion() }, setIntervalTime)
|
|
|
+ }
|
|
|
+ })
|
|
|
+})
|
|
|
+onUnmounted(() => {
|
|
|
+ if (timer.value) clearInterval(timer.value)
|
|
|
+})
|
|
|
|
|
|
-// const timer = ref(null)
|
|
|
-// onMounted(() => {
|
|
|
- // console.log(1, 'import.meta.env', import.meta.env)
|
|
|
- // if (process.env.NODE_ENV === 'production') {
|
|
|
- // if (timer.value) clearInterval(timer.value)
|
|
|
- // timer.value = setInterval(() => { checkVersion() }, 3000)
|
|
|
- // }
|
|
|
-// })
|
|
|
-// onUnmounted(() => {
|
|
|
-// if (timer.value) clearInterval(timer.value)
|
|
|
-// })
|
|
|
+// 检查版本号
|
|
|
+const checkVersion = () => {
|
|
|
+ const baseUrl = import.meta.env.VITE_BASE_URL || ''
|
|
|
+ const version = import.meta.env?.VITE_VERSION || testVersion
|
|
|
+ const tenantId = import.meta.env?.VITE_TENANTCODE || ''
|
|
|
+ if (!baseUrl || !version) return
|
|
|
+ axios.get(`${baseUrl}/app-api/menduner/system/get/version`, {
|
|
|
+ headers: { ['tenant-id']: tenantId }
|
|
|
+ }).then((res) => {
|
|
|
+ if (res?.data?.data !== version) {
|
|
|
+ const option = {
|
|
|
+ autoCloseTime: setIntervalTime + 5000
|
|
|
+ }
|
|
|
+ Confirm('系统提示', '发现新版本,是否立即刷新页面', option).then(() => {
|
|
|
+ window.location.reload()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ console.log('checkVersion-err', err)
|
|
|
+ })
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<template>
|