pujiaming před 2 roky
rodič
revize
4c1607de30
5 změnil soubory, kde provedl 54 přidání a 11 odebrání
  1. 0 4
      index.html
  2. 0 1
      src/App.vue
  3. 2 4
      src/components/MobileCom.vue
  4. 4 2
      src/router/index.ts
  5. 48 0
      src/utils/version.ts

+ 0 - 4
index.html

@@ -43,10 +43,6 @@
 <body>
   <div id="app" style="height:100%"></div>
   <script type="module" src="/src/main.ts"></script>
-  <script>
-    const VITEPLA = import.meta.env.VITE_LOGO_VISIBLE
-    document.title = VITEPLA === 'QingQue' ? '朱雀游戏中心' : '游戏中心'
-  </script>
 </body>
 
 </html>

+ 0 - 1
src/App.vue

@@ -1,5 +1,4 @@
 <template>
-  <!-- 一级路由出口 -->
   <router-view></router-view>
 
 </template>

+ 2 - 4
src/components/MobileCom.vue

@@ -11,7 +11,7 @@
                     : 'm_search'
             })" /></p>
 
-            <div class="psa" style="bottom: 0;left: 0; z-index: 20;color: #ed8c0f;">客服qq:2885393309</div>
+            <div class="psa" style="bottom: 0;left: 0; z-index: 1;color: #ed8c0f;">客服qq:2885393309</div>
         </div>
         <div class="right_menu df aic jcc psr">
             <van-icon name="bars" size="26" />
@@ -111,7 +111,5 @@ onMounted(() => {
         border-bottom: 1px solid rgba(0, 0, 0, .1);
     }
 }
-.van-dropdown-item__content{
-    position: absolute!important;
-}
+
 </style>

+ 4 - 2
src/router/index.ts

@@ -2,7 +2,7 @@ import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
 
 const redirectPath = /Android|webOS|iPhone|iPod|BlackBerry|iPad/i.test(navigator.userAgent) ? '/m_index' : '/p_index'
 const VITEPLA:'QingQue'|'KuPai' = import.meta.env.VITE_LOGO_VISIBLE
-
+import { getVersionFR } from '@/utils/version'
 // 引入页面级别组件
 // 静态加载  初始化可见的页面----首屏加速
 import Layout from '@/layout/Layout.vue'
@@ -227,5 +227,7 @@ router.beforeEach((to, form, next) => {
     next()
   }
 })
-
+router.afterEach(() => {
+  getVersionFR()
+})
 export default router

+ 48 - 0
src/utils/version.ts

@@ -0,0 +1,48 @@
+declare global { // 设置全局属性
+  interface Window { // window对象属性
+    pendingETAG: boolean; // 加入对象
+  }
+}
+export function getVersion() {
+  // main.js 和 拦截器中加入
+  if (('pendingETAG' in window && window.pendingETAG) || import.meta.env.VITE_ENV === 'development') return
+  const htmlFileUrl = `${location.origin}${location.pathname}`
+  window.pendingETAG = true
+  setTimeout(() => {
+    window.pendingETAG = false
+  }, 20000)
+  fetch(htmlFileUrl, {
+    method: 'HEAD',
+    cache: 'no-cache'
+  }).then(res => {
+    const version:string | undefined = res.headers.get('etag') as string || undefined
+    if (!version) throw new Error('can not get version')
+    const previousVersion = localStorage.getItem('version')
+    if (!previousVersion) return localStorage.setItem('version', version)
+    if (version !== previousVersion) {
+      const isConfirm = confirm('检测到存在可用更新,是否更新?')
+      if (isConfirm) {
+        localStorage.setItem('version', version)
+        location.reload()
+      }
+    }
+  })
+}
+export function getVersionFR() {
+  // 或者 路由守卫afterEach 中加入
+  if (import.meta.env.VITE_ENV === 'development') return
+  const htmlFileUrl = `${location.origin}${location.pathname}`
+  fetch(htmlFileUrl, {
+    method: 'HEAD',
+    cache: 'no-cache'
+  }).then(res => {
+    const version:string | undefined = res.headers.get('etag') as string || undefined
+    if (!version) throw new Error('can not get version')
+    const previousVersion = localStorage.getItem('version')
+    if (!previousVersion) return localStorage.setItem('version', version)
+    if (version !== previousVersion) {
+      localStorage.setItem('version', version)
+      location.reload()
+    }
+  })
+}