Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
let userInfo = toRaw(userStore.getUserInfo);
while (!userInfo) {
userInfo = toRaw(userStore.getUserInfo);
await sleep(100);
await sleep(500);
}
tenants.value = userInfo.tenants;
const tenant: TenantVo = tenants.value?.find((tenant) => tenant.id == userStore.getTenantId) as TenantVo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
let userInfo = toRaw(userStore.getUserInfo);
while (!userInfo) {
userInfo = toRaw(userStore.getUserInfo);
await sleep(100);
await sleep(500);
}
getUserInfo.id = userInfo.id;
getUserInfo.nickname = userInfo.nickname ? userInfo.nickname : userInfo.account;
Expand Down
2 changes: 1 addition & 1 deletion src/logics/InitAppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { sleep } from "/@/utils/Utils";
export async function initAppConfigStore() {
const userStore = useUserStoreWithOut();
while (!userStore.getUserInfo) {
await sleep(100);
await sleep(500);
}
setAppConfigStore().then();
}
Expand Down
7 changes: 4 additions & 3 deletions src/store/modules/Lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineStore } from "pinia";
import { LOCK_INFO_KEY } from "/@/enums/CacheEnum";
import { Persistent } from "/@/utils/cache/Persistent";
import { useUserStore } from "./User";
import { oauth2Config } from "/@/settings/LoginSetting";

interface LockState {
lockInfo: Nullable<LockInfo>;
Expand Down Expand Up @@ -40,10 +41,10 @@ export const useLockStore = defineStore({
const res = await userStore.login({
username: username!,
password: password!,
client_id: "system",
client_secret: "system",
client_id: oauth2Config.client_id,
client_secret: oauth2Config.client_secret,
grant_type: "password",
redirect_uri: "http://baidu.com",
redirect_uri: oauth2Config.redirect_uri,
mode: "none"
});
if (res) {
Expand Down
20 changes: 9 additions & 11 deletions src/store/modules/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,15 @@ export const useUserStore = defineStore({
async logout() {
if (this.getToken) {
try {
const result = await doLogout();
if (result) {
this.setToken(undefined);
this.setRefreshToken(undefined);
this.setSessionTimeout(false);
this.setUserInfo(null);
this.setTenantId(undefined);
clearAuthCache(true);
this.setIsLogout(true);
await router.push(PageEnum.BASE_LOGIN);
}
await doLogout();
this.setToken(undefined);
this.setRefreshToken(undefined);
this.setSessionTimeout(false);
this.setUserInfo(null);
this.setTenantId(undefined);
clearAuthCache(true);
this.setIsLogout(true);
await router.push(PageEnum.BASE_LOGIN);
} catch {
throw new Error("注销Token失败");
}
Expand Down
3 changes: 1 addition & 2 deletions src/utils/http/axios/CheckStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ export function checkStatus(
break;
// 401: 认证失败返回401
case 401:
userStore.setToken(undefined);
errMessage = t("sys.api.errMsg401");
if (stp === SessionTimeoutProcessingEnum.PAGE_COVERAGE) {
userStore.setSessionTimeout(true);
break;
}
userStore.logout();
userStore.logout().then();
break;
case 403:
errMessage = t("sys.api.errMsg403");
Expand Down
15 changes: 2 additions & 13 deletions src/utils/http/axios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { deepMerge, setObjToUrlParams } from "/@/utils";
import { useErrorLogStoreWithOut } from "/@/store/modules/ErrorLog";
import { useI18n } from "/@/hooks/web/UseI18n";
import { formatRequestDate, joinTimestamp, messageTips } from "./Helper";
import { useUserStoreWithOut } from "/@/store/modules/User";
import { AxiosRetry } from "/@/utils/http/axios/AxiosRetry";

const globSetting = useGlobSetting();
Expand Down Expand Up @@ -42,8 +41,8 @@ const transform: AxiosTransform = {
// 抛出请求异常
throw new Error(t("sys.api.apiRequestFailed"));
}
let { code, msg } = data;
const hasSuccess = data && code === ResultEnum.SUCCESS;
let { msg } = data;
const hasSuccess = data && data.code === ResultEnum.SUCCESS;
if (hasSuccess) {
if (msg === null || msg === undefined || msg === "") {
msg = t("sys.api.operationSuccess");
Expand All @@ -54,16 +53,6 @@ const transform: AxiosTransform = {
}
return data.data;
}
// 在此处根据自己项目的实际情况对不同的code执行不同的操作
// 如果不希望中断当前请求,请return数据,否则直接抛出异常即可
switch (code) {
case ResultEnum.TIMEOUT:
msg = t("sys.api.timeoutMessage");
const userStore = useUserStoreWithOut();
userStore.setToken(undefined);
userStore.logout().then();
break;
}
// errorMessageMode=‘modal’的时候会显示modal错误弹窗,而不是消息提示,用于一些比较重要的错误
// errorMessageMode='none' 一般是调用时明确表示不希望自动弹出错误提示
messageTips(options.errorMessageMode, msg, true, 0);
Expand Down