lex vor 1 Jahr
Ursprung
Commit
cebb1d74a4
2 geänderte Dateien mit 19 neuen und 6 gelöschten Zeilen
  1. 17 2
      src/main.ts
  2. 2 4
      src/router/router-guards.ts

+ 17 - 2
src/main.ts

@@ -1,14 +1,30 @@
 import { createApp } from 'vue';
 import App from './App';
-import router, { setupRouter } from './router/index';
+import router, { parseQuery, setupRouter } from './router/index';
 import dayjs from 'dayjs';
 import { setupNaive } from './plugins';
 import { setupStore } from './store';
 import 'dayjs/locale/zh-cn';
 import './styles/index.less';
 import './utils/rem';
+import { storage } from './utils/storage';
+import { ACCESS_TOKEN } from './store/mutation-types';
 
 async function setupApp() {
+  // 处理token
+  const authLoadNum = sessionStorage.getItem('authLoadNum');
+
+  if (location.search && authLoadNum !== '1') {
+    const parse = location.search.substring(1, location.search.length);
+    const result = parseQuery(parse);
+    if (result.Authorization) {
+      const ex = 7 * 24 * 60 * 60 * 1000;
+      storage.set(ACCESS_TOKEN, result.Authorization, ex);
+      sessionStorage.setItem('authLoadNum', '1');
+    }
+  } else {
+    sessionStorage.removeItem('authLoadNum');
+  }
   // app loading
   // const appLoading = createApp(AppLoading);
   // appLoading.mount('#appLoading');
@@ -24,7 +40,6 @@ async function setupApp() {
   dayjs.locale('zh-ch');
 
   // app.use(router);
-
   await router.isReady();
 
   // mount app

+ 2 - 4
src/router/router-guards.ts

@@ -26,16 +26,14 @@ const isChrome = () => {
 export function createRouterGuards(router: Router) {
   const userStore = useUserStore();
   router.beforeEach(async (to, from, next) => {
-    // console.log(to, '修改标题');
-    // console.log('access token');
     if (to.path === '/attend-class') {
       let title = to.meta.title;
       if (to.query.type === 'preview') {
         title = '预览课件';
       }
-      document.title = title ? title : ('音乐数字课堂' as string);
+      (document as any).title = title ? title : ('音乐数字课堂' as string);
     } else {
-      document.title = to.meta.title
+      (document as any).title = to.meta.title
         ? to.meta.title
         : ('音乐数字课堂' as string);
     }