Browse Source

统一登录跳转

wuhb 2 months ago
parent
commit
05518f9507
2 changed files with 12 additions and 8 deletions
  1. 3 0
      App.uvue
  2. 9 8
      pages/login/index.uvue

+ 3 - 0
App.uvue

@@ -31,6 +31,7 @@
 			
 			// 清空之前的缓存
 			uni.removeStorageSync('emcs_ticket')
+			uni.removeStorageSync('emcs_nextUrl')
 			
 			// 如果有启动参数,尝试提取apptoken
 			if (options != null) {
@@ -38,10 +39,12 @@
 				const query = options.query
 				if (query != null) {
 					const ticketValue = query['ticket']
+					const nextUrl = query['next']
 					if (ticketValue != null) {
 						const ticket = ticketValue as string
 						console.log('保存ticket到缓存:', ticket)
 						uni.setStorageSync('emcs_ticket', ticket)
+						uni.setStorageSync('emcs_nextUrl', nextUrl)
 					}
 				}
 			}

+ 9 - 8
pages/login/index.uvue

@@ -182,7 +182,7 @@
 	};
 	
 	
-	const loginSuccess = async(result: any) : Promise<void> => {
+	const loginSuccess = async(result: any, nextUrl:string) : Promise<void> => {
 		// 提取 data 部分
 		const resultObj = result as UTSJSONObject
 		// const data = resultObj['data'] as UTSJSONObject
@@ -218,9 +218,9 @@
 
 		// 跳转到首页
 		setTimeout(() => {
-            uni.redirectTo({
-                url: '/pages/index/index'
-            })
+			uni.redirectTo({
+			    url: '/pages/index/index'
+			})
         }, 1000)
 	}
 	
@@ -255,7 +255,7 @@
 			saveStoreIsKey(isKey); */
 
             const result = await loginByAccount(username.value, password.value)
-            loginSuccess(result);
+            loginSuccess(result, null);
 		
 			uni.showToast({
 				title: '登录成功',
@@ -274,11 +274,11 @@
         }
     }
 	
-	const handleLoginSSO = async (apptoken:string): Promise<void> => {
+	const handleLoginSSO = async (apptoken:string, nextUrl:string): Promise<void> => {
 		try {
 			let result = await loginSSO(apptoken)
 			console.log('自动登录:', result)
-			loginSuccess(result);
+			loginSuccess(result, nextUrl);
 		} catch (e: any) {
 		    uni.showToast({
 		        title: e.message ?? '登录失败',
@@ -421,12 +421,13 @@
 			// 2. 从页面参数获取
 			if (options != null) {
 				const ticketValue = options['ticket']
+				const nextUrl = options['next']
 				if (ticketValue != null) {
 					if (typeof ticketValue == 'string') {
 						if(ticketValue.length > 0){
 							const ticket = ticketValue as string
 							console.log('获取到自动登录ticket:', ticket)
-							handleLoginSSO(ticket);
+							handleLoginSSO(ticket, nextUrl);
 						}
 					}
 				}