2022-06-10 10:44:44 +08:00
|
|
|
|
import type { UserInfo, LoginInfo } from '/#/store';
|
2021-10-20 14:32:09 +08:00
|
|
|
|
import type { ErrorMessageMode } from '/#/axios';
|
|
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
|
import { store } from '/@/store';
|
|
|
|
|
import { RoleEnum } from '/@/enums/roleEnum';
|
|
|
|
|
import { PageEnum } from '/@/enums/pageEnum';
|
2023-10-18 14:55:25 +08:00
|
|
|
|
import { ROLES_KEY, TOKEN_KEY, USER_INFO_KEY, LOGIN_INFO_KEY, DB_DICT_DATA_KEY, TENANT_ID, OAUTH2_THIRD_LOGIN_TENANT_ID } from '/@/enums/cacheEnum';
|
2022-06-21 17:53:49 +08:00
|
|
|
|
import { getAuthCache, setAuthCache, removeAuthCache } from '/@/utils/auth';
|
2022-06-10 10:44:44 +08:00
|
|
|
|
import { GetUserInfoModel, LoginParams, ThirdLoginParams } from '/@/api/sys/model/userModel';
|
|
|
|
|
import { doLogout, getUserInfo, loginApi, phoneLoginApi, thirdLogin } from '/@/api/sys/user';
|
2021-10-20 14:32:09 +08:00
|
|
|
|
import { useI18n } from '/@/hooks/web/useI18n';
|
|
|
|
|
import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
|
|
import { router } from '/@/router';
|
|
|
|
|
import { usePermissionStore } from '/@/store/modules/permission';
|
|
|
|
|
import { RouteRecordRaw } from 'vue-router';
|
|
|
|
|
import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
|
2022-03-10 09:47:29 +08:00
|
|
|
|
import { isArray } from '/@/utils/is';
|
|
|
|
|
import { useGlobSetting } from '/@/hooks/setting';
|
2022-06-21 17:53:49 +08:00
|
|
|
|
import { JDragConfigEnum } from '/@/enums/jeecgEnum';
|
2022-06-10 10:44:44 +08:00
|
|
|
|
import { useSso } from '/@/hooks/web/useSso';
|
2023-10-18 14:55:25 +08:00
|
|
|
|
import { isOAuth2AppEnv } from "/@/views/sys/login/useLogin";
|
2024-03-25 16:00:52 +08:00
|
|
|
|
interface dictType {
|
|
|
|
|
[key: string]: any;
|
|
|
|
|
}
|
2021-10-20 14:32:09 +08:00
|
|
|
|
interface UserState {
|
|
|
|
|
userInfo: Nullable<UserInfo>;
|
|
|
|
|
token?: string;
|
|
|
|
|
roleList: RoleEnum[];
|
2024-03-25 16:00:52 +08:00
|
|
|
|
dictItems?: dictType | null;
|
2021-10-20 14:32:09 +08:00
|
|
|
|
sessionTimeout?: boolean;
|
|
|
|
|
lastUpdateTime: number;
|
2022-06-10 10:44:44 +08:00
|
|
|
|
tenantid?: string | number;
|
2023-10-18 14:55:25 +08:00
|
|
|
|
shareTenantId?: Nullable<string | number>;
|
2022-03-10 09:47:29 +08:00
|
|
|
|
loginInfo?: Nullable<LoginInfo>;
|
2021-10-20 14:32:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const useUserStore = defineStore({
|
|
|
|
|
id: 'app-user',
|
|
|
|
|
state: (): UserState => ({
|
2022-03-10 09:47:29 +08:00
|
|
|
|
// 用户信息
|
2021-10-20 14:32:09 +08:00
|
|
|
|
userInfo: null,
|
|
|
|
|
// token
|
|
|
|
|
token: undefined,
|
2022-03-10 09:47:29 +08:00
|
|
|
|
// 角色列表
|
2021-10-20 14:32:09 +08:00
|
|
|
|
roleList: [],
|
2022-03-10 09:47:29 +08:00
|
|
|
|
// 字典
|
2024-03-25 16:00:52 +08:00
|
|
|
|
dictItems: null,
|
2022-03-10 09:47:29 +08:00
|
|
|
|
// session过期时间
|
2021-10-20 14:32:09 +08:00
|
|
|
|
sessionTimeout: false,
|
|
|
|
|
// Last fetch time
|
|
|
|
|
lastUpdateTime: 0,
|
2022-03-10 09:47:29 +08:00
|
|
|
|
//租户id
|
|
|
|
|
tenantid: '',
|
2023-10-18 14:55:25 +08:00
|
|
|
|
// 分享租户ID
|
|
|
|
|
// 用于分享页面所属租户与当前用户登录租户不一致的情况
|
|
|
|
|
shareTenantId: null,
|
2022-03-10 09:47:29 +08:00
|
|
|
|
//登录返回信息
|
|
|
|
|
loginInfo: null,
|
2021-10-20 14:32:09 +08:00
|
|
|
|
}),
|
|
|
|
|
getters: {
|
|
|
|
|
getUserInfo(): UserInfo {
|
2024-03-06 16:33:03 +08:00
|
|
|
|
if(this.userInfo == null){
|
|
|
|
|
this.userInfo = getAuthCache<UserInfo>(USER_INFO_KEY)!=null ? getAuthCache<UserInfo>(USER_INFO_KEY) : null;
|
|
|
|
|
}
|
2021-10-20 14:32:09 +08:00
|
|
|
|
return this.userInfo || getAuthCache<UserInfo>(USER_INFO_KEY) || {};
|
|
|
|
|
},
|
2022-03-10 09:47:29 +08:00
|
|
|
|
getLoginInfo(): LoginInfo {
|
|
|
|
|
return this.loginInfo || getAuthCache<LoginInfo>(LOGIN_INFO_KEY) || {};
|
|
|
|
|
},
|
2021-10-20 14:32:09 +08:00
|
|
|
|
getToken(): string {
|
|
|
|
|
return this.token || getAuthCache<string>(TOKEN_KEY);
|
|
|
|
|
},
|
2022-06-10 10:44:44 +08:00
|
|
|
|
getAllDictItems(): [] {
|
2022-03-10 09:47:29 +08:00
|
|
|
|
return this.dictItems || getAuthCache(DB_DICT_DATA_KEY);
|
|
|
|
|
},
|
2021-10-20 14:32:09 +08:00
|
|
|
|
getRoleList(): RoleEnum[] {
|
|
|
|
|
return this.roleList.length > 0 ? this.roleList : getAuthCache<RoleEnum[]>(ROLES_KEY);
|
|
|
|
|
},
|
|
|
|
|
getSessionTimeout(): boolean {
|
|
|
|
|
return !!this.sessionTimeout;
|
|
|
|
|
},
|
|
|
|
|
getLastUpdateTime(): number {
|
|
|
|
|
return this.lastUpdateTime;
|
|
|
|
|
},
|
2022-06-10 10:44:44 +08:00
|
|
|
|
getTenant(): string | number {
|
|
|
|
|
return this.tenantid || getAuthCache<string | number>(TENANT_ID);
|
|
|
|
|
},
|
2023-10-18 14:55:25 +08:00
|
|
|
|
// 是否有分享租户id
|
|
|
|
|
hasShareTenantId(): boolean {
|
|
|
|
|
return this.shareTenantId != null && this.shareTenantId !== '';
|
|
|
|
|
},
|
2021-10-20 14:32:09 +08:00
|
|
|
|
},
|
|
|
|
|
actions: {
|
|
|
|
|
setToken(info: string | undefined) {
|
2022-03-10 09:47:29 +08:00
|
|
|
|
this.token = info ? info : ''; // for null or undefined value
|
2021-10-20 14:32:09 +08:00
|
|
|
|
setAuthCache(TOKEN_KEY, info);
|
|
|
|
|
},
|
|
|
|
|
setRoleList(roleList: RoleEnum[]) {
|
|
|
|
|
this.roleList = roleList;
|
|
|
|
|
setAuthCache(ROLES_KEY, roleList);
|
|
|
|
|
},
|
2022-03-10 09:47:29 +08:00
|
|
|
|
setUserInfo(info: UserInfo | null) {
|
2021-10-20 14:32:09 +08:00
|
|
|
|
this.userInfo = info;
|
|
|
|
|
this.lastUpdateTime = new Date().getTime();
|
|
|
|
|
setAuthCache(USER_INFO_KEY, info);
|
|
|
|
|
},
|
2022-03-10 09:47:29 +08:00
|
|
|
|
setLoginInfo(info: LoginInfo | null) {
|
2022-06-10 10:44:44 +08:00
|
|
|
|
this.loginInfo = info;
|
2022-03-10 09:47:29 +08:00
|
|
|
|
setAuthCache(LOGIN_INFO_KEY, info);
|
2022-06-10 10:44:44 +08:00
|
|
|
|
},
|
2022-03-10 09:47:29 +08:00
|
|
|
|
setAllDictItems(dictItems) {
|
|
|
|
|
this.dictItems = dictItems;
|
|
|
|
|
setAuthCache(DB_DICT_DATA_KEY, dictItems);
|
|
|
|
|
},
|
2024-03-25 16:00:52 +08:00
|
|
|
|
setAllDictItemsByLocal() {
|
|
|
|
|
// update-begin--author:liaozhiyang---date:20240321---for:【QQYUN-8572】表格行选择卡顿问题(customRender中字典引起的)
|
|
|
|
|
if (!this.dictItems) {
|
|
|
|
|
const allDictItems = getAuthCache(DB_DICT_DATA_KEY);
|
|
|
|
|
if (allDictItems) {
|
|
|
|
|
this.dictItems = allDictItems;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// update-end--author:liaozhiyang---date:20240321---for:【QQYUN-8572】表格行选择卡顿问题(customRender中字典引起的)
|
|
|
|
|
},
|
2022-06-10 10:44:44 +08:00
|
|
|
|
setTenant(id) {
|
2022-03-10 09:47:29 +08:00
|
|
|
|
this.tenantid = id;
|
|
|
|
|
setAuthCache(TENANT_ID, id);
|
|
|
|
|
},
|
2023-10-18 14:55:25 +08:00
|
|
|
|
setShareTenantId(id: NonNullable<typeof this.shareTenantId>) {
|
|
|
|
|
this.shareTenantId = id;
|
|
|
|
|
},
|
2021-10-20 14:32:09 +08:00
|
|
|
|
setSessionTimeout(flag: boolean) {
|
|
|
|
|
this.sessionTimeout = flag;
|
|
|
|
|
},
|
|
|
|
|
resetState() {
|
|
|
|
|
this.userInfo = null;
|
2024-03-25 16:00:52 +08:00
|
|
|
|
this.dictItems = null;
|
2021-10-20 14:32:09 +08:00
|
|
|
|
this.token = '';
|
|
|
|
|
this.roleList = [];
|
|
|
|
|
this.sessionTimeout = false;
|
|
|
|
|
},
|
|
|
|
|
/**
|
2022-03-10 09:47:29 +08:00
|
|
|
|
* 登录事件
|
2021-10-20 14:32:09 +08:00
|
|
|
|
*/
|
|
|
|
|
async login(
|
|
|
|
|
params: LoginParams & {
|
|
|
|
|
goHome?: boolean;
|
|
|
|
|
mode?: ErrorMessageMode;
|
2022-06-10 10:44:44 +08:00
|
|
|
|
}
|
2021-10-20 14:32:09 +08:00
|
|
|
|
): Promise<GetUserInfoModel | null> {
|
|
|
|
|
try {
|
|
|
|
|
const { goHome = true, mode, ...loginParams } = params;
|
|
|
|
|
const data = await loginApi(loginParams, mode);
|
2023-03-05 11:41:15 +08:00
|
|
|
|
const { token, userInfo } = data;
|
2021-10-20 14:32:09 +08:00
|
|
|
|
// save token
|
|
|
|
|
this.setToken(token);
|
2023-03-05 11:41:15 +08:00
|
|
|
|
this.setTenant(userInfo.loginTenantId);
|
2022-06-10 10:44:44 +08:00
|
|
|
|
return this.afterLoginAction(goHome, data);
|
2021-10-20 14:32:09 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-03-10 09:47:29 +08:00
|
|
|
|
/**
|
|
|
|
|
* 扫码登录事件
|
|
|
|
|
*/
|
|
|
|
|
async qrCodeLogin(token): Promise<GetUserInfoModel | null> {
|
|
|
|
|
try {
|
|
|
|
|
// save token
|
|
|
|
|
this.setToken(token);
|
2022-06-10 10:44:44 +08:00
|
|
|
|
return this.afterLoginAction(true, {});
|
2022-03-10 09:47:29 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 登录完成处理
|
|
|
|
|
* @param goHome
|
|
|
|
|
*/
|
2022-06-10 10:44:44 +08:00
|
|
|
|
async afterLoginAction(goHome?: boolean, data?: any): Promise<any | null> {
|
2022-03-10 09:47:29 +08:00
|
|
|
|
if (!this.getToken) return null;
|
|
|
|
|
//获取用户信息
|
|
|
|
|
const userInfo = await this.getUserInfoAction();
|
|
|
|
|
const sessionTimeout = this.sessionTimeout;
|
|
|
|
|
if (sessionTimeout) {
|
|
|
|
|
this.setSessionTimeout(false);
|
|
|
|
|
} else {
|
2024-03-06 16:33:03 +08:00
|
|
|
|
//update-begin---author:scott ---date::2024-02-21 for:【QQYUN-8326】登录不需要构建路由,进入首页有构建---
|
|
|
|
|
// // 构建后台菜单路由
|
|
|
|
|
// const permissionStore = usePermissionStore();
|
|
|
|
|
// if (!permissionStore.isDynamicAddedRoute) {
|
|
|
|
|
// const routes = await permissionStore.buildRoutesAction();
|
|
|
|
|
// routes.forEach((route) => {
|
|
|
|
|
// router.addRoute(route as unknown as RouteRecordRaw);
|
|
|
|
|
// });
|
|
|
|
|
// router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw);
|
|
|
|
|
// permissionStore.setDynamicAddedRoute(true);
|
|
|
|
|
// }
|
|
|
|
|
//update-end---author:scott ---date::2024-02-21 for:【QQYUN-8326】登录不需要构建路由,进入首页有构建---
|
|
|
|
|
|
2022-06-21 17:53:49 +08:00
|
|
|
|
await this.setLoginInfo({ ...data, isLogin: true });
|
|
|
|
|
//update-begin-author:liusq date:2022-5-5 for:登录成功后缓存拖拽模块的接口前缀
|
|
|
|
|
localStorage.setItem(JDragConfigEnum.DRAG_BASE_URL, useGlobSetting().domainUrl);
|
|
|
|
|
//update-end-author:liusq date:2022-5-5 for: 登录成功后缓存拖拽模块的接口前缀
|
2023-10-18 14:55:25 +08:00
|
|
|
|
|
|
|
|
|
// update-begin-author:sunjianlei date:20230306 for: 修复登录成功后,没有正确重定向的问题
|
|
|
|
|
let redirect = router.currentRoute.value?.query?.redirect as string;
|
|
|
|
|
// 判断是否有 redirect 重定向地址
|
|
|
|
|
//update-begin---author:wangshuai ---date:20230424 for:【QQYUN-5195】登录之后直接刷新页面导致没有进入创建组织页面------------
|
|
|
|
|
if (redirect && goHome) {
|
|
|
|
|
//update-end---author:wangshuai ---date:20230424 for:【QQYUN-5195】登录之后直接刷新页面导致没有进入创建组织页面------------
|
2024-01-07 17:11:30 +08:00
|
|
|
|
// update-begin--author:liaozhiyang---date:20240104---for:【QQYUN-7804】部署生产环境,登录跳转404问题
|
|
|
|
|
const publicPath = import.meta.env.VITE_PUBLIC_PATH;
|
|
|
|
|
if (publicPath && publicPath != '/') {
|
|
|
|
|
redirect = publicPath + redirect;
|
|
|
|
|
}
|
|
|
|
|
// update-end--author:liaozhiyang---date:20240104---for:【QQYUN-7804】部署生产环境,登录跳转404问题
|
2023-10-18 14:55:25 +08:00
|
|
|
|
// 当前页面打开
|
|
|
|
|
window.open(redirect, '_self')
|
2023-10-31 13:46:48 +08:00
|
|
|
|
return data;
|
2023-10-18 14:55:25 +08:00
|
|
|
|
}
|
|
|
|
|
// update-end-author:sunjianlei date:20230306 for: 修复登录成功后,没有正确重定向的问题
|
|
|
|
|
|
2022-06-10 10:44:44 +08:00
|
|
|
|
goHome && (await router.replace((userInfo && userInfo.homePath) || PageEnum.BASE_HOME));
|
2022-03-10 09:47:29 +08:00
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 手机号登录
|
|
|
|
|
* @param params
|
|
|
|
|
*/
|
2021-10-20 14:32:09 +08:00
|
|
|
|
async phoneLogin(
|
|
|
|
|
params: LoginParams & {
|
|
|
|
|
goHome?: boolean;
|
|
|
|
|
mode?: ErrorMessageMode;
|
2022-06-10 10:44:44 +08:00
|
|
|
|
}
|
2021-10-20 14:32:09 +08:00
|
|
|
|
): Promise<GetUserInfoModel | null> {
|
|
|
|
|
try {
|
|
|
|
|
const { goHome = true, mode, ...loginParams } = params;
|
|
|
|
|
const data = await phoneLoginApi(loginParams, mode);
|
|
|
|
|
const { token } = data;
|
|
|
|
|
// save token
|
|
|
|
|
this.setToken(token);
|
2022-06-10 10:44:44 +08:00
|
|
|
|
return this.afterLoginAction(goHome, data);
|
2021-10-20 14:32:09 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-03-10 09:47:29 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取用户信息
|
|
|
|
|
*/
|
|
|
|
|
async getUserInfoAction(): Promise<UserInfo | null> {
|
|
|
|
|
if (!this.getToken) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-06-10 10:44:44 +08:00
|
|
|
|
const { userInfo, sysAllDictItems } = await getUserInfo();
|
|
|
|
|
if (userInfo) {
|
2022-03-10 09:47:29 +08:00
|
|
|
|
const { roles = [] } = userInfo;
|
|
|
|
|
if (isArray(roles)) {
|
|
|
|
|
const roleList = roles.map((item) => item.value) as RoleEnum[];
|
|
|
|
|
this.setRoleList(roleList);
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.roles = [];
|
|
|
|
|
this.setRoleList([]);
|
|
|
|
|
}
|
2021-10-20 14:32:09 +08:00
|
|
|
|
this.setUserInfo(userInfo);
|
|
|
|
|
}
|
2022-03-10 09:47:29 +08:00
|
|
|
|
/**
|
|
|
|
|
* 添加字典信息到缓存
|
|
|
|
|
* @updateBy:lsq
|
|
|
|
|
* @updateDate:2021-09-08
|
|
|
|
|
*/
|
2022-06-10 10:44:44 +08:00
|
|
|
|
if (sysAllDictItems) {
|
2022-03-10 09:47:29 +08:00
|
|
|
|
this.setAllDictItems(sysAllDictItems);
|
|
|
|
|
}
|
2021-10-20 14:32:09 +08:00
|
|
|
|
return userInfo;
|
|
|
|
|
},
|
|
|
|
|
/**
|
2022-03-10 09:47:29 +08:00
|
|
|
|
* 退出登录
|
2021-10-20 14:32:09 +08:00
|
|
|
|
*/
|
|
|
|
|
async logout(goLogin = false) {
|
2022-03-10 09:47:29 +08:00
|
|
|
|
if (this.getToken) {
|
2021-10-20 14:32:09 +08:00
|
|
|
|
try {
|
|
|
|
|
await doLogout();
|
|
|
|
|
} catch {
|
|
|
|
|
console.log('注销Token失败');
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-21 17:53:49 +08:00
|
|
|
|
|
|
|
|
|
// //update-begin-author:taoyan date:2022-5-5 for: src/layouts/default/header/index.vue showLoginSelect方法 获取tenantId 退出登录后再次登录依然能获取到值,没有清空
|
|
|
|
|
// let username:any = this.userInfo && this.userInfo.username;
|
|
|
|
|
// if(username){
|
|
|
|
|
// removeAuthCache(username)
|
|
|
|
|
// }
|
|
|
|
|
// //update-end-author:taoyan date:2022-5-5 for: src/layouts/default/header/index.vue showLoginSelect方法 获取tenantId 退出登录后再次登录依然能获取到值,没有清空
|
|
|
|
|
|
2022-03-10 09:47:29 +08:00
|
|
|
|
this.setToken('');
|
|
|
|
|
setAuthCache(TOKEN_KEY, null);
|
2021-10-20 14:32:09 +08:00
|
|
|
|
this.setSessionTimeout(false);
|
2022-03-10 09:47:29 +08:00
|
|
|
|
this.setUserInfo(null);
|
|
|
|
|
this.setLoginInfo(null);
|
2023-03-05 11:41:15 +08:00
|
|
|
|
this.setTenant(null);
|
2024-03-06 16:33:03 +08:00
|
|
|
|
this.setAllDictItems(null);
|
2022-06-21 17:53:49 +08:00
|
|
|
|
//update-begin-author:liusq date:2022-5-5 for:退出登录后清除拖拽模块的接口前缀
|
|
|
|
|
localStorage.removeItem(JDragConfigEnum.DRAG_BASE_URL);
|
|
|
|
|
//update-end-author:liusq date:2022-5-5 for: 退出登录后清除拖拽模块的接口前缀
|
2022-03-10 09:47:29 +08:00
|
|
|
|
|
|
|
|
|
//如果开启单点登录,则跳转到单点统一登录中心
|
|
|
|
|
const openSso = useGlobSetting().openSso;
|
2022-06-10 10:44:44 +08:00
|
|
|
|
if (openSso == 'true') {
|
2022-03-10 09:47:29 +08:00
|
|
|
|
await useSso().ssoLoginOut();
|
|
|
|
|
}
|
2023-10-18 14:55:25 +08:00
|
|
|
|
//update-begin---author:wangshuai ---date:20230224 for:[QQYUN-3440]新建企业微信和钉钉配置表,通过租户模式隔离------------
|
|
|
|
|
//退出登录的时候需要用的应用id
|
|
|
|
|
if(isOAuth2AppEnv()){
|
|
|
|
|
let tenantId = getAuthCache(OAUTH2_THIRD_LOGIN_TENANT_ID);
|
|
|
|
|
removeAuthCache(OAUTH2_THIRD_LOGIN_TENANT_ID);
|
|
|
|
|
goLogin && await router.push({ name:"Login",query:{ tenantId:tenantId }})
|
|
|
|
|
}else{
|
|
|
|
|
// update-begin-author:sunjianlei date:20230306 for: 修复登录成功后,没有正确重定向的问题
|
|
|
|
|
goLogin && (await router.push({
|
|
|
|
|
path: PageEnum.BASE_LOGIN,
|
|
|
|
|
query: {
|
|
|
|
|
// 传入当前的路由,登录成功后跳转到当前路由
|
|
|
|
|
redirect: router.currentRoute.value.fullPath,
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
// update-end-author:sunjianlei date:20230306 for: 修复登录成功后,没有正确重定向的问题
|
2021-10-20 14:32:09 +08:00
|
|
|
|
|
2023-10-18 14:55:25 +08:00
|
|
|
|
}
|
|
|
|
|
//update-end---author:wangshuai ---date:20230224 for:[QQYUN-3440]新建企业微信和钉钉配置表,通过租户模式隔离------------
|
2022-03-10 09:47:29 +08:00
|
|
|
|
},
|
2022-06-10 10:44:44 +08:00
|
|
|
|
/**
|
|
|
|
|
* 登录事件
|
|
|
|
|
*/
|
|
|
|
|
async ThirdLogin(
|
|
|
|
|
params: ThirdLoginParams & {
|
|
|
|
|
goHome?: boolean;
|
|
|
|
|
mode?: ErrorMessageMode;
|
|
|
|
|
}
|
|
|
|
|
): Promise<any | null> {
|
2022-03-10 09:47:29 +08:00
|
|
|
|
try {
|
2022-06-10 10:44:44 +08:00
|
|
|
|
const { goHome = true, mode, ...ThirdLoginParams } = params;
|
|
|
|
|
const data = await thirdLogin(ThirdLoginParams, mode);
|
|
|
|
|
const { token } = data;
|
|
|
|
|
// save token
|
|
|
|
|
this.setToken(token);
|
|
|
|
|
return this.afterLoginAction(goHome, data);
|
2022-03-10 09:47:29 +08:00
|
|
|
|
} catch (error) {
|
2022-06-10 10:44:44 +08:00
|
|
|
|
return Promise.reject(error);
|
2022-03-10 09:47:29 +08:00
|
|
|
|
}
|
2022-06-10 10:44:44 +08:00
|
|
|
|
},
|
2021-10-20 14:32:09 +08:00
|
|
|
|
/**
|
2022-03-10 09:47:29 +08:00
|
|
|
|
* 退出询问
|
2021-10-20 14:32:09 +08:00
|
|
|
|
*/
|
|
|
|
|
confirmLoginOut() {
|
|
|
|
|
const { createConfirm } = useMessage();
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
|
createConfirm({
|
|
|
|
|
iconType: 'warning',
|
|
|
|
|
title: t('sys.app.logoutTip'),
|
|
|
|
|
content: t('sys.app.logoutMessage'),
|
|
|
|
|
onOk: async () => {
|
|
|
|
|
await this.logout(true);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Need to be used outside the setup
|
|
|
|
|
export function useUserStoreWithOut() {
|
|
|
|
|
return useUserStore(store);
|
|
|
|
|
}
|