zhengnaiwen_citu преди 4 месеца
родител
ревизия
531c85d878
променени са 4 файла, в които са добавени 35 реда и са изтрити 23 реда
  1. 0 4
      components.d.ts
  2. 21 6
      src/App.vue
  3. 5 7
      src/config/axios/service.js
  4. 9 6
      src/store/system.js

+ 0 - 4
components.d.ts

@@ -30,7 +30,6 @@ declare module 'vue' {
     CtTextField: typeof import('./src/components/CtVuetify/CtTextField/index.vue')['default']
     DatePicker: typeof import('./src/components/DatePicker/index.vue')['default']
     Echarts: typeof import('./src/components/Echarts/index.vue')['default']
-    ElCascader: typeof import('element-plus/es')['ElCascader']
     ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
     Empty: typeof import('./src/components/Empty/index.vue')['default']
     File: typeof import('./src/components/Upload/file.vue')['default']
@@ -73,7 +72,4 @@ declare module 'vue' {
     VerifySlide: typeof import('./src/components/Verifition/Verify/VerifySlide.vue')['default']
     WangEditor: typeof import('./src/components/FormUI/wangEditor/index.vue')['default']
   }
-  export interface ComponentCustomProperties {
-    vLoading: typeof import('element-plus/es')['ElLoadingDirective']
-  }
 }

+ 21 - 6
src/App.vue

@@ -6,7 +6,7 @@ import axios from 'axios'
 import { vue_version } from './version.js'
 import { useSystem } from '@/store/system'
 
-const { setBeijingTimestamp } = useSystem()
+const { setTimeDifference } = useSystem()
 const timer = ref(null)
 // const setFn = ref()
 const setIntervalTime = 3000 // 接口调用间隔时间
@@ -33,6 +33,24 @@ onUnmounted(() => {
 // window.location.reload(true)                  // true参数会忽略缓存的内容,强制重新从服务器下载所有内容.包括 JavaScript 文件,图像,文本文件等。这样可以保证显示网页的最新内容,但是会消耗更多的流量和时间。
 // window.location.replace(window.location.href) // 方法会把浏览器中的临时文件夹的文件删除再重新从服务器下载。这样可以清除一些可能造成问题的缓存文件,但是也会消耗更多的流量和时间。
 
+const getVersion = () => {
+  return new Promise((resolve, reject) => {
+    const baseUrl = import.meta.env.VITE_BASE_URL || ''
+    const tenantId = import.meta.env?.VITE_TENANTCODE || ''
+    axios.get(`${baseUrl}/app-api/menduner/system/get/version`, {
+      headers: { ['tenant-id']: tenantId },
+      cache: 'no-store' // 禁用缓存
+    }).then(resolve)
+  })
+}
+
+getVersion().then(({ data }) => {
+  const _now = new Date().getTime()
+  const { time } = data?.data
+  // 设置浏览器和服务器时间差
+  setTimeDifference(time - _now)
+})
+
 let ConfirmDone = false
 // 检查版本号
 const checkVersion = () => {
@@ -42,12 +60,9 @@ const checkVersion = () => {
   const get_v = localStorage.getItem('RES_VERSION') || ''
   // 
   if (!baseUrl || !vue_version || !tenantId) return
-  axios.get(`${baseUrl}/app-api/menduner/system/get/version`, {
-    headers: { ['tenant-id']: tenantId },
-    cache: 'no-store' // 禁用缓存
-  }).then(({ data }) => {
+
+  getVersion().then(({ data }) => {
     const { version, time } = data?.data
-    setBeijingTimestamp(time)
     if (!version || version === vue_version ) { // 接口报错和版本一致不弹Confirm
       return
     }

+ 5 - 7
src/config/axios/service.js

@@ -107,7 +107,7 @@ service.interceptors.request.use(
 
     // 开启参数加密
     if (config.openEncryption) {
-      const { getBeijingTimestamp, setBeijingTimestamp, systemInfo } = useSystem()
+      const { getTimeDifference, setTimeDifference, systemInfo } = useSystem()
       const raw = config.url.split('?')[1]
       // const raw = config.encodeParams ? config.url.split('?')[1] : config.url.split('?')[1]
       const body = {
@@ -119,11 +119,9 @@ service.interceptors.request.use(
        * params: { data, params, raw }
        * content
        */
-      const env = import.meta.env.VITE_USER_NODE_ENV
-      // console.log(env)
-      if (env === 'production' && systemInfo.beijingTimestamp === 0) {
-        const _timestamp = await getBeijingTimestamp()
-        setBeijingTimestamp(_timestamp)
+      if (systemInfo.timeDifference === undefined) {
+        const _difference = await getTimeDifference()
+        setTimeDifference(_difference)
       }
       
       const header = encryptionFun({
@@ -132,7 +130,7 @@ service.interceptors.request.use(
         appId: 'web_client',
         AppSecret: 'fa0fc0b5098b974b',
         // timestamp: 1735282548997,
-        timestamp: env === 'production' ? systemInfo.beijingTimestamp : new Date().getTime(),
+        timestamp: new Date().getTime() + systemInfo.timeDifference,
       })
       const content = {
         data: config.data,

+ 9 - 6
src/store/system.js

@@ -6,14 +6,15 @@ export const useSystem = defineStore('system',
   () => {
 
     const systemInfo = ref({
+      timeDifference: undefined, // 服务器时间 - 浏览器时间
       beijingTimestamp: 0
     })
 
-    const setBeijingTimestamp = (timestamp) => {
-      systemInfo.value.beijingTimestamp = timestamp
+    const setTimeDifference = (Difference) => {
+      systemInfo.value.timeDifference = Difference
     }
 
-    const getBeijingTimestamp = () => {
+    const getTimeDifference = () => {
       const baseUrl = import.meta.env.VITE_BASE_URL
       const tenantId = import.meta.env?.VITE_TENANTCODE
       return new Promise((resolve, reject) => {
@@ -22,7 +23,9 @@ export const useSystem = defineStore('system',
           cache: 'no-store' // 禁用缓存
         }).then(({ data }) => {
           const { time } = data?.data
-          resolve(time)
+          const _now = new Date().getTime()
+          const _tem = time - _now
+          resolve(_tem)
         })
       })
     }
@@ -50,8 +53,8 @@ export const useSystem = defineStore('system',
     }
     return {
       systemInfo,
-      setBeijingTimestamp,
-      getBeijingTimestamp,
+      setTimeDifference,
+      getTimeDifference,
       setBreadcrumbs,
       breadcrumbs
     }