Ver Fonte

Merge branch 'dev' of https://git.citupro.com/zhengnaiwen_citu/menduner into dev

Xiao_123 há 6 meses atrás
pai
commit
3fadc12404
4 ficheiros alterados com 60 adições e 36 exclusões
  1. 9 6
      .env.development
  2. 41 29
      src/App.vue
  3. 9 0
      src/plugins/confirm/confirm.vue
  4. 1 1
      src/utils/openEncryption.js

+ 9 - 6
.env.development

@@ -1,18 +1,21 @@
 NODE_ENV = 'development'
 
+# 版本号
+VITE_VERSION = 'v24.11.07.1937'
+
 VITE_APP_TITLE = 门墩儿
 
 # 访问路径
-# VITE_ACCESS_BASE_URL = 'http://menduner.citupro.com:7878' # 测试环境
-VITE_ACCESS_BASE_URL = 'https://www.menduner.com' # 生产环境
+VITE_ACCESS_BASE_URL = 'http://menduner.citupro.com:7878' # 测试环境
+# VITE_ACCESS_BASE_URL = 'https://www.menduner.com' # 生产环境
 # 
 # 请求路径
-# VITE_BASE_URL = 'http://menduner.citupro.com:7878' # 测试环境
-VITE_BASE_URL = 'https://www.menduner.com' # 生产环境
+VITE_BASE_URL = 'http://menduner.citupro.com:7878' # 测试环境
+# VITE_BASE_URL = 'https://www.menduner.com' # 生产环境
 
 # 预览路径
-# VITE_PREVIEW_URL = 'http://192.168.3.91:8012' # 测试环境
-VITE_PREVIEW_URL = 'https://kkfileview.menduner.com/' # 生产环境
+VITE_PREVIEW_URL = 'http://192.168.3.91:8012' # 测试环境
+# VITE_PREVIEW_URL = 'https://kkfileview.menduner.com/' # 生产环境
 
 # 租户id
 VITE_TENANTCODE = '155'

+ 41 - 29
src/App.vue

@@ -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>

+ 9 - 0
src/plugins/confirm/confirm.vue

@@ -20,6 +20,15 @@ const hideCancelBtn = props.option.hideCancelBtn || false
 const cancelText = props.option.cancelText || '取消'
 const sureText = props.option.sureText || '确认'
 const otherBtnText = props.option.otherBtnText || ''
+const autoCloseTime = props.option.autoCloseTime || 0
+
+// 自动关闭弹窗
+if (autoCloseTime && Number.isInteger(autoCloseTime) && autoCloseTime >= 1000) {
+  setTimeout(() => {
+    console.log('自动关闭弹窗')
+    props.cancel()
+  }, autoCloseTime)
+}
 // const show = () => {
 //   dialog.value = true
 // }

+ 1 - 1
src/utils/openEncryption.js

@@ -11,7 +11,7 @@ export const encryptionFun = (config) => {
   const initSign = {
     appId: 'web_client', // 与后端协商一致使用
     nonce: generateUUID(), // 前端生成唯一参数
-    timestamp: new Date().getTime() + 1000,
+    timestamp: new Date().getTime() + 3000, // 多加两秒时间
   }
   // 固定的参数初始化成字符串
   const paramsToStrSort = ['appId', 'nonce', 'timestamp'] // 顺序不能变