--添加测试模块
This commit is contained in:
@ -5,7 +5,8 @@ import { defineStore } from 'pinia';
|
||||
import { LOCK_INFO_KEY } from '/@/enums/cacheEnum';
|
||||
import { Persistent } from '/@/utils/cache/persistent';
|
||||
import { useUserStore } from './user';
|
||||
|
||||
import { usePermissionStore } from '/@/store/modules/permission';
|
||||
import { sendMobileLoginCode } from '/@/api/system/login';
|
||||
interface LockState {
|
||||
lockInfo: Nullable<LockInfo>;
|
||||
}
|
||||
@ -32,21 +33,23 @@ export const useLockStore = defineStore({
|
||||
// Unlock
|
||||
async unLock(password?: string) {
|
||||
const userStore = useUserStore();
|
||||
if (this.lockInfo?.pwd === password) {
|
||||
if (userStore.getToken && this.lockInfo?.pwd === password) {
|
||||
this.resetLockInfo();
|
||||
return true;
|
||||
}
|
||||
const tryLogin = async () => {
|
||||
try {
|
||||
const userName = userStore.getUserInfo?.userName;
|
||||
const tenantCode = userStore.getUserInfo?.tenantCode || '';
|
||||
const res = await userStore.login({
|
||||
userName,
|
||||
password: password!,
|
||||
tenantCode: tenantCode, // 补充
|
||||
goHome: false,
|
||||
mode: 'none',
|
||||
});
|
||||
if (res) {
|
||||
this.resetLockInfo();
|
||||
this.updatePermissionAndResetLock();
|
||||
}
|
||||
return res;
|
||||
} catch (error) {
|
||||
@ -55,5 +58,34 @@ export const useLockStore = defineStore({
|
||||
};
|
||||
return await tryLogin();
|
||||
},
|
||||
// Unlock by phone
|
||||
async unLockByPhone(code?: string) {
|
||||
const tryLogin = async () => {
|
||||
try {
|
||||
const userStore = useUserStore();
|
||||
const mobile = userStore.getUserInfo?.mobile;
|
||||
let params = {
|
||||
mobile: mobile,
|
||||
code: code
|
||||
}
|
||||
let res = await sendMobileLoginCode(params)
|
||||
if (res) {
|
||||
let params = {mode: 'none', goHome: false };
|
||||
userStore.tokenLogin(res.token, params);
|
||||
this.updatePermissionAndResetLock();
|
||||
}
|
||||
return res;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
return await tryLogin();
|
||||
},
|
||||
// 更新权限 关闭 锁屏页
|
||||
async updatePermissionAndResetLock() {
|
||||
const permissionStore = usePermissionStore();
|
||||
await permissionStore.changePermissionCode();
|
||||
this.resetLockInfo();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@ -25,6 +25,7 @@ import { MenuAuthModel } from '/@/api/system/login/model';
|
||||
import { getSubSystemList } from '/@/api/system/subSystem';
|
||||
|
||||
interface PermissionState {
|
||||
allButtonPermCodeList: string[];
|
||||
// Permission code list
|
||||
permCodeList: MenuAuthModel[];
|
||||
// Whether the route has been dynamically added
|
||||
@ -40,6 +41,7 @@ interface PermissionState {
|
||||
export const usePermissionStore = defineStore({
|
||||
id: 'app-permission',
|
||||
state: (): PermissionState => ({
|
||||
allButtonPermCodeList: [],
|
||||
permCodeList: [],
|
||||
// Whether the route has been dynamically added
|
||||
isDynamicAddedRoute: false,
|
||||
@ -54,6 +56,9 @@ export const usePermissionStore = defineStore({
|
||||
subSystemList: [],
|
||||
}),
|
||||
getters: {
|
||||
getAllButtonPermCodeList(): string[] {
|
||||
return this.allButtonPermCodeList || [];
|
||||
},
|
||||
getPermCodeList(): MenuAuthModel[] {
|
||||
return this.permCodeList || [];
|
||||
},
|
||||
@ -77,6 +82,12 @@ export const usePermissionStore = defineStore({
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setAllButtonPermCodeList(permList: string[]) {
|
||||
this.allButtonPermCodeList = permList;
|
||||
},
|
||||
getHasPermission(code) {
|
||||
return this.allButtonPermCodeList.includes(code);
|
||||
},
|
||||
setPermCodeList(permList: MenuAuthModel[]) {
|
||||
this.permCodeList = permList;
|
||||
},
|
||||
@ -138,6 +149,13 @@ export const usePermissionStore = defineStore({
|
||||
userInfo.desktopSchema = permResult.desktopSchema;
|
||||
|
||||
userStore.setUserInfo(userInfo);
|
||||
let allButtonPermCode = [];
|
||||
permResult.menuAuthList.forEach((item) => {
|
||||
if (item.buttonAuthCode) {
|
||||
allButtonPermCode = allButtonPermCode.concat(item.buttonAuthCode);
|
||||
}
|
||||
})
|
||||
this.setAllButtonPermCodeList(allButtonPermCode)
|
||||
this.setPermCodeList(permResult.menuAuthList);
|
||||
},
|
||||
async buildRoutesAction(isRefrashPermisson = true): Promise<AppRouteRecordRaw[]> {
|
||||
|
||||
@ -92,7 +92,7 @@ export const useUserStore = defineStore({
|
||||
): Promise<GetUserInfoModel | null> {
|
||||
try {
|
||||
const { token } = params;
|
||||
params.goHome=true;
|
||||
params.goHome = true;
|
||||
return await this.tokenLogin(token,params);
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
@ -111,7 +111,7 @@ export const useUserStore = defineStore({
|
||||
const { goHome = true, mode, ...loginParams } = params;
|
||||
const data = await loginApi(loginParams, mode);
|
||||
const { token } = data;
|
||||
params.goHome=true;
|
||||
params.goHome = true;
|
||||
return await this.tokenLogin(token,params);
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
|
||||
Reference in New Issue
Block a user