Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 925ebe9bb9 | |||
| 258fa4a9f5 | |||
| 45147426e0 | |||
| 7b2e4dc72e | |||
| 0fc854cd33 | |||
| 20649c67a9 | |||
| 3a154198e9 | |||
| c84c9df5d4 | |||
| 71606ebfe5 | |||
| a7e0366fb7 | |||
| 5bb31516a0 | |||
| 2560d9d529 | |||
| 6534723050 | |||
| f031501286 | |||
| 525f94cb80 | |||
| 127834e8dc | |||
| e7d4e6cd51 | |||
| 6e4c831870 | |||
| ff544b9766 | |||
| 9c966dde26 |
@@ -124,10 +124,13 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 确保构建产物可读
|
||||
chmod -R a+r "$H5_SOURCE_DIR"
|
||||
|
||||
# 使用 rsync 同步文件
|
||||
# 修正: 将 -e 参数移到前面
|
||||
rsync -rltzv --delete --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r \
|
||||
-e "ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no" \
|
||||
rsync -rltvz --delete \
|
||||
--no-perms --no-times --no-owner --no-group \
|
||||
-e "ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no" \
|
||||
"$H5_SOURCE_DIR/" \
|
||||
"root@${TARGET}:${WEB_ROOT}/"
|
||||
|
||||
|
||||
+2
-2
@@ -6,8 +6,8 @@ build/
|
||||
# --- 依赖目录 ---
|
||||
node_modules/
|
||||
|
||||
# --- uni-app 插件模块 ---
|
||||
uni_modules/
|
||||
# --- uni-app 插件模块 (仅忽略根目录,src/uni_modules 是项目代码) ---
|
||||
/uni_modules/
|
||||
|
||||
# --- 编辑器配置与缓存 ---
|
||||
.vscode/
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
70011ed2d63c3cfa7094f5cb2a9aafea
|
||||
@@ -0,0 +1 @@
|
||||
2K94E8Rn63mn6Nys
|
||||
@@ -0,0 +1 @@
|
||||
sfIpUAfcT78BnMBv
|
||||
+89
-45
@@ -1,31 +1,106 @@
|
||||
<script>
|
||||
import { initEnv } from '@/utils/env.js';
|
||||
import { handleAuthCallback, onAuthSuccess } from '@/utils/auth-guard.js';
|
||||
import config from '@/config/env.js';
|
||||
|
||||
export default {
|
||||
onLaunch: function(options) {
|
||||
console.log('App Launch')
|
||||
|
||||
// 0. Mock 模式:仅首次进入时清除登录状态(刷新时保留)
|
||||
if (config.mockWechatLogin) {
|
||||
const mockInitialized = uni.getStorageSync('__mock_initialized');
|
||||
if (!mockInitialized) {
|
||||
uni.removeStorageSync('token');
|
||||
uni.removeStorageSync('user_info');
|
||||
uni.removeStorageSync('temp_token');
|
||||
uni.removeStorageSync('auth_info');
|
||||
uni.setStorageSync('__mock_initialized', 'true');
|
||||
console.log('[Mock] 首次进入,清除登录状态');
|
||||
} else {
|
||||
console.log('[Mock] 刷新页面,保留登录状态');
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 环境检测 + 缓存 app_no/platform
|
||||
initEnv();
|
||||
|
||||
// #ifdef H5
|
||||
// 2. 处理授权回调(URL 中带 code/auth_code 参数)
|
||||
this.handleAuthRedirect();
|
||||
// 2. 解析设备编号:优先从 query 参数获取,其次从路径解析
|
||||
let deviceId = '';
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
deviceId = urlParams.get('device_id') || '';
|
||||
|
||||
// 3. 解析 URL 路径中的设备编号(如 /A1036)
|
||||
const path = window.location.pathname;
|
||||
const segments = path.split('/').filter(Boolean);
|
||||
if (segments.length > 0) {
|
||||
const last = segments[segments.length - 1];
|
||||
// 匹配设备编号格式:大写字母开头 + 大写字母/数字
|
||||
if (/^[A-Z][A-Z0-9]+$/.test(last)) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/index/index?device_id=' + last
|
||||
});
|
||||
return;
|
||||
// 兜底:从路径解析(如 /N1154)
|
||||
if (!deviceId) {
|
||||
const path = window.location.pathname;
|
||||
const segments = path.split('/').filter(Boolean);
|
||||
if (segments.length > 0) {
|
||||
const last = segments[segments.length - 1];
|
||||
if (/^[A-Z][A-Z0-9]+$/.test(last)) {
|
||||
deviceId = last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 检查 URL 中是否有授权回调的 code
|
||||
const code = urlParams.get('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 解析失败,忽略
|
||||
}
|
||||
let loadingUrl = '/pages/auth/loading?code=' + encodeURIComponent(code);
|
||||
if (action) {
|
||||
loadingUrl += '&action=' + action;
|
||||
}
|
||||
if (callbackDeviceId) {
|
||||
loadingUrl += '&device_id=' + callbackDeviceId;
|
||||
}
|
||||
uni.redirectTo({ url: loadingUrl });
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. 判断是否为根路径或设备编号路径(如 / 或 /N1154)
|
||||
const currentPath = window.location.pathname;
|
||||
const isRootOrDevice = currentPath === '/' || /^\/[A-Z][A-Z0-9]+$/.test(currentPath);
|
||||
|
||||
// 5. 检查 JWT
|
||||
const token = uni.getStorageSync('token');
|
||||
|
||||
if (token) {
|
||||
if (isRootOrDevice) {
|
||||
// 根路径/设备编号路径 → 跳转首页
|
||||
const homeUrl = deviceId
|
||||
? `/pages/index/index?device_id=${deviceId}`
|
||||
: '/pages/index/scan';
|
||||
uni.redirectTo({ url: homeUrl });
|
||||
} else {
|
||||
// 其他业务页面 → 留在当前页面
|
||||
console.log('[App] 已登录,保留在当前页面');
|
||||
}
|
||||
} 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
|
||||
},
|
||||
onShow: function() {
|
||||
@@ -33,37 +108,6 @@
|
||||
},
|
||||
onHide: function() {
|
||||
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>
|
||||
|
||||
+22
-3
@@ -6,16 +6,35 @@ const dev = {
|
||||
apiBaseUrl: 'http://192.168.0.23:4000',
|
||||
|
||||
// 网关地址(vms-gateway,端口 4001)— 用户授权、短信等接口走网关
|
||||
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
||||
apiGatewayUrl: 'http://192.168.0.23:4001',
|
||||
|
||||
// 授权回调地址(支付宝/微信 OAuth redirect_uri)
|
||||
authRedirectUri: 'https://gateway.arklinksmart.cn/api/v1/user/auth/callback',
|
||||
// 授权回调地址(微信 OAuth redirect_uri,必须 HTTPS,指向前端页面)
|
||||
authRedirectUri: 'https://m.arklinksmart.cn/pages/auth/loading',
|
||||
|
||||
// 开发阶段硬编码 Token(生产环境应从登录流程获取)
|
||||
bearerToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRlZXB2ZW5kaW5nIiwic3ViIjoiMTY0MDI0MTEyNiIsImZyb20iOiJwb3MiLCJyb2xlIjoicG9zIiwibWFpbmJvYXJkX2lkIjoiVDEwMDIiLCJwb3Nfc24iOiIxNjQwMjQxMTI2IiwiaWF0IjoxNzc4NDkxOTA3LCJleHAiOjE3NzkwOTY3MDd9.DjscZtrTCr30XOngToUifxoel4q2EGES_uqGQernkvg',
|
||||
|
||||
// 是否开启请求日志
|
||||
enableRequestLog: true,
|
||||
|
||||
// Mock 微信登录(跳过 OAuth 流程)
|
||||
// 'skip' → 直接登录进首页
|
||||
// 'register' → 模拟新用户,走注册流程
|
||||
// 'login' → 模拟已注册用户,走登录流程
|
||||
// false → 走真实微信 OAuth
|
||||
mockWechatLogin: 'register',
|
||||
mockAppNo: '60000001102001',
|
||||
mockUser: {
|
||||
token: 'mock_token_dev_2024',
|
||||
user_info: {
|
||||
user_id: 'mock_user_001',
|
||||
phone: '13264706088',
|
||||
open_id: 'mock_openid_002',
|
||||
union_id: 'test_union_id',
|
||||
nickname: '测试用户',
|
||||
avatar: 'https://img.wewemivending.com/vms/us/img/uploads/2025/12/18/6943d37c7d82b3439.jpeg',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default dev;
|
||||
|
||||
+4
-4
@@ -3,13 +3,13 @@
|
||||
*/
|
||||
const prod = {
|
||||
// 业务 API 地址(vms-api)
|
||||
apiBaseUrl: 'https://api.arklink.com',
|
||||
apiBaseUrl: 'http://101.200.86.98:4000',
|
||||
|
||||
// 网关地址(vms-gateway)— 用户授权、短信等接口走网关
|
||||
apiGatewayUrl: 'https://gateway.arklink.com',
|
||||
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
||||
|
||||
// 授权回调地址(支付宝/微信 OAuth redirect_uri)
|
||||
authRedirectUri: 'https://gateway.arklink.com/api/v1/user/auth/callback',
|
||||
// 授权回调地址(微信 OAuth redirect_uri,必须 HTTPS,指向前端页面)
|
||||
authRedirectUri: 'https://m.arklinksmart.cn/pages/auth/loading',
|
||||
|
||||
// 生产环境 Token 从登录流程获取,此处为空
|
||||
bearerToken: '',
|
||||
|
||||
+8
-2
@@ -1,13 +1,19 @@
|
||||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/register/register",
|
||||
"path": "pages/index/scan",
|
||||
"style": {
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/index/scan",
|
||||
"path": "pages/auth/loading",
|
||||
"style": {
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/register/register",
|
||||
"style": {
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,448 @@
|
||||
<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: '',
|
||||
action: '',
|
||||
};
|
||||
},
|
||||
onLoad(options) {
|
||||
this.deviceId = options.device_id || '';
|
||||
this.action = options.action || '';
|
||||
|
||||
// #ifdef H5
|
||||
// Mock 模式:跳过微信 OAuth,直接登录
|
||||
if (config.mockWechatLogin && this.action !== 'userinfo') {
|
||||
this.mockLogin();
|
||||
return;
|
||||
}
|
||||
|
||||
// 从 URL 参数获取 code(App.vue 跳转时带过来)
|
||||
let code = options.code || '';
|
||||
if (!code) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
code = urlParams.get('code') || '';
|
||||
}
|
||||
|
||||
// 兜底:从 localStorage 恢复(redirect_uri 参数为主,localStorage 为备用)
|
||||
if (!this.action) {
|
||||
this.action = localStorage.getItem('__auth_action') || '';
|
||||
}
|
||||
if (!this.deviceId) {
|
||||
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') {
|
||||
// 获取用户信息流程
|
||||
if (code) {
|
||||
this.handleUserInfoCallback(code);
|
||||
} else {
|
||||
this.startUserInfoAuth();
|
||||
}
|
||||
} else {
|
||||
// 登录流程
|
||||
if (code) {
|
||||
this.handleCallback(code);
|
||||
} else {
|
||||
this.startAuth();
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifndef H5
|
||||
// 小程序环境暂不支持,跳回扫码页
|
||||
uni.redirectTo({ url: '/pages/index/scan' });
|
||||
// #endif
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 发起 OAuth 授权(静默授权,只获取 openid)
|
||||
*/
|
||||
async startAuth() {
|
||||
const platform = detectPlatform();
|
||||
const appNo = getAppNo(platform);
|
||||
|
||||
if (!appNo) {
|
||||
// 非微信环境,跳转注册页(手机号注册)
|
||||
this.goToRegister();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.statusText = '正在获取授权...';
|
||||
|
||||
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
||||
const redirectUri = config.authRedirectUri || (
|
||||
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||
);
|
||||
|
||||
// 使用 snsapi_base 静默授权,不弹窗
|
||||
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||
app_no: appNo,
|
||||
scopes: 'snsapi_base',
|
||||
redirect_uri: redirectUri,
|
||||
});
|
||||
|
||||
const data = res.data || {};
|
||||
if (data.code === 0 && data.data && data.data.auth_url) {
|
||||
// 通过 state 传递 device_id(OAuth 标准保证 state 原样回传)
|
||||
let authUrl = data.data.auth_url;
|
||||
if (this.deviceId) {
|
||||
const stateVal = encodeURIComponent(JSON.stringify({ device_id: this.deviceId }));
|
||||
try {
|
||||
const urlObj = new URL(authUrl);
|
||||
urlObj.searchParams.set('state', stateVal);
|
||||
authUrl = urlObj.toString();
|
||||
} catch (_) {
|
||||
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + stateVal;
|
||||
}
|
||||
}
|
||||
// 跳转微信授权页(静默,不弹窗)
|
||||
window.location.href = authUrl;
|
||||
} 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);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理授权回调(用 code 换 openid,再用 openid 登录)
|
||||
*/
|
||||
async handleCallback(code) {
|
||||
const appNo = uni.getStorageSync('app_no') || getAppNo(detectPlatform());
|
||||
|
||||
if (!appNo) {
|
||||
uni.showToast({ title: '无法获取应用信息', icon: 'none' });
|
||||
this.goToScan();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.statusText = '正在验证身份...';
|
||||
|
||||
// 1. 用 code 换取 openid(snsapi_base 静默授权)
|
||||
const callbackRes = await gatewayPost('/api/v1/user/auth/exchange', {
|
||||
app_no: appNo,
|
||||
code: code,
|
||||
});
|
||||
|
||||
const callbackData = callbackRes.data || {};
|
||||
console.log('[loading] auth callback response:', JSON.stringify(callbackData, null, 2));
|
||||
|
||||
if (callbackData.code !== 0 || !callbackData.data) {
|
||||
uni.showToast({ title: callbackData.message || '授权失败', icon: 'none' });
|
||||
setTimeout(() => this.goToScan(), 1500);
|
||||
return;
|
||||
}
|
||||
|
||||
const openid = callbackData.data.openid;
|
||||
if (!openid) {
|
||||
uni.showToast({ title: '获取用户标识失败', icon: 'none' });
|
||||
setTimeout(() => this.goToScan(), 1500);
|
||||
return;
|
||||
}
|
||||
|
||||
// 清除 URL 中的 code 参数,避免刷新重复处理
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.delete('code');
|
||||
url.searchParams.delete('state');
|
||||
window.history.replaceState({}, '', url.toString());
|
||||
|
||||
// 存储 openid
|
||||
uni.setStorageSync('openid', openid);
|
||||
|
||||
// 2. 用 openid 调用登录接口
|
||||
this.statusText = '正在登录...';
|
||||
const loginRes = await gatewayPost('/api/v1/user/login', {
|
||||
app_no: appNo,
|
||||
openid: openid,
|
||||
});
|
||||
|
||||
const data = loginRes.data || {};
|
||||
console.log('[loading] login response:', JSON.stringify(data, null, 2));
|
||||
|
||||
if (data.code === 0 && data.data) {
|
||||
const result = data.data;
|
||||
|
||||
if (result.register) {
|
||||
// 已注册 → 存 token → 进入开门页
|
||||
uni.setStorageSync('token', result.token);
|
||||
this.goToHome();
|
||||
} else {
|
||||
// 未注册 → 存 temp_token → 跳注册页
|
||||
uni.setStorageSync('temp_token', result.temp_token);
|
||||
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);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 发起非静默授权获取用户信息(snsapi_userinfo,弹窗确认)
|
||||
*/
|
||||
async startUserInfoAuth() {
|
||||
const platform = detectPlatform();
|
||||
const appNo = getAppNo(platform);
|
||||
|
||||
if (!appNo) {
|
||||
// 非微信环境,直接跳回首页
|
||||
this.goToHomeWithAction();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.statusText = '正在获取用户信息...';
|
||||
|
||||
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
||||
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) {
|
||||
// 通过 state 传递 action 和 device_id(OAuth 标准保证 state 原样回传)
|
||||
const stateObj = { action: 'userinfo' };
|
||||
if (this.deviceId) {
|
||||
stateObj.device_id = this.deviceId;
|
||||
}
|
||||
const stateVal = encodeURIComponent(JSON.stringify(stateObj));
|
||||
let authUrl = data.data.auth_url;
|
||||
try {
|
||||
const urlObj = new URL(authUrl);
|
||||
urlObj.searchParams.set('state', stateVal);
|
||||
authUrl = urlObj.toString();
|
||||
} catch (_) {
|
||||
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + stateVal;
|
||||
}
|
||||
// 跳转微信授权页(弹窗确认)
|
||||
window.location.href = authUrl;
|
||||
} else {
|
||||
uni.showToast({ title: data.message || '获取授权失败', icon: 'none' });
|
||||
setTimeout(() => this.goToHomeWithAction(), 1500);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[Auth] startUserInfoAuth error:', e);
|
||||
uni.showToast({ title: '网络请求失败', icon: 'none' });
|
||||
setTimeout(() => this.goToHomeWithAction(), 1500);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理用户信息授权回调(用 code 调 /api/v1/user/info 获取头像昵称)
|
||||
*/
|
||||
async handleUserInfoCallback(code) {
|
||||
const appNo = uni.getStorageSync('app_no') || getAppNo(detectPlatform());
|
||||
|
||||
if (!appNo) {
|
||||
this.goToHomeWithAction();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.statusText = '正在获取用户信息...';
|
||||
|
||||
// 清除 URL 中的 code/action 参数,避免刷新重复处理
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.delete('code');
|
||||
url.searchParams.delete('state');
|
||||
url.searchParams.delete('action');
|
||||
window.history.replaceState({}, '', url.toString());
|
||||
|
||||
// 用 code 调用 POST /api/v1/user/info 获取用户信息(必须用 POST,GET 是另一个端点)
|
||||
console.log('[loading] 请求 POST user/info, app_no:', appNo, 'code:', code);
|
||||
const res = await gatewayPost('/api/v1/user/info', {
|
||||
app_no: appNo,
|
||||
code: code,
|
||||
});
|
||||
|
||||
const data = res.data || {};
|
||||
console.log('[loading] user/info response:', JSON.stringify(data, null, 2));
|
||||
console.log('[loading] user/info statusCode:', res.statusCode);
|
||||
|
||||
if (data.code === 0 && data.data) {
|
||||
const userInfo = data.data;
|
||||
// 存入缓存
|
||||
uni.setStorageSync('user_info', {
|
||||
nickname: userInfo.nickname || '',
|
||||
avatar: userInfo.avatar || '',
|
||||
phone: userInfo.phone || '',
|
||||
});
|
||||
} else {
|
||||
console.warn('[loading] 获取用户信息失败:', data.message);
|
||||
}
|
||||
|
||||
// 跳回首页(我的 tab)
|
||||
this.goToHomeWithAction();
|
||||
} catch (e) {
|
||||
console.error('[Auth] handleUserInfoCallback error:', e);
|
||||
this.goToHomeWithAction();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 跳回首页并标记为"我的"tab
|
||||
*/
|
||||
goToHomeWithAction() {
|
||||
const url = this.deviceId
|
||||
? `/pages/index/index?device_id=${this.deviceId}&action=mine`
|
||||
: '/pages/index/index?action=mine';
|
||||
uni.redirectTo({ url });
|
||||
},
|
||||
|
||||
goToHome() {
|
||||
const url = this.deviceId
|
||||
? `/pages/index/index?device_id=${this.deviceId}`
|
||||
: '/pages/index/index';
|
||||
uni.redirectTo({ url });
|
||||
},
|
||||
|
||||
goToRegister() {
|
||||
// 记录扫码时的原始 URL,注册完成后跳回
|
||||
const scanUrl = this.deviceId
|
||||
? `/pages/index/index?device_id=${this.deviceId}`
|
||||
: '';
|
||||
if (scanUrl) {
|
||||
uni.setStorageSync('__scan_redirect_url', scanUrl);
|
||||
}
|
||||
|
||||
const url = this.deviceId
|
||||
? `/pages/register/register?device_id=${this.deviceId}`
|
||||
: '/pages/register/register';
|
||||
uni.redirectTo({ url });
|
||||
},
|
||||
|
||||
goToScan() {
|
||||
uni.redirectTo({ url: '/pages/index/scan' });
|
||||
},
|
||||
|
||||
/**
|
||||
* Mock 登录(跳过微信授权,调用真实登录接口)
|
||||
*/
|
||||
async mockLogin() {
|
||||
const mode = config.mockWechatLogin;
|
||||
const mock = config.mockUser;
|
||||
const mockOpenid = mock.user_info.open_id;
|
||||
|
||||
// 'skip' 模式直接登录,不调接口
|
||||
if (mode === 'skip') {
|
||||
this.statusText = '模拟登录中...';
|
||||
uni.setStorageSync('token', mock.token);
|
||||
uni.setStorageSync('openid', mockOpenid);
|
||||
console.log('[Auth] Mock skip → home');
|
||||
setTimeout(() => this.goToHome(), 500);
|
||||
return;
|
||||
}
|
||||
|
||||
// 'register' / 'login' 模式:调用真实登录接口,传 mock openid
|
||||
this.statusText = '模拟:调用登录接口...';
|
||||
const appNo = uni.getStorageSync('app_no') || config.mockAppNo;
|
||||
|
||||
try {
|
||||
const res = await gatewayPost('/api/v1/user/login', {
|
||||
app_no: appNo,
|
||||
openid: mockOpenid,
|
||||
});
|
||||
|
||||
const data = res.data || {};
|
||||
console.log('[Auth] Mock login response:', JSON.stringify(data, null, 2));
|
||||
|
||||
if (data.code === 0 && data.data) {
|
||||
const result = data.data;
|
||||
|
||||
// 存储 openid
|
||||
uni.setStorageSync('openid', result.openid || mockOpenid);
|
||||
|
||||
if (result.register) {
|
||||
// 已注册 → 存 token → 跳首页
|
||||
uni.setStorageSync('token', result.token);
|
||||
console.log('[Auth] Mock: existing user → home');
|
||||
this.goToHome();
|
||||
} else {
|
||||
// 未注册 → 存 temp_token → 跳注册页
|
||||
uni.setStorageSync('temp_token', result.temp_token);
|
||||
console.log('[Auth] Mock: new user → register');
|
||||
this.goToRegister();
|
||||
}
|
||||
} else {
|
||||
uni.showToast({ title: data.message || '登录失败', icon: 'none' });
|
||||
console.error('[Auth] Mock login failed:', data);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[Auth] Mock login error:', e);
|
||||
uni.showToast({ title: '网络请求失败', icon: 'none' });
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</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>
|
||||
+204
-28
@@ -67,24 +67,33 @@
|
||||
|
||||
<!-- 底部导航栏 -->
|
||||
<view class="tab-bar">
|
||||
<view class="tab-item" :class="{ active: currentTab === 'home' }" @click="switchTab('home')">
|
||||
<view class="home-icon">
|
||||
<view class="home-roof"></view>
|
||||
<view class="home-body"></view>
|
||||
<view class="tab-bar-row">
|
||||
<view class="tab-item" :class="{ active: currentTab === 'home' }" @click="switchTab('home')">
|
||||
<view class="home-icon">
|
||||
<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>
|
||||
<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 v-if="isWechat" class="payscore-info">
|
||||
<image class="payscore-logo" src="/static/payscore-logo.png" mode="aspectFit" />
|
||||
<view class="payscore-divider"></view>
|
||||
<text class="payscore-text">微信支付分 | 550分及以上优享</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -94,7 +103,7 @@
|
||||
<!-- 蓝色个人信息区域 -->
|
||||
<view class="user-header">
|
||||
<view class="user-info">
|
||||
<view class="avatar-wrapper">
|
||||
<view class="avatar-wrapper" @click="handleAvatarClick">
|
||||
<image class="avatar" :src="userInfo.avatar || '/static/default-avatar.png'" mode="aspectFill" />
|
||||
</view>
|
||||
<view class="user-detail">
|
||||
@@ -113,6 +122,13 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 退出登录 -->
|
||||
<view class="menu-list logout-btn" @click="handleLogout">
|
||||
<view class="menu-item">
|
||||
<text class="menu-text" style="color: #e4393c; text-align: center; width: 100%;">退出登录</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 开发调试工具(仅开发环境显示) -->
|
||||
<view v-if="isDev" class="dev-tools">
|
||||
<view class="dev-tools-title">开发工具</view>
|
||||
@@ -125,7 +141,7 @@
|
||||
|
||||
<!-- 底部左右箭头导航条 -->
|
||||
<page-nav-bar
|
||||
:hasPrev="true"
|
||||
:hasPrev="canGoBack"
|
||||
:hasNext="false"
|
||||
@prev="handleNavPrev"
|
||||
@next="handleNavNext"
|
||||
@@ -147,8 +163,8 @@
|
||||
<script>
|
||||
import PageNavBar from '@/components/page-nav-bar/page-nav-bar.vue';
|
||||
import config from '@/config/env.js';
|
||||
import { get } from '@/utils/request.js';
|
||||
import { checkLoginWithPrompt, getCachedUserInfo } from '@/utils/auth-guard.js';
|
||||
import { get, gatewayGet } from '@/utils/request.js';
|
||||
import { checkLoginWithPrompt, getCachedUserInfo, isLoggedIn } from '@/utils/auth-guard.js';
|
||||
import { isVConsoleEnabled, showVConsole, hideVConsole } from '@/utils/vconsole';
|
||||
|
||||
export default {
|
||||
@@ -162,6 +178,9 @@ export default {
|
||||
categoryList: [],
|
||||
activeCategory: 'all',
|
||||
userInfo: { nickname: '', phone: '', avatar: '' },
|
||||
avatarClickCount: 0,
|
||||
avatarClickTimer: null,
|
||||
fromPage: '', // 记录从哪个页面跳转过来的
|
||||
menuList: [
|
||||
{ title: '我的订单', action: 'order' },
|
||||
{ title: '常见问题', action: 'faq' },
|
||||
@@ -169,11 +188,16 @@ export default {
|
||||
{ title: '公众号信息', action: 'qrcode' }
|
||||
],
|
||||
servicePhone: config.servicePhone,
|
||||
isWechat: false,
|
||||
isDev: process.env.NODE_ENV === 'development',
|
||||
vconsoleEnabled: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
canGoBack() {
|
||||
// 有上一页,或者从 tab 切换过来的,都可以返回
|
||||
return getCurrentPages().length > 1 || this.fromPage === 'tab';
|
||||
},
|
||||
maskedPhone() {
|
||||
const p = this.userInfo.phone;
|
||||
return p ? p.substring(0,3) + '****' + p.substring(7) : '';
|
||||
@@ -194,17 +218,37 @@ export default {
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
// 检测是否在微信环境中打开
|
||||
// #ifdef MP-WEIXIN
|
||||
this.isWechat = true;
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
this.isWechat = /MicroMessenger/i.test(navigator.userAgent);
|
||||
// #endif
|
||||
|
||||
// 处理"我的"用户信息授权回调(从 loading 页跳回)
|
||||
if (options.action === 'mine') {
|
||||
this.currentTab = 'mine';
|
||||
this.fromPage = 'navigate';
|
||||
}
|
||||
|
||||
// 支持通过 tab 参数切换到"我的"页面
|
||||
if (options.tab === 'mine') {
|
||||
this.currentTab = 'mine';
|
||||
this.fromPage = 'navigate';
|
||||
}
|
||||
|
||||
if (options.device_id) {
|
||||
this.deviceId = options.device_id;
|
||||
uni.setNavigationBarTitle({ title: `智能货柜-${this.deviceId}` });
|
||||
this.fetchProducts();
|
||||
} else if (!options.tab) {
|
||||
// 无设备编号且非 tab 跳转,跳回扫码页
|
||||
uni.redirectTo({ url: '/pages/index/scan' });
|
||||
} else if (!options.tab && options.action !== 'mine') {
|
||||
// 无设备编号且非 tab/action 跳转,提示并跳至扫码页
|
||||
uni.showToast({ title: '请扫描设备二维码', icon: 'none' });
|
||||
setTimeout(() => {
|
||||
uni.redirectTo({ url: '/pages/index/scan' });
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
|
||||
// 加载缓存的用户信息
|
||||
@@ -223,9 +267,21 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
switchTab(tab) {
|
||||
// 切换到"我的"Tab 时检查登录
|
||||
if (tab === 'mine' && !checkLoginWithPrompt('mine')) return;
|
||||
this.currentTab = tab;
|
||||
if (tab === 'mine') {
|
||||
// 切换到"我的"Tab 时检查登录
|
||||
if (!checkLoginWithPrompt('mine')) return;
|
||||
this.currentTab = tab;
|
||||
this.fromPage = 'tab';
|
||||
// 已有缓存的用户信息则直接显示,否则发起非静默授权获取
|
||||
const cached = getCachedUserInfo();
|
||||
if (cached && cached.nickname) {
|
||||
this.userInfo = { ...this.userInfo, ...cached };
|
||||
} else {
|
||||
this.startUserInfoAuth();
|
||||
}
|
||||
} else {
|
||||
this.currentTab = tab;
|
||||
}
|
||||
},
|
||||
switchCategory(cat) { this.activeCategory = cat; },
|
||||
getDisplayPrice(item) {
|
||||
@@ -236,11 +292,78 @@ export default {
|
||||
// 从缓存加载用户信息
|
||||
loadUserInfo() {
|
||||
const cached = getCachedUserInfo();
|
||||
console.log('[index] getCachedUserInfo:', JSON.stringify(cached, null, 2));
|
||||
if (cached) {
|
||||
this.userInfo = { ...this.userInfo, ...cached };
|
||||
} else {
|
||||
this.userInfo = { nickname: '', phone: '', avatar: '' };
|
||||
}
|
||||
console.log('[index] this.userInfo:', JSON.stringify(this.userInfo, null, 2));
|
||||
},
|
||||
// 发起非静默授权获取用户信息(snsapi_userinfo)
|
||||
async startUserInfoAuth() {
|
||||
// Mock 模式下,直接使用 mock 数据
|
||||
if (config.mockWechatLogin) {
|
||||
const cached = getCachedUserInfo();
|
||||
if (cached && cached.nickname) {
|
||||
this.userInfo = { ...this.userInfo, ...cached };
|
||||
} else {
|
||||
this.userInfo = {
|
||||
nickname: config.mockUser.user_info.nickname || '',
|
||||
phone: config.mockUser.user_info.phone || '',
|
||||
avatar: config.mockUser.user_info.avatar || '',
|
||||
};
|
||||
uni.setStorageSync('user_info', this.userInfo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const appNo = uni.getStorageSync('app_no');
|
||||
if (!appNo) {
|
||||
console.warn('[index] 无法获取应用信息');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
||||
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) {
|
||||
// 通过 state 传递 action 和 device_id(OAuth 标准保证 state 原样回传)
|
||||
const stateObj = { action: 'userinfo' };
|
||||
if (this.deviceId) {
|
||||
stateObj.device_id = this.deviceId;
|
||||
}
|
||||
const stateVal = encodeURIComponent(JSON.stringify(stateObj));
|
||||
// 解析 auth_url,安全地设置 state 参数(避免重复)
|
||||
let authUrl = data.data.auth_url;
|
||||
try {
|
||||
const urlObj = new URL(authUrl);
|
||||
urlObj.searchParams.set('state', stateVal);
|
||||
authUrl = urlObj.toString();
|
||||
} catch (_) {
|
||||
// URL 解析失败时直接拼接
|
||||
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + stateVal;
|
||||
}
|
||||
console.log('[index] 跳转授权页:', authUrl);
|
||||
// 跳转微信授权页(弹窗确认)
|
||||
window.location.href = authUrl;
|
||||
} else {
|
||||
console.warn('[index] 获取授权链接失败:', data.message);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[index] startUserInfoAuth error:', e);
|
||||
}
|
||||
},
|
||||
async fetchProducts() {
|
||||
this.loading = true;
|
||||
@@ -287,8 +410,54 @@ export default {
|
||||
break;
|
||||
}
|
||||
},
|
||||
handleNavPrev() { this.currentTab = 'home'; },
|
||||
handleNavPrev() {
|
||||
if (this.fromPage === 'navigate') {
|
||||
// 从其他页面 navigateTo 过来的,返回上一页
|
||||
uni.navigateBack();
|
||||
} else if (this.fromPage === 'tab') {
|
||||
// 从首页 tab 切换过来的,切换回首页
|
||||
this.currentTab = 'home';
|
||||
}
|
||||
// 其他情况不执行操作
|
||||
},
|
||||
handleNavNext() { uni.showToast({ title: '暂无下一页', icon: 'none' }); },
|
||||
handleAvatarClick() {
|
||||
this.avatarClickCount++;
|
||||
clearTimeout(this.avatarClickTimer);
|
||||
|
||||
if (this.avatarClickCount >= 10) {
|
||||
// 点击10次,清除缓存
|
||||
this.avatarClickCount = 0;
|
||||
this.clearCacheAndReload();
|
||||
} else {
|
||||
// 2秒后重置计数
|
||||
this.avatarClickTimer = setTimeout(() => {
|
||||
this.avatarClickCount = 0;
|
||||
}, 2000);
|
||||
}
|
||||
},
|
||||
handleLogout() {
|
||||
uni.showModal({
|
||||
title: '退出登录',
|
||||
content: '确定要退出登录吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.clearCacheAndReload();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
clearCacheAndReload() {
|
||||
uni.clearStorageSync();
|
||||
uni.showToast({ title: '已退出登录', icon: 'success' });
|
||||
setTimeout(() => {
|
||||
// 跳转到干净的URL,去掉code/state参数,避免重复使用旧code
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.delete('code');
|
||||
url.searchParams.delete('state');
|
||||
window.location.href = url.toString();
|
||||
}, 1000);
|
||||
},
|
||||
onVConsoleChange(e) {
|
||||
const enabled = e.detail.value;
|
||||
if (enabled) {
|
||||
@@ -309,6 +478,7 @@ page { height: 100%; background-color: #fff; }
|
||||
|
||||
/* ====== 首页样式 ====== */
|
||||
.home-page { display: flex; flex-direction: column; height: 100%; }
|
||||
|
||||
.product-area { flex: 1; overflow-y: auto; height: 0; }
|
||||
|
||||
/* 热销商品标题 + 装饰 */
|
||||
@@ -337,10 +507,11 @@ page { height: 100%; background-color: #fff; }
|
||||
.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-text { font-size: 28rpx; color: #999; font-weight: normal; }
|
||||
.tab-bar .tab-item.active .tab-text { color: #2979ff; }
|
||||
@@ -413,6 +584,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 { 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 */
|
||||
.empty-tip, .loading-tip { text-align: center; padding: 60rpx; color: #999; font-size: 28rpx; }
|
||||
@@ -432,6 +607,7 @@ page { height: 100%; background-color: #fff; }
|
||||
.menu-item:last-child { border-bottom: none; }
|
||||
.menu-text { font-size: 30rpx; color: #333; }
|
||||
.menu-arrow { font-size: 28rpx; color: #ccc; }
|
||||
.logout-btn { margin-top: 20rpx; }
|
||||
|
||||
/* 开发工具区域 */
|
||||
.dev-tools { margin-top: 20rpx; background-color: #fff; border-radius: 16rpx; overflow: hidden; }
|
||||
|
||||
@@ -67,7 +67,15 @@ export default {
|
||||
};
|
||||
},
|
||||
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) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/index/index?device_id=' + options.device_id,
|
||||
@@ -76,7 +84,7 @@ export default {
|
||||
}
|
||||
|
||||
// #ifdef H5
|
||||
// 2. URL 路径中携带设备编号(如 http://xxx/A1036)
|
||||
// 3. URL 路径中携带设备编号(如 http://xxx/A1036)
|
||||
const path = window.location.pathname;
|
||||
const segments = path.split('/').filter(Boolean);
|
||||
if (segments.length > 0) {
|
||||
@@ -93,7 +101,25 @@ export default {
|
||||
methods: {
|
||||
handleScan() {
|
||||
// #ifdef H5
|
||||
uni.showToast({ title: 'H5 环境暂不支持扫码', icon: 'none' });
|
||||
// 检测是否在微信环境
|
||||
const isWechat = /MicroMessenger/i.test(navigator.userAgent);
|
||||
if (isWechat) {
|
||||
// 微信环境:拉起微信扫一扫
|
||||
// 注意:需要后端配合引入微信 JS-SDK 并完成签名配置
|
||||
uni.showToast({ title: '请使用微信扫一扫功能', icon: 'none' });
|
||||
// 如果已配置微信 JS-SDK,可以使用:
|
||||
// wx.scanQRCode({
|
||||
// needResult: 1,
|
||||
// scanType: ['qrCode', 'barCode'],
|
||||
// success: (res) => {
|
||||
// const result = res.resultStr;
|
||||
// this.parseScanResult(result);
|
||||
// }
|
||||
// });
|
||||
} else {
|
||||
// 非微信环境
|
||||
uni.showToast({ title: '请使用微信扫码或在小程序中打开', icon: 'none' });
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
|
||||
+101
-37
@@ -6,6 +6,12 @@
|
||||
<view class="subtitle">请输入手机号获取验证码完成注册</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">
|
||||
<!-- 手机号 -->
|
||||
@@ -62,8 +68,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { gatewayPost } from '@/utils/request.js';
|
||||
import config from '@/config/env.js';
|
||||
import { post } from '@/utils/request.js';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@@ -71,7 +77,10 @@ export default {
|
||||
phone: '',
|
||||
code: '',
|
||||
countdown: 0,
|
||||
timer: null
|
||||
timer: null,
|
||||
tempToken: '',
|
||||
authInfo: { nickname: '', avatar: '' },
|
||||
deviceId: '',
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -79,8 +88,22 @@ export default {
|
||||
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() {
|
||||
// 清除定时器
|
||||
if (this.timer) {
|
||||
clearInterval(this.timer);
|
||||
this.timer = null;
|
||||
@@ -91,15 +114,21 @@ export default {
|
||||
async handleGetCode() {
|
||||
if (this.countdown > 0) return;
|
||||
|
||||
// 验证手机号
|
||||
if (!/^1[3-9]\d{9}$/.test(this.phone)) {
|
||||
uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.tempToken) {
|
||||
uni.showToast({ title: '授权信息已过期,请重新登录', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await post('/auth/send-sms-code', {
|
||||
phone: this.phone
|
||||
const res = await gatewayPost('/api/v1/user/sms/send', {
|
||||
phone: this.phone,
|
||||
temp_token: this.tempToken,
|
||||
purpose: 'register',
|
||||
});
|
||||
|
||||
const ret = res.data || {};
|
||||
@@ -114,7 +143,6 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
// 开始倒计时
|
||||
startCountdown() {
|
||||
this.countdown = 60;
|
||||
this.timer = setInterval(() => {
|
||||
@@ -126,56 +154,59 @@ export default {
|
||||
}, 1000);
|
||||
},
|
||||
|
||||
// 注册
|
||||
// 注册(Mock 模式也走真实接口)
|
||||
async handleRegister() {
|
||||
if (!this.canSubmit) return;
|
||||
|
||||
// 验证手机号
|
||||
if (!/^1[3-9]\d{9}$/.test(this.phone)) {
|
||||
uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证验证码
|
||||
if (this.code.length < 4) {
|
||||
uni.showToast({ title: '请输入验证码', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.tempToken) {
|
||||
uni.showToast({ title: '授权信息已过期,请重新登录', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showLoading({ title: '注册中...' });
|
||||
|
||||
try {
|
||||
const res = await post('/auth/register', {
|
||||
const res = await gatewayPost('/api/v1/user/register', {
|
||||
temp_token: this.tempToken,
|
||||
phone: this.phone,
|
||||
code: this.code
|
||||
code: this.code,
|
||||
});
|
||||
|
||||
const ret = res.data || {};
|
||||
if (ret.code === 0) {
|
||||
if (ret.code === 0 && ret.data) {
|
||||
// 保存 token
|
||||
const token = ret.data && ret.data.token;
|
||||
if (token) {
|
||||
uni.setStorageSync('token', token);
|
||||
uni.setStorageSync('token', ret.data.token);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// 保存用户信息
|
||||
const userInfo = ret.data && ret.data.userInfo;
|
||||
if (userInfo) {
|
||||
uni.setStorageSync('userInfo', userInfo);
|
||||
}
|
||||
// 清除临时数据
|
||||
uni.removeStorageSync('temp_token');
|
||||
uni.removeStorageSync('auth_info');
|
||||
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: '注册成功', icon: 'success' });
|
||||
|
||||
// 返回上一页或跳转首页
|
||||
setTimeout(() => {
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length > 1) {
|
||||
uni.navigateBack();
|
||||
} else {
|
||||
uni.redirectTo({ url: '/pages/index/index' });
|
||||
}
|
||||
}, 1500);
|
||||
setTimeout(() => this.navigateToTarget(), 1500);
|
||||
} else {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: ret.message || '注册失败', icon: 'none' });
|
||||
@@ -186,7 +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' });
|
||||
@@ -210,7 +253,7 @@ page {
|
||||
/* 顶部标题 */
|
||||
.header {
|
||||
padding-top: 180rpx;
|
||||
margin-bottom: 80rpx;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.title {
|
||||
@@ -225,6 +268,29 @@ page {
|
||||
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 {
|
||||
width: 100%;
|
||||
@@ -302,10 +368,8 @@ page {
|
||||
|
||||
/* 底部协议 */
|
||||
.agreement {
|
||||
position: absolute;
|
||||
bottom: 80rpx;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin-top: 80rpx;
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
@@ -0,0 +1,8 @@
|
||||
## 1.0.3(2022-01-21)
|
||||
- 优化 组件示例
|
||||
## 1.0.2(2021-11-22)
|
||||
- 修复 / 符号在 vue 不同版本兼容问题引起的报错问题
|
||||
## 1.0.1(2021-11-22)
|
||||
- 修复 vue3中scss语法兼容问题
|
||||
## 1.0.0(2021-11-18)
|
||||
- init
|
||||
@@ -0,0 +1 @@
|
||||
@import './styles/index.scss';
|
||||
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"id": "uni-scss",
|
||||
"displayName": "uni-scss 辅助样式",
|
||||
"version": "1.0.3",
|
||||
"description": "uni-sass是uni-ui提供的一套全局样式 ,通过一些简单的类名和sass变量,实现简单的页面布局操作,比如颜色、边距、圆角等。",
|
||||
"keywords": [
|
||||
"uni-scss",
|
||||
"uni-ui",
|
||||
"辅助样式"
|
||||
],
|
||||
"repository": "https://github.com/dcloudio/uni-ui",
|
||||
"engines": {
|
||||
"HBuilderX": "^3.1.0"
|
||||
},
|
||||
"dcloudext": {
|
||||
"category": [
|
||||
"JS SDK",
|
||||
"通用 SDK"
|
||||
],
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "无",
|
||||
"data": "无",
|
||||
"permissions": "无"
|
||||
},
|
||||
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui"
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": [],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "y",
|
||||
"aliyun": "y"
|
||||
},
|
||||
"client": {
|
||||
"App": {
|
||||
"app-vue": "y",
|
||||
"app-nvue": "u"
|
||||
},
|
||||
"H5-mobile": {
|
||||
"Safari": "y",
|
||||
"Android Browser": "y",
|
||||
"微信浏览器(Android)": "y",
|
||||
"QQ浏览器(Android)": "y"
|
||||
},
|
||||
"H5-pc": {
|
||||
"Chrome": "y",
|
||||
"IE": "y",
|
||||
"Edge": "y",
|
||||
"Firefox": "y",
|
||||
"Safari": "y"
|
||||
},
|
||||
"小程序": {
|
||||
"微信": "y",
|
||||
"阿里": "y",
|
||||
"百度": "y",
|
||||
"字节跳动": "y",
|
||||
"QQ": "y"
|
||||
},
|
||||
"快应用": {
|
||||
"华为": "n",
|
||||
"联盟": "n"
|
||||
},
|
||||
"Vue": {
|
||||
"vue2": "y",
|
||||
"vue3": "y"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
`uni-sass` 是 `uni-ui`提供的一套全局样式 ,通过一些简单的类名和`sass`变量,实现简单的页面布局操作,比如颜色、边距、圆角等。
|
||||
|
||||
### [查看文档](https://uniapp.dcloud.io/component/uniui/uni-sass)
|
||||
#### 如使用过程中有任何问题,或者您对uni-ui有一些好的建议,欢迎加入 uni-ui 交流群:871950839
|
||||
@@ -0,0 +1,7 @@
|
||||
@import './setting/_variables.scss';
|
||||
@import './setting/_border.scss';
|
||||
@import './setting/_color.scss';
|
||||
@import './setting/_space.scss';
|
||||
@import './setting/_radius.scss';
|
||||
@import './setting/_text.scss';
|
||||
@import './setting/_styles.scss';
|
||||
@@ -0,0 +1,3 @@
|
||||
.uni-border {
|
||||
border: 1px $uni-border-1 solid;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
|
||||
// TODO 暂时不需要 class ,需要用户使用变量实现 ,如果使用类名其实并不推荐
|
||||
// @mixin get-styles($k,$c) {
|
||||
// @if $k == size or $k == weight{
|
||||
// font-#{$k}:#{$c}
|
||||
// }@else{
|
||||
// #{$k}:#{$c}
|
||||
// }
|
||||
// }
|
||||
$uni-ui-color:(
|
||||
// 主色
|
||||
primary: $uni-primary,
|
||||
primary-disable: $uni-primary-disable,
|
||||
primary-light: $uni-primary-light,
|
||||
// 辅助色
|
||||
success: $uni-success,
|
||||
success-disable: $uni-success-disable,
|
||||
success-light: $uni-success-light,
|
||||
warning: $uni-warning,
|
||||
warning-disable: $uni-warning-disable,
|
||||
warning-light: $uni-warning-light,
|
||||
error: $uni-error,
|
||||
error-disable: $uni-error-disable,
|
||||
error-light: $uni-error-light,
|
||||
info: $uni-info,
|
||||
info-disable: $uni-info-disable,
|
||||
info-light: $uni-info-light,
|
||||
// 中性色
|
||||
main-color: $uni-main-color,
|
||||
base-color: $uni-base-color,
|
||||
secondary-color: $uni-secondary-color,
|
||||
extra-color: $uni-extra-color,
|
||||
// 背景色
|
||||
bg-color: $uni-bg-color,
|
||||
// 边框颜色
|
||||
border-1: $uni-border-1,
|
||||
border-2: $uni-border-2,
|
||||
border-3: $uni-border-3,
|
||||
border-4: $uni-border-4,
|
||||
// 黑色
|
||||
black:$uni-black,
|
||||
// 白色
|
||||
white:$uni-white,
|
||||
// 透明
|
||||
transparent:$uni-transparent
|
||||
) !default;
|
||||
@each $key, $child in $uni-ui-color {
|
||||
.uni-#{"" + $key} {
|
||||
color: $child;
|
||||
}
|
||||
.uni-#{"" + $key}-bg {
|
||||
background-color: $child;
|
||||
}
|
||||
}
|
||||
.uni-shadow-sm {
|
||||
box-shadow: $uni-shadow-sm;
|
||||
}
|
||||
.uni-shadow-base {
|
||||
box-shadow: $uni-shadow-base;
|
||||
}
|
||||
.uni-shadow-lg {
|
||||
box-shadow: $uni-shadow-lg;
|
||||
}
|
||||
.uni-mask {
|
||||
background-color:$uni-mask;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
@mixin radius($r,$d:null ,$important: false){
|
||||
$radius-value:map-get($uni-radius, $r) if($important, !important, null);
|
||||
// Key exists within the $uni-radius variable
|
||||
@if (map-has-key($uni-radius, $r) and $d){
|
||||
@if $d == t {
|
||||
border-top-left-radius:$radius-value;
|
||||
border-top-right-radius:$radius-value;
|
||||
}@else if $d == r {
|
||||
border-top-right-radius:$radius-value;
|
||||
border-bottom-right-radius:$radius-value;
|
||||
}@else if $d == b {
|
||||
border-bottom-left-radius:$radius-value;
|
||||
border-bottom-right-radius:$radius-value;
|
||||
}@else if $d == l {
|
||||
border-top-left-radius:$radius-value;
|
||||
border-bottom-left-radius:$radius-value;
|
||||
}@else if $d == tl {
|
||||
border-top-left-radius:$radius-value;
|
||||
}@else if $d == tr {
|
||||
border-top-right-radius:$radius-value;
|
||||
}@else if $d == br {
|
||||
border-bottom-right-radius:$radius-value;
|
||||
}@else if $d == bl {
|
||||
border-bottom-left-radius:$radius-value;
|
||||
}
|
||||
}@else{
|
||||
border-radius:$radius-value;
|
||||
}
|
||||
}
|
||||
|
||||
@each $key, $child in $uni-radius {
|
||||
@if($key){
|
||||
.uni-radius-#{"" + $key} {
|
||||
@include radius($key)
|
||||
}
|
||||
}@else{
|
||||
.uni-radius {
|
||||
@include radius($key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@each $direction in t, r, b, l,tl, tr, br, bl {
|
||||
@each $key, $child in $uni-radius {
|
||||
@if($key){
|
||||
.uni-radius-#{"" + $direction}-#{"" + $key} {
|
||||
@include radius($key,$direction,false)
|
||||
}
|
||||
}@else{
|
||||
.uni-radius-#{$direction} {
|
||||
@include radius($key,$direction,false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
|
||||
@mixin fn($space,$direction,$size,$n) {
|
||||
@if $n {
|
||||
#{$space}-#{$direction}: #{$size*$uni-space-root}px
|
||||
} @else {
|
||||
#{$space}-#{$direction}: #{-$size*$uni-space-root}px
|
||||
}
|
||||
}
|
||||
@mixin get-styles($direction,$i,$space,$n){
|
||||
@if $direction == t {
|
||||
@include fn($space, top,$i,$n);
|
||||
}
|
||||
@if $direction == r {
|
||||
@include fn($space, right,$i,$n);
|
||||
}
|
||||
@if $direction == b {
|
||||
@include fn($space, bottom,$i,$n);
|
||||
}
|
||||
@if $direction == l {
|
||||
@include fn($space, left,$i,$n);
|
||||
}
|
||||
@if $direction == x {
|
||||
@include fn($space, left,$i,$n);
|
||||
@include fn($space, right,$i,$n);
|
||||
}
|
||||
@if $direction == y {
|
||||
@include fn($space, top,$i,$n);
|
||||
@include fn($space, bottom,$i,$n);
|
||||
}
|
||||
@if $direction == a {
|
||||
@if $n {
|
||||
#{$space}:#{$i*$uni-space-root}px;
|
||||
} @else {
|
||||
#{$space}:#{-$i*$uni-space-root}px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@each $orientation in m,p {
|
||||
$space: margin;
|
||||
@if $orientation == m {
|
||||
$space: margin;
|
||||
} @else {
|
||||
$space: padding;
|
||||
}
|
||||
@for $i from 0 through 16 {
|
||||
@each $direction in t, r, b, l, x, y, a {
|
||||
.uni-#{$orientation}#{$direction}-#{$i} {
|
||||
@include get-styles($direction,$i,$space,true);
|
||||
}
|
||||
.uni-#{$orientation}#{$direction}-n#{$i} {
|
||||
@include get-styles($direction,$i,$space,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/* #ifndef APP-NVUE */
|
||||
|
||||
$-color-white:#fff;
|
||||
$-color-black:#000;
|
||||
@mixin base-style($color) {
|
||||
color: #fff;
|
||||
background-color: $color;
|
||||
border-color: mix($-color-black, $color, 8%);
|
||||
&:not([hover-class]):active {
|
||||
background: mix($-color-black, $color, 10%);
|
||||
border-color: mix($-color-black, $color, 20%);
|
||||
color: $-color-white;
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
@mixin is-color($color) {
|
||||
@include base-style($color);
|
||||
&[loading] {
|
||||
@include base-style($color);
|
||||
&::before {
|
||||
margin-right:5px;
|
||||
}
|
||||
}
|
||||
&[disabled] {
|
||||
&,
|
||||
&[loading],
|
||||
&:not([hover-class]):active {
|
||||
color: $-color-white;
|
||||
border-color: mix(darken($color,10%), $-color-white);
|
||||
background-color: mix($color, $-color-white);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@mixin base-plain-style($color) {
|
||||
color:$color;
|
||||
background-color: mix($-color-white, $color, 90%);
|
||||
border-color: mix($-color-white, $color, 70%);
|
||||
&:not([hover-class]):active {
|
||||
background: mix($-color-white, $color, 80%);
|
||||
color: $color;
|
||||
outline: none;
|
||||
border-color: mix($-color-white, $color, 50%);
|
||||
}
|
||||
}
|
||||
@mixin is-plain($color){
|
||||
&[plain] {
|
||||
@include base-plain-style($color);
|
||||
&[loading] {
|
||||
@include base-plain-style($color);
|
||||
&::before {
|
||||
margin-right:5px;
|
||||
}
|
||||
}
|
||||
&[disabled] {
|
||||
&,
|
||||
&:active {
|
||||
color: mix($-color-white, $color, 40%);
|
||||
background-color: mix($-color-white, $color, 90%);
|
||||
border-color: mix($-color-white, $color, 80%);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.uni-btn {
|
||||
margin: 5px;
|
||||
color: #393939;
|
||||
border:1px solid #ccc;
|
||||
font-size: 16px;
|
||||
font-weight: 200;
|
||||
background-color: #F9F9F9;
|
||||
// TODO 暂时处理边框隐藏一边的问题
|
||||
overflow: visible;
|
||||
&::after{
|
||||
border: none;
|
||||
}
|
||||
|
||||
&:not([type]),&[type=default] {
|
||||
color: #999;
|
||||
&[loading] {
|
||||
background: none;
|
||||
&::before {
|
||||
margin-right:5px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
&[disabled]{
|
||||
color: mix($-color-white, #999, 60%);
|
||||
&,
|
||||
&[loading],
|
||||
&:active {
|
||||
color: mix($-color-white, #999, 60%);
|
||||
background-color: mix($-color-white,$-color-black , 98%);
|
||||
border-color: mix($-color-white, #999, 85%);
|
||||
}
|
||||
}
|
||||
|
||||
&[plain] {
|
||||
color: #999;
|
||||
background: none;
|
||||
border-color: $uni-border-1;
|
||||
&:not([hover-class]):active {
|
||||
background: none;
|
||||
color: mix($-color-white, $-color-black, 80%);
|
||||
border-color: mix($-color-white, $-color-black, 90%);
|
||||
outline: none;
|
||||
}
|
||||
&[disabled]{
|
||||
&,
|
||||
&[loading],
|
||||
&:active {
|
||||
background: none;
|
||||
color: mix($-color-white, #999, 60%);
|
||||
border-color: mix($-color-white, #999, 85%);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:not([hover-class]):active {
|
||||
color: mix($-color-white, $-color-black, 50%);
|
||||
}
|
||||
|
||||
&[size=mini] {
|
||||
font-size: 16px;
|
||||
font-weight: 200;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
&.uni-btn-small {
|
||||
font-size: 14px;
|
||||
}
|
||||
&.uni-btn-mini {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
&.uni-btn-radius {
|
||||
border-radius: 999px;
|
||||
}
|
||||
&[type=primary] {
|
||||
@include is-color($uni-primary);
|
||||
@include is-plain($uni-primary)
|
||||
}
|
||||
&[type=success] {
|
||||
@include is-color($uni-success);
|
||||
@include is-plain($uni-success)
|
||||
}
|
||||
&[type=error] {
|
||||
@include is-color($uni-error);
|
||||
@include is-plain($uni-error)
|
||||
}
|
||||
&[type=warning] {
|
||||
@include is-color($uni-warning);
|
||||
@include is-plain($uni-warning)
|
||||
}
|
||||
&[type=info] {
|
||||
@include is-color($uni-info);
|
||||
@include is-plain($uni-info)
|
||||
}
|
||||
}
|
||||
/* #endif */
|
||||
@@ -0,0 +1,24 @@
|
||||
@mixin get-styles($k,$c) {
|
||||
@if $k == size or $k == weight{
|
||||
font-#{$k}:#{$c}
|
||||
}@else{
|
||||
#{$k}:#{$c}
|
||||
}
|
||||
}
|
||||
|
||||
@each $key, $child in $uni-headings {
|
||||
/* #ifndef APP-NVUE */
|
||||
.uni-#{$key} {
|
||||
@each $k, $c in $child {
|
||||
@include get-styles($k,$c)
|
||||
}
|
||||
}
|
||||
/* #endif */
|
||||
/* #ifdef APP-NVUE */
|
||||
.container .uni-#{$key} {
|
||||
@each $k, $c in $child {
|
||||
@include get-styles($k,$c)
|
||||
}
|
||||
}
|
||||
/* #endif */
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
// @use "sass:math";
|
||||
@import '../tools/functions.scss';
|
||||
// 间距基础倍数
|
||||
$uni-space-root: 2 !default;
|
||||
// 边框半径默认值
|
||||
$uni-radius-root:5px !default;
|
||||
$uni-radius: () !default;
|
||||
// 边框半径断点
|
||||
$uni-radius: map-deep-merge(
|
||||
(
|
||||
0: 0,
|
||||
// TODO 当前版本暂时不支持 sm 属性
|
||||
// 'sm': math.div($uni-radius-root, 2),
|
||||
null: $uni-radius-root,
|
||||
'lg': $uni-radius-root * 2,
|
||||
'xl': $uni-radius-root * 6,
|
||||
'pill': 9999px,
|
||||
'circle': 50%
|
||||
),
|
||||
$uni-radius
|
||||
);
|
||||
// 字体家族
|
||||
$body-font-family: 'Roboto', sans-serif !default;
|
||||
// 文本
|
||||
$heading-font-family: $body-font-family !default;
|
||||
$uni-headings: () !default;
|
||||
$letterSpacing: -0.01562em;
|
||||
$uni-headings: map-deep-merge(
|
||||
(
|
||||
'h1': (
|
||||
size: 32px,
|
||||
weight: 300,
|
||||
line-height: 50px,
|
||||
// letter-spacing:-0.01562em
|
||||
),
|
||||
'h2': (
|
||||
size: 28px,
|
||||
weight: 300,
|
||||
line-height: 40px,
|
||||
// letter-spacing: -0.00833em
|
||||
),
|
||||
'h3': (
|
||||
size: 24px,
|
||||
weight: 400,
|
||||
line-height: 32px,
|
||||
// letter-spacing: normal
|
||||
),
|
||||
'h4': (
|
||||
size: 20px,
|
||||
weight: 400,
|
||||
line-height: 30px,
|
||||
// letter-spacing: 0.00735em
|
||||
),
|
||||
'h5': (
|
||||
size: 16px,
|
||||
weight: 400,
|
||||
line-height: 24px,
|
||||
// letter-spacing: normal
|
||||
),
|
||||
'h6': (
|
||||
size: 14px,
|
||||
weight: 500,
|
||||
line-height: 18px,
|
||||
// letter-spacing: 0.0125em
|
||||
),
|
||||
'subtitle': (
|
||||
size: 12px,
|
||||
weight: 400,
|
||||
line-height: 20px,
|
||||
// letter-spacing: 0.00937em
|
||||
),
|
||||
'body': (
|
||||
font-size: 14px,
|
||||
font-weight: 400,
|
||||
line-height: 22px,
|
||||
// letter-spacing: 0.03125em
|
||||
),
|
||||
'caption': (
|
||||
'size': 12px,
|
||||
'weight': 400,
|
||||
'line-height': 20px,
|
||||
// 'letter-spacing': 0.03333em,
|
||||
// 'text-transform': false
|
||||
)
|
||||
),
|
||||
$uni-headings
|
||||
);
|
||||
|
||||
|
||||
|
||||
// 主色
|
||||
$uni-primary: #2979ff !default;
|
||||
$uni-primary-disable:lighten($uni-primary,20%) !default;
|
||||
$uni-primary-light: lighten($uni-primary,25%) !default;
|
||||
|
||||
// 辅助色
|
||||
// 除了主色外的场景色,需要在不同的场景中使用(例如危险色表示危险的操作)。
|
||||
$uni-success: #18bc37 !default;
|
||||
$uni-success-disable:lighten($uni-success,20%) !default;
|
||||
$uni-success-light: lighten($uni-success,25%) !default;
|
||||
|
||||
$uni-warning: #f3a73f !default;
|
||||
$uni-warning-disable:lighten($uni-warning,20%) !default;
|
||||
$uni-warning-light: lighten($uni-warning,25%) !default;
|
||||
|
||||
$uni-error: #e43d33 !default;
|
||||
$uni-error-disable:lighten($uni-error,20%) !default;
|
||||
$uni-error-light: lighten($uni-error,25%) !default;
|
||||
|
||||
$uni-info: #8f939c !default;
|
||||
$uni-info-disable:lighten($uni-info,20%) !default;
|
||||
$uni-info-light: lighten($uni-info,25%) !default;
|
||||
|
||||
// 中性色
|
||||
// 中性色用于文本、背景和边框颜色。通过运用不同的中性色,来表现层次结构。
|
||||
$uni-main-color: #3a3a3a !default; // 主要文字
|
||||
$uni-base-color: #6a6a6a !default; // 常规文字
|
||||
$uni-secondary-color: #909399 !default; // 次要文字
|
||||
$uni-extra-color: #c7c7c7 !default; // 辅助说明
|
||||
|
||||
// 边框颜色
|
||||
$uni-border-1: #F0F0F0 !default;
|
||||
$uni-border-2: #EDEDED !default;
|
||||
$uni-border-3: #DCDCDC !default;
|
||||
$uni-border-4: #B9B9B9 !default;
|
||||
|
||||
// 常规色
|
||||
$uni-black: #000000 !default;
|
||||
$uni-white: #ffffff !default;
|
||||
$uni-transparent: rgba($color: #000000, $alpha: 0) !default;
|
||||
|
||||
// 背景色
|
||||
$uni-bg-color: #f7f7f7 !default;
|
||||
|
||||
/* 水平间距 */
|
||||
$uni-spacing-sm: 8px !default;
|
||||
$uni-spacing-base: 15px !default;
|
||||
$uni-spacing-lg: 30px !default;
|
||||
|
||||
// 阴影
|
||||
$uni-shadow-sm:0 0 5px rgba($color: #d8d8d8, $alpha: 0.5) !default;
|
||||
$uni-shadow-base:0 1px 8px 1px rgba($color: #a5a5a5, $alpha: 0.2) !default;
|
||||
$uni-shadow-lg:0px 1px 10px 2px rgba($color: #a5a4a4, $alpha: 0.5) !default;
|
||||
|
||||
// 蒙版
|
||||
$uni-mask: rgba($color: #000000, $alpha: 0.4) !default;
|
||||
@@ -0,0 +1,19 @@
|
||||
// 合并 map
|
||||
@function map-deep-merge($parent-map, $child-map){
|
||||
$result: $parent-map;
|
||||
@each $key, $child in $child-map {
|
||||
$parent-has-key: map-has-key($result, $key);
|
||||
$parent-value: map-get($result, $key);
|
||||
$parent-type: type-of($parent-value);
|
||||
$child-type: type-of($child);
|
||||
$parent-is-map: $parent-type == map;
|
||||
$child-is-map: $child-type == map;
|
||||
|
||||
@if (not $parent-has-key) or ($parent-type != $child-type) or (not ($parent-is-map and $child-is-map)){
|
||||
$result: map-merge($result, ( $key: $child ));
|
||||
}@else {
|
||||
$result: map-merge($result, ( $key: map-deep-merge($parent-value, $child) ));
|
||||
}
|
||||
}
|
||||
@return $result;
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
// 间距基础倍数
|
||||
$uni-space-root: 2;
|
||||
// 边框半径默认值
|
||||
$uni-radius-root:5px;
|
||||
// 主色
|
||||
$uni-primary: #2979ff;
|
||||
// 辅助色
|
||||
$uni-success: #4cd964;
|
||||
// 警告色
|
||||
$uni-warning: #f0ad4e;
|
||||
// 错误色
|
||||
$uni-error: #dd524d;
|
||||
// 描述色
|
||||
$uni-info: #909399;
|
||||
// 中性色
|
||||
$uni-main-color: #303133;
|
||||
$uni-base-color: #606266;
|
||||
$uni-secondary-color: #909399;
|
||||
$uni-extra-color: #C0C4CC;
|
||||
// 背景色
|
||||
$uni-bg-color: #f5f5f5;
|
||||
// 边框颜色
|
||||
$uni-border-1: #DCDFE6;
|
||||
$uni-border-2: #E4E7ED;
|
||||
$uni-border-3: #EBEEF5;
|
||||
$uni-border-4: #F2F6FC;
|
||||
|
||||
// 常规色
|
||||
$uni-black: #000000;
|
||||
$uni-white: #ffffff;
|
||||
$uni-transparent: rgba($color: #000000, $alpha: 0);
|
||||
@@ -0,0 +1,62 @@
|
||||
@import './styles/setting/_variables.scss';
|
||||
// 间距基础倍数
|
||||
$uni-space-root: 2;
|
||||
// 边框半径默认值
|
||||
$uni-radius-root:5px;
|
||||
|
||||
// 主色
|
||||
$uni-primary: #2979ff;
|
||||
$uni-primary-disable:mix(#fff,$uni-primary,50%);
|
||||
$uni-primary-light: mix(#fff,$uni-primary,80%);
|
||||
|
||||
// 辅助色
|
||||
// 除了主色外的场景色,需要在不同的场景中使用(例如危险色表示危险的操作)。
|
||||
$uni-success: #18bc37;
|
||||
$uni-success-disable:mix(#fff,$uni-success,50%);
|
||||
$uni-success-light: mix(#fff,$uni-success,80%);
|
||||
|
||||
$uni-warning: #f3a73f;
|
||||
$uni-warning-disable:mix(#fff,$uni-warning,50%);
|
||||
$uni-warning-light: mix(#fff,$uni-warning,80%);
|
||||
|
||||
$uni-error: #e43d33;
|
||||
$uni-error-disable:mix(#fff,$uni-error,50%);
|
||||
$uni-error-light: mix(#fff,$uni-error,80%);
|
||||
|
||||
$uni-info: #8f939c;
|
||||
$uni-info-disable:mix(#fff,$uni-info,50%);
|
||||
$uni-info-light: mix(#fff,$uni-info,80%);
|
||||
|
||||
// 中性色
|
||||
// 中性色用于文本、背景和边框颜色。通过运用不同的中性色,来表现层次结构。
|
||||
$uni-main-color: #3a3a3a; // 主要文字
|
||||
$uni-base-color: #6a6a6a; // 常规文字
|
||||
$uni-secondary-color: #909399; // 次要文字
|
||||
$uni-extra-color: #c7c7c7; // 辅助说明
|
||||
|
||||
// 边框颜色
|
||||
$uni-border-1: #F0F0F0;
|
||||
$uni-border-2: #EDEDED;
|
||||
$uni-border-3: #DCDCDC;
|
||||
$uni-border-4: #B9B9B9;
|
||||
|
||||
// 常规色
|
||||
$uni-black: #000000;
|
||||
$uni-white: #ffffff;
|
||||
$uni-transparent: rgba($color: #000000, $alpha: 0);
|
||||
|
||||
// 背景色
|
||||
$uni-bg-color: #f7f7f7;
|
||||
|
||||
/* 水平间距 */
|
||||
$uni-spacing-sm: 8px;
|
||||
$uni-spacing-base: 15px;
|
||||
$uni-spacing-lg: 30px;
|
||||
|
||||
// 阴影
|
||||
$uni-shadow-sm:0 0 5px rgba($color: #d8d8d8, $alpha: 0.5);
|
||||
$uni-shadow-base:0 1px 8px 1px rgba($color: #a5a5a5, $alpha: 0.2);
|
||||
$uni-shadow-lg:0px 1px 10px 2px rgba($color: #a5a4a4, $alpha: 0.5);
|
||||
|
||||
// 蒙版
|
||||
$uni-mask: rgba($color: #000000, $alpha: 0.4);
|
||||
+20
-185
@@ -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} 是否已登录
|
||||
*/
|
||||
export function checkLoginWithPrompt(scene = '') {
|
||||
if (isLoggedIn()) return true;
|
||||
|
||||
const SCENE_TIPS = {
|
||||
order: '登录后即可查看订单',
|
||||
mine: '登录后即可查看个人信息',
|
||||
pay: '登录后即可下单购买',
|
||||
};
|
||||
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: SCENE_TIPS[scene] || '需要登录后操作',
|
||||
@@ -39,7 +37,8 @@ export function checkLoginWithPrompt(scene = '') {
|
||||
cancelText: '暂不',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
startAuth();
|
||||
// 跳转到授权 Loading 页
|
||||
uni.redirectTo({ url: '/pages/auth/loading' });
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -48,153 +47,15 @@ export function checkLoginWithPrompt(scene = '') {
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查登录状态,未登录时静默跳转授权(不弹窗)
|
||||
* 检查登录状态,未登录时静默跳转
|
||||
* @returns {boolean} 是否已登录
|
||||
*/
|
||||
export function requireLogin() {
|
||||
if (isLoggedIn()) return true;
|
||||
startAuth();
|
||||
uni.redirectTo({ url: '/pages/auth/loading' });
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
@@ -211,36 +72,10 @@ export function logout() {
|
||||
*/
|
||||
export function getCachedUserInfo() {
|
||||
try {
|
||||
return uni.getStorageSync('user_info') || null;
|
||||
const userInfo = uni.getStorageSync('user_info');
|
||||
console.log('[auth-guard] getCachedUserInfo raw:', JSON.stringify(userInfo, null, 2));
|
||||
return userInfo || null;
|
||||
} catch {
|
||||
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,15 @@ export function request(options = {}) {
|
||||
...options.header,
|
||||
};
|
||||
|
||||
// 公开接口(授权相关)不带 Authorization,避免 CORS 预检和 JWT 拦截
|
||||
const publicPaths = ['/api/v1/user/auth/url', '/api/v1/user/auth/callback'];
|
||||
// 公开接口(授权/登录/注册相关)不带 Authorization,避免 CORS 预检和 JWT 拦截
|
||||
const publicPaths = [
|
||||
'/api/v1/user/auth/url',
|
||||
'/api/v1/user/auth/exchange',
|
||||
'/api/v1/user/login',
|
||||
'/api/v1/user/register',
|
||||
'/api/v1/user/sms/send',
|
||||
'/api/v1/user/info',
|
||||
];
|
||||
const isPublic = publicPaths.some((p) => url.includes(p));
|
||||
|
||||
if (token && !isPublic) {
|
||||
|
||||
+25
-1
@@ -1,8 +1,31 @@
|
||||
import { defineConfig } from 'vite'
|
||||
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({
|
||||
plugins: [uni()],
|
||||
plugins: [servePublicFiles(), uni()],
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
scss: {
|
||||
@@ -10,4 +33,5 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
},
|
||||
publicDir: 'public',
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user