mirror of https://github.com/jeecgboot/jeecg-boot
【重要更新】vue3前端为了适配springboot3 sas分支(Spring Authorization Server)特定修改
parent
8e54e06978
commit
9e25566271
|
@ -4,11 +4,13 @@
|
|||
export interface LoginParams {
|
||||
username: string;
|
||||
password: string;
|
||||
grant_type: string;
|
||||
}
|
||||
|
||||
export interface ThirdLoginParams {
|
||||
token: string;
|
||||
thirdType: string;
|
||||
grant_type: string;
|
||||
}
|
||||
|
||||
export interface RoleInfo {
|
||||
|
|
|
@ -13,7 +13,7 @@ import { ExceptionEnum } from "@/enums/exceptionEnum";
|
|||
const { createErrorModal } = useMessage();
|
||||
enum Api {
|
||||
Login = '/sys/login',
|
||||
phoneLogin = '/sys/phoneLogin',
|
||||
phoneLogin = '/oauth2/token',
|
||||
Logout = '/sys/logout',
|
||||
GetUserInfo = '/sys/user/getUserInfo',
|
||||
// 获取系统权限
|
||||
|
@ -36,7 +36,7 @@ enum Api {
|
|||
//修改密码
|
||||
passwordChange = '/sys/user/passwordChange',
|
||||
//第三方登录
|
||||
thirdLogin = '/sys/thirdLogin/getLoginUser',
|
||||
thirdLogin = '/oauth2/token',
|
||||
//第三方登录
|
||||
getThirdCaptcha = '/sys/thirdSms',
|
||||
//获取二维码信息
|
||||
|
@ -53,6 +53,10 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal')
|
|||
{
|
||||
url: Api.Login,
|
||||
params,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Authorization': 'Basic amVlY2ctY2xpZW50OnNlY3JldA=='
|
||||
},
|
||||
},
|
||||
{
|
||||
errorMessageMode: mode,
|
||||
|
@ -68,8 +72,13 @@ export function phoneLoginApi(params: LoginParams, mode: ErrorMessageMode = 'mod
|
|||
{
|
||||
url: Api.phoneLogin,
|
||||
params,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Authorization': 'Basic amVlY2ctY2xpZW50OnNlY3JldA=='
|
||||
},
|
||||
},
|
||||
{
|
||||
isTransformResponse: false,
|
||||
errorMessageMode: mode,
|
||||
}
|
||||
);
|
||||
|
@ -171,12 +180,19 @@ export function thirdLogin(params, mode: ErrorMessageMode = 'modal') {
|
|||
tenantId = params.tenantId;
|
||||
}
|
||||
//==========end 第三方登录/auth2登录需要传递租户id===========
|
||||
return defHttp.get<LoginResultModel>(
|
||||
return defHttp.post<LoginResultModel>(
|
||||
{
|
||||
url: `${Api.thirdLogin}/${params.token}/${params.thirdType}/${tenantId}`,
|
||||
url: `${Api.thirdLogin}`,
|
||||
params,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Authorization': 'Basic amVlY2ctY2xpZW50OnNlY3JldA=='
|
||||
},
|
||||
},
|
||||
{
|
||||
isTransformResponse: false,
|
||||
errorMessageMode: mode,
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -151,6 +151,7 @@ export const useUserStore = defineStore({
|
|||
): Promise<GetUserInfoModel | null> {
|
||||
try {
|
||||
const { goHome = true, mode, ...loginParams } = params;
|
||||
loginParams.grant_type = 'password';
|
||||
const data = await loginApi(loginParams, mode);
|
||||
const { token, userInfo } = data;
|
||||
// save token
|
||||
|
@ -248,10 +249,11 @@ export const useUserStore = defineStore({
|
|||
): Promise<GetUserInfoModel | null> {
|
||||
try {
|
||||
const { goHome = true, mode, ...loginParams } = params;
|
||||
loginParams.grant_type = 'phone';
|
||||
const data = await phoneLoginApi(loginParams, mode);
|
||||
const { token } = data;
|
||||
const { access_token } = data;
|
||||
// save token
|
||||
this.setToken(token);
|
||||
this.setToken(access_token);
|
||||
return this.afterLoginAction(goHome, data);
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
|
@ -356,10 +358,11 @@ export const useUserStore = defineStore({
|
|||
): Promise<any | null> {
|
||||
try {
|
||||
const { goHome = true, mode, ...ThirdLoginParams } = params;
|
||||
ThirdLoginParams.grant_type = "social";
|
||||
const data = await thirdLogin(ThirdLoginParams, mode);
|
||||
const { token } = data;
|
||||
const { access_token } = data;
|
||||
// save token
|
||||
this.setToken(token);
|
||||
this.setToken(access_token);
|
||||
return this.afterLoginAction(goHome, data);
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
|
|
|
@ -165,7 +165,7 @@ const transform: AxiosTransform = {
|
|||
// update-end--author:liaozhiyang---date:20240509---for:【issues/1220】登录时,vue3版本不加载字典数据设置无效
|
||||
if (token && (config as Recordable)?.requestOptions?.withToken !== false) {
|
||||
// jwt token
|
||||
config.headers.Authorization = options.authenticationScheme ? `${options.authenticationScheme} ${token}` : token;
|
||||
config.headers.Authorization = options.authenticationScheme ? `${options.authenticationScheme} ${token}` : 'Bearer ' + token;
|
||||
config.headers[ConfigEnum.TOKEN] = token;
|
||||
|
||||
// 将签名和时间戳,添加在请求接口 Header
|
||||
|
|
|
@ -149,6 +149,7 @@
|
|||
username: data.account,
|
||||
captcha: data.inputCode,
|
||||
checkKey: randCodeData.checkKey,
|
||||
grant_type: 'password',
|
||||
mode: 'none', //不要默认的错误提示
|
||||
})
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue