Compare commits

..

10 Commits

Author SHA1 Message Date
kk 4e612b1c12 清除旧的回调标记
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 50s
2026-07-22 10:36:24 +08:00
kk d326912bd3 redirectTo改为reLaunch
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 46s
2026-07-22 10:03:13 +08:00
kk be976f939f 简化state参数
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 46s
2026-07-20 17:55:22 +08:00
kk e1f71fb220 简化state参数
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 1m7s
2026-07-20 17:45:44 +08:00
kk 558e1380db 正在获取用户信息
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 47s
2026-07-20 17:00:41 +08:00
kk 1b9602f66b 总数量显示订单总数
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 46s
2026-07-20 11:50:41 +08:00
kk a071f760d3 授权回调code支持auth_code
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 48s
2026-07-20 10:30:59 +08:00
kk 445d428d8b 授权获取用户信息scope是auth_user
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 1m12s
2026-07-17 17:45:24 +08:00
kk bbbd386e1e 修改scope
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 41s
2026-07-17 17:19:35 +08:00
kk fd3cd58123 scope参数问题处理
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 40s
2026-07-17 16:22:57 +08:00
4 changed files with 23 additions and 73 deletions
+9 -28
View File
@@ -42,39 +42,20 @@
} }
} }
// 3. 检查 URL 中是否有授权回调的 code // 3. 检查 URL 中是否有授权回调的 code(支付宝用 auth_code,微信用 code
const code = urlParams.get('code'); const code = urlParams.get('code') || urlParams.get('auth_code');
if (code) { if (code) {
// 有 code → 进入授权 Loading 页处理 // 有 code → 进入授权 Loading 页处理
// state 中解析 device_id 和 actionOAuth 标准保证 state 原样回传) // state 为 "base" 或 "userinfo",直接透传
let action = ''; const state = urlParams.get('state') || '';
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);
}
let loadingUrl = '/pages/auth/loading?code=' + encodeURIComponent(code); let loadingUrl = '/pages/auth/loading?code=' + encodeURIComponent(code);
if (action) { if (state) {
loadingUrl += '&action=' + action; loadingUrl += '&state=' + state;
} }
if (callbackDeviceId) { // 必须用 reLaunch:支付宝回调时当前页可能就是 loading 页,
loadingUrl += '&device_id=' + callbackDeviceId; // redirectTo 到同一页面不会重新触发 onLoad,导致请求卡住
} uni.reLaunch({ url: loadingUrl });
uni.redirectTo({ url: loadingUrl });
return; return;
} }
+12 -36
View File
@@ -24,6 +24,9 @@ export default {
this.action = options.action || ''; this.action = options.action || '';
// #ifdef H5 // #ifdef H5
// 每次进入页面清除旧的回调标记,防止上次异常退出后标记残留导致 startAuth 被跳过
uni.removeStorageSync('__auth_callback_done');
// Mock 模式:跳过微信 OAuth,直接登录 // Mock 模式:跳过微信 OAuth,直接登录
if (config.mockWechatLogin && this.action !== 'userinfo') { if (config.mockWechatLogin && this.action !== 'userinfo') {
this.mockLogin(); this.mockLogin();
@@ -38,28 +41,15 @@ export default {
code = urlParams.get('code') || urlParams.get('auth_code') || ''; code = urlParams.get('code') || urlParams.get('auth_code') || '';
} }
// 解析 state 参数(OAuth 标准保证 state 原样回传,包含 action 和 device_id // 解析 state 参数(OAuth 原样回传,"base" 或 "userinfo"
if (!this.action || !this.deviceId) { if (!this.action) {
const stateRaw = options.state || ''; const state = options.state || '';
if (stateRaw) { if (state === 'userinfo') {
try { this.action = 'userinfo';
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 兜底
}
} }
} }
// 兜底:从 localStorage 恢复(页面复用时 onLoad 不触发,localStorage 由跳转函数清理) // 兜底:从 localStorage 恢复(页面复用时 onLoad 不触发,localStorage 由跳转函数清理)
if (!this.action) {
this.action = localStorage.getItem('__auth_action') || '';
}
if (!this.deviceId) { if (!this.deviceId) {
this.deviceId = localStorage.getItem('__auth_device_id') || ''; this.deviceId = localStorage.getItem('__auth_device_id') || '';
} }
@@ -67,6 +57,7 @@ export default {
if (this.action === 'userinfo') { if (this.action === 'userinfo') {
// 获取用户信息流程 // 获取用户信息流程
this.statusText = '正在获取用户信息...';
if (code) { if (code) {
this.handleUserInfoCallback(code); this.handleUserInfoCallback(code);
} else { } else {
@@ -132,17 +123,11 @@ export default {
// 静默授权:微信用 snsapi_base,支付宝用 auth_base // 静默授权:微信用 snsapi_base,支付宝用 auth_base
const scopes = platform === 'alipay' ? 'auth_base' : 'snsapi_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', { const res = await gatewayGet('/api/v1/user/auth/url', {
app_no: appNo, app_no: appNo,
scopes: scopes, scopes: scopes,
redirect_uri: redirectUri, redirect_uri: redirectUri,
state: Object.keys(stateObj).length > 0 ? JSON.stringify(stateObj) : '', state: 'base',
}); });
const data = res.data || {}; const data = res.data || {};
@@ -297,7 +282,6 @@ export default {
this.statusText = '正在获取用户信息...'; this.statusText = '正在获取用户信息...';
// 存入 localStorage(页面复用时 onLoad 不会重新触发,需要从 localStorage 读取) // 存入 localStorage(页面复用时 onLoad 不会重新触发,需要从 localStorage 读取)
localStorage.setItem('__auth_action', 'userinfo');
if (this.deviceId) { if (this.deviceId) {
localStorage.setItem('__auth_device_id', this.deviceId); localStorage.setItem('__auth_device_id', this.deviceId);
} }
@@ -310,17 +294,11 @@ export default {
// 用户信息授权:微信用 snsapi_userinfo,支付宝用 auth_user // 用户信息授权:微信用 snsapi_userinfo,支付宝用 auth_user
const scopes = platform === 'alipay' ? 'auth_user' : 'snsapi_userinfo'; 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', { const res = await gatewayGet('/api/v1/user/auth/url', {
app_no: appNo, app_no: appNo,
scopes: scopes, scopes: scopes,
redirect_uri: redirectUri, redirect_uri: redirectUri,
state: JSON.stringify(stateObj), state: 'userinfo',
}); });
const data = res.data || {}; const data = res.data || {};
@@ -366,12 +344,11 @@ export default {
} }
uni.setStorageSync('__used_auth_code', code); uni.setStorageSync('__used_auth_code', code);
// 立即清除 URL 中的 code/action 参数,避免刷新重复处理 // 立即清除 URL 中的 code/state 参数,避免刷新重复处理
const url = new URL(window.location.href); const url = new URL(window.location.href);
url.searchParams.delete('code'); url.searchParams.delete('code');
url.searchParams.delete('auth_code'); url.searchParams.delete('auth_code');
url.searchParams.delete('state'); url.searchParams.delete('state');
url.searchParams.delete('action');
window.history.replaceState({}, '', url.toString()); window.history.replaceState({}, '', url.toString());
try { try {
@@ -421,7 +398,6 @@ export default {
? `/pages/index/index?device_id=${deviceId}&action=mine` ? `/pages/index/index?device_id=${deviceId}&action=mine`
: '/pages/index/index?action=mine'; : '/pages/index/index?action=mine';
localStorage.removeItem('__auth_device_id'); localStorage.removeItem('__auth_device_id');
localStorage.removeItem('__auth_action');
uni.removeStorageSync('__auth_callback_done'); uni.removeStorageSync('__auth_callback_done');
uni.redirectTo({ url }); uni.redirectTo({ url });
}, },
+1 -8
View File
@@ -334,7 +334,6 @@ export default {
try { try {
// 存入 localStorageloading 页面复用时 onLoad 不会重新触发,需要从 localStorage 读取) // 存入 localStorageloading 页面复用时 onLoad 不会重新触发,需要从 localStorage 读取)
localStorage.setItem('__auth_action', 'userinfo');
if (this.deviceId) { if (this.deviceId) {
localStorage.setItem('__auth_device_id', this.deviceId); localStorage.setItem('__auth_device_id', this.deviceId);
} }
@@ -344,12 +343,6 @@ export default {
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname 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 // 用户信息授权:微信用 snsapi_userinfo,支付宝用 auth_user
const platform = uni.getStorageSync('platform') || 'wechat'; const platform = uni.getStorageSync('platform') || 'wechat';
const scopes = platform === 'alipay' ? 'auth_user' : 'snsapi_userinfo'; const scopes = platform === 'alipay' ? 'auth_user' : 'snsapi_userinfo';
@@ -358,7 +351,7 @@ export default {
app_no: appNo, app_no: appNo,
scopes: scopes, scopes: scopes,
redirect_uri: redirectUri, redirect_uri: redirectUri,
state: JSON.stringify(stateObj), state: 'userinfo',
}); });
const data = res.data || {}; const data = res.data || {};
+1 -1
View File
@@ -30,7 +30,7 @@
<!-- 数量统计和筛选 --> <!-- 数量统计和筛选 -->
<view class="filter-bar"> <view class="filter-bar">
<text class="total-count">总数量: {{ filteredOrders.length }}</text> <text class="total-count">总数量: {{ total }}</text>
<view class="search-btn" @click="showFilterSidebar = true"> <view class="search-btn" @click="showFilterSidebar = true">
<text class="search-icon">🔍</text> <text class="search-icon">🔍</text>
</view> </view>