瀏覽代碼

检查版本号

lifanagju_citu 7 月之前
父節點
當前提交
9bf169f4aa
共有 1 個文件被更改,包括 38 次插入29 次删除
  1. 38 29
      src/App.vue

+ 38 - 29
src/App.vue

@@ -1,36 +1,45 @@
 <script setup>
 <script setup>
 import { RouterView } from 'vue-router'
 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 timer = ref(null)
+onMounted(() => {
+  nextTick(() => {
+    console.log(1, 'NODE_ENV', import.meta.env?.NODE_ENV); console.log(1, 'process_ENV', process.env.NODE_ENV)
+    //
+    const process_ENV = process?.env?.NODE_ENV || ''
+    const open = false
+    if (process_ENV === 'development' && open) { // development production
+      if (timer.value) clearInterval(timer.value)
+      timer.value = setInterval(() => { checkVersion() }, 10000)
+    }
+  })
+})
+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 = () => {
+  alertReload()
+  const baseUrl = import.meta.env.VITE_BASE_URL || 'https://www.menduner.com'
+  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 === '123') {
+      Confirm('系统提示', '发现新版本,是否立即刷新页面').then(() => {
+        window.location.reload()
+      })
+    }
+  }).catch(err => {
+    console.log('checkVersion-err', err)
+  })
+}
 </script>
 </script>
 
 
 <template>
 <template>