|
|
@@ -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(() => {
|