feat(@vben/web-antd): 企业微信扫码登录及绑定(适配 hash 路由)
- 登录页新增企业微信扫码登录入口(TDesign 官方图标) - 个人中心开放企业微信绑定/解绑功能 - 适配 hash 路由模式:OAuth 回调 code 在 URL query 中, 通过路由守卫转存 sessionStorage 并重定向到个人中心处理绑定 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -49,12 +49,40 @@ function setupCommonGuard(router: Router) {
|
||||
* @param router
|
||||
*/
|
||||
function setupAccessGuard(router: Router) {
|
||||
// 一次性检查:hash 路由模式下,OAuth 回调的 code/state 在 URL query(?code=xxx)中,
|
||||
// Vue Router 读不到,需要转存到 sessionStorage 供个人中心绑定页面使用
|
||||
const pendingBind = sessionStorage.getItem('socialBindAction');
|
||||
if (pendingBind === 'bind') {
|
||||
const url = new URL(window.location.href);
|
||||
const code = url.searchParams.get('code');
|
||||
const state = url.searchParams.get('state');
|
||||
if (code) {
|
||||
sessionStorage.setItem('socialBindCode', code);
|
||||
sessionStorage.setItem('socialBindState', state || '');
|
||||
sessionStorage.removeItem('socialBindAction');
|
||||
// 清理 URL 中的 OAuth 参数
|
||||
url.searchParams.delete('code');
|
||||
url.searchParams.delete('state');
|
||||
url.searchParams.delete('appid');
|
||||
window.history.replaceState({}, '', url.toString());
|
||||
}
|
||||
}
|
||||
|
||||
router.beforeEach(async (to, from) => {
|
||||
const accessStore = useAccessStore();
|
||||
const userStore = useUserStore();
|
||||
const authStore = useAuthStore();
|
||||
const dictStore = useDictStore();
|
||||
|
||||
// 社交绑定回调:检测到待处理的绑定参数,重定向到个人中心处理
|
||||
if (
|
||||
sessionStorage.getItem('socialBindCode') &&
|
||||
accessStore.accessToken &&
|
||||
to.path !== '/profile'
|
||||
) {
|
||||
return '/profile';
|
||||
}
|
||||
|
||||
// 基本路由,这些路由不需要进入权限拦截
|
||||
if (coreRouteNames.includes(to.name as string)) {
|
||||
if (to.path === LOGIN_PATH && accessStore.accessToken) {
|
||||
|
||||
Reference in New Issue
Block a user