Pre Merge pull request !801 from 李志家/master
commit
a9ba42467d
|
|
@ -59,10 +59,27 @@ export const smsLogin = (data: SmsLoginVO) => {
|
||||||
|
|
||||||
// 社交快捷登录,使用 code 授权码
|
// 社交快捷登录,使用 code 授权码
|
||||||
export function socialLogin(type: string, code: string, state: string) {
|
export function socialLogin(type: string, code: string, state: string) {
|
||||||
|
const message = useMessage()
|
||||||
|
|
||||||
|
// 如果 type 为空,尝试从 sessionStorage 获取(主要用于微软平台)
|
||||||
|
let finalType = type
|
||||||
|
if (!finalType) {
|
||||||
|
const storedType = sessionStorage.getItem('social_bind_type')
|
||||||
|
// 只有微软平台需要从 sessionStorage 获取 type,其他平台不需要
|
||||||
|
if (storedType && storedType === '40') {
|
||||||
|
finalType = storedType
|
||||||
|
// 使用后清除,避免影响后续操作
|
||||||
|
sessionStorage.removeItem('social_bind_type')
|
||||||
|
} else {
|
||||||
|
message.error('无法获取社交平台类型信息')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return request.post({
|
return request.post({
|
||||||
url: '/system/auth/social-login',
|
url: '/system/auth/social-login',
|
||||||
data: {
|
data: {
|
||||||
type,
|
type: finalType,
|
||||||
code,
|
code,
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +89,12 @@ export function socialLogin(type: string, code: string, state: string) {
|
||||||
// 社交授权的跳转
|
// 社交授权的跳转
|
||||||
export const socialAuthRedirect = (type: number, redirectUri: string) => {
|
export const socialAuthRedirect = (type: number, redirectUri: string) => {
|
||||||
return request.get({
|
return request.get({
|
||||||
url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri
|
url:
|
||||||
|
'/system/auth/social-auth-redirect?type=' +
|
||||||
|
type +
|
||||||
|
'&redirectUri=' +
|
||||||
|
redirectUri +
|
||||||
|
'&callbackType=login'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 获取验证图片以及 token
|
// 获取验证图片以及 token
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,11 @@ export const socialUnbind = (type, openid) => {
|
||||||
// 社交授权的跳转
|
// 社交授权的跳转
|
||||||
export const socialAuthRedirect = (type, redirectUri) => {
|
export const socialAuthRedirect = (type, redirectUri) => {
|
||||||
return request.get({
|
return request.get({
|
||||||
url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri
|
url:
|
||||||
|
'/system/auth/social-auth-redirect?type=' +
|
||||||
|
type +
|
||||||
|
'&redirectUri=' +
|
||||||
|
redirectUri +
|
||||||
|
'&callbackType=bind'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,12 @@ export const SystemUserSocialTypeEnum = {
|
||||||
type: 30,
|
type: 30,
|
||||||
source: 'wechat_enterprise',
|
source: 'wechat_enterprise',
|
||||||
img: 'https://s1.ax1x.com/2022/05/22/OzMrzn.png'
|
img: 'https://s1.ax1x.com/2022/05/22/OzMrzn.png'
|
||||||
|
},
|
||||||
|
MICROSOFT: {
|
||||||
|
title: '微软',
|
||||||
|
type: 40,
|
||||||
|
source: 'microsoft',
|
||||||
|
img: 'https://upload.wikimedia.org/wikipedia/commons/4/44/Microsoft_logo.svg' // 可换成你喜欢的微软logo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,9 @@ const socialList = [
|
||||||
{ icon: 'ant-design:wechat-filled', type: 30 },
|
{ icon: 'ant-design:wechat-filled', type: 30 },
|
||||||
{ icon: 'ant-design:dingtalk-circle-filled', type: 20 },
|
{ icon: 'ant-design:dingtalk-circle-filled', type: 20 },
|
||||||
{ icon: 'ant-design:github-filled', type: 0 },
|
{ icon: 'ant-design:github-filled', type: 0 },
|
||||||
{ icon: 'ant-design:alipay-circle-filled', type: 0 }
|
{ icon: 'ant-design:alipay-circle-filled', type: 0 },
|
||||||
|
// 新增微软三方登录按钮,type请与后端约定(如40)
|
||||||
|
{ icon: 'ant-design:windows-filled', type: 40 }
|
||||||
]
|
]
|
||||||
|
|
||||||
// 获取验证码
|
// 获取验证码
|
||||||
|
|
@ -313,10 +315,19 @@ const doSocialLogin = async (type: number) => {
|
||||||
// 计算 redirectUri
|
// 计算 redirectUri
|
||||||
// 注意: type、redirect 需要先 encode 一次,否则钉钉回调会丢失。
|
// 注意: type、redirect 需要先 encode 一次,否则钉钉回调会丢失。
|
||||||
// 配合 social-login.vue#getUrlValue() 使用
|
// 配合 social-login.vue#getUrlValue() 使用
|
||||||
const redirectUri =
|
// 对于微软平台,不在回调地址中添加查询参数
|
||||||
location.origin +
|
let redirectUri: string
|
||||||
'/social-login?' +
|
if (type === 40) {
|
||||||
encodeURIComponent(`type=${type}&redirect=${redirect.value || '/'}`)
|
// 微软平台使用纯回调地址,但将 type 存储到 sessionStorage
|
||||||
|
sessionStorage.setItem('social_bind_type', type.toString())
|
||||||
|
redirectUri = location.origin + '/social-login'
|
||||||
|
} else {
|
||||||
|
// 其他平台可以在回调地址中添加 type 参数
|
||||||
|
redirectUri =
|
||||||
|
location.origin +
|
||||||
|
'/social-login?' +
|
||||||
|
encodeURIComponent(`type=${type}&redirect=${redirect.value || '/'}`)
|
||||||
|
}
|
||||||
|
|
||||||
// 进行跳转
|
// 进行跳转
|
||||||
window.location.href = await LoginApi.socialAuthRedirect(type, encodeURIComponent(redirectUri))
|
window.location.href = await LoginApi.socialAuthRedirect(type, encodeURIComponent(redirectUri))
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,22 @@ const bindSocial = () => {
|
||||||
if (!code) {
|
if (!code) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
socialBind(type, code, state).then(() => {
|
|
||||||
|
// 如果 type 为空,尝试从 sessionStorage 获取(主要用于微软平台)
|
||||||
|
let finalType = type
|
||||||
|
if (!finalType) {
|
||||||
|
const storedType = sessionStorage.getItem('social_bind_type')
|
||||||
|
if (storedType) {
|
||||||
|
finalType = storedType
|
||||||
|
// 使用后清除,避免影响后续操作
|
||||||
|
sessionStorage.removeItem('social_bind_type')
|
||||||
|
} else {
|
||||||
|
message.error('无法获取社交平台类型信息')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
socialBind(finalType, code, state).then(() => {
|
||||||
message.success('绑定成功')
|
message.success('绑定成功')
|
||||||
emit('update:activeName', 'userSocial')
|
emit('update:activeName', 'userSocial')
|
||||||
})
|
})
|
||||||
|
|
@ -77,7 +92,16 @@ function getUrlValue(key: string): string {
|
||||||
|
|
||||||
const bind = (row) => {
|
const bind = (row) => {
|
||||||
// 双层 encode 解决钉钉回调 type 参数丢失的问题
|
// 双层 encode 解决钉钉回调 type 参数丢失的问题
|
||||||
const redirectUri = location.origin + '/user/profile?' + encodeURIComponent(`type=${row.type}`)
|
let redirectUri: string
|
||||||
|
// 对于微软平台,不在回调地址中添加查询参数
|
||||||
|
if (row.type === 40) {
|
||||||
|
// 微软平台使用纯回调地址,但将 type 存储到 sessionStorage
|
||||||
|
sessionStorage.setItem('social_bind_type', row.type.toString())
|
||||||
|
redirectUri = location.origin + '/user/profile'
|
||||||
|
} else {
|
||||||
|
// 其他平台可以在回调地址中添加 type 参数
|
||||||
|
redirectUri = location.origin + '/user/profile?' + encodeURIComponent(`type=${row.type}`)
|
||||||
|
}
|
||||||
// 进行跳转
|
// 进行跳转
|
||||||
socialAuthRedirect(row.type, encodeURIComponent(redirectUri)).then((res) => {
|
socialAuthRedirect(row.type, encodeURIComponent(redirectUri)).then((res) => {
|
||||||
window.location.href = res
|
window.location.href = res
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue