Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2560d9d529 | |||
| 6534723050 | |||
| f031501286 | |||
| 525f94cb80 | |||
| 127834e8dc |
@@ -0,0 +1 @@
|
|||||||
|
70011ed2d63c3cfa7094f5cb2a9aafea
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
2K94E8Rn63mn6Nys
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
sfIpUAfcT78BnMBv
|
||||||
+38
-41
@@ -1,6 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
import { initEnv } from '@/utils/env.js';
|
import { initEnv } from '@/utils/env.js';
|
||||||
import { handleAuthCallback, onAuthSuccess } from '@/utils/auth-guard.js';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
onLaunch: function(options) {
|
onLaunch: function(options) {
|
||||||
@@ -10,22 +9,51 @@
|
|||||||
initEnv();
|
initEnv();
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
// 2. 处理授权回调(URL 中带 code/auth_code 参数)
|
// 2. 解析 URL 路径中的设备编号(如 /A1036)
|
||||||
this.handleAuthRedirect();
|
let deviceId = '';
|
||||||
|
|
||||||
// 3. 解析 URL 路径中的设备编号(如 /A1036)
|
|
||||||
const path = window.location.pathname;
|
const path = window.location.pathname;
|
||||||
const segments = path.split('/').filter(Boolean);
|
const segments = path.split('/').filter(Boolean);
|
||||||
if (segments.length > 0) {
|
if (segments.length > 0) {
|
||||||
const last = segments[segments.length - 1];
|
const last = segments[segments.length - 1];
|
||||||
// 匹配设备编号格式:大写字母开头 + 大写字母/数字
|
|
||||||
if (/^[A-Z][A-Z0-9]+$/.test(last)) {
|
if (/^[A-Z][A-Z0-9]+$/.test(last)) {
|
||||||
uni.redirectTo({
|
deviceId = last;
|
||||||
url: '/pages/index/index?device_id=' + last
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. 检查 URL 中是否有授权回调的 code
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const code = urlParams.get('code');
|
||||||
|
|
||||||
|
if (code) {
|
||||||
|
// 有 code → 进入授权 Loading 页处理
|
||||||
|
const loadingUrl = deviceId
|
||||||
|
? `/pages/auth/loading?device_id=${deviceId}`
|
||||||
|
: '/pages/auth/loading';
|
||||||
|
uni.redirectTo({ url: loadingUrl });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 检查 JWT
|
||||||
|
const token = uni.getStorageSync('token');
|
||||||
|
|
||||||
|
if (token) {
|
||||||
|
// 有 JWT → 直接进入首页
|
||||||
|
const homeUrl = deviceId
|
||||||
|
? `/pages/index/index?device_id=${deviceId}`
|
||||||
|
: '/pages/index/scan';
|
||||||
|
uni.redirectTo({ url: homeUrl });
|
||||||
|
} else {
|
||||||
|
// 无 JWT → 进入授权 Loading 页
|
||||||
|
const loadingUrl = deviceId
|
||||||
|
? `/pages/auth/loading?device_id=${deviceId}`
|
||||||
|
: '/pages/auth/loading';
|
||||||
|
uni.redirectTo({ url: loadingUrl });
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifndef H5
|
||||||
|
// 小程序环境:直接进入扫码页
|
||||||
|
uni.redirectTo({ url: '/pages/index/scan' });
|
||||||
// #endif
|
// #endif
|
||||||
},
|
},
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
@@ -33,37 +61,6 @@
|
|||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
console.log('App Hide')
|
console.log('App Hide')
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
// #ifdef H5
|
|
||||||
async handleAuthRedirect() {
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
const code = urlParams.get('code') || urlParams.get('auth_code') || '';
|
|
||||||
|
|
||||||
if (!code) return;
|
|
||||||
|
|
||||||
// 有授权码,调用后端回调接口
|
|
||||||
const result = await handleAuthCallback();
|
|
||||||
if (result) {
|
|
||||||
onAuthSuccess(result);
|
|
||||||
|
|
||||||
// 清除 URL 中的 code 参数,避免刷新重复处理
|
|
||||||
const url = new URL(window.location.href);
|
|
||||||
url.searchParams.delete('code');
|
|
||||||
url.searchParams.delete('auth_code');
|
|
||||||
url.searchParams.delete('state');
|
|
||||||
window.history.replaceState({}, '', url.toString());
|
|
||||||
|
|
||||||
// 如果需要绑定手机号
|
|
||||||
if (result.need_bindphone) {
|
|
||||||
uni.setStorageSync('temp_token', result.temp_token);
|
|
||||||
uni.showToast({ title: '请绑定手机号完成注册', icon: 'none' });
|
|
||||||
} else {
|
|
||||||
uni.showToast({ title: '登录成功', icon: 'success' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// #endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
+2
-2
@@ -8,8 +8,8 @@ const dev = {
|
|||||||
// 网关地址(vms-gateway,端口 4001)— 用户授权、短信等接口走网关
|
// 网关地址(vms-gateway,端口 4001)— 用户授权、短信等接口走网关
|
||||||
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
||||||
|
|
||||||
// 授权回调地址(支付宝/微信 OAuth redirect_uri)
|
// 授权回调地址(微信 OAuth redirect_uri,必须 HTTPS,指向前端页面)
|
||||||
authRedirectUri: 'https://gateway.arklinksmart.cn/api/v1/user/auth/callback',
|
authRedirectUri: 'https://m.arklinksmart.cn/pages/auth/loading',
|
||||||
|
|
||||||
// 开发阶段硬编码 Token(生产环境应从登录流程获取)
|
// 开发阶段硬编码 Token(生产环境应从登录流程获取)
|
||||||
bearerToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRlZXB2ZW5kaW5nIiwic3ViIjoiMTY0MDI0MTEyNiIsImZyb20iOiJwb3MiLCJyb2xlIjoicG9zIiwibWFpbmJvYXJkX2lkIjoiVDEwMDIiLCJwb3Nfc24iOiIxNjQwMjQxMTI2IiwiaWF0IjoxNzc4NDkxOTA3LCJleHAiOjE3NzkwOTY3MDd9.DjscZtrTCr30XOngToUifxoel4q2EGES_uqGQernkvg',
|
bearerToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRlZXB2ZW5kaW5nIiwic3ViIjoiMTY0MDI0MTEyNiIsImZyb20iOiJwb3MiLCJyb2xlIjoicG9zIiwibWFpbmJvYXJkX2lkIjoiVDEwMDIiLCJwb3Nfc24iOiIxNjQwMjQxMTI2IiwiaWF0IjoxNzc4NDkxOTA3LCJleHAiOjE3NzkwOTY3MDd9.DjscZtrTCr30XOngToUifxoel4q2EGES_uqGQernkvg',
|
||||||
|
|||||||
+2
-2
@@ -8,8 +8,8 @@ const prod = {
|
|||||||
// 网关地址(vms-gateway)— 用户授权、短信等接口走网关
|
// 网关地址(vms-gateway)— 用户授权、短信等接口走网关
|
||||||
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
||||||
|
|
||||||
// 授权回调地址(支付宝/微信 OAuth redirect_uri)
|
// 授权回调地址(微信 OAuth redirect_uri,必须 HTTPS,指向前端页面)
|
||||||
authRedirectUri: 'https://gateway.arklinksmart.cn/api/v1/user/auth/callback',
|
authRedirectUri: 'https://m.arklinksmart.cn/pages/auth/loading',
|
||||||
|
|
||||||
// 生产环境 Token 从登录流程获取,此处为空
|
// 生产环境 Token 从登录流程获取,此处为空
|
||||||
bearerToken: '',
|
bearerToken: '',
|
||||||
|
|||||||
+9
-3
@@ -1,13 +1,19 @@
|
|||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
{
|
{
|
||||||
"path": "pages/register/register",
|
"path": "pages/index/scan",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/index/scan",
|
"path": "pages/auth/loading",
|
||||||
|
"style": {
|
||||||
|
"navigationStyle": "custom"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/register/register",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
@@ -43,4 +49,4 @@
|
|||||||
"navigationBarBackgroundColor": "#F8F8F8",
|
"navigationBarBackgroundColor": "#F8F8F8",
|
||||||
"backgroundColor": "#F8F8F8"
|
"backgroundColor": "#F8F8F8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,193 @@
|
|||||||
|
<template>
|
||||||
|
<view class="loading-page">
|
||||||
|
<view class="loading-spinner"></view>
|
||||||
|
<text class="loading-text">{{ statusText }}</text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import config from '@/config/env.js';
|
||||||
|
import { gatewayGet, gatewayPost } from '@/utils/request.js';
|
||||||
|
import { detectPlatform, getAppNo } from '@/utils/env.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
statusText: '正在登录...',
|
||||||
|
deviceId: '',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
onLoad(options) {
|
||||||
|
this.deviceId = options.device_id || '';
|
||||||
|
|
||||||
|
// #ifdef H5
|
||||||
|
// 检查 URL 中是否有授权回调的 code
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const code = urlParams.get('code');
|
||||||
|
|
||||||
|
if (code) {
|
||||||
|
// 有 code → 调用后端登录
|
||||||
|
this.handleCallback(code);
|
||||||
|
} else {
|
||||||
|
// 无 code → 发起 OAuth 授权
|
||||||
|
this.startAuth();
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifndef H5
|
||||||
|
// 小程序环境暂不支持,跳回扫码页
|
||||||
|
uni.redirectTo({ url: '/pages/index/scan' });
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* 发起 OAuth 授权
|
||||||
|
*/
|
||||||
|
async startAuth() {
|
||||||
|
const platform = detectPlatform();
|
||||||
|
const appNo = getAppNo(platform);
|
||||||
|
|
||||||
|
if (!appNo) {
|
||||||
|
// 非微信环境,跳转注册页(手机号注册)
|
||||||
|
this.goToRegister();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.statusText = '正在获取授权...';
|
||||||
|
|
||||||
|
// 回调地址必须是 HTTPS,使用配置文件中的地址
|
||||||
|
const redirectUri = config.authRedirectUri || (
|
||||||
|
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||||
|
);
|
||||||
|
|
||||||
|
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||||
|
app_no: appNo,
|
||||||
|
scopes: 'snsapi_userinfo',
|
||||||
|
redirect_uri: redirectUri,
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = res.data || {};
|
||||||
|
if (data.code === 0 && data.data && data.data.auth_url) {
|
||||||
|
// 跳转微信授权页
|
||||||
|
window.location.href = data.data.auth_url;
|
||||||
|
} else {
|
||||||
|
uni.showToast({ title: data.message || '获取授权失败', icon: 'none' });
|
||||||
|
setTimeout(() => this.goToScan(), 1500);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[Auth] startAuth error:', e);
|
||||||
|
uni.showToast({ title: '网络请求失败', icon: 'none' });
|
||||||
|
setTimeout(() => this.goToScan(), 1500);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理授权回调(从 URL 中获取 code 后调用后端 /login)
|
||||||
|
*/
|
||||||
|
async handleCallback(code) {
|
||||||
|
const appNo = uni.getStorageSync('app_no') || getAppNo(detectPlatform());
|
||||||
|
|
||||||
|
if (!appNo) {
|
||||||
|
uni.showToast({ title: '无法获取应用信息', icon: 'none' });
|
||||||
|
this.goToScan();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.statusText = '正在验证身份...';
|
||||||
|
|
||||||
|
const res = await gatewayPost('/api/v1/user/login', {
|
||||||
|
app_no: appNo,
|
||||||
|
code: code,
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = res.data || {};
|
||||||
|
if (data.code === 0 && data.data) {
|
||||||
|
const result = data.data;
|
||||||
|
|
||||||
|
// 清除 URL 中的 code 参数,避免刷新重复处理
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
url.searchParams.delete('code');
|
||||||
|
url.searchParams.delete('state');
|
||||||
|
window.history.replaceState({}, '', url.toString());
|
||||||
|
|
||||||
|
if (result.register) {
|
||||||
|
// 已注册 → 缓存 JWT → 跳转首页
|
||||||
|
uni.setStorageSync('token', result.token);
|
||||||
|
uni.setStorageSync('user_info', result.user_info);
|
||||||
|
this.goToHome();
|
||||||
|
} else {
|
||||||
|
// 未注册 → 缓存临时数据 → 跳转注册页
|
||||||
|
uni.setStorageSync('temp_token', result.temp_token);
|
||||||
|
uni.setStorageSync('auth_info', result.auth_info);
|
||||||
|
this.goToRegister();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uni.showToast({ title: data.message || '登录失败', icon: 'none' });
|
||||||
|
setTimeout(() => this.goToScan(), 1500);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[Auth] login error:', e);
|
||||||
|
uni.showToast({ title: '网络请求失败', icon: 'none' });
|
||||||
|
setTimeout(() => this.goToScan(), 1500);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
goToHome() {
|
||||||
|
const url = this.deviceId
|
||||||
|
? `/pages/index/index?device_id=${this.deviceId}`
|
||||||
|
: '/pages/index/index';
|
||||||
|
uni.redirectTo({ url });
|
||||||
|
},
|
||||||
|
|
||||||
|
goToRegister() {
|
||||||
|
const url = this.deviceId
|
||||||
|
? `/pages/register/register?device_id=${this.deviceId}`
|
||||||
|
: '/pages/register/register';
|
||||||
|
uni.redirectTo({ url });
|
||||||
|
},
|
||||||
|
|
||||||
|
goToScan() {
|
||||||
|
uni.redirectTo({ url: '/pages/index/scan' });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
page {
|
||||||
|
height: 100%;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 100vh;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spinner {
|
||||||
|
width: 64rpx;
|
||||||
|
height: 64rpx;
|
||||||
|
border: 6rpx solid #e5e5e5;
|
||||||
|
border-top-color: #2979ff;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 0.8s linear infinite;
|
||||||
|
margin-bottom: 32rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
+40
-17
@@ -67,24 +67,33 @@
|
|||||||
|
|
||||||
<!-- 底部导航栏 -->
|
<!-- 底部导航栏 -->
|
||||||
<view class="tab-bar">
|
<view class="tab-bar">
|
||||||
<view class="tab-item" :class="{ active: currentTab === 'home' }" @click="switchTab('home')">
|
<view class="tab-bar-row">
|
||||||
<view class="home-icon">
|
<view class="tab-item" :class="{ active: currentTab === 'home' }" @click="switchTab('home')">
|
||||||
<view class="home-roof"></view>
|
<view class="home-icon">
|
||||||
<view class="home-body"></view>
|
<view class="home-roof"></view>
|
||||||
|
<view class="home-body"></view>
|
||||||
|
</view>
|
||||||
|
<text class="tab-text">首页</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="door-btn-wrapper" @click="handleOpenDoor">
|
||||||
|
<view class="door-btn">开门</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="tab-item" :class="{ active: currentTab === 'mine' }" @click="switchTab('mine')">
|
||||||
|
<view class="mine-icon">
|
||||||
|
<view class="mine-head"></view>
|
||||||
|
<view class="mine-body"></view>
|
||||||
|
</view>
|
||||||
|
<text class="tab-text">我的</text>
|
||||||
</view>
|
</view>
|
||||||
<text class="tab-text">首页</text>
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="door-btn-wrapper" @click="handleOpenDoor">
|
<!-- 支付分信息(仅微信环境显示) -->
|
||||||
<view class="door-btn">开门</view>
|
<view v-if="isWechat" class="payscore-info">
|
||||||
</view>
|
<image class="payscore-logo" src="/static/payscore-logo.png" mode="aspectFit" />
|
||||||
|
<view class="payscore-divider"></view>
|
||||||
<view class="tab-item" :class="{ active: currentTab === 'mine' }" @click="switchTab('mine')">
|
<text class="payscore-text">微信支付分 | 550分及以上优享</text>
|
||||||
<view class="mine-icon">
|
|
||||||
<view class="mine-head"></view>
|
|
||||||
<view class="mine-body"></view>
|
|
||||||
</view>
|
|
||||||
<text class="tab-text">我的</text>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -169,6 +178,7 @@ export default {
|
|||||||
{ title: '公众号信息', action: 'qrcode' }
|
{ title: '公众号信息', action: 'qrcode' }
|
||||||
],
|
],
|
||||||
servicePhone: config.servicePhone,
|
servicePhone: config.servicePhone,
|
||||||
|
isWechat: false,
|
||||||
isDev: process.env.NODE_ENV === 'development',
|
isDev: process.env.NODE_ENV === 'development',
|
||||||
vconsoleEnabled: false
|
vconsoleEnabled: false
|
||||||
};
|
};
|
||||||
@@ -194,6 +204,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
|
// 检测是否在微信环境中打开
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
this.isWechat = true;
|
||||||
|
// #endif
|
||||||
|
// #ifdef H5
|
||||||
|
this.isWechat = /MicroMessenger/i.test(navigator.userAgent);
|
||||||
|
// #endif
|
||||||
|
|
||||||
// 支持通过 tab 参数切换到"我的"页面
|
// 支持通过 tab 参数切换到"我的"页面
|
||||||
if (options.tab === 'mine') {
|
if (options.tab === 'mine') {
|
||||||
this.currentTab = 'mine';
|
this.currentTab = 'mine';
|
||||||
@@ -337,10 +355,11 @@ page { height: 100%; background-color: #fff; }
|
|||||||
.price-num { font-size: 32rpx; }
|
.price-num { font-size: 32rpx; }
|
||||||
|
|
||||||
/* 底部占位 */
|
/* 底部占位 */
|
||||||
.bottom-spacer { height: 160rpx; }
|
.bottom-spacer { height: 200rpx; }
|
||||||
|
|
||||||
/* 底部导航栏 */
|
/* 底部导航栏 */
|
||||||
.tab-bar { position: absolute; bottom: 0; left: 0; right: 0; height: 120rpx; background: #fff; display: flex; align-items: center; justify-content: space-around; box-shadow: 0 -2rpx 16rpx rgba(0,0,0,0.08); z-index: 999; padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); }
|
.tab-bar { position: absolute; bottom: 0; left: 0; right: 0; background: #fff; display: flex; flex-direction: column; align-items: center; box-shadow: 0 -2rpx 16rpx rgba(0,0,0,0.08); z-index: 999; padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); }
|
||||||
|
.tab-bar-row { width: 100%; height: 120rpx; display: flex; align-items: center; justify-content: space-around; }
|
||||||
.tab-bar .tab-item { flex: 1; display: flex; align-items: center; justify-content: center; height: 100%; }
|
.tab-bar .tab-item { flex: 1; display: flex; align-items: center; justify-content: center; height: 100%; }
|
||||||
.tab-bar .tab-text { font-size: 28rpx; color: #999; font-weight: normal; }
|
.tab-bar .tab-text { font-size: 28rpx; color: #999; font-weight: normal; }
|
||||||
.tab-bar .tab-item.active .tab-text { color: #2979ff; }
|
.tab-bar .tab-item.active .tab-text { color: #2979ff; }
|
||||||
@@ -413,6 +432,10 @@ page { height: 100%; background-color: #fff; }
|
|||||||
}
|
}
|
||||||
.door-btn-wrapper { position: relative; display: flex; align-items: center; justify-content: center; margin-top: -80rpx; }
|
.door-btn-wrapper { position: relative; display: flex; align-items: center; justify-content: center; margin-top: -80rpx; }
|
||||||
.door-btn { width: 160rpx; height: 160rpx; border-radius: 50%; background: linear-gradient(135deg, #2979ff, #1e60e0); color: #fff; font-size: 38rpx; font-weight: bold; display: flex; align-items: center; justify-content: center; box-shadow: 0 10rpx 36rpx rgba(41,121,255,0.55); }
|
.door-btn { width: 160rpx; height: 160rpx; border-radius: 50%; background: linear-gradient(135deg, #2979ff, #1e60e0); color: #fff; font-size: 38rpx; font-weight: bold; display: flex; align-items: center; justify-content: center; box-shadow: 0 10rpx 36rpx rgba(41,121,255,0.55); }
|
||||||
|
.payscore-info { display: flex; align-items: center; padding-bottom: 16rpx; }
|
||||||
|
.payscore-logo { width: 34rpx; height: 34rpx; }
|
||||||
|
.payscore-divider { width: 2rpx; height: 24rpx; background-color: rgba(102, 102, 102, 0.6); margin: 0 10rpx; }
|
||||||
|
.payscore-text { font-size: 24rpx; color: #666; white-space: nowrap; }
|
||||||
|
|
||||||
/* 空状态 / Loading */
|
/* 空状态 / Loading */
|
||||||
.empty-tip, .loading-tip { text-align: center; padding: 60rpx; color: #999; font-size: 28rpx; }
|
.empty-tip, .loading-tip { text-align: center; padding: 60rpx; color: #999; font-size: 28rpx; }
|
||||||
|
|||||||
@@ -67,7 +67,15 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
// 1. query 参数中携带设备编号
|
// 1. 检查 JWT(App.vue 已处理首次跳转,这里兜底)
|
||||||
|
const token = uni.getStorageSync('token');
|
||||||
|
if (!token) {
|
||||||
|
// 无 JWT → 跳转授权 Loading 页
|
||||||
|
uni.redirectTo({ url: '/pages/auth/loading' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 有 JWT + query 参数中携带设备编号
|
||||||
if (options.device_id) {
|
if (options.device_id) {
|
||||||
uni.redirectTo({
|
uni.redirectTo({
|
||||||
url: '/pages/index/index?device_id=' + options.device_id,
|
url: '/pages/index/index?device_id=' + options.device_id,
|
||||||
@@ -76,7 +84,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
// 2. URL 路径中携带设备编号(如 http://xxx/A1036)
|
// 3. URL 路径中携带设备编号(如 http://xxx/A1036)
|
||||||
const path = window.location.pathname;
|
const path = window.location.pathname;
|
||||||
const segments = path.split('/').filter(Boolean);
|
const segments = path.split('/').filter(Boolean);
|
||||||
if (segments.length > 0) {
|
if (segments.length > 0) {
|
||||||
|
|||||||
@@ -6,6 +6,12 @@
|
|||||||
<view class="subtitle">请输入手机号获取验证码完成注册</view>
|
<view class="subtitle">请输入手机号获取验证码完成注册</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 用户信息展示(来自微信授权) -->
|
||||||
|
<view v-if="authInfo.nickname" class="auth-info">
|
||||||
|
<image class="auth-avatar" :src="authInfo.avatar || '/static/default-avatar.png'" mode="aspectFill" />
|
||||||
|
<text class="auth-nickname">{{ authInfo.nickname }}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
<!-- 表单区域 -->
|
<!-- 表单区域 -->
|
||||||
<view class="form-area">
|
<view class="form-area">
|
||||||
<!-- 手机号 -->
|
<!-- 手机号 -->
|
||||||
@@ -62,8 +68,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import config from '@/config/env.js';
|
import { gatewayPost } from '@/utils/request.js';
|
||||||
import { post } from '@/utils/request.js';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@@ -71,7 +76,10 @@ export default {
|
|||||||
phone: '',
|
phone: '',
|
||||||
code: '',
|
code: '',
|
||||||
countdown: 0,
|
countdown: 0,
|
||||||
timer: null
|
timer: null,
|
||||||
|
tempToken: '',
|
||||||
|
authInfo: { nickname: '', avatar: '' },
|
||||||
|
deviceId: '',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -79,8 +87,22 @@ export default {
|
|||||||
return this.phone.length === 11 && this.code.length >= 4;
|
return this.phone.length === 11 && this.code.length >= 4;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onLoad(options) {
|
||||||
|
this.deviceId = options.device_id || '';
|
||||||
|
|
||||||
|
// 从缓存读取授权信息(loading 页写入)
|
||||||
|
this.tempToken = uni.getStorageSync('temp_token') || '';
|
||||||
|
const cachedAuthInfo = uni.getStorageSync('auth_info');
|
||||||
|
if (cachedAuthInfo) {
|
||||||
|
this.authInfo = cachedAuthInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有 temp_token,提示用户重新授权
|
||||||
|
if (!this.tempToken) {
|
||||||
|
uni.showToast({ title: '授权信息已过期,请重新登录', icon: 'none' });
|
||||||
|
}
|
||||||
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
// 清除定时器
|
|
||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
clearInterval(this.timer);
|
clearInterval(this.timer);
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
@@ -91,15 +113,21 @@ export default {
|
|||||||
async handleGetCode() {
|
async handleGetCode() {
|
||||||
if (this.countdown > 0) return;
|
if (this.countdown > 0) return;
|
||||||
|
|
||||||
// 验证手机号
|
|
||||||
if (!/^1[3-9]\d{9}$/.test(this.phone)) {
|
if (!/^1[3-9]\d{9}$/.test(this.phone)) {
|
||||||
uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
|
uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.tempToken) {
|
||||||
|
uni.showToast({ title: '授权信息已过期,请重新登录', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await post('/auth/send-sms-code', {
|
const res = await gatewayPost('/api/v1/user/sms/send', {
|
||||||
phone: this.phone
|
phone: this.phone,
|
||||||
|
temp_token: this.tempToken,
|
||||||
|
purpose: 'register',
|
||||||
});
|
});
|
||||||
|
|
||||||
const ret = res.data || {};
|
const ret = res.data || {};
|
||||||
@@ -114,7 +142,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 开始倒计时
|
|
||||||
startCountdown() {
|
startCountdown() {
|
||||||
this.countdown = 60;
|
this.countdown = 60;
|
||||||
this.timer = setInterval(() => {
|
this.timer = setInterval(() => {
|
||||||
@@ -130,51 +157,49 @@ export default {
|
|||||||
async handleRegister() {
|
async handleRegister() {
|
||||||
if (!this.canSubmit) return;
|
if (!this.canSubmit) return;
|
||||||
|
|
||||||
// 验证手机号
|
|
||||||
if (!/^1[3-9]\d{9}$/.test(this.phone)) {
|
if (!/^1[3-9]\d{9}$/.test(this.phone)) {
|
||||||
uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
|
uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证验证码
|
|
||||||
if (this.code.length < 4) {
|
if (this.code.length < 4) {
|
||||||
uni.showToast({ title: '请输入验证码', icon: 'none' });
|
uni.showToast({ title: '请输入验证码', icon: 'none' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.tempToken) {
|
||||||
|
uni.showToast({ title: '授权信息已过期,请重新登录', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uni.showLoading({ title: '注册中...' });
|
uni.showLoading({ title: '注册中...' });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await post('/auth/register', {
|
const res = await gatewayPost('/api/v1/user/register', {
|
||||||
|
temp_token: this.tempToken,
|
||||||
phone: this.phone,
|
phone: this.phone,
|
||||||
code: this.code
|
code: this.code,
|
||||||
});
|
});
|
||||||
|
|
||||||
const ret = res.data || {};
|
const ret = res.data || {};
|
||||||
if (ret.code === 0) {
|
if (ret.code === 0 && ret.data) {
|
||||||
// 保存 token
|
// 保存 token 和用户信息
|
||||||
const token = ret.data && ret.data.token;
|
uni.setStorageSync('token', ret.data.token);
|
||||||
if (token) {
|
uni.setStorageSync('user_info', ret.data.user_info);
|
||||||
uni.setStorageSync('token', token);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存用户信息
|
// 清除临时数据
|
||||||
const userInfo = ret.data && ret.data.userInfo;
|
uni.removeStorageSync('temp_token');
|
||||||
if (userInfo) {
|
uni.removeStorageSync('auth_info');
|
||||||
uni.setStorageSync('userInfo', userInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
uni.showToast({ title: '注册成功', icon: 'success' });
|
uni.showToast({ title: '注册成功', icon: 'success' });
|
||||||
|
|
||||||
// 返回上一页或跳转首页
|
// 跳转首页
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const pages = getCurrentPages();
|
const url = this.deviceId
|
||||||
if (pages.length > 1) {
|
? `/pages/index/index?device_id=${this.deviceId}`
|
||||||
uni.navigateBack();
|
: '/pages/index/index';
|
||||||
} else {
|
uni.redirectTo({ url });
|
||||||
uni.redirectTo({ url: '/pages/index/index' });
|
|
||||||
}
|
|
||||||
}, 1500);
|
}, 1500);
|
||||||
} else {
|
} else {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
@@ -186,7 +211,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 显示协议
|
|
||||||
showAgreement(type) {
|
showAgreement(type) {
|
||||||
const title = type === 'user' ? '用户协议' : '隐私政策';
|
const title = type === 'user' ? '用户协议' : '隐私政策';
|
||||||
uni.showToast({ title: title + '开发中', icon: 'none' });
|
uni.showToast({ title: title + '开发中', icon: 'none' });
|
||||||
@@ -210,7 +234,7 @@ page {
|
|||||||
/* 顶部标题 */
|
/* 顶部标题 */
|
||||||
.header {
|
.header {
|
||||||
padding-top: 180rpx;
|
padding-top: 180rpx;
|
||||||
margin-bottom: 80rpx;
|
margin-bottom: 40rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
@@ -225,6 +249,29 @@ page {
|
|||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 微信授权信息 */
|
||||||
|
.auth-info {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 24rpx 0;
|
||||||
|
margin-bottom: 40rpx;
|
||||||
|
border-bottom: 1rpx solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-avatar {
|
||||||
|
width: 80rpx;
|
||||||
|
height: 80rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-right: 20rpx;
|
||||||
|
background-color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-nickname {
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #333;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
/* 表单区域 */
|
/* 表单区域 */
|
||||||
.form-area {
|
.form-area {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
+17
-184
@@ -1,20 +1,12 @@
|
|||||||
/**
|
/**
|
||||||
* 用户授权工具
|
* 用户授权工具
|
||||||
* 登录检查、授权跳转、回调处理、绑定手机号
|
* 登录检查、授权跳转、退出登录
|
||||||
*
|
*
|
||||||
* 授权相关接口(auth/url、auth/callback、sms/send、bindPhone)走网关 apiGatewayUrl
|
* 新流程:
|
||||||
* 业务接口(商品列表等)走 apiBaseUrl
|
* - App.vue 检查 JWT,无则跳转 /pages/auth/loading
|
||||||
|
* - loading 页发起 OAuth → 获取 code → 调用 /login
|
||||||
|
* - 未注册用户跳转 /pages/register/register
|
||||||
*/
|
*/
|
||||||
import config from '@/config/env.js';
|
|
||||||
import { gatewayGet, gatewayPost } from './request.js';
|
|
||||||
|
|
||||||
// 场景提示文案
|
|
||||||
const SCENE_TIPS = {
|
|
||||||
order: '登录后即可查看订单',
|
|
||||||
mine: '登录后即可查看个人信息',
|
|
||||||
pay: '登录后即可下单购买',
|
|
||||||
bindPhone: '需要绑定手机号完成登录',
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查是否已登录
|
* 检查是否已登录
|
||||||
@@ -25,13 +17,19 @@ export function isLoggedIn() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查登录状态,未登录时弹窗引导授权
|
* 检查登录状态,未登录时弹窗引导
|
||||||
* @param {string} scene - 触发场景:'order' | 'mine' | 'pay' | 'bindPhone'
|
* @param {string} scene - 触发场景:'order' | 'mine' | 'pay'
|
||||||
* @returns {boolean} 是否已登录
|
* @returns {boolean} 是否已登录
|
||||||
*/
|
*/
|
||||||
export function checkLoginWithPrompt(scene = '') {
|
export function checkLoginWithPrompt(scene = '') {
|
||||||
if (isLoggedIn()) return true;
|
if (isLoggedIn()) return true;
|
||||||
|
|
||||||
|
const SCENE_TIPS = {
|
||||||
|
order: '登录后即可查看订单',
|
||||||
|
mine: '登录后即可查看个人信息',
|
||||||
|
pay: '登录后即可下单购买',
|
||||||
|
};
|
||||||
|
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
content: SCENE_TIPS[scene] || '需要登录后操作',
|
content: SCENE_TIPS[scene] || '需要登录后操作',
|
||||||
@@ -39,7 +37,8 @@ export function checkLoginWithPrompt(scene = '') {
|
|||||||
cancelText: '暂不',
|
cancelText: '暂不',
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
startAuth();
|
// 跳转到授权 Loading 页
|
||||||
|
uni.redirectTo({ url: '/pages/auth/loading' });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -48,153 +47,15 @@ export function checkLoginWithPrompt(scene = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查登录状态,未登录时静默跳转授权(不弹窗)
|
* 检查登录状态,未登录时静默跳转
|
||||||
* @returns {boolean} 是否已登录
|
* @returns {boolean} 是否已登录
|
||||||
*/
|
*/
|
||||||
export function requireLogin() {
|
export function requireLogin() {
|
||||||
if (isLoggedIn()) return true;
|
if (isLoggedIn()) return true;
|
||||||
startAuth();
|
uni.redirectTo({ url: '/pages/auth/loading' });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发起授权跳转
|
|
||||||
* 获取 auth_url 后跳转到微信/支付宝授权页
|
|
||||||
*/
|
|
||||||
export async function startAuth() {
|
|
||||||
const appNo = uni.getStorageSync('app_no') || '';
|
|
||||||
|
|
||||||
if (!appNo) {
|
|
||||||
uni.showToast({ title: '当前环境不支持授权', icon: 'none' });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await gatewayGet('/api/v1/user/auth/url', {
|
|
||||||
app_no: appNo,
|
|
||||||
scopes: '',
|
|
||||||
redirect_uri: config.authRedirectUri || '',
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = res.data || {};
|
|
||||||
if (data.code === 0 && data.data && data.data.auth_url) {
|
|
||||||
// #ifdef H5
|
|
||||||
window.location.href = data.data.auth_url;
|
|
||||||
// #endif
|
|
||||||
// #ifndef H5
|
|
||||||
// 小程序环境走其他授权方式
|
|
||||||
uni.setStorageSync('pending_auth', true);
|
|
||||||
// #endif
|
|
||||||
} else {
|
|
||||||
uni.showToast({ title: data.message || '获取授权地址失败', icon: 'none' });
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('[Auth] startAuth error:', e);
|
|
||||||
uni.showToast({ title: '网络请求失败', icon: 'none' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理授权回调
|
|
||||||
* 解析 URL 中的 code/auth_code 参数,调用后端回调接口
|
|
||||||
* @returns {Promise<Object>} 回调结果
|
|
||||||
*/
|
|
||||||
export async function handleAuthCallback() {
|
|
||||||
// #ifdef H5
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
const code = urlParams.get('code') || urlParams.get('auth_code') || '';
|
|
||||||
const appNo = urlParams.get('state') || uni.getStorageSync('app_no') || '';
|
|
||||||
|
|
||||||
if (!code) return null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await gatewayGet('/api/v1/user/auth/callback', {
|
|
||||||
app_no: appNo,
|
|
||||||
code,
|
|
||||||
state: appNo,
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = res.data || {};
|
|
||||||
if (data.code === 0 && data.data) {
|
|
||||||
return data.data;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} catch (e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// #ifndef H5
|
|
||||||
return null;
|
|
||||||
// #endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 授权成功后处理
|
|
||||||
* 缴存 token 和用户信息
|
|
||||||
* @param {Object} authResult - 后端返回的授权结果
|
|
||||||
*/
|
|
||||||
export function onAuthSuccess(authResult) {
|
|
||||||
if (!authResult) return;
|
|
||||||
|
|
||||||
const { token, user_info, auth_info } = authResult;
|
|
||||||
|
|
||||||
if (token) {
|
|
||||||
uni.setStorageSync('token', token);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user_info) {
|
|
||||||
uni.setStorageSync('user_info', user_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auth_info) {
|
|
||||||
uni.setStorageSync('auth_info', auth_info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送短信验证码
|
|
||||||
* @param {string} phone - 手机号
|
|
||||||
* @param {string} tempToken - 临时 token
|
|
||||||
* @returns {Promise<Object>}
|
|
||||||
*/
|
|
||||||
export async function sendSmsCode(phone, tempToken) {
|
|
||||||
const res = await gatewayPost('/api/v1/user/sms/send', {
|
|
||||||
phone,
|
|
||||||
temp_token: tempToken,
|
|
||||||
purpose: 'bindPhone',
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = res.data || {};
|
|
||||||
return data.code === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 绑定手机号
|
|
||||||
* @param {string} tempToken - 临时 token
|
|
||||||
* @param {string} phone - 手机号
|
|
||||||
* @param {string} code - 验证码
|
|
||||||
* @returns {Promise<Object>} 绑定结果(含 token 和 user_info)
|
|
||||||
*/
|
|
||||||
export async function bindPhone(tempToken, phone, code) {
|
|
||||||
const res = await gatewayPost('/api/v1/user/bindPhone', {
|
|
||||||
temp_token: tempToken,
|
|
||||||
phone,
|
|
||||||
code,
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = res.data || {};
|
|
||||||
if (data.code === 0 && data.data) {
|
|
||||||
// 绑定成功,缓存 token 和用户信息
|
|
||||||
onAuthSuccess(data.data);
|
|
||||||
uni.removeStorageSync('temp_token');
|
|
||||||
return data.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
uni.showToast({ title: data.message || '绑定失败', icon: 'none' });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出登录
|
* 退出登录
|
||||||
*/
|
*/
|
||||||
@@ -216,31 +77,3 @@ export function getCachedUserInfo() {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 显示绑定手机号弹窗
|
|
||||||
* @param {string} tempToken - 临时 token
|
|
||||||
* @param {Function} onSuccess - 绑定成功回调
|
|
||||||
*/
|
|
||||||
export function showBindPhoneDialog(tempToken, onSuccess) {
|
|
||||||
let phone = '';
|
|
||||||
let code = '';
|
|
||||||
let countdown = 0;
|
|
||||||
let timer = null;
|
|
||||||
|
|
||||||
// 使用 uni.showModal 不够灵活,这里用自定义弹窗
|
|
||||||
// 简化实现:先弹出手机号输入
|
|
||||||
uni.showModal({
|
|
||||||
title: '绑定手机号',
|
|
||||||
content: '请先绑定手机号完成注册',
|
|
||||||
confirmText: '去绑定',
|
|
||||||
cancelText: '取消',
|
|
||||||
success: async (res) => {
|
|
||||||
if (res.confirm) {
|
|
||||||
// 跳转到绑定手机号页面(预留)
|
|
||||||
// 后续可实现专门的绑定手机号页面
|
|
||||||
uni.showToast({ title: '绑定手机号功能开发中', icon: 'none' });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -37,8 +37,14 @@ export function request(options = {}) {
|
|||||||
...options.header,
|
...options.header,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 公开接口(授权相关)不带 Authorization,避免 CORS 预检和 JWT 拦截
|
// 公开接口(授权/登录/注册相关)不带 Authorization,避免 CORS 预检和 JWT 拦截
|
||||||
const publicPaths = ['/api/v1/user/auth/url', '/api/v1/user/auth/callback'];
|
const publicPaths = [
|
||||||
|
'/api/v1/user/auth/url',
|
||||||
|
'/api/v1/user/auth/callback',
|
||||||
|
'/api/v1/user/login',
|
||||||
|
'/api/v1/user/register',
|
||||||
|
'/api/v1/user/sms/send',
|
||||||
|
];
|
||||||
const isPublic = publicPaths.some((p) => url.includes(p));
|
const isPublic = publicPaths.some((p) => url.includes(p));
|
||||||
|
|
||||||
if (token && !isPublic) {
|
if (token && !isPublic) {
|
||||||
|
|||||||
+25
-1
@@ -1,8 +1,31 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import uni from '@dcloudio/vite-plugin-uni'
|
import uni from '@dcloudio/vite-plugin-uni'
|
||||||
|
import { existsSync, readFileSync } from 'fs'
|
||||||
|
import { resolve } from 'path'
|
||||||
|
|
||||||
|
// 开发服务器:显式处理 public 目录下的静态文件,避免被 SPA history 路由拦截
|
||||||
|
function servePublicFiles() {
|
||||||
|
return {
|
||||||
|
name: 'serve-public-files',
|
||||||
|
configureServer(server) {
|
||||||
|
server.middlewares.use((req, res, next) => {
|
||||||
|
if (req.url) {
|
||||||
|
const filePath = resolve(__dirname, 'public', req.url.slice(1))
|
||||||
|
if (existsSync(filePath) && filePath.endsWith('.txt')) {
|
||||||
|
const content = readFileSync(filePath, 'utf-8')
|
||||||
|
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
|
||||||
|
res.end(content)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [uni()],
|
plugins: [servePublicFiles(), uni()],
|
||||||
css: {
|
css: {
|
||||||
preprocessorOptions: {
|
preprocessorOptions: {
|
||||||
scss: {
|
scss: {
|
||||||
@@ -10,4 +33,5 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
publicDir: 'public',
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user