Pre Merge pull request !801 from 李志家/master

pull/801/MERGE
李志家 2025-08-31 03:31:05 +00:00 committed by Gitee
commit a9ba42467d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 78 additions and 10 deletions

View File

@ -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

View File

@ -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'
}) })
} }

View File

@ -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
} }
} }

View File

@ -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 },
// type40
{ icon: 'ant-design:windows-filled', type: 40 }
] ]
// //
@ -313,10 +315,19 @@ const doSocialLogin = async (type: number) => {
// redirectUri // redirectUri
// : typeredirect encode // : typeredirect 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))

View File

@ -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