修改用户授权逻辑先静默授权,点击我的时才非静默授权
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 51s

This commit is contained in:
kk
2026-07-10 18:34:07 +08:00
parent 20649c67a9
commit 0fc854cd33
4 changed files with 159 additions and 97 deletions
+30 -23
View File
@@ -69,6 +69,7 @@
<script>
import { gatewayPost } from '@/utils/request.js';
import config from '@/config/env.js';
export default {
data() {
@@ -153,7 +154,7 @@ export default {
}, 1000);
},
// 注册
// 注册Mock 模式也走真实接口)
async handleRegister() {
if (!this.canSubmit) return;
@@ -183,16 +184,21 @@ export default {
const ret = res.data || {};
if (ret.code === 0 && ret.data) {
// 合并微信授权信息(头像、昵称)到 user_info
const authInfo = uni.getStorageSync('auth_info') || {};
const userInfo = {
...authInfo,
...ret.data.user_info,
};
// 保存 token 和用户信息
// 保存 token
uni.setStorageSync('token', ret.data.token);
uni.setStorageSync('user_info', userInfo);
// Mock 模式下,合并真实注册信息和 mock 配置
if (config.mockWechatLogin) {
const mockInfo = config.mockUser.user_info;
const userInfo = {
user_id: ret.data.user_id || mockInfo.user_id,
phone: this.phone, // 使用真实注册的手机号
nickname: mockInfo.nickname,
avatar: mockInfo.avatar,
};
uni.setStorageSync('user_info', userInfo);
console.log('[register] Mock 模式,合并用户信息:', userInfo);
}
// 清除临时数据
uni.removeStorageSync('temp_token');
@@ -200,19 +206,7 @@ export default {
uni.hideLoading();
uni.showToast({ title: '注册成功', icon: 'success' });
// 跳转到扫码时的页面(优先使用缓存的扫码URL)
setTimeout(() => {
const scanRedirectUrl = uni.getStorageSync('__scan_redirect_url');
uni.removeStorageSync('__scan_redirect_url'); // 使用后立即清除
const url = scanRedirectUrl
? scanRedirectUrl
: this.deviceId
? `/pages/index/index?device_id=${this.deviceId}`
: '/pages/index/index';
uni.redirectTo({ url });
}, 1500);
setTimeout(() => this.navigateToTarget(), 1500);
} else {
uni.hideLoading();
uni.showToast({ title: ret.message || '注册失败', icon: 'none' });
@@ -223,6 +217,19 @@ export default {
}
},
// 跳转到目标页面
navigateToTarget() {
const scanRedirectUrl = uni.getStorageSync('__scan_redirect_url');
uni.removeStorageSync('__scan_redirect_url');
const url = scanRedirectUrl
? scanRedirectUrl
: this.deviceId
? `/pages/index/index?device_id=${this.deviceId}`
: '/pages/index/index';
uni.redirectTo({ url });
},
showAgreement(type) {
const title = type === 'user' ? '用户协议' : '隐私政策';
uni.showToast({ title: title + '开发中', icon: 'none' });