From 9e25566271db4240ed72225e7684011ff1964744 Mon Sep 17 00:00:00 2001 From: JEECG <445654970@qq.com> Date: Sun, 23 Jun 2024 11:25:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E9=87=8D=E8=A6=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E3=80=91vue3=E5=89=8D=E7=AB=AF=E4=B8=BA=E4=BA=86=E9=80=82?= =?UTF-8?q?=E9=85=8Dspringboot3=20sas=E5=88=86=E6=94=AF(Spring=20Authoriza?= =?UTF-8?q?tion=20Server)=E7=89=B9=E5=AE=9A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jeecgboot-vue3/src/api/sys/model/userModel.ts | 2 ++ jeecgboot-vue3/src/api/sys/user.ts | 24 +++++++++++++++---- jeecgboot-vue3/src/store/modules/user.ts | 11 +++++---- jeecgboot-vue3/src/utils/http/axios/index.ts | 2 +- .../src/views/sys/login/LoginForm.vue | 1 + 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/jeecgboot-vue3/src/api/sys/model/userModel.ts b/jeecgboot-vue3/src/api/sys/model/userModel.ts index f1d9be79..64f730bf 100644 --- a/jeecgboot-vue3/src/api/sys/model/userModel.ts +++ b/jeecgboot-vue3/src/api/sys/model/userModel.ts @@ -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 { diff --git a/jeecgboot-vue3/src/api/sys/user.ts b/jeecgboot-vue3/src/api/sys/user.ts index 5ed47e36..c00f2f5f 100644 --- a/jeecgboot-vue3/src/api/sys/user.ts +++ b/jeecgboot-vue3/src/api/sys/user.ts @@ -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( + return defHttp.post( { - 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, + } ); } diff --git a/jeecgboot-vue3/src/store/modules/user.ts b/jeecgboot-vue3/src/store/modules/user.ts index ebc70ed8..8dcee973 100644 --- a/jeecgboot-vue3/src/store/modules/user.ts +++ b/jeecgboot-vue3/src/store/modules/user.ts @@ -151,6 +151,7 @@ export const useUserStore = defineStore({ ): Promise { 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 { 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 { 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); diff --git a/jeecgboot-vue3/src/utils/http/axios/index.ts b/jeecgboot-vue3/src/utils/http/axios/index.ts index ab0248d8..29dc2484 100644 --- a/jeecgboot-vue3/src/utils/http/axios/index.ts +++ b/jeecgboot-vue3/src/utils/http/axios/index.ts @@ -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 diff --git a/jeecgboot-vue3/src/views/sys/login/LoginForm.vue b/jeecgboot-vue3/src/views/sys/login/LoginForm.vue index 1bb1cb7f..5f14b0d6 100644 --- a/jeecgboot-vue3/src/views/sys/login/LoginForm.vue +++ b/jeecgboot-vue3/src/views/sys/login/LoginForm.vue @@ -149,6 +149,7 @@ username: data.account, captcha: data.inputCode, checkKey: randCodeData.checkKey, + grant_type: 'password', mode: 'none', //不要默认的错误提示 }) );