fix
This commit is contained in:
@@ -31,7 +31,7 @@ export type LoginByPasswordDTO = {
|
||||
*/
|
||||
export type TokenDTO = {
|
||||
/** token */
|
||||
token: string;
|
||||
accessToken: string;
|
||||
/** 当前登录的用户 */
|
||||
currentUser: CurrentLoginUserDTO;
|
||||
};
|
||||
@@ -80,17 +80,17 @@ export type DictionaryData = {
|
||||
|
||||
/** 获取系统配置接口 */
|
||||
export const getConfig = () => {
|
||||
return http.request<ResponseData<ConfigDTO>>("get", "/getConfig");
|
||||
return http.request<ResponseData<ConfigDTO>>("get", "/auth/getConfig");
|
||||
};
|
||||
|
||||
/** 验证码接口 */
|
||||
export const getCaptchaCode = () => {
|
||||
return http.request<ResponseData<CaptchaDTO>>("get", "/captchaImage");
|
||||
return http.request<ResponseData<CaptchaDTO>>("get", "/captcha/code");
|
||||
};
|
||||
|
||||
/** 登录接口 */
|
||||
export const loginByPassword = (data: LoginByPasswordDTO) => {
|
||||
return http.request<ResponseData<TokenDTO>>("post", "/login", { data });
|
||||
return http.request<ResponseData<TokenDTO>>("post", "/auth/login", { data });
|
||||
};
|
||||
|
||||
/** 获取当前登录用户接口 */
|
||||
@@ -159,6 +159,6 @@ function withId(result: AsyncRoutesResponse) {
|
||||
* TODO:对于开发环境下此处可以对路由数据做一些校验,比如说 name 是否重复,name+path 是否重复等等
|
||||
*/
|
||||
export const getAsyncRoutes = async () => {
|
||||
const result = await http.request<AsyncRoutesResponse>("get", "/getRouters");
|
||||
const result = await http.request<AsyncRoutesResponse>("get", "/auth/getRouters");
|
||||
return withId(result);
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ export function getToken(): TokenDTO {
|
||||
// 此处与`TokenKey`相同,此写法解决初始化时`Cookies`中不存在`TokenKey`报错
|
||||
return Cookies.get(tokenKey)
|
||||
? JSON.parse(Cookies.get(tokenKey))
|
||||
: storageSession().getItem<TokenDTO>(sessionKey)?.token;
|
||||
: storageSession().getItem<TokenDTO>(sessionKey)?.accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,9 +40,9 @@ export function setTokenFromBackend(data: TokenDTO): void {
|
||||
const cookieString = JSON.stringify(data);
|
||||
Cookies.set(tokenKey, cookieString);
|
||||
|
||||
useUserStoreHook().SET_USERNAME(data.currentUser.userInfo.username);
|
||||
useUserStoreHook().SET_ROLES([data.currentUser.roleKey]);
|
||||
storageSession().setItem(sessionKey, data);
|
||||
// useUserStoreHook().SET_USERNAME(data.currentUser.userInfo.username);
|
||||
// useUserStoreHook().SET_ROLES([data.currentUser.roleKey]);
|
||||
// storageSession().setItem(sessionKey, data);
|
||||
}
|
||||
|
||||
/** 删除`token`以及key值为`user-info`的session信息 */
|
||||
|
||||
@@ -83,15 +83,15 @@ class PureHttp {
|
||||
/** 请求白名单,放置一些不需要token的接口(通过设置请求白名单,防止token过期后再请求造成的死循环问题) */
|
||||
const whiteList = [
|
||||
"/refreshToken",
|
||||
"/login",
|
||||
"/captchaImage",
|
||||
"/getConfig"
|
||||
"/auth/login",
|
||||
"/captcha/code",
|
||||
"/auth/getConfig"
|
||||
];
|
||||
return whiteList.some(v => config.url.endsWith(v))
|
||||
? config
|
||||
: new Promise(resolve => {
|
||||
const data = getToken();
|
||||
config.headers["Authorization"] = formatToken(data.token);
|
||||
config.headers["Authorization"] = formatToken(data.accessToken);
|
||||
resolve(config);
|
||||
});
|
||||
},
|
||||
@@ -134,7 +134,7 @@ class PureHttp {
|
||||
}
|
||||
|
||||
// 请求返回失败时,有业务错误时,弹出错误提示
|
||||
if (response.data.code !== 0) {
|
||||
if (response.data.code !== 200) {
|
||||
// token失效时弹出过期提示
|
||||
if (response.data.code === 106) {
|
||||
ElMessageBox.confirm(
|
||||
|
||||
@@ -81,7 +81,9 @@ const onLogin = async (formEl: FormInstance | undefined) => {
|
||||
username: ruleForm.username,
|
||||
password: rsaEncrypt(ruleForm.password),
|
||||
captchaCode: ruleForm.captchaCode,
|
||||
captchaCodeKey: ruleForm.captchaCodeKey
|
||||
captchaCodeKey: ruleForm.captchaCodeKey,
|
||||
grantType: "password",
|
||||
clientId: "1"
|
||||
})
|
||||
.then(({ data }) => {
|
||||
// 登录成功后 将token存储到sessionStorage中
|
||||
|
||||
Reference in New Issue
Block a user