This commit is contained in:
+22
-18
@@ -29,22 +29,25 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
// 优先从页面参数获取 code(App.vue 跳转时带过来)
|
||||
// 兜底从 URL search 参数获取(微信直接回调时)
|
||||
// 从 URL 参数获取 code(App.vue 跳转时带过来)
|
||||
let code = options.code || '';
|
||||
if (!code) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
code = urlParams.get('code') || '';
|
||||
// 同步获取 action(可能在 URL 参数中)
|
||||
if (!this.action) {
|
||||
this.action = urlParams.get('action') || '';
|
||||
}
|
||||
// 同步获取 device_id
|
||||
if (!this.deviceId) {
|
||||
this.deviceId = urlParams.get('device_id') || '';
|
||||
}
|
||||
}
|
||||
|
||||
// 兜底:从 localStorage 恢复(redirect_uri 参数为主,localStorage 为备用)
|
||||
if (!this.action) {
|
||||
this.action = localStorage.getItem('__auth_action') || '';
|
||||
}
|
||||
if (!this.deviceId) {
|
||||
this.deviceId = localStorage.getItem('__auth_device_id') || '';
|
||||
}
|
||||
// 清理 localStorage(一次性使用,避免残留影响下次流程)
|
||||
localStorage.removeItem('__auth_action');
|
||||
localStorage.removeItem('__auth_device_id');
|
||||
console.log('[loading] onLoad - action:', this.action, 'deviceId:', this.deviceId, 'code:', code ? 'yes' : 'no');
|
||||
|
||||
if (this.action === 'userinfo') {
|
||||
// 获取用户信息流程
|
||||
if (code) {
|
||||
@@ -84,10 +87,13 @@ export default {
|
||||
try {
|
||||
this.statusText = '正在获取授权...';
|
||||
|
||||
// 回调地址必须是 HTTPS,使用配置文件中的地址
|
||||
const redirectUri = config.authRedirectUri || (
|
||||
// 回调地址:基础地址 + device_id 参数(回调时保留)
|
||||
let redirectUri = config.authRedirectUri || (
|
||||
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||
);
|
||||
if (this.deviceId) {
|
||||
redirectUri += (redirectUri.includes('?') ? '&' : '?') + 'device_id=' + encodeURIComponent(this.deviceId);
|
||||
}
|
||||
|
||||
// 使用 snsapi_base 静默授权,不弹窗
|
||||
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||
@@ -206,16 +212,14 @@ export default {
|
||||
try {
|
||||
this.statusText = '正在获取用户信息...';
|
||||
|
||||
// 回调地址:当前 loading 页,带 action=userinfo 和 device_id
|
||||
const baseUri = config.authRedirectUri || (
|
||||
// 回调地址:基础地址 + action + device_id 参数(回调时保留)
|
||||
let redirectUri = config.authRedirectUri || (
|
||||
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||
);
|
||||
const redirectUriObj = new URL(baseUri);
|
||||
redirectUriObj.searchParams.set('action', 'userinfo');
|
||||
redirectUri += (redirectUri.includes('?') ? '&' : '?') + 'action=userinfo';
|
||||
if (this.deviceId) {
|
||||
redirectUriObj.searchParams.set('device_id', this.deviceId);
|
||||
redirectUri += '&device_id=' + encodeURIComponent(this.deviceId);
|
||||
}
|
||||
const redirectUri = redirectUriObj.toString();
|
||||
|
||||
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||
app_no: appNo,
|
||||
|
||||
@@ -325,14 +325,14 @@ export default {
|
||||
}
|
||||
|
||||
try {
|
||||
// 回调地址:loading 页处理后跳回首页(带 action 和 device_id)
|
||||
const baseUri = config.authRedirectUri || window.location.origin + '/pages/auth/loading';
|
||||
const redirectUriObj = new URL(baseUri);
|
||||
redirectUriObj.searchParams.set('action', 'userinfo');
|
||||
// 回调地址:基础地址 + action + device_id 参数(回调时保留)
|
||||
let redirectUri = config.authRedirectUri || (
|
||||
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||
);
|
||||
redirectUri += (redirectUri.includes('?') ? '&' : '?') + 'action=userinfo';
|
||||
if (this.deviceId) {
|
||||
redirectUriObj.searchParams.set('device_id', this.deviceId);
|
||||
redirectUri += '&device_id=' + encodeURIComponent(this.deviceId);
|
||||
}
|
||||
const redirectUri = redirectUriObj.toString();
|
||||
|
||||
// 获取非静默授权链接(会弹窗确认)
|
||||
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||
|
||||
Reference in New Issue
Block a user