Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 45147426e0 |
+6
-4
@@ -30,7 +30,7 @@
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
deviceId = urlParams.get('device_id') || '';
|
||||
|
||||
// 兜底:从路径解析(如 /pages/index/index/N1154)
|
||||
// 兜底:从路径解析(如 /N1154)
|
||||
if (!deviceId) {
|
||||
const path = window.location.pathname;
|
||||
const segments = path.split('/').filter(Boolean);
|
||||
@@ -46,14 +46,16 @@
|
||||
const code = urlParams.get('code');
|
||||
|
||||
if (code) {
|
||||
// 有 code → 进入授权 Loading 页处理,保留 code/action/device_id 参数
|
||||
// 有 code → 进入授权 Loading 页处理
|
||||
// redirect_uri 已携带 device_id 和 action,回调时直接从 URL 取
|
||||
const action = urlParams.get('action') || '';
|
||||
const callbackDeviceId = urlParams.get('device_id') || deviceId || '';
|
||||
let loadingUrl = '/pages/auth/loading?code=' + encodeURIComponent(code);
|
||||
if (action) {
|
||||
loadingUrl += '&action=' + action;
|
||||
}
|
||||
if (deviceId) {
|
||||
loadingUrl += '&device_id=' + deviceId;
|
||||
if (callbackDeviceId) {
|
||||
loadingUrl += '&device_id=' + callbackDeviceId;
|
||||
}
|
||||
uni.redirectTo({ url: loadingUrl });
|
||||
return;
|
||||
|
||||
+19
-15
@@ -29,21 +29,24 @@ 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 参数中)
|
||||
}
|
||||
|
||||
// 兜底:从 localStorage 恢复(redirect_uri 参数为主,localStorage 为备用)
|
||||
if (!this.action) {
|
||||
this.action = urlParams.get('action') || '';
|
||||
this.action = localStorage.getItem('__auth_action') || '';
|
||||
}
|
||||
// 同步获取 device_id
|
||||
if (!this.deviceId) {
|
||||
this.deviceId = urlParams.get('device_id') || '';
|
||||
}
|
||||
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') {
|
||||
// 获取用户信息流程
|
||||
@@ -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