zhengnaiwen_citu преди 4 месеца
родител
ревизия
030ee5f14a
променени са 4 файла, в които са добавени 54 реда и са изтрити 10 реда
  1. 9 5
      src/App.vue
  2. 16 3
      src/config/axios/service.js
  3. 27 0
      src/store/system.js
  4. 2 2
      src/utils/openEncryption.js

+ 9 - 5
src/App.vue

@@ -4,8 +4,11 @@ import { ref, onMounted, onUnmounted, nextTick } from 'vue'
 import Confirm from '@/plugins/confirm'
 import axios from 'axios'
 import { vue_version } from './version.js'
+import { useSystem } from '@/store/system'
 
+const { setBeijingTimestamp } = useSystem()
 const timer = ref(null)
+// const setFn = ref()
 const setIntervalTime = 3000 // 接口调用间隔时间
 
 function open () {
@@ -42,22 +45,23 @@ const checkVersion = () => {
   axios.get(`${baseUrl}/app-api/menduner/system/get/version`, {
     headers: { ['tenant-id']: tenantId },
     cache: 'no-store' // 禁用缓存
-  }).then((res) => {
-    const res_v = res?.data?.data || ''
-    if (!res_v || res_v === vue_version ) { // 接口报错和版本一致不弹Confirm
+  }).then(({ data }) => {
+    const { version, time } = data?.data
+    setBeijingTimestamp(time)
+    if (!version || version === vue_version ) { // 接口报错和版本一致不弹Confirm
       return
     }
     if (ConfirmDone) {
       return
     }
-    if (res_v === get_v && res_v !== vue_version) { // reload(true)刷新不成功,清除缓存刷新
+    if (version === get_v && version !== vue_version) { // reload(true)刷新不成功,清除缓存刷新
       localStorage.clear()
       window.location.replace(window.location.href)
       return
     }
     ConfirmDone = true  // 后续不弹Confirm
     Confirm('系统提示', '发现新版本,将立即刷新页面', { hideCancelBtn: true }).then(() => {
-      localStorage.setItem('RES_VERSION', res_v)
+      localStorage.setItem('RES_VERSION', version)
       window.location.reload(true)
     })
   }).catch(err => {

+ 16 - 3
src/config/axios/service.js

@@ -13,7 +13,8 @@ import { rewardEventTrackClick } from '@/api/integral'
 import errorCode from './errorCode'
 import { useI18n } from '@/hooks/web/useI18n'
 import { sendError } from '@/api/Verifition'
-import { generateUUID } from "@/utils" 
+
+import { useSystem } from '@/store/system'
 
 // import { resetRouter } from '@/router'
 // import { deleteUserCache } from '@/hooks/web/useCache'
@@ -60,7 +61,7 @@ const service = axios.create({
 
 // request拦截器
 service.interceptors.request.use(
-  (config) => {
+  async (config) => {
     const userStore = useUserStore()
     config.headers['Accept-Language'] = getCurrentLocaleLang() ?? 'zh_CN'
     // 是否需要设置 token
@@ -106,6 +107,7 @@ service.interceptors.request.use(
 
     // 开启参数加密
     if (config.openEncryption) {
+      const { getBeijingTimestamp, setBeijingTimestamp, systemInfo } = useSystem()
       const raw = config.url.split('?')[1]
       // const raw = config.encodeParams ? config.url.split('?')[1] : config.url.split('?')[1]
       const body = {
@@ -117,7 +119,18 @@ service.interceptors.request.use(
        * params: { data, params, raw }
        * content
        */
-      const { noSign, ...header} = encryptionFun({raw, body, appId: 'web_client', AppSecret: 'fa0fc0b5098b974b'})
+      if (systemInfo.beijingTimestamp === 0 && process?.env?.NODE_ENV === 'production') {
+        const _timestamp = await getBeijingTimestamp()
+        setBeijingTimestamp(_timestamp)
+      }
+      
+      const { noSign, ...header} = encryptionFun({
+        raw,
+        body,
+        appId: 'web_client',
+        AppSecret: 'fa0fc0b5098b974b',
+        timestamp: process?.env?.NODE_ENV === 'production' ? systemInfo.beijingTimestamp + 3000 : new Date().getTime() + 3000,
+      })
       const content = {
         data: config.data,
         params: config.params,

+ 27 - 0
src/store/system.js

@@ -1,8 +1,32 @@
 import { defineStore } from 'pinia'
 import { ref } from 'vue'
+import axios from 'axios'
 
 export const useSystem = defineStore('system', 
   () => {
+
+    const systemInfo = ref({
+      beijingTimestamp: 0
+    })
+
+    const setBeijingTimestamp = (timestamp) => {
+      systemInfo.value.beijingTimestamp = timestamp
+    }
+
+    const getBeijingTimestamp = () => {
+      const baseUrl = import.meta.env.VITE_BASE_URL
+      const tenantId = import.meta.env?.VITE_TENANTCODE
+      return new Promise((resolve, reject) => {
+        axios.get(`${baseUrl}/app-api/menduner/system/get/version`, {
+          headers: { ['tenant-id']: tenantId },
+          cache: 'no-store' // 禁用缓存
+        }).then(({ data }) => {
+          const { time } = data?.data
+          resolve(time)
+        })
+      })
+    }
+
     const breadcrumbs = ref([])
 
     const setBreadcrumbs = (matched, fullPath) => {
@@ -25,6 +49,9 @@ export const useSystem = defineStore('system',
       breadcrumbs.value =  arr
     }
     return {
+      systemInfo,
+      setBeijingTimestamp,
+      getBeijingTimestamp,
       setBreadcrumbs,
       breadcrumbs
     }

+ 2 - 2
src/utils/openEncryption.js

@@ -19,11 +19,11 @@ import { sha256 } from 'js-sha256'
  * @param { Object } body
  * @returns 
 */
-export const encryptionFun = ({raw, body, appId, AppSecret}) => {
+export const encryptionFun = ({raw, body, appId, AppSecret, timestamp}) => {
   const initSign = {
     appId,
     nonce: generateUUID(),
-    timestamp: new Date().getTime() + 3000,
+    timestamp,
   }
   const _initSignArr = Object.keys(initSign).map(key => {
     return `${key}=${initSign[key]}`