Browse Source

ICE登录

wuhb 2 months ago
parent
commit
7cec542dea
4 changed files with 118 additions and 59 deletions
  1. 17 0
      api/auth/login.uts
  2. 98 56
      pages/login/index.uvue
  3. 1 1
      pages/order/index.uvue
  4. 2 2
      utils/request.uts

+ 17 - 0
api/auth/login.uts

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

+ 98 - 56
pages/login/index.uvue

@@ -80,7 +80,7 @@
 
 <script setup lang="uts">
     import { ref, computed, onMounted } from 'vue'
-    import { loginByAccount, getUserInfo, resetPassword , getIsKey} from '../../api/auth/login'
+    import { loginByAccount, loginSSO, getUserInfo, resetPassword , getIsKey} from '../../api/auth/login'
 	import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
     import {
         saveAccessToken,
@@ -161,6 +161,60 @@
 		    })
 		}
 	};
+	
+	
+	const loginSuccess = async(result: any) : Promise<void> => {
+		// 提取 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")
+		
+		// 保存登录信息
+		saveAccessToken(resultObj['token'] as string)
+		
+		const userInfoJson = await getUserInfo();
+		console.log(userInfoJson);
+		
+		const userInfoObj = userInfoJson as UTSJSONObject
+		const userInfo = userInfoObj['user'] as UTSJSONObject
+		const deptInfo = userInfo['dept'] as UTSJSONObject
+		const permissions = userInfoObj['permissions'] as any[]
+		saveUserInfo({
+		    userId: userInfo['userId'],
+		    userName: userInfo['userName'],
+			nickName: userInfo['nickName'],
+			phone: userInfo['phonenumber'],
+			deptName: deptInfo['deptName'],
+			roleNames: userInfoObj['roleNames'],
+			permissions: permissions
+		})
+		
+		// 保存或清除记住的账号密码
+		if (rememberPassword.value) {
+		    saveRememberedAccount(username.value, password.value)
+		} else {
+		    clearRememberedAccount()
+		}
+
+		// 跳转到首页
+		setTimeout(() => {
+		    /* uni.redirectTo({
+		        url: '/pages/index/index'
+		    }) */
+			uni.redirectTo({
+			    url: '/pages/splash/index'
+			}) 
+		}, 1000)
+	}
+	
     // 登录处理
     const handleLogin = async (): Promise<void> => {
 
@@ -192,61 +246,13 @@
 			saveStoreIsKey(isKey);
 
             const result = await loginByAccount(username.value, password.value)
-            // 提取 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")
-			
-            // 保存登录信息
-            saveAccessToken(resultObj['token'] as string)
-
-			const userInfoJson = await getUserInfo();
-			console.log(userInfoJson);
-
-			const userInfoObj = userInfoJson as UTSJSONObject
-			const userInfo = userInfoObj['user'] as UTSJSONObject
-			const deptInfo = userInfo['dept'] as UTSJSONObject
-			const permissions = userInfoObj['permissions'] as any[]
-            saveUserInfo({
-                userId: userInfo['userId'],
-                userName: userInfo['userName'],
-				nickName: userInfo['nickName'],
-				phone: userInfo['phonenumber'],
-				deptName: deptInfo['deptName'],
-				roleNames: userInfoObj['roleNames'],
-				permissions: permissions
-            })
-
-            // 保存或清除记住的账号密码
-            if (rememberPassword.value) {
-                saveRememberedAccount(username.value, password.value)
-            } else {
-                clearRememberedAccount()
-            }
-
-            uni.showToast({
-                title: '登录成功',
-                icon: 'success'
-            })
-
-            // 跳转到首页
-            setTimeout(() => {
-                /* uni.redirectTo({
-                    url: '/pages/index/index'
-                }) */
-				uni.redirectTo({
-				    url: '/pages/splash/index'
-				}) 
-            }, 1000)
-
+            loginSuccess(result);
+		
+			uni.showToast({
+				title: '登录成功',
+				icon: 'success'
+			})
+		
         } catch (e: any) {
             uni.showToast({
                 title: e.message ?? '登录失败',
@@ -257,6 +263,42 @@
             loading.value = false
         }
     }
+	
+	const handleLoginSSO = async (apptoken:string): Promise<void> => {
+		try {
+			const resultKey = await getIsKey();
+			const resultKeyObj = resultKey as UTSJSONObject
+			const isKey = resultKeyObj["data"] as string |'0'
+			saveStoreIsKey(isKey);
+			
+			let result = await loginSSO(apptoken)
+			console.log('自动登录:', result)
+			loginSuccess(result);
+		} catch (e: any) {
+		    uni.showToast({
+		        title: e.message ?? '登录失败',
+		        icon: 'none',
+		        duration: 2000
+		    })
+		} finally {
+		    loading.value = false
+		}
+	}
+	
+	onLoad((options: UTSJSONObject | null) => {
+	    console.log('URL参数:', options)
+	    if(options != null){
+			// 获取apptoken参数
+			const apptokenValue = options['apptoken']
+			if (apptokenValue != null) {
+				if (typeof apptokenValue == 'string') {
+					const apptoken = apptokenValue as string
+					console.log('获取到自动登录apptoken:', apptoken)
+					handleLoginSSO(apptoken);
+				}
+			}
+		}
+	})
 
     // 初始化:加载记住的账号密码
     onMounted(() => {

+ 1 - 1
pages/order/index.uvue

@@ -11,7 +11,7 @@
         </view>
 
 		<view class="status-bar">
-			<scroll-view class="scroll-view_H" direction="horizontal" show-scrollbar="false">
+			<scroll-view class="scroll-view_H" direction="horizontal" :show-scrollbar="false">
 				<view class="scroll-view-item_H uni-bg-red">
 					<text class="status-txt" :class="{'stauts-sel': currentStatus === 'all'}" @click="switchStatus('all')">全部</text>
 				</view>

+ 2 - 2
utils/request.uts

@@ -16,8 +16,8 @@ export type RequestConfig = {
 // const BASE_URL = "http://192.168.110.105:8080";
 // const BASE_URL = "http://222.243.138.146:5095" //测试服务器;
 	// const BASE_URL = "http://222.243.138.146:5097" //正式服务器;
-// const BASE_URL = "http://10.170.129.135:8089";
-const BASE_URL = "http://222.243.138.146:5096/prod-api"
+const BASE_URL = "http://10.170.129.135:8089";
+// const BASE_URL = "http://222.243.138.146:5096/prod-api"
 // const BASE_URL = "http://10.170.129.135/prod-api";
 
 /**