Compare commits
9 Commits
v1.0.9-beta
...
v1.0.43
| Author | SHA1 | Date | |
|---|---|---|---|
| d326912bd3 | |||
| be976f939f | |||
| e1f71fb220 | |||
| 558e1380db | |||
| 1b9602f66b | |||
| a071f760d3 | |||
| 445d428d8b | |||
| bbbd386e1e | |||
| fd3cd58123 |
+9
-28
@@ -42,39 +42,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 检查 URL 中是否有授权回调的 code
|
||||
const code = urlParams.get('code');
|
||||
// 3. 检查 URL 中是否有授权回调的 code(支付宝用 auth_code,微信用 code)
|
||||
const code = urlParams.get('code') || urlParams.get('auth_code');
|
||||
|
||||
if (code) {
|
||||
// 有 code → 进入授权 Loading 页处理
|
||||
// 从 state 中解析 device_id 和 action(OAuth 标准保证 state 原样回传)
|
||||
let action = '';
|
||||
let callbackDeviceId = deviceId || '';
|
||||
try {
|
||||
const stateStr = urlParams.get('state');
|
||||
if (stateStr) {
|
||||
const stateObj = JSON.parse(decodeURIComponent(stateStr));
|
||||
action = stateObj.action || action;
|
||||
callbackDeviceId = stateObj.device_id || callbackDeviceId;
|
||||
}
|
||||
} catch (_) {
|
||||
// state 解析失败,忽略
|
||||
}
|
||||
// 存入 localStorage,确保 loading 页面复用时也能获取(redirectTo 可能不触发 onLoad)
|
||||
if (action) {
|
||||
localStorage.setItem('__auth_action', action);
|
||||
}
|
||||
if (callbackDeviceId) {
|
||||
localStorage.setItem('__auth_device_id', callbackDeviceId);
|
||||
}
|
||||
// state 为 "base" 或 "userinfo",直接透传
|
||||
const state = urlParams.get('state') || '';
|
||||
let loadingUrl = '/pages/auth/loading?code=' + encodeURIComponent(code);
|
||||
if (action) {
|
||||
loadingUrl += '&action=' + action;
|
||||
if (state) {
|
||||
loadingUrl += '&state=' + state;
|
||||
}
|
||||
if (callbackDeviceId) {
|
||||
loadingUrl += '&device_id=' + callbackDeviceId;
|
||||
}
|
||||
uni.redirectTo({ url: loadingUrl });
|
||||
// 必须用 reLaunch:支付宝回调时当前页可能就是 loading 页,
|
||||
// redirectTo 到同一页面不会重新触发 onLoad,导致请求卡住
|
||||
uni.reLaunch({ url: loadingUrl });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,28 +38,15 @@ export default {
|
||||
code = urlParams.get('code') || urlParams.get('auth_code') || '';
|
||||
}
|
||||
|
||||
// 解析 state 参数(OAuth 标准保证 state 原样回传,包含 action 和 device_id)
|
||||
if (!this.action || !this.deviceId) {
|
||||
const stateRaw = options.state || '';
|
||||
if (stateRaw) {
|
||||
try {
|
||||
const stateObj = JSON.parse(decodeURIComponent(stateRaw));
|
||||
if (!this.action && stateObj.action) {
|
||||
this.action = stateObj.action;
|
||||
}
|
||||
if (!this.deviceId && stateObj.device_id) {
|
||||
this.deviceId = stateObj.device_id;
|
||||
}
|
||||
} catch (_) {
|
||||
// state 解析失败,继续用 localStorage 兜底
|
||||
}
|
||||
// 解析 state 参数(OAuth 原样回传,"base" 或 "userinfo")
|
||||
if (!this.action) {
|
||||
const state = options.state || '';
|
||||
if (state === 'userinfo') {
|
||||
this.action = 'userinfo';
|
||||
}
|
||||
}
|
||||
|
||||
// 兜底:从 localStorage 恢复(页面复用时 onLoad 不触发,localStorage 由跳转函数清理)
|
||||
if (!this.action) {
|
||||
this.action = localStorage.getItem('__auth_action') || '';
|
||||
}
|
||||
if (!this.deviceId) {
|
||||
this.deviceId = localStorage.getItem('__auth_device_id') || '';
|
||||
}
|
||||
@@ -67,6 +54,7 @@ export default {
|
||||
|
||||
if (this.action === 'userinfo') {
|
||||
// 获取用户信息流程
|
||||
this.statusText = '正在获取用户信息...';
|
||||
if (code) {
|
||||
this.handleUserInfoCallback(code);
|
||||
} else {
|
||||
@@ -132,17 +120,11 @@ export default {
|
||||
// 静默授权:微信用 snsapi_base,支付宝用 auth_base
|
||||
const scopes = platform === 'alipay' ? 'auth_base' : 'snsapi_base';
|
||||
|
||||
// 构建 state(包含 device_id,回调时原样回传)
|
||||
const stateObj = {};
|
||||
if (this.deviceId) {
|
||||
stateObj.device_id = this.deviceId;
|
||||
}
|
||||
|
||||
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||
app_no: appNo,
|
||||
scopes: scopes,
|
||||
redirect_uri: redirectUri,
|
||||
state: Object.keys(stateObj).length > 0 ? JSON.stringify(stateObj) : '',
|
||||
state: 'base',
|
||||
});
|
||||
|
||||
const data = res.data || {};
|
||||
@@ -297,7 +279,6 @@ export default {
|
||||
this.statusText = '正在获取用户信息...';
|
||||
|
||||
// 存入 localStorage(页面复用时 onLoad 不会重新触发,需要从 localStorage 读取)
|
||||
localStorage.setItem('__auth_action', 'userinfo');
|
||||
if (this.deviceId) {
|
||||
localStorage.setItem('__auth_device_id', this.deviceId);
|
||||
}
|
||||
@@ -310,17 +291,11 @@ export default {
|
||||
// 用户信息授权:微信用 snsapi_userinfo,支付宝用 auth_user
|
||||
const scopes = platform === 'alipay' ? 'auth_user' : 'snsapi_userinfo';
|
||||
|
||||
// 构建 state(包含 action 和 device_id,回调时原样回传)
|
||||
const stateObj = { action: 'userinfo' };
|
||||
if (this.deviceId) {
|
||||
stateObj.device_id = this.deviceId;
|
||||
}
|
||||
|
||||
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||
app_no: appNo,
|
||||
scopes: scopes,
|
||||
redirect_uri: redirectUri,
|
||||
state: JSON.stringify(stateObj),
|
||||
state: 'userinfo',
|
||||
});
|
||||
|
||||
const data = res.data || {};
|
||||
@@ -366,12 +341,11 @@ export default {
|
||||
}
|
||||
uni.setStorageSync('__used_auth_code', code);
|
||||
|
||||
// 立即清除 URL 中的 code/action 参数,避免刷新重复处理
|
||||
// 立即清除 URL 中的 code/state 参数,避免刷新重复处理
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.delete('code');
|
||||
url.searchParams.delete('auth_code');
|
||||
url.searchParams.delete('state');
|
||||
url.searchParams.delete('action');
|
||||
window.history.replaceState({}, '', url.toString());
|
||||
|
||||
try {
|
||||
@@ -421,7 +395,6 @@ export default {
|
||||
? `/pages/index/index?device_id=${deviceId}&action=mine`
|
||||
: '/pages/index/index?action=mine';
|
||||
localStorage.removeItem('__auth_device_id');
|
||||
localStorage.removeItem('__auth_action');
|
||||
uni.removeStorageSync('__auth_callback_done');
|
||||
uni.redirectTo({ url });
|
||||
},
|
||||
|
||||
@@ -334,7 +334,6 @@ export default {
|
||||
|
||||
try {
|
||||
// 存入 localStorage(loading 页面复用时 onLoad 不会重新触发,需要从 localStorage 读取)
|
||||
localStorage.setItem('__auth_action', 'userinfo');
|
||||
if (this.deviceId) {
|
||||
localStorage.setItem('__auth_device_id', this.deviceId);
|
||||
}
|
||||
@@ -344,12 +343,6 @@ export default {
|
||||
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||
);
|
||||
|
||||
// 构建 state(包含 action 和 device_id,回调时原样回传)
|
||||
const stateObj = { action: 'userinfo' };
|
||||
if (this.deviceId) {
|
||||
stateObj.device_id = this.deviceId;
|
||||
}
|
||||
|
||||
// 用户信息授权:微信用 snsapi_userinfo,支付宝用 auth_user
|
||||
const platform = uni.getStorageSync('platform') || 'wechat';
|
||||
const scopes = platform === 'alipay' ? 'auth_user' : 'snsapi_userinfo';
|
||||
@@ -358,7 +351,7 @@ export default {
|
||||
app_no: appNo,
|
||||
scopes: scopes,
|
||||
redirect_uri: redirectUri,
|
||||
state: JSON.stringify(stateObj),
|
||||
state: 'userinfo',
|
||||
});
|
||||
|
||||
const data = res.data || {};
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
<!-- 数量统计和筛选 -->
|
||||
<view class="filter-bar">
|
||||
<text class="total-count">总数量: {{ filteredOrders.length }}</text>
|
||||
<text class="total-count">总数量: {{ total }}</text>
|
||||
<view class="search-btn" @click="showFilterSidebar = true">
|
||||
<text class="search-icon">🔍</text>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user