duanshenglang 1 day ago
parent
commit
f758b52800
2 changed files with 14 additions and 7 deletions
  1. 14 2
      App.vue
  2. 0 5
      pages/index/index.vue

+ 14 - 2
App.vue

@@ -1,15 +1,27 @@
 <script setup>
 import { onLaunch, onShow, onError } from '@dcloudio/uni-app';
 import sheep from '@/common';
-
 onLaunch(() => {
+  const params = {};
+  const queryString = window.location.search.substring(1);
+  if (queryString) {
+    queryString.split('&').forEach(item => {
+      const [key, value] = item.split('=');
+      if (key) params[key] = decodeURIComponent(value || '');
+    });
+  }
+  // 获取token参数
+  if (params && params.token) {
+    sheep.$store('user').setToken(params.token)
+    sheep.$store('task').resetTaskData()
+  }
   // 隐藏原生导航栏 使用自定义底部导航
   uni.hideTabBar({
     fail: () => { },
   });
 
   //游客游客模式注释
-  if (!uni.getStorageSync("token")) {
+  if (!uni.getStorageSync("token") && (!params && !params.token)) {
     uni.reLaunch({
       url: '/pages/index/index'
     })

+ 0 - 5
pages/index/index.vue

@@ -111,11 +111,6 @@ onShow(async () => {
 	}
 })
 onLoad((options) => {
-	// 获取token参数
-	if (options.token) {
-		sheep.$store('user').setToken(options.token)
-		sheep.$store('task').resetTaskData()
-	}
 })
 async function onTaskDel() {
 	let res = await taskApi.taskDel({