Browse Source

大更新

ZaiZai 1 year ago
parent
commit
6569909ec3
3 changed files with 22 additions and 38 deletions
  1. 3 31
      src/App.vue
  2. 19 6
      src/api/request/index.js
  3. 0 1
      src/main.js

+ 3 - 31
src/App.vue

@@ -6,41 +6,13 @@
 
 <script setup>
 import { nextTick } from 'vue'
-import { getObjValue } from 'js-fast-way'
-import { getStore, setStore } from 'hc-vue3-ui'
-import { getVersionJson } from '~api/other'
-import split from 'split.js'
+import { detectionBrowser, getAppVersion } from 'hc-vue3-ui'
 
 nextTick(() => {
+    detectionBrowser()
     //生产环境下,检测更新
     if (import.meta.env.PROD) {
-        getVersionJsonApi()
-        setInterval(() => {
-            getVersionJsonApi()
-        }, 1000 * 60)
+        getAppVersion()
     }
-    window['$split'] = split
 })
-
-//获取版本更新信息
-const getVersionJsonApi = async () => {
-    const cache_version = getStore('version')
-    const { res } = await getVersionJson()
-    const version = getObjValue(res)?.value
-    setStore('version', version)
-    if (cache_version && cache_version !== version) {
-        window?.$messageBox?.alert('检测到有新版本更新,请点击更新,或手动刷新网页更新,如果不更新,将无法使用相关功能', '更新提醒', {
-            showCancelButton: true,
-            confirmButtonText: '立即更新',
-            cancelButtonText: '暂不更新',
-            type: 'warning',
-            callback: (action) => {
-                if (action === 'confirm') {
-                    //刷新页面
-                    window.location.reload()
-                }
-            },
-        })
-    }
-}
 </script>

+ 19 - 6
src/api/request/index.js

@@ -1,26 +1,39 @@
-import { httpApi } from 'hc-vue3-ui'
+import { HcWarMsg, httpApi } from 'hc-vue3-ui'
 import router from '~src/router/index'
+import pinia from '~src/store/init'
+import { useAppStore } from '~src/store'
+import website from '~src/config'
+
+//初始变量
+const store = useAppStore(pinia)
 
 //封装的请求
-export const HcApi = async (obj, msg = true) => {
+export const HcApi = async (obj, msg) => {
     return new Promise((resolve) => {
+        //处理统一的请求头
+        obj.headers = obj.headers ?? {}
+        obj.headers['Client-Id'] = obj.headers['Client-Id'] ?? website.clientId
+        obj.headers['Tenant-Id'] = obj.headers['Tenant-Id'] ?? store.tenantId
         //发起请求
         httpApi(obj).then((response) => {
-            //console.log(response)
             resolve(response)
         }).catch((response) => {
-            getResData(response, msg)
+            getResData(response)
             resolve(response)
         })
     })
 }
 
 //处理数据
-const getResData = ({ code, msg }, isMsg = false) => {
+const getResData = async ({ code }) => {
     if (code === 401) {
         window.$message?.error('身份失效,请重新登录!')
         router.push({ path: '/login' }).then()
     } else if (code !== 404 && code !== 500 && code !== 504) {
-        if (isMsg) window.$message?.error(msg)
+        await HcWarMsg({
+            type: 'warning',
+            title: '服务器异常,请稍后重试',
+            text: '服务器异常了,如有需要,请联系管理员!',
+        })
     }
 }

+ 0 - 1
src/main.js

@@ -3,7 +3,6 @@ import 'virtual:uno.css'
 import { createApp } from 'vue'
 import setupPinia from './store/init'
 import router, { setupRouter } from './router'
-
 import App from './App.vue'
 
 //挂载全局