Browse Source

chore: Fuse Initialize User Return

master
wangxiang 2 years ago
parent
commit
8abb46478e
No known key found for this signature in database
GPG Key ID: 1BA7946AB6B232E4
  1. 1
      src/api/platform/core/entity/user.ts
  2. 12
      src/store/modules/user.ts
  3. 3
      src/views/system/ssoLogin/kics/index.vue
  4. 3
      src/views/system/ssoLogin/klab/index.vue

1
src/api/platform/core/entity/user.ts

@ -16,6 +16,7 @@ export interface LoginParams {
code?: string; code?: string;
clientId?: string; clientId?: string;
options?: RequestOptions; options?: RequestOptions;
performPostLoginAction?: boolean;
[key: string]: any; [key: string]: any;
} }

12
src/store/modules/user.ts

@ -112,7 +112,7 @@ export const useUserStore = defineStore({
/** 登录 */ /** 登录 */
async login(params: LoginParams): Promise<KiccUser | null> { async login(params: LoginParams): Promise<KiccUser | null> {
try { try {
const { goHome = true, clientId = '', ...loginParams } = params; const { goHome = true, clientId = '', performPostLoginAction = true, ...loginParams } = params;
// 处理自定义授权客户端 // 处理自定义授权客户端
if (clientId) { if (clientId) {
const client = getAuthClient(clientId); const client = getAuthClient(clientId);
@ -128,14 +128,14 @@ export const useUserStore = defineStore({
this.setUserInfo(data.user_info); this.setUserInfo(data.user_info);
this.setAccessToken(access_token); this.setAccessToken(access_token);
this.setRefreshToken(refresh_token); this.setRefreshToken(refresh_token);
return this.afterLoginAction(goHome); return performPostLoginAction ? this.afterLoginAction(goHome) : null;
} catch (error) { } catch (error) {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
/** 登录成功后动作 */ /** 登录成功后动作 */
async afterLoginAction(goHome?: boolean): Promise<KiccUser | null> { async afterLoginAction(goHome?: boolean): Promise<Partial<KiccUser>> {
if (!this.getAccessToken) return null; if (!this.getAccessToken) return {};
// 获取用户信息 // 获取用户信息
const userInfo = await this.getUserInfoAction(); const userInfo = await this.getUserInfoAction();
const sessionTimeout = this.sessionTimeout; const sessionTimeout = this.sessionTimeout;
@ -157,7 +157,7 @@ export const useUserStore = defineStore({
return userInfo; return userInfo;
}, },
/** 获取用户信息 */ /** 获取用户信息 */
async getUserInfoAction(): Promise<KiccUser> { async getUserInfoAction(): Promise<Partial<KiccUser>> {
const { apiUrl } = useGlobSetting(); const { apiUrl } = useGlobSetting();
const { t } = useI18n(); const { t } = useI18n();
try { try {
@ -173,7 +173,7 @@ export const useUserStore = defineStore({
this.setPermissions(userInfo.permissions); this.setPermissions(userInfo.permissions);
return userInfo; return userInfo;
} catch (error) { console.error(error); } } catch (error) { console.error(error); }
return Promise.resolve({} as KiccUser); return Promise.resolve({});
}, },
/** 登出 */ /** 登出 */
async logout(goLogin = false) { async logout(goLogin = false) {

3
src/views/system/ssoLogin/kics/index.vue

@ -115,7 +115,8 @@
password: formData.password, password: formData.password,
username: formData.username, username: formData.username,
goHome: false, goHome: false,
clientId: 'kics' clientId: 'kics',
performPostLoginAction: false
}); });
// sso // sso
document.location.reload(); document.location.reload();

3
src/views/system/ssoLogin/klab/index.vue

@ -114,7 +114,8 @@
password: formData.password, password: formData.password,
username: formData.username, username: formData.username,
goHome: false, goHome: false,
clientId: 'klab' clientId: 'klab',
performPostLoginAction: false
}); });
// sso // sso
document.location.reload(); document.location.reload();

Loading…
Cancel
Save