Commit 9e9e4f8f authored by heduo's avatar heduo

fix(hd):登录异常问题

parent 754206f1
import { defHttp, tmallabHttp } from '/@/utils/http/axios';
import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';
import { LoginParams, LoginResultModel } from './model/userModel';
import { getAuthCache } from '/@/utils/auth';
import { USER_INFO_KEY } from '/@/enums/cacheEnum';
import { ErrorMessageMode } from '/#/axios';
......@@ -30,7 +32,8 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal')
* @description: getUserInfo
*/
export function getUserInfo() {
return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
// return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
return getAuthCache(USER_INFO_KEY) || {};
}
export function getPermCode() {
......
......@@ -75,15 +75,19 @@
const { t } = useI18n();
const { getShowDoc, getUseLockPage } = useHeaderSetting();
const userStore = useUserStore();
const getUserInfo = computed(() => {
console.log('------------', userStore.getUserInfo)
console.log('------------', userStore.getUserInfo);
const { userName: realName = '', avatar, desc } = userStore.getUserInfo || {};
return { realName, avatar: avatar || headerImg, desc };
});
const { changeRole } = usePermission();
const roleList = ref([]);
roleList.value = userStore.getUserInfo.roleList;
roleList.value = userStore.getUserInfo.userRoles.map((v) => {
return {
roleNum: v.roleNum,
roleName: v.roleName,
};
});
// const [register, { openModal }] = useModal();
const [register] = useModal();
......
......@@ -49,7 +49,7 @@ export const useUserStore = defineStore({
}),
getters: {
getUserInfo(): GetUserInfoModel {
return this.userInfo || getAuthCache<UserInfo>(USER_INFO_KEY) || {};
return getAuthCache<UserInfo>(USER_INFO_KEY) || {};
},
getToken(): string {
return this.token || getAuthCache<string>(TOKEN_KEY);
......@@ -119,15 +119,19 @@ export const useUserStore = defineStore({
},
//数据对接模拟登录
async tmallabSimulationLogin(params: { loginName: string; password: string }): Promise<any> {
const data = await tmallabLoginApi(params);
this.setTmallabToken(data.token);
return data;
try {
const data = await tmallabLoginApi(params);
this.setTmallabToken(data.token);
this.setToken(data.token);
return this.afterLoginAction(true, data);
} catch (error) {
return Promise.reject(error);
}
},
async afterLoginAction(goHome?: boolean): Promise<GetUserInfoModel | null> {
if (!this.getToken) return null;
async afterLoginAction(goHome?: boolean, data?: any): Promise<GetUserInfoModel | null> {
if (!this.getTmallabToken) return null;
// get user info
const userInfo = await getUserInfo();
const userInfo = await this.getUserInfoAction(data);
const sessionTimeout = this.sessionTimeout;
if (sessionTimeout) {
this.setSessionTimeout(false);
......@@ -147,19 +151,20 @@ export const useUserStore = defineStore({
this.setUserInfo(userInfo);
return userInfo;
},
async getUserInfoAction(): Promise<UserInfo | null> {
if (!this.getToken) return null;
let userInfo: any = this.userInfo;
if (!userInfo.userId) {
userInfo = await getUserInfo();
}
const { roles = [] } = userInfo;
if (isArray(roles)) {
const role = userInfo.roleNum;
async getUserInfoAction(data): Promise<UserInfo | null> {
if (!this.getTmallabToken) return null;
const userInfo = data;
// if (!userInfo.userId) {
// userInfo = await getUserInfo();
// }
const { userRoles } = userInfo;
if (isArray(userRoles)) {
const role = userInfo.userRoles[0].roleNum;
//取第一个为默认角色
const roleList = Array.from(RoleEnum[role]);
this.setRoleList(roleList as []);
} else {
userInfo.roles = [];
userInfo.userRoles = [];
this.setRoleList([]);
}
this.setUserInfo(userInfo);
......
......@@ -135,8 +135,8 @@
const rememberMe = ref(false);
const formData = reactive({
account: 't1',
password: '123456Aa@',
account: '',
password: '',
});
const { validForm } = useFormValid(formRef);
......@@ -150,18 +150,17 @@
if (!data) return;
try {
loading.value = true;
let jsEncrypt = new JSEncrypt();
jsEncrypt.setPublicKey(RSA_PUBLIC_KEY);
const encryptPwd: string = jsEncrypt.encrypt(data.password) as string;
const userInfo = await userStore.login({
password: encryptPwd,
username: data.account,
mode: 'none', //不要默认的错误提示
// let jsEncrypt = new JSEncrypt();
// jsEncrypt.setPublicKey(RSA_PUBLIC_KEY);
// const encryptPwd: string = jsEncrypt.encrypt(data.password) as string;
const userInfo = await userStore.tmallabSimulationLogin({
password: formData.password,
loginName: formData.account,
});
if (userInfo) {
notification.success({
message: t('sys.login.loginSuccessTitle'),
description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.userName}`,
description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.name}`,
duration: 3,
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment