Browse Source

SSO登录

wuhb 2 months ago
parent
commit
cbb72ed544
4 changed files with 30 additions and 19 deletions
  1. 18 0
      App.uvue
  2. 3 3
      api/auth/login.uts
  3. 2 2
      pages/apply/applyInfo.uvue
  4. 7 14
      pages/login/index.uvue

+ 18 - 0
App.uvue

@@ -28,6 +28,24 @@
 					}
 				}
 			})
+			
+			// 清空之前的缓存
+			uni.removeStorageSync('emcs_ticket')
+			
+			// 如果有启动参数,尝试提取apptoken
+			if (options != null) {
+				// 1. 从query获取
+				const query = options.query
+				if (query != null) {
+					const ticketValue = query['ticket']
+					if (ticketValue != null) {
+						const ticket = ticketValue as string
+						console.log('保存ticket到缓存:', ticket)
+						uni.setStorageSync('emcs_ticket', ticket)
+					}
+				}
+			}
+			
 			uni.setStorageSync("notify_key", "0")
 		},
 		onShow: function (options: OnShowOptions) {

+ 3 - 3
api/auth/login.uts

@@ -38,15 +38,15 @@ export const loginByAccount = async (username: string, password: string): Promis
  * SSO账号登录
  * @returns 返回整个响应对象 { status, msg, success, data }
  */
-export const loginSSO = async (apptoken: string): Promise<any> => {	
+export const loginSSO = async (ticket: string): Promise<any> => {	
 	return request({
-        url: `/ice/sso/login`,
+        url: `/callback`,
         method: 'POST',
 		header: {
 		  isToken: false,
 		  repeatSubmit: false
 		},
-		data:  {apptoken: apptoken}
+		data: { ticket: ticket }
     })
 }
 

+ 2 - 2
pages/apply/applyInfo.uvue

@@ -179,8 +179,8 @@
 
     const loadDetail = (): void => {
         if (applyId.value.length === 0) return
-        getPurchaseApplyById(applyId.value).then((res: any) => {
-            const res = res as UTSJSONObject
+        getPurchaseApplyById(applyId.value).then((response: any) => {
+            const res = response as UTSJSONObject
 			const data = res["data"] as UTSJSONObject
             applyCode.value = data['applyCode'] != null ? data['applyCode'].toString() : ''
             applyStatus.value = data['status'] != null ? data['status'].toString() : ''

+ 7 - 14
pages/login/index.uvue

@@ -186,13 +186,6 @@
 		// 提取 data 部分
 		const resultObj = result as UTSJSONObject
 		// const data = resultObj['data'] as UTSJSONObject
-				
-		const isInitPassword = resultObj["isInitPassword"] as boolean | null;
-		// console.log("================"+ code)
-		if(isInitPassword==true){
-			showPasswordPicker.value = true;
-			return
-		}
 		
 		uni.setStorageSync("login_key", "1")
 		
@@ -427,13 +420,13 @@
 		setTimeout(() => {
 			// 2. 从页面参数获取
 			if (options != null) {
-				const apptokenValue = options['apptoken']
-				if (apptokenValue != null) {
-					if (typeof apptokenValue == 'string') {
-						if(apptokenValue.length > 0){
-							const apptoken = apptokenValue as string
-							console.log('获取到自动登录apptoken:', apptoken)
-							handleLoginSSO(apptoken);
+				const ticketValue = options['ticket']
+				if (ticketValue != null) {
+					if (typeof ticketValue == 'string') {
+						if(ticketValue.length > 0){
+							const ticket = ticketValue as string
+							console.log('获取到自动登录ticket:', ticket)
+							handleLoginSSO(ticket);
 						}
 					}
 				}