Compare commits
43 Commits
v1.0.8
...
v1.0.12-beta
| Author | SHA1 | Date | |
|---|---|---|---|
| fd3cd58123 | |||
| 97d4be5772 | |||
| b2b92ec6b4 | |||
| b336b901d3 | |||
| 9439bcf9d7 | |||
| d862cad1a0 | |||
| 85d5193071 | |||
| 9551d9d8b2 | |||
| 81bec5ba3b | |||
| 729bc3c70e | |||
| 2e84a00f6e | |||
| 8b5d68592b | |||
| 42c2b8de07 | |||
| 580350cb33 | |||
| 020e131df0 | |||
| 533170f0a9 | |||
| b1924e2623 | |||
| e12663052f | |||
| 842defea21 | |||
| d392ff98b7 | |||
| 18870f3e7d | |||
| 878778f8f9 | |||
| eac66c965b | |||
| 149fcdd231 | |||
| 2978ac25f7 | |||
| a08afd0cfd | |||
| 4292c0f819 | |||
| a9ec1092d5 | |||
| 9ecd6d963b | |||
| 925ebe9bb9 | |||
| 258fa4a9f5 | |||
| 45147426e0 | |||
| 7b2e4dc72e | |||
| 0fc854cd33 | |||
| 20649c67a9 | |||
| 3a154198e9 | |||
| c84c9df5d4 | |||
| 71606ebfe5 | |||
| a7e0366fb7 | |||
| 5bb31516a0 | |||
| 2560d9d529 | |||
| 6534723050 | |||
| f031501286 |
@@ -92,11 +92,15 @@ jobs:
|
|||||||
# 3. 安装依赖 & 构建 Uni-app (H5)
|
# 3. 安装依赖 & 构建 Uni-app (H5)
|
||||||
###############################################
|
###############################################
|
||||||
- name: Install dependencies and Build H5
|
- name: Install dependencies and Build H5
|
||||||
|
env:
|
||||||
|
DEPLOY_ENV: ${{ steps.detect.outputs.env }}
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
# pnpm真实路径
|
# pnpm真实路径
|
||||||
PNPM_PATH="/root/.nvm/versions/node/v20.20.2/bin/pnpm"
|
PNPM_PATH="/root/.nvm/versions/node/v20.20.2/bin/pnpm"
|
||||||
|
|
||||||
|
echo "构建环境: DEPLOY_ENV=$DEPLOY_ENV"
|
||||||
|
|
||||||
# 1. 配置镜像并安装依赖
|
# 1. 配置镜像并安装依赖
|
||||||
$PNPM_PATH config set registry https://registry.npmmirror.com
|
$PNPM_PATH config set registry https://registry.npmmirror.com
|
||||||
$PNPM_PATH install --frozen-lockfile
|
$PNPM_PATH install --frozen-lockfile
|
||||||
@@ -110,9 +114,16 @@ jobs:
|
|||||||
- name: Upload dist to server
|
- name: Upload dist to server
|
||||||
run: |
|
run: |
|
||||||
TARGET="${{ steps.detect.outputs.target }}"
|
TARGET="${{ steps.detect.outputs.target }}"
|
||||||
|
ENV_NAME="${{ steps.detect.outputs.env }}"
|
||||||
# 请根据你的实际构建输出路径调整
|
# 请根据你的实际构建输出路径调整
|
||||||
H5_SOURCE_DIR="dist/build/h5"
|
H5_SOURCE_DIR="dist/build/h5"
|
||||||
WEB_ROOT="${{ vars.PROJECT_DIR }}"
|
|
||||||
|
# 根据发布类型选择项目路径
|
||||||
|
if [ "$ENV_NAME" = "staging" ]; then
|
||||||
|
WEB_ROOT="${{ vars.STG_PROJECT_DIR }}"
|
||||||
|
else
|
||||||
|
WEB_ROOT="${{ vars.PROJECT_DIR }}"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "部署到: $TARGET"
|
echo "部署到: $TARGET"
|
||||||
echo "源目录: $H5_SOURCE_DIR"
|
echo "源目录: $H5_SOURCE_DIR"
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
2K94E8Rn63mn6Nys
|
||||||
+71
-17
@@ -1,47 +1,101 @@
|
|||||||
<script>
|
<script>
|
||||||
import { initEnv } from '@/utils/env.js';
|
import { initEnv } from '@/utils/env.js';
|
||||||
|
import config from '@/config/env.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
onLaunch: function(options) {
|
onLaunch: function(options) {
|
||||||
console.log('App Launch')
|
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
|
// 1. 环境检测 + 缓存 app_no/platform
|
||||||
initEnv();
|
initEnv();
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
// 2. 解析 URL 路径中的设备编号(如 /A1036)
|
// 2. 解析设备编号:优先从 query 参数获取,其次从路径解析
|
||||||
let deviceId = '';
|
let deviceId = '';
|
||||||
const path = window.location.pathname;
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const segments = path.split('/').filter(Boolean);
|
deviceId = urlParams.get('device_id') || '';
|
||||||
if (segments.length > 0) {
|
|
||||||
const last = segments[segments.length - 1];
|
// 兜底:从路径解析(如 /N1154)
|
||||||
if (/^[A-Z][A-Z0-9]+$/.test(last)) {
|
if (!deviceId) {
|
||||||
deviceId = last;
|
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
|
// 3. 检查 URL 中是否有授权回调的 code
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
const code = urlParams.get('code');
|
const code = urlParams.get('code');
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
// 有 code → 进入授权 Loading 页处理
|
// 有 code → 进入授权 Loading 页处理
|
||||||
const loadingUrl = deviceId
|
// 从 state 中解析 device_id 和 action(OAuth 标准保证 state 原样回传)
|
||||||
? `/pages/auth/loading?device_id=${deviceId}`
|
let action = '';
|
||||||
: '/pages/auth/loading';
|
let callbackDeviceId = deviceId || '';
|
||||||
|
try {
|
||||||
|
const stateStr = urlParams.get('state');
|
||||||
|
if (stateStr) {
|
||||||
|
const stateObj = JSON.parse(decodeURIComponent(stateStr));
|
||||||
|
action = stateObj.action || action;
|
||||||
|
callbackDeviceId = stateObj.device_id || callbackDeviceId;
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
// state 解析失败,忽略
|
||||||
|
}
|
||||||
|
// 存入 localStorage,确保 loading 页面复用时也能获取(redirectTo 可能不触发 onLoad)
|
||||||
|
if (action) {
|
||||||
|
localStorage.setItem('__auth_action', action);
|
||||||
|
}
|
||||||
|
if (callbackDeviceId) {
|
||||||
|
localStorage.setItem('__auth_device_id', callbackDeviceId);
|
||||||
|
}
|
||||||
|
let loadingUrl = '/pages/auth/loading?code=' + encodeURIComponent(code);
|
||||||
|
if (action) {
|
||||||
|
loadingUrl += '&action=' + action;
|
||||||
|
}
|
||||||
|
if (callbackDeviceId) {
|
||||||
|
loadingUrl += '&device_id=' + callbackDeviceId;
|
||||||
|
}
|
||||||
uni.redirectTo({ url: loadingUrl });
|
uni.redirectTo({ url: loadingUrl });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 检查 JWT
|
// 4. 判断是否为根路径或设备编号路径(如 / 或 /N1154)
|
||||||
|
const currentPath = window.location.pathname;
|
||||||
|
const isRootOrDevice = currentPath === '/' || /^\/[A-Z][A-Z0-9]+$/.test(currentPath);
|
||||||
|
|
||||||
|
// 5. 检查 JWT
|
||||||
const token = uni.getStorageSync('token');
|
const token = uni.getStorageSync('token');
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
// 有 JWT → 直接进入首页
|
if (isRootOrDevice) {
|
||||||
const homeUrl = deviceId
|
// 根路径/设备编号路径 → 跳转首页
|
||||||
? `/pages/index/index?device_id=${deviceId}`
|
const homeUrl = deviceId
|
||||||
: '/pages/index/scan';
|
? `/pages/index/index?device_id=${deviceId}`
|
||||||
uni.redirectTo({ url: homeUrl });
|
: '/pages/index/scan';
|
||||||
|
uni.redirectTo({ url: homeUrl });
|
||||||
|
} else {
|
||||||
|
// 其他业务页面 → 留在当前页面
|
||||||
|
console.log('[App] 已登录,保留在当前页面');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 无 JWT → 进入授权 Loading 页
|
// 无 JWT → 进入授权 Loading 页
|
||||||
const loadingUrl = deviceId
|
const loadingUrl = deviceId
|
||||||
|
|||||||
@@ -0,0 +1,660 @@
|
|||||||
|
<template>
|
||||||
|
<view v-if="step" class="door-overlay">
|
||||||
|
|
||||||
|
<!-- 开门中 -->
|
||||||
|
<view v-if="step === 'opening'" class="door-overlay-content">
|
||||||
|
<view class="door-spinner">
|
||||||
|
<view class="spinner-dot" v-for="i in 3" :key="i"></view>
|
||||||
|
</view>
|
||||||
|
<text class="door-overlay-text">开门中...</text>
|
||||||
|
<text class="door-overlay-tip">请稍候,正在为您打开柜门</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 已开门 -->
|
||||||
|
<view v-if="step === 'opened'" class="door-state-bg">
|
||||||
|
<view class="door-state-content">
|
||||||
|
<view class="door-state-icon-wrap">
|
||||||
|
<view class="door-state-ring"></view>
|
||||||
|
<view class="door-state-icon">
|
||||||
|
<view class="icon-door-left"></view>
|
||||||
|
<view class="icon-door-right"></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<text class="door-state-title">门锁已打开</text>
|
||||||
|
<text class="door-state-desc">请先拉开柜门,取走商品后随手关门</text>
|
||||||
|
<view class="door-state-divider"></view>
|
||||||
|
<view class="door-steps">
|
||||||
|
<view class="step-item">
|
||||||
|
<view class="step-dot active">1</view>
|
||||||
|
<text class="step-text">取走商品</text>
|
||||||
|
</view>
|
||||||
|
<view class="step-line"></view>
|
||||||
|
<view class="step-item">
|
||||||
|
<view class="step-dot">2</view>
|
||||||
|
<text class="step-text">关闭柜门</text>
|
||||||
|
</view>
|
||||||
|
<view class="step-line"></view>
|
||||||
|
<view class="step-item">
|
||||||
|
<view class="step-dot">3</view>
|
||||||
|
<text class="step-text">完成订单</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="door-btn-area">
|
||||||
|
<view class="door-btn-close" @click="handleClose">返回首页</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 已关门 -->
|
||||||
|
<view v-if="step === 'closed'" class="door-state-bg">
|
||||||
|
<view class="door-state-content">
|
||||||
|
<view class="door-state-icon-wrap">
|
||||||
|
<view class="door-state-ring warning-ring"></view>
|
||||||
|
<view class="door-state-icon">
|
||||||
|
<view class="icon-lock">
|
||||||
|
<view class="lock-body"></view>
|
||||||
|
<view class="lock-hole"></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<text class="door-state-title">柜门已关闭</text>
|
||||||
|
<text class="door-state-desc">订单处理中,请稍候...</text>
|
||||||
|
<view class="door-state-divider"></view>
|
||||||
|
<view class="door-steps">
|
||||||
|
<view class="step-item">
|
||||||
|
<view class="step-dot done">✓</view>
|
||||||
|
<text class="step-text">取走商品</text>
|
||||||
|
</view>
|
||||||
|
<view class="step-line done"></view>
|
||||||
|
<view class="step-item">
|
||||||
|
<view class="step-dot active">2</view>
|
||||||
|
<text class="step-text">已关柜门</text>
|
||||||
|
</view>
|
||||||
|
<view class="step-line"></view>
|
||||||
|
<view class="step-item">
|
||||||
|
<view class="step-dot">3</view>
|
||||||
|
<text class="step-text">完成订单</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="door-btn-area">
|
||||||
|
<view class="door-btn-close" @click="handleClose">返回首页</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 订单完成 -->
|
||||||
|
<view v-if="step === 'complete'" class="door-state-bg">
|
||||||
|
<view class="door-state-content door-complete-content">
|
||||||
|
<view class="door-state-icon-wrap">
|
||||||
|
<view class="door-state-ring success-ring"></view>
|
||||||
|
<view class="door-state-icon">
|
||||||
|
<view class="icon-check"></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<text class="door-state-title">订单已完成</text>
|
||||||
|
<text class="door-state-desc">感谢您的购买</text>
|
||||||
|
|
||||||
|
<!-- 订单信息 -->
|
||||||
|
<view class="door-order-card" v-if="orderInfo">
|
||||||
|
<!-- 商品列表 -->
|
||||||
|
<view class="door-product-list" v-if="orderInfo.products && orderInfo.products.length">
|
||||||
|
<view class="door-product-item" v-for="(p, idx) in orderInfo.products" :key="idx">
|
||||||
|
<image class="door-product-img" :src="p.image" mode="aspectFill" />
|
||||||
|
<view class="door-product-info">
|
||||||
|
<text class="door-product-name">{{ p.name }}</text>
|
||||||
|
<text class="door-product-price">¥{{ getDecimal(p.unit_price) }} x {{ p.qty }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="door-order-row">
|
||||||
|
<text class="door-order-label">订单编号</text>
|
||||||
|
<text class="door-order-value">{{ orderInfo.order_no }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="door-order-row">
|
||||||
|
<text class="door-order-label">商品数量</text>
|
||||||
|
<text class="door-order-value">{{ orderInfo.total_qty || '-' }} 件</text>
|
||||||
|
</view>
|
||||||
|
<view class="door-order-row total">
|
||||||
|
<text class="door-order-label">订单金额</text>
|
||||||
|
<text class="door-order-value door-price">¥{{ getDecimal(orderInfo.total_amount) }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="door-btn-area">
|
||||||
|
<view class="door-btn-detail" @click="goOrderDetail">查看订单详情</view>
|
||||||
|
<view class="door-btn-close" @click="handleClose">返回首页</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { get, post } from '@/utils/request.js';
|
||||||
|
import { detectPlatform } from '@/utils/env.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
deviceId: { type: String, default: '' },
|
||||||
|
userId: { type: String, default: '' }
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
step: '', // '' | 'opening' | 'opened' | 'closed' | 'complete'
|
||||||
|
flowId: '',
|
||||||
|
orderInfo: null,
|
||||||
|
orderLoading: false,
|
||||||
|
cancelled: false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
this.cancelled = true;
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 外部调用:启动开门流程
|
||||||
|
async open(userId) {
|
||||||
|
if (this.step) return;
|
||||||
|
|
||||||
|
this.cancelled = false;
|
||||||
|
this.step = 'opening';
|
||||||
|
|
||||||
|
const uid = userId || this.userId;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await post('/device-scan/open', {
|
||||||
|
device_id: this.deviceId,
|
||||||
|
door_index: 0,
|
||||||
|
user_id: uid,
|
||||||
|
platform: detectPlatform()
|
||||||
|
});
|
||||||
|
|
||||||
|
const ret = res.data || {};
|
||||||
|
if (ret.code !== 0) {
|
||||||
|
this.step = '';
|
||||||
|
uni.showToast({ title: ret.message || '开门失败', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const flowId = ret.data && ret.data.flow_id;
|
||||||
|
if (!flowId) {
|
||||||
|
this.step = '';
|
||||||
|
uni.showToast({ title: '未获取到开门流水号', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.flowId = flowId;
|
||||||
|
this.pollStatus(flowId);
|
||||||
|
} catch (e) {
|
||||||
|
this.step = '';
|
||||||
|
uni.showToast({ title: '网络请求失败', icon: 'none' });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 轮询状态
|
||||||
|
async pollStatus(flowId) {
|
||||||
|
const maxRetries = 30;
|
||||||
|
const interval = 2000;
|
||||||
|
let remaining = maxRetries;
|
||||||
|
let lastStep = '';
|
||||||
|
|
||||||
|
while (remaining > 0) {
|
||||||
|
if (this.step === 'complete' || this.cancelled) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await get('/flow/getStatusLog', {
|
||||||
|
flow_id: flowId,
|
||||||
|
status: '101,103,201'
|
||||||
|
});
|
||||||
|
|
||||||
|
const ret = res.data || {};
|
||||||
|
if (ret.code === 0 && Array.isArray(ret.data) && ret.data.length > 0) {
|
||||||
|
const latestStatus = ret.data[0].status;
|
||||||
|
let newStep = '';
|
||||||
|
|
||||||
|
if (latestStatus === 101) {
|
||||||
|
newStep = 'opened';
|
||||||
|
} else if (latestStatus === 103) {
|
||||||
|
newStep = 'closed';
|
||||||
|
} else if (latestStatus === 201) {
|
||||||
|
this.step = 'complete';
|
||||||
|
this.fetchOrder(flowId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 状态真正变化时才重置计数器
|
||||||
|
if (newStep && newStep !== lastStep) {
|
||||||
|
this.step = newStep;
|
||||||
|
lastStep = newStep;
|
||||||
|
remaining = maxRetries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[door-panel] 轮询失败:', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
remaining--;
|
||||||
|
await new Promise(resolve => setTimeout(resolve, interval));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 轮询结束
|
||||||
|
if (this.step === 'opening') {
|
||||||
|
this.step = '';
|
||||||
|
uni.showToast({ title: '开门超时,请重试', icon: 'none' });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 查询订单信息
|
||||||
|
async fetchOrder(orderId) {
|
||||||
|
if (!orderId || !this.userId) {
|
||||||
|
this.orderLoading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.orderLoading = true;
|
||||||
|
try {
|
||||||
|
const res = await get('/user/orders', {
|
||||||
|
page: 1,
|
||||||
|
limit: 1,
|
||||||
|
filter: JSON.stringify({ user_id: this.userId, order_id: orderId })
|
||||||
|
});
|
||||||
|
const ret = res.data || {};
|
||||||
|
if (ret.code === 0 && Array.isArray(ret.data) && ret.data.length > 0) {
|
||||||
|
this.orderInfo = ret.data[0];
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[door-panel] 获取订单信息失败:', e);
|
||||||
|
} finally {
|
||||||
|
this.orderLoading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// MongoDB Decimal128 转换
|
||||||
|
getDecimal(val) {
|
||||||
|
if (val == null) return '0.00';
|
||||||
|
if (typeof val === 'object' && val.$numberDecimal) return val.$numberDecimal;
|
||||||
|
return String(val);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 跳转订单详情
|
||||||
|
goOrderDetail() {
|
||||||
|
if (this.orderInfo) {
|
||||||
|
const orderId = this.orderInfo.order_id || '';
|
||||||
|
uni.setStorageSync('__order_detail_cache', this.orderInfo);
|
||||||
|
uni.navigateTo({ url: `/pages/order/detail?order_id=${orderId}` });
|
||||||
|
} else if (this.flowId) {
|
||||||
|
uni.navigateTo({ url: `/pages/order/detail?flow_id=${this.flowId}` });
|
||||||
|
} else {
|
||||||
|
uni.showToast({ title: '无法获取订单信息', icon: 'none' });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 关闭遮罩
|
||||||
|
handleClose() {
|
||||||
|
this.step = '';
|
||||||
|
this.flowId = '';
|
||||||
|
this.orderInfo = null;
|
||||||
|
this.orderLoading = false;
|
||||||
|
this.$emit('close');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
/* ====== 开门中遮罩 ====== */
|
||||||
|
.door-overlay {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.7);
|
||||||
|
z-index: 3000;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.door-overlay-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: 60rpx;
|
||||||
|
}
|
||||||
|
.door-spinner {
|
||||||
|
display: flex;
|
||||||
|
gap: 16rpx;
|
||||||
|
margin-bottom: 40rpx;
|
||||||
|
}
|
||||||
|
.spinner-dot {
|
||||||
|
width: 20rpx;
|
||||||
|
height: 20rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #fff;
|
||||||
|
animation: spinner-bounce 1.2s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
.spinner-dot:nth-child(2) { animation-delay: 0.2s; }
|
||||||
|
.spinner-dot:nth-child(3) { animation-delay: 0.4s; }
|
||||||
|
@keyframes spinner-bounce {
|
||||||
|
0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
|
||||||
|
30% { transform: translateY(-20rpx); opacity: 1; }
|
||||||
|
}
|
||||||
|
.door-overlay-text {
|
||||||
|
font-size: 36rpx;
|
||||||
|
color: #fff;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 16rpx;
|
||||||
|
}
|
||||||
|
.door-overlay-tip {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: rgba(255, 255, 255, 0.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ====== 通用状态页背景 ====== */
|
||||||
|
.door-state-bg {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background: #fff;
|
||||||
|
z-index: 3000;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.door-state-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 60rpx;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.door-complete-content {
|
||||||
|
max-height: 85vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ====== 图标区域 ====== */
|
||||||
|
.door-state-icon-wrap {
|
||||||
|
position: relative;
|
||||||
|
width: 180rpx;
|
||||||
|
height: 180rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin-bottom: 48rpx;
|
||||||
|
/* 动效环 scale(1.6) 会超出容器,预留空间避免被裁剪 */
|
||||||
|
margin-top: 60rpx;
|
||||||
|
}
|
||||||
|
.door-state-ring {
|
||||||
|
position: absolute;
|
||||||
|
width: 180rpx;
|
||||||
|
height: 180rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 4rpx solid rgba(41, 121, 255, 0.3);
|
||||||
|
animation: ring-pulse 2s ease-out infinite;
|
||||||
|
}
|
||||||
|
.warning-ring {
|
||||||
|
border-color: rgba(250, 173, 20, 0.3);
|
||||||
|
}
|
||||||
|
.success-ring {
|
||||||
|
border-color: rgba(82, 196, 26, 0.3);
|
||||||
|
}
|
||||||
|
@keyframes ring-pulse {
|
||||||
|
0% { transform: scale(0.8); opacity: 1; }
|
||||||
|
100% { transform: scale(1.6); opacity: 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.door-state-icon {
|
||||||
|
width: 80rpx;
|
||||||
|
height: 80rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 柜门图标(已开门) */
|
||||||
|
.icon-door-left {
|
||||||
|
width: 28rpx;
|
||||||
|
height: 56rpx;
|
||||||
|
background: #2979ff;
|
||||||
|
border-radius: 6rpx;
|
||||||
|
transform: perspective(200rpx) rotateY(25deg);
|
||||||
|
animation: door-left-open 0.8s ease-out forwards;
|
||||||
|
}
|
||||||
|
.icon-door-right {
|
||||||
|
width: 28rpx;
|
||||||
|
height: 56rpx;
|
||||||
|
background: #2979ff;
|
||||||
|
border-radius: 6rpx;
|
||||||
|
transform: perspective(200rpx) rotateY(-25deg);
|
||||||
|
animation: door-right-open 0.8s ease-out forwards;
|
||||||
|
}
|
||||||
|
@keyframes door-left-open {
|
||||||
|
0% { transform: perspective(200rpx) rotateY(0deg); }
|
||||||
|
100% { transform: perspective(200rpx) rotateY(35deg); }
|
||||||
|
}
|
||||||
|
@keyframes door-right-open {
|
||||||
|
0% { transform: perspective(200rpx) rotateY(0deg); }
|
||||||
|
100% { transform: perspective(200rpx) rotateY(-35deg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 锁图标(已关门) */
|
||||||
|
.icon-lock {
|
||||||
|
position: relative;
|
||||||
|
width: 48rpx;
|
||||||
|
height: 56rpx;
|
||||||
|
}
|
||||||
|
.lock-body {
|
||||||
|
width: 48rpx;
|
||||||
|
height: 36rpx;
|
||||||
|
background: #faad14;
|
||||||
|
border-radius: 6rpx;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
.lock-hole {
|
||||||
|
width: 28rpx;
|
||||||
|
height: 24rpx;
|
||||||
|
border: 5rpx solid #faad14;
|
||||||
|
border-radius: 14rpx 14rpx 0 0;
|
||||||
|
border-bottom: none;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 勾图标(订单完成) */
|
||||||
|
.icon-check {
|
||||||
|
width: 40rpx;
|
||||||
|
height: 24rpx;
|
||||||
|
border-left: 5rpx solid #52c41a;
|
||||||
|
border-bottom: 5rpx solid #52c41a;
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
margin-top: -8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ====== 标题 ====== */
|
||||||
|
.door-state-title {
|
||||||
|
font-size: 44rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 16rpx;
|
||||||
|
letter-spacing: 4rpx;
|
||||||
|
}
|
||||||
|
.door-state-desc {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #999;
|
||||||
|
margin-bottom: 48rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ====== 分割线 ====== */
|
||||||
|
.door-state-divider {
|
||||||
|
width: 80rpx;
|
||||||
|
height: 4rpx;
|
||||||
|
background: linear-gradient(90deg, transparent, #2979ff, transparent);
|
||||||
|
border-radius: 2rpx;
|
||||||
|
margin-bottom: 48rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ====== 步骤条 ====== */
|
||||||
|
.door-steps {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.step-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12rpx;
|
||||||
|
}
|
||||||
|
.step-dot {
|
||||||
|
width: 44rpx;
|
||||||
|
height: 44rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #f5f5f5;
|
||||||
|
border: 2rpx solid #e0e0e0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 22rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
.step-dot.active {
|
||||||
|
background: rgba(41, 121, 255, 0.1);
|
||||||
|
border-color: #2979ff;
|
||||||
|
color: #2979ff;
|
||||||
|
}
|
||||||
|
.step-dot.done {
|
||||||
|
background: rgba(41, 121, 255, 0.1);
|
||||||
|
border-color: #2979ff;
|
||||||
|
color: #2979ff;
|
||||||
|
font-size: 20rpx;
|
||||||
|
}
|
||||||
|
.step-text {
|
||||||
|
font-size: 22rpx;
|
||||||
|
color: #999;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.step-line {
|
||||||
|
width: 60rpx;
|
||||||
|
height: 2rpx;
|
||||||
|
background: #e0e0e0;
|
||||||
|
margin-bottom: 36rpx;
|
||||||
|
}
|
||||||
|
.step-line.done {
|
||||||
|
background: #2979ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ====== 订单卡片 ====== */
|
||||||
|
.door-order-card {
|
||||||
|
width: 100%;
|
||||||
|
background: #f8f8f8;
|
||||||
|
border: 1rpx solid #f0f0f0;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
padding: 24rpx 30rpx;
|
||||||
|
margin-top: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 商品列表 */
|
||||||
|
.door-product-list {
|
||||||
|
margin-bottom: 12rpx;
|
||||||
|
}
|
||||||
|
.door-product-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 12rpx 0;
|
||||||
|
}
|
||||||
|
.door-product-item + .door-product-item {
|
||||||
|
border-top: 1rpx solid #f0f0f0;
|
||||||
|
}
|
||||||
|
.door-product-img {
|
||||||
|
width: 80rpx;
|
||||||
|
height: 80rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
background: #f0f0f0;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.door-product-info {
|
||||||
|
flex: 1;
|
||||||
|
margin-left: 16rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6rpx;
|
||||||
|
}
|
||||||
|
.door-product-name {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #333;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.door-product-price {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
.door-order-row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 16rpx 0;
|
||||||
|
}
|
||||||
|
.door-order-row + .door-order-row {
|
||||||
|
border-top: 1rpx solid #f0f0f0;
|
||||||
|
}
|
||||||
|
.door-order-row.total {
|
||||||
|
border-top: 1rpx solid #e0e0e0;
|
||||||
|
margin-top: 8rpx;
|
||||||
|
padding-top: 20rpx;
|
||||||
|
}
|
||||||
|
.door-order-label {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
.door-order-value {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.door-price {
|
||||||
|
font-size: 36rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #e4393c;
|
||||||
|
}
|
||||||
|
.door-order-loading {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #999;
|
||||||
|
text-align: center;
|
||||||
|
padding: 16rpx 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ====== 按钮区域 ====== */
|
||||||
|
.door-btn-area {
|
||||||
|
margin-top: 64rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ====== 查看订单详情按钮 ====== */
|
||||||
|
.door-btn-detail {
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #fff;
|
||||||
|
padding: 24rpx 80rpx;
|
||||||
|
background: linear-gradient(135deg, #2979ff, #1e60e0);
|
||||||
|
border-radius: 48rpx;
|
||||||
|
letter-spacing: 2rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ====== 关闭按钮 ====== */
|
||||||
|
.door-btn-close {
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #2979ff;
|
||||||
|
padding: 24rpx 100rpx;
|
||||||
|
background: #fff;
|
||||||
|
border: 2rpx solid #2979ff;
|
||||||
|
border-radius: 48rpx;
|
||||||
|
letter-spacing: 2rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
+22
-3
@@ -6,16 +6,35 @@ const dev = {
|
|||||||
apiBaseUrl: 'http://192.168.0.23:4000',
|
apiBaseUrl: 'http://192.168.0.23:4000',
|
||||||
|
|
||||||
// 网关地址(vms-gateway,端口 4001)— 用户授权、短信等接口走网关
|
// 网关地址(vms-gateway,端口 4001)— 用户授权、短信等接口走网关
|
||||||
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
apiGatewayUrl: 'http://192.168.0.23:4001',
|
||||||
|
|
||||||
// 授权回调地址(支付宝/微信 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',
|
||||||
|
|
||||||
// 是否开启请求日志
|
// 是否开启请求日志
|
||||||
enableRequestLog: true,
|
enableRequestLog: true,
|
||||||
|
|
||||||
|
// Mock 微信登录(跳过 OAuth 流程)
|
||||||
|
// 'skip' → 直接登录进首页
|
||||||
|
// 'register' → 模拟新用户,走注册流程
|
||||||
|
// 'login' → 模拟已注册用户,走登录流程
|
||||||
|
// false → 走真实微信 OAuth
|
||||||
|
mockWechatLogin: 'register',
|
||||||
|
mockAppNo: '60000001102001',
|
||||||
|
mockUser: {
|
||||||
|
token: 'mock_token_dev_2024',
|
||||||
|
user_info: {
|
||||||
|
user_id: 'abc123456',
|
||||||
|
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;
|
export default dev;
|
||||||
|
|||||||
+16
-2
@@ -1,16 +1,30 @@
|
|||||||
/**
|
/**
|
||||||
* 环境配置入口
|
* 环境配置入口
|
||||||
* 根据编译模式自动选择 dev / prod 配置
|
* 根据编译模式自动选择 dev / staging / prod 配置
|
||||||
|
*
|
||||||
|
* DEPLOY_ENV 环境变量:
|
||||||
|
* - 'staging' → 预发布环境
|
||||||
|
* - 'production' → 生产环境(默认)
|
||||||
|
* - 未设置且 NODE_ENV !== 'production' → 开发环境
|
||||||
*/
|
*/
|
||||||
import common from './index.js';
|
import common from './index.js';
|
||||||
import dev from './dev.js';
|
import dev from './dev.js';
|
||||||
|
import staging from './staging.js';
|
||||||
import prod from './prod.js';
|
import prod from './prod.js';
|
||||||
|
|
||||||
// uni-app 编译时通过 define 注译 __UNI_PLATFORM__
|
// uni-app 编译时通过 define 注译 __UNI_PLATFORM__
|
||||||
// H5 开发模式下 process.env.NODE_ENV === 'development'
|
// H5 开发模式下 process.env.NODE_ENV === 'development'
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
|
const deployEnv = process.env.DEPLOY_ENV;
|
||||||
|
|
||||||
const envConfig = isProd ? prod : dev;
|
let envConfig;
|
||||||
|
if (!isProd) {
|
||||||
|
envConfig = dev;
|
||||||
|
} else if (deployEnv === 'staging') {
|
||||||
|
envConfig = staging;
|
||||||
|
} else {
|
||||||
|
envConfig = prod;
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
...common,
|
...common,
|
||||||
|
|||||||
+3
-3
@@ -3,13 +3,13 @@
|
|||||||
*/
|
*/
|
||||||
const prod = {
|
const prod = {
|
||||||
// 业务 API 地址(vms-api)
|
// 业务 API 地址(vms-api)
|
||||||
apiBaseUrl: 'http://101.200.86.98:4000',
|
apiBaseUrl: 'https://vmsapi.arklinksmart.cn',
|
||||||
|
|
||||||
// 网关地址(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: '',
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* 预发布环境配置
|
||||||
|
*/
|
||||||
|
const staging = {
|
||||||
|
// 业务 API 地址(vms-api)
|
||||||
|
apiBaseUrl: 'https://vmsapi.arklinksmart.cn',
|
||||||
|
|
||||||
|
// 网关地址(vms-gateway)— 用户授权、短信等接口走网关
|
||||||
|
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
||||||
|
|
||||||
|
// 授权回调地址(微信 OAuth redirect_uri,必须 HTTPS,指向前端页面)
|
||||||
|
authRedirectUri: 'https://pre-m.arklinksmart.cn/pages/auth/loading',
|
||||||
|
|
||||||
|
// 生产环境 Token 从登录流程获取,此处为空
|
||||||
|
bearerToken: '',
|
||||||
|
|
||||||
|
enableRequestLog: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default staging;
|
||||||
@@ -41,6 +41,12 @@
|
|||||||
"style": {
|
"style": {
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/order/detail",
|
||||||
|
"style": {
|
||||||
|
"navigationStyle": "custom"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"globalStyle": {
|
"globalStyle": {
|
||||||
|
|||||||
+406
-29
@@ -15,22 +15,70 @@ export default {
|
|||||||
return {
|
return {
|
||||||
statusText: '正在登录...',
|
statusText: '正在登录...',
|
||||||
deviceId: '',
|
deviceId: '',
|
||||||
|
action: '',
|
||||||
|
navigating: false, // 防止重复跳转
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
this.deviceId = options.device_id || '';
|
this.deviceId = options.device_id || '';
|
||||||
|
this.action = options.action || '';
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
// 检查 URL 中是否有授权回调的 code
|
// Mock 模式:跳过微信 OAuth,直接登录
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
if (config.mockWechatLogin && this.action !== 'userinfo') {
|
||||||
const code = urlParams.get('code');
|
this.mockLogin();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (code) {
|
// 从 URL 参数获取 code(App.vue 跳转时带过来)
|
||||||
// 有 code → 调用后端登录
|
// 支付宝回调参数名是 auth_code,微信是 code
|
||||||
this.handleCallback(code);
|
let code = options.code || options.auth_code || '';
|
||||||
|
if (!code) {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
code = urlParams.get('code') || urlParams.get('auth_code') || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析 state 参数(OAuth 标准保证 state 原样回传,包含 action 和 device_id)
|
||||||
|
if (!this.action || !this.deviceId) {
|
||||||
|
const stateRaw = options.state || '';
|
||||||
|
if (stateRaw) {
|
||||||
|
try {
|
||||||
|
const stateObj = JSON.parse(decodeURIComponent(stateRaw));
|
||||||
|
if (!this.action && stateObj.action) {
|
||||||
|
this.action = stateObj.action;
|
||||||
|
}
|
||||||
|
if (!this.deviceId && stateObj.device_id) {
|
||||||
|
this.deviceId = stateObj.device_id;
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
// state 解析失败,继续用 localStorage 兜底
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 兜底:从 localStorage 恢复(页面复用时 onLoad 不触发,localStorage 由跳转函数清理)
|
||||||
|
if (!this.action) {
|
||||||
|
this.action = localStorage.getItem('__auth_action') || '';
|
||||||
|
}
|
||||||
|
if (!this.deviceId) {
|
||||||
|
this.deviceId = localStorage.getItem('__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 {
|
} else {
|
||||||
// 无 code → 发起 OAuth 授权
|
// 登录流程
|
||||||
this.startAuth();
|
if (code) {
|
||||||
|
this.handleCallback(code);
|
||||||
|
} else {
|
||||||
|
this.startAuth();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
@@ -41,9 +89,24 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/**
|
/**
|
||||||
* 发起 OAuth 授权
|
* 发起 OAuth 授权(静默授权,只获取 openid)
|
||||||
*/
|
*/
|
||||||
async startAuth() {
|
async startAuth() {
|
||||||
|
// 防止重复调用(实例级 + storage 级双重保护)
|
||||||
|
if (this.navigating) {
|
||||||
|
console.log('[Auth] 已在跳转中,忽略重复 startAuth');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// handleCallback 正在处理中或已完成,禁止发起新授权
|
||||||
|
if (uni.getStorageSync('__auth_callback_done')) {
|
||||||
|
console.log('[Auth] 回调处理中/已完成,跳过 startAuth');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.navigating = true;
|
||||||
|
|
||||||
|
// 清除上次使用的 code 标记(仅在发起新授权时清除,不在 handleCallback 流程中)
|
||||||
|
uni.removeStorageSync('__used_auth_code');
|
||||||
|
|
||||||
const platform = detectPlatform();
|
const platform = detectPlatform();
|
||||||
const appNo = getAppNo(platform);
|
const appNo = getAppNo(platform);
|
||||||
|
|
||||||
@@ -56,20 +119,35 @@ export default {
|
|||||||
try {
|
try {
|
||||||
this.statusText = '正在获取授权...';
|
this.statusText = '正在获取授权...';
|
||||||
|
|
||||||
// 构建回调地址(当前页面地址)
|
// 存入 localStorage(页面复用时 onLoad 不会重新触发,需要从 localStorage 读取)
|
||||||
const redirectUri = encodeURIComponent(
|
if (this.deviceId) {
|
||||||
window.location.origin + window.location.pathname
|
localStorage.setItem('__auth_device_id', this.deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
||||||
|
const redirectUri = config.authRedirectUri || (
|
||||||
|
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 静默授权:微信用 snsapi_base,支付宝用 auth_base
|
||||||
|
const scopes = platform === 'alipay' ? 'auth_base' : 'snsapi_base';
|
||||||
|
|
||||||
|
// 构建 state(包含 device_id,回调时原样回传)
|
||||||
|
const stateObj = {};
|
||||||
|
if (this.deviceId) {
|
||||||
|
stateObj.device_id = this.deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
const res = await gatewayGet('/api/v1/user/auth/url', {
|
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||||
app_no: appNo,
|
app_no: appNo,
|
||||||
scopes: 'snsapi_userinfo',
|
scopes: scopes,
|
||||||
redirect_uri: redirectUri,
|
redirect_uri: redirectUri,
|
||||||
|
state: Object.keys(stateObj).length > 0 ? JSON.stringify(stateObj) : '',
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = res.data || {};
|
const data = res.data || {};
|
||||||
if (data.code === 0 && data.data && data.data.auth_url) {
|
if (data.code === 0 && data.data && data.data.auth_url) {
|
||||||
// 跳转微信授权页
|
// 后端已将 state 写入授权 URL,直接跳转
|
||||||
window.location.href = data.data.auth_url;
|
window.location.href = data.data.auth_url;
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({ title: data.message || '获取授权失败', icon: 'none' });
|
uni.showToast({ title: data.message || '获取授权失败', icon: 'none' });
|
||||||
@@ -83,9 +161,18 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理授权回调(从 URL 中获取 code 后调用后端 /login)
|
* 处理授权回调(用 code 换 openid,再用 openid 登录)
|
||||||
*/
|
*/
|
||||||
async handleCallback(code) {
|
async handleCallback(code) {
|
||||||
|
// 防止重复调用(实例级 + storage 级双重保护)
|
||||||
|
if (this.navigating) {
|
||||||
|
console.log('[Auth] 已在跳转中,忽略重复 handleCallback');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.navigating = true;
|
||||||
|
// storage 级保护:跨页面实例生效,防止支付宝整页重载后重复执行
|
||||||
|
uni.setStorageSync('__auth_callback_done', '1');
|
||||||
|
|
||||||
const appNo = uni.getStorageSync('app_no') || getAppNo(detectPlatform());
|
const appNo = uni.getStorageSync('app_no') || getAppNo(detectPlatform());
|
||||||
|
|
||||||
if (!appNo) {
|
if (!appNo) {
|
||||||
@@ -94,33 +181,78 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 防止 code 重复提交:先检查再标记
|
||||||
|
const usedCode = uni.getStorageSync('__used_auth_code');
|
||||||
|
if (usedCode === code) {
|
||||||
|
console.warn('[loading] code 已使用过,跳过');
|
||||||
|
this.navigating = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uni.setStorageSync('__used_auth_code', code);
|
||||||
|
|
||||||
|
// 立即清除 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());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.statusText = '正在验证身份...';
|
this.statusText = '正在验证身份...';
|
||||||
|
|
||||||
const res = await gatewayPost('/api/v1/user/login', {
|
// 1. 用 code 换取 openid(snsapi_base 静默授权)
|
||||||
|
const callbackRes = await gatewayPost('/api/v1/user/auth/exchange', {
|
||||||
app_no: appNo,
|
app_no: appNo,
|
||||||
code: code,
|
code: code,
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = res.data || {};
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存储 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) {
|
if (data.code === 0 && data.data) {
|
||||||
const result = 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) {
|
if (result.register) {
|
||||||
// 已注册 → 缓存 JWT → 跳转首页
|
// 已注册 → 存 token → 进入开门页
|
||||||
uni.setStorageSync('token', result.token);
|
uni.setStorageSync('token', result.token);
|
||||||
uni.setStorageSync('user_info', result.user_info);
|
// 存储 user_info(接口返回的字段,后续 snsapi_userinfo 授权可补充)
|
||||||
|
const existing = uni.getStorageSync('user_info') || {};
|
||||||
|
uni.setStorageSync('user_info', {
|
||||||
|
user_id: result.user_id || existing.user_id || '',
|
||||||
|
phone: result.phone || existing.phone || '',
|
||||||
|
nickname: result.nickname || existing.nickname || '',
|
||||||
|
avatar: result.avatar || existing.avatar || '',
|
||||||
|
});
|
||||||
this.goToHome();
|
this.goToHome();
|
||||||
} else {
|
} else {
|
||||||
// 未注册 → 缓存临时数据 → 跳转注册页
|
// 未注册 → 存 temp_token → 跳注册页
|
||||||
uni.setStorageSync('temp_token', result.temp_token);
|
uni.setStorageSync('temp_token', result.temp_token);
|
||||||
uni.setStorageSync('auth_info', result.auth_info);
|
|
||||||
this.goToRegister();
|
this.goToRegister();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -134,23 +266,268 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发起非静默授权获取用户信息(snsapi_userinfo,弹窗确认)
|
||||||
|
*/
|
||||||
|
async startUserInfoAuth() {
|
||||||
|
// 防止重复调用(实例级 + storage 级双重保护)
|
||||||
|
if (this.navigating) {
|
||||||
|
console.log('[Auth] 已在跳转中,忽略重复 startUserInfoAuth');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (uni.getStorageSync('__auth_callback_done')) {
|
||||||
|
console.log('[Auth] 回调处理中/已完成,跳过 startUserInfoAuth');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.navigating = true;
|
||||||
|
|
||||||
|
// 清除上次使用的 code 标记
|
||||||
|
uni.removeStorageSync('__used_auth_code');
|
||||||
|
|
||||||
|
const platform = detectPlatform();
|
||||||
|
const appNo = getAppNo(platform);
|
||||||
|
|
||||||
|
if (!appNo) {
|
||||||
|
// 非微信环境,直接跳回首页
|
||||||
|
this.goToHomeWithAction();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.statusText = '正在获取用户信息...';
|
||||||
|
|
||||||
|
// 存入 localStorage(页面复用时 onLoad 不会重新触发,需要从 localStorage 读取)
|
||||||
|
localStorage.setItem('__auth_action', 'userinfo');
|
||||||
|
if (this.deviceId) {
|
||||||
|
localStorage.setItem('__auth_device_id', this.deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
||||||
|
const redirectUri = config.authRedirectUri || (
|
||||||
|
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||||
|
);
|
||||||
|
|
||||||
|
// 用户信息授权:微信用 snsapi_userinfo,支付宝用 auth_userinfo
|
||||||
|
const scopes = platform === 'alipay' ? 'auth_userinfo' : 'snsapi_userinfo';
|
||||||
|
|
||||||
|
// 构建 state(包含 action 和 device_id,回调时原样回传)
|
||||||
|
const stateObj = { action: 'userinfo' };
|
||||||
|
if (this.deviceId) {
|
||||||
|
stateObj.device_id = this.deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||||
|
app_no: appNo,
|
||||||
|
scopes: scopes,
|
||||||
|
redirect_uri: redirectUri,
|
||||||
|
state: JSON.stringify(stateObj),
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = res.data || {};
|
||||||
|
if (data.code === 0 && data.data && data.data.auth_url) {
|
||||||
|
// 后端已将 state 写入授权 URL,直接跳转
|
||||||
|
window.location.href = data.data.auth_url;
|
||||||
|
} 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) {
|
||||||
|
// 防止重复调用(实例级 + storage 级双重保护)
|
||||||
|
if (this.navigating) {
|
||||||
|
console.log('[Auth] 已在跳转中,忽略重复 handleUserInfoCallback');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.navigating = true;
|
||||||
|
uni.setStorageSync('__auth_callback_done', '1');
|
||||||
|
|
||||||
|
const appNo = uni.getStorageSync('app_no') || getAppNo(detectPlatform());
|
||||||
|
|
||||||
|
if (!appNo) {
|
||||||
|
this.goToHomeWithAction();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 防止 code 重复提交
|
||||||
|
const usedCode = uni.getStorageSync('__used_auth_code');
|
||||||
|
if (usedCode === code) {
|
||||||
|
console.warn('[loading] code 已使用过,跳过');
|
||||||
|
this.navigating = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uni.setStorageSync('__used_auth_code', code);
|
||||||
|
|
||||||
|
// 立即清除 URL 中的 code/action 参数,避免刷新重复处理
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
url.searchParams.delete('code');
|
||||||
|
url.searchParams.delete('auth_code');
|
||||||
|
url.searchParams.delete('state');
|
||||||
|
url.searchParams.delete('action');
|
||||||
|
window.history.replaceState({}, '', url.toString());
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.statusText = '正在获取用户信息...';
|
||||||
|
|
||||||
|
// 用 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;
|
||||||
|
// 合并已有缓存(保留 user_id 等字段),覆盖头像昵称手机
|
||||||
|
const existing = uni.getStorageSync('user_info') || {};
|
||||||
|
uni.setStorageSync('user_info', {
|
||||||
|
...existing,
|
||||||
|
user_id: userInfo.user_id || existing.user_id || '',
|
||||||
|
nickname: userInfo.nickname || existing.nickname || '',
|
||||||
|
avatar: userInfo.avatar || existing.avatar || '',
|
||||||
|
phone: userInfo.phone || existing.phone || '',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn('[loading] 获取用户信息失败:', data.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 跳回首页(我的 tab)
|
||||||
|
this.goToHomeWithAction();
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[Auth] handleUserInfoCallback error:', e);
|
||||||
|
this.goToHomeWithAction();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跳回首页并标记为"我的"tab
|
||||||
|
*/
|
||||||
|
goToHomeWithAction() {
|
||||||
|
// 兼容页面复用:优先 this.deviceId,其次 localStorage
|
||||||
|
const deviceId = this.deviceId || localStorage.getItem('__auth_device_id') || '';
|
||||||
|
const url = deviceId
|
||||||
|
? `/pages/index/index?device_id=${deviceId}&action=mine`
|
||||||
|
: '/pages/index/index?action=mine';
|
||||||
|
localStorage.removeItem('__auth_device_id');
|
||||||
|
localStorage.removeItem('__auth_action');
|
||||||
|
uni.removeStorageSync('__auth_callback_done');
|
||||||
|
uni.redirectTo({ url });
|
||||||
|
},
|
||||||
|
|
||||||
goToHome() {
|
goToHome() {
|
||||||
const url = this.deviceId
|
const deviceId = this.deviceId || localStorage.getItem('__auth_device_id') || '';
|
||||||
? `/pages/index/index?device_id=${this.deviceId}`
|
const url = deviceId
|
||||||
|
? `/pages/index/index?device_id=${deviceId}`
|
||||||
: '/pages/index/index';
|
: '/pages/index/index';
|
||||||
|
localStorage.removeItem('__auth_device_id');
|
||||||
|
uni.removeStorageSync('__auth_callback_done');
|
||||||
uni.redirectTo({ url });
|
uni.redirectTo({ url });
|
||||||
},
|
},
|
||||||
|
|
||||||
goToRegister() {
|
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
|
const url = this.deviceId
|
||||||
? `/pages/register/register?device_id=${this.deviceId}`
|
? `/pages/register/register?device_id=${this.deviceId}`
|
||||||
: '/pages/register/register';
|
: '/pages/register/register';
|
||||||
|
uni.removeStorageSync('__auth_callback_done');
|
||||||
uni.redirectTo({ url });
|
uni.redirectTo({ url });
|
||||||
},
|
},
|
||||||
|
|
||||||
goToScan() {
|
goToScan() {
|
||||||
uni.redirectTo({ url: '/pages/index/scan' });
|
uni.redirectTo({ url: '/pages/index/scan' });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock 登录(跳过微信授权,调用真实登录接口)
|
||||||
|
*/
|
||||||
|
async mockLogin() {
|
||||||
|
const mode = config.mockWechatLogin;
|
||||||
|
const mock = config.mockUser;
|
||||||
|
const mockUserInfo = mock.user_info;
|
||||||
|
const mockOpenid = mockUserInfo.open_id;
|
||||||
|
|
||||||
|
// 'skip' 模式直接登录,不调接口
|
||||||
|
if (mode === 'skip') {
|
||||||
|
this.statusText = '模拟登录中...';
|
||||||
|
uni.setStorageSync('token', mock.token);
|
||||||
|
uni.setStorageSync('openid', mockOpenid);
|
||||||
|
// 按生产结构存储 user_info
|
||||||
|
uni.setStorageSync('user_info', {
|
||||||
|
user_id: mockUserInfo.user_id,
|
||||||
|
phone: mockUserInfo.phone,
|
||||||
|
nickname: mockUserInfo.nickname,
|
||||||
|
avatar: mockUserInfo.avatar,
|
||||||
|
});
|
||||||
|
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 + user_info → 跳首页
|
||||||
|
uni.setStorageSync('token', result.token);
|
||||||
|
// 按生产结构存储 user_info(接口返回优先,mock 补充)
|
||||||
|
uni.setStorageSync('user_info', {
|
||||||
|
user_id: result.user_id || mockUserInfo.user_id,
|
||||||
|
phone: result.phone || mockUserInfo.phone,
|
||||||
|
nickname: result.nickname || mockUserInfo.nickname,
|
||||||
|
avatar: result.avatar || mockUserInfo.avatar,
|
||||||
|
});
|
||||||
|
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>
|
</script>
|
||||||
|
|||||||
+2
-22
@@ -44,17 +44,7 @@ export default {
|
|||||||
faqList: [
|
faqList: [
|
||||||
{
|
{
|
||||||
question: '如何购买商品?',
|
question: '如何购买商品?',
|
||||||
answer: '在首页浏览商品,点击商品卡片选择商品,确认后即可完成购买。支持微信支付和支付宝支付。',
|
answer: '使用微信或支付宝扫描柜体上的二维码,进入开门页面,如果是首次使用需先进行授权登录与注册,浏览设备中售卖的商品及价格,点击开门,待门锁打开后,拉开门选购商品,关门即完成购买,约1-2分钟内系统将自动识别并完成扣款。',
|
||||||
expanded: false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
question: '如何开门取货?',
|
|
||||||
answer: '下单成功后,点击首页底部中间的"开门"按钮,柜门会自动打开,取出商品后关闭柜门即可。',
|
|
||||||
expanded: false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
question: '商品质量问题怎么办?',
|
|
||||||
answer: '如发现商品有质量问题,请在24小时内通过"联系客服"反馈,我们会为您办理退款或换货。',
|
|
||||||
expanded: false
|
expanded: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -62,16 +52,6 @@ export default {
|
|||||||
answer: '进入"我的"页面,点击"我的订单"可查看所有订单记录,包括待付款、已完成、已退款等状态。',
|
answer: '进入"我的"页面,点击"我的订单"可查看所有订单记录,包括待付款、已完成、已退款等状态。',
|
||||||
expanded: false
|
expanded: false
|
||||||
},
|
},
|
||||||
{
|
|
||||||
question: '忘记密码怎么办?',
|
|
||||||
answer: '在登录页面点击"忘记密码",输入注册手机号,通过短信验证码即可重置密码。',
|
|
||||||
expanded: false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
question: '如何修改收货地址?',
|
|
||||||
answer: '进入"我的"页面,点击"收货地址",可以新增、编辑或删除收货地址信息。',
|
|
||||||
expanded: false
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
question: '支持哪些支付方式?',
|
question: '支持哪些支付方式?',
|
||||||
answer: '目前支持微信支付、支付宝支付两种方式,后续将开通更多支付渠道。',
|
answer: '目前支持微信支付、支付宝支付两种方式,后续将开通更多支付渠道。',
|
||||||
@@ -79,7 +59,7 @@ export default {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
question: '退款多久到账?',
|
question: '退款多久到账?',
|
||||||
answer: '退款申请审核通过后,微信支付1-3个工作日到账,支付宝1-5个工作日到账,具体以银行处理时间为准。',
|
answer: '审核通过后,一般1-3个工作日到账,具体到账时间以支付渠道为准。',
|
||||||
expanded: false
|
expanded: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
+216
-20
@@ -103,7 +103,7 @@
|
|||||||
<!-- 蓝色个人信息区域 -->
|
<!-- 蓝色个人信息区域 -->
|
||||||
<view class="user-header">
|
<view class="user-header">
|
||||||
<view class="user-info">
|
<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" />
|
<image class="avatar" :src="userInfo.avatar || '/static/default-avatar.png'" mode="aspectFill" />
|
||||||
</view>
|
</view>
|
||||||
<view class="user-detail">
|
<view class="user-detail">
|
||||||
@@ -122,6 +122,13 @@
|
|||||||
</view>
|
</view>
|
||||||
</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 v-if="isDev" class="dev-tools">
|
||||||
<view class="dev-tools-title">开发工具</view>
|
<view class="dev-tools-title">开发工具</view>
|
||||||
@@ -134,7 +141,7 @@
|
|||||||
|
|
||||||
<!-- 底部左右箭头导航条 -->
|
<!-- 底部左右箭头导航条 -->
|
||||||
<page-nav-bar
|
<page-nav-bar
|
||||||
:hasPrev="true"
|
:hasPrev="canGoBack"
|
||||||
:hasNext="false"
|
:hasNext="false"
|
||||||
@prev="handleNavPrev"
|
@prev="handleNavPrev"
|
||||||
@next="handleNavNext"
|
@next="handleNavNext"
|
||||||
@@ -150,18 +157,22 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 开门流程组件 -->
|
||||||
|
<door-panel ref="doorPanel" :device-id="deviceId" :user-id="userId" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import PageNavBar from '@/components/page-nav-bar/page-nav-bar.vue';
|
import PageNavBar from '@/components/page-nav-bar/page-nav-bar.vue';
|
||||||
|
import DoorPanel from '@/components/door-panel/door-panel.vue';
|
||||||
import config from '@/config/env.js';
|
import config from '@/config/env.js';
|
||||||
import { get } from '@/utils/request.js';
|
import { get, gatewayGet } from '@/utils/request.js';
|
||||||
import { checkLoginWithPrompt, getCachedUserInfo } from '@/utils/auth-guard.js';
|
import { checkLoginWithPrompt, getCachedUserInfo, isLoggedIn } from '@/utils/auth-guard.js';
|
||||||
import { isVConsoleEnabled, showVConsole, hideVConsole } from '@/utils/vconsole';
|
import { isVConsoleEnabled, showVConsole, hideVConsole } from '@/utils/vconsole';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { PageNavBar },
|
components: { PageNavBar, DoorPanel },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
deviceId: '',
|
deviceId: '',
|
||||||
@@ -170,7 +181,10 @@ export default {
|
|||||||
loading: false,
|
loading: false,
|
||||||
categoryList: [],
|
categoryList: [],
|
||||||
activeCategory: 'all',
|
activeCategory: 'all',
|
||||||
userInfo: { nickname: '', phone: '', avatar: '' },
|
userInfo: { user_id: '', nickname: '', phone: '', avatar: '' },
|
||||||
|
avatarClickCount: 0,
|
||||||
|
avatarClickTimer: null,
|
||||||
|
fromPage: '', // 记录从哪个页面跳转过来的
|
||||||
menuList: [
|
menuList: [
|
||||||
{ title: '我的订单', action: 'order' },
|
{ title: '我的订单', action: 'order' },
|
||||||
{ title: '常见问题', action: 'faq' },
|
{ title: '常见问题', action: 'faq' },
|
||||||
@@ -184,6 +198,13 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
userId() {
|
||||||
|
return this.userInfo.user_id || '';
|
||||||
|
},
|
||||||
|
canGoBack() {
|
||||||
|
// 有上一页,或者从 tab 切换过来的,都可以返回
|
||||||
|
return getCurrentPages().length > 1 || this.fromPage === 'tab';
|
||||||
|
},
|
||||||
maskedPhone() {
|
maskedPhone() {
|
||||||
const p = this.userInfo.phone;
|
const p = this.userInfo.phone;
|
||||||
return p ? p.substring(0,3) + '****' + p.substring(7) : '';
|
return p ? p.substring(0,3) + '****' + p.substring(7) : '';
|
||||||
@@ -212,17 +233,29 @@ export default {
|
|||||||
this.isWechat = /MicroMessenger/i.test(navigator.userAgent);
|
this.isWechat = /MicroMessenger/i.test(navigator.userAgent);
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
|
// 处理"我的"用户信息授权回调(从 loading 页跳回)
|
||||||
|
if (options.action === 'mine') {
|
||||||
|
this.currentTab = 'mine';
|
||||||
|
this.fromPage = 'navigate';
|
||||||
|
}
|
||||||
|
|
||||||
// 支持通过 tab 参数切换到"我的"页面
|
// 支持通过 tab 参数切换到"我的"页面
|
||||||
if (options.tab === 'mine') {
|
if (options.tab === 'mine') {
|
||||||
this.currentTab = 'mine';
|
this.currentTab = 'mine';
|
||||||
|
this.fromPage = 'navigate';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.device_id) {
|
if (options.device_id) {
|
||||||
this.deviceId = options.device_id;
|
this.deviceId = options.device_id;
|
||||||
|
uni.setNavigationBarTitle({ title: `智能货柜-${this.deviceId}` });
|
||||||
this.fetchProducts();
|
this.fetchProducts();
|
||||||
} else if (!options.tab) {
|
} else if (!options.tab && options.action !== 'mine') {
|
||||||
// 无设备编号且非 tab 跳转,跳回扫码页
|
// 无设备编号且非 tab/action 跳转,提示并跳至扫码页
|
||||||
uni.redirectTo({ url: '/pages/index/scan' });
|
uni.showToast({ title: '请扫描设备二维码', icon: 'none' });
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.redirectTo({ url: '/pages/index/scan' });
|
||||||
|
}, 1500);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载缓存的用户信息
|
// 加载缓存的用户信息
|
||||||
@@ -241,9 +274,21 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
switchTab(tab) {
|
switchTab(tab) {
|
||||||
// 切换到"我的"Tab 时检查登录
|
if (tab === 'mine') {
|
||||||
if (tab === 'mine' && !checkLoginWithPrompt('mine')) return;
|
// 切换到"我的"Tab 时检查登录
|
||||||
this.currentTab = 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; },
|
switchCategory(cat) { this.activeCategory = cat; },
|
||||||
getDisplayPrice(item) {
|
getDisplayPrice(item) {
|
||||||
@@ -254,10 +299,78 @@ export default {
|
|||||||
// 从缓存加载用户信息
|
// 从缓存加载用户信息
|
||||||
loadUserInfo() {
|
loadUserInfo() {
|
||||||
const cached = getCachedUserInfo();
|
const cached = getCachedUserInfo();
|
||||||
|
console.log('[index] getCachedUserInfo:', JSON.stringify(cached, null, 2));
|
||||||
if (cached) {
|
if (cached) {
|
||||||
this.userInfo = { ...this.userInfo, ...cached };
|
this.userInfo = { ...this.userInfo, ...cached };
|
||||||
} else {
|
} else {
|
||||||
this.userInfo = { nickname: '', phone: '', avatar: '' };
|
this.userInfo = { user_id: '', 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 = {
|
||||||
|
user_id: config.mockUser.user_info.user_id || '',
|
||||||
|
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 {
|
||||||
|
// 存入 localStorage(loading 页面复用时 onLoad 不会重新触发,需要从 localStorage 读取)
|
||||||
|
localStorage.setItem('__auth_action', 'userinfo');
|
||||||
|
if (this.deviceId) {
|
||||||
|
localStorage.setItem('__auth_device_id', this.deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
||||||
|
const redirectUri = config.authRedirectUri || (
|
||||||
|
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||||
|
);
|
||||||
|
|
||||||
|
// 构建 state(包含 action 和 device_id,回调时原样回传)
|
||||||
|
const stateObj = { action: 'userinfo' };
|
||||||
|
if (this.deviceId) {
|
||||||
|
stateObj.device_id = this.deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户信息授权:微信用 snsapi_userinfo,支付宝用 auth_userinfo
|
||||||
|
const platform = uni.getStorageSync('platform') || 'wechat';
|
||||||
|
const scopes = platform === 'alipay' ? 'auth_userinfo' : 'snsapi_userinfo';
|
||||||
|
|
||||||
|
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||||
|
app_no: appNo,
|
||||||
|
scopes: scopes,
|
||||||
|
redirect_uri: redirectUri,
|
||||||
|
state: JSON.stringify(stateObj),
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = res.data || {};
|
||||||
|
if (data.code === 0 && data.data && data.data.auth_url) {
|
||||||
|
console.log('[index] 跳转授权页:', data.data.auth_url);
|
||||||
|
// 后端已将 state 写入授权 URL,直接跳转
|
||||||
|
window.location.href = data.data.auth_url;
|
||||||
|
} else {
|
||||||
|
console.warn('[index] 获取授权链接失败:', data.message);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[index] startUserInfoAuth error:', e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async fetchProducts() {
|
async fetchProducts() {
|
||||||
@@ -280,12 +393,49 @@ export default {
|
|||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleOpenDoor() {
|
async handleOpenDoor() {
|
||||||
uni.showModal({
|
// 检查登录状态
|
||||||
title: '开门',
|
if (!isLoggedIn()) {
|
||||||
content: '确认打开柜门?',
|
checkLoginWithPrompt('door');
|
||||||
success: r => r.confirm && uni.showToast({ title: '柜门已打开', icon: 'success' })
|
return;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// 检查设备ID
|
||||||
|
if (!this.deviceId) {
|
||||||
|
uni.showToast({ title: '请先扫描设备二维码', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查用户信息,若缓存中没有则调接口获取
|
||||||
|
if (!this.userId) {
|
||||||
|
try {
|
||||||
|
const openId = uni.getStorageSync('openid') || '';
|
||||||
|
const infoRes = await gatewayGet('/api/v1/user/info', { open_id: openId });
|
||||||
|
const infoData = (infoRes.data || {}).data || {};
|
||||||
|
const userInfo = infoData.user_info || {};
|
||||||
|
if (userInfo.user_id) {
|
||||||
|
const existing = getCachedUserInfo() || {};
|
||||||
|
uni.setStorageSync('user_info', {
|
||||||
|
...existing,
|
||||||
|
user_id: userInfo.user_id,
|
||||||
|
nickname: userInfo.nickname || existing.nickname || '',
|
||||||
|
avatar: userInfo.avatar || existing.avatar || '',
|
||||||
|
phone: userInfo.phone || existing.phone || '',
|
||||||
|
});
|
||||||
|
this.loadUserInfo();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[handleOpenDoor] 获取用户信息失败:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.userId) {
|
||||||
|
uni.showToast({ title: '无法获取用户信息,请重新登录', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用组件方法启动开门流程
|
||||||
|
this.$refs.doorPanel.open(this.userId);
|
||||||
},
|
},
|
||||||
handleMenuClick(item) {
|
handleMenuClick(item) {
|
||||||
switch (item.action) {
|
switch (item.action) {
|
||||||
@@ -305,8 +455,51 @@ export default {
|
|||||||
break;
|
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' }); },
|
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(() => {
|
||||||
|
uni.setStorageSync('__logout_flag', true);
|
||||||
|
uni.reLaunch({ url: '/pages/index/scan' });
|
||||||
|
}, 1000);
|
||||||
|
},
|
||||||
onVConsoleChange(e) {
|
onVConsoleChange(e) {
|
||||||
const enabled = e.detail.value;
|
const enabled = e.detail.value;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
@@ -327,6 +520,7 @@ page { height: 100%; background-color: #fff; }
|
|||||||
|
|
||||||
/* ====== 首页样式 ====== */
|
/* ====== 首页样式 ====== */
|
||||||
.home-page { display: flex; flex-direction: column; height: 100%; }
|
.home-page { display: flex; flex-direction: column; height: 100%; }
|
||||||
|
|
||||||
.product-area { flex: 1; overflow-y: auto; height: 0; }
|
.product-area { flex: 1; overflow-y: auto; height: 0; }
|
||||||
|
|
||||||
/* 热销商品标题 + 装饰 */
|
/* 热销商品标题 + 装饰 */
|
||||||
@@ -455,6 +649,7 @@ page { height: 100%; background-color: #fff; }
|
|||||||
.menu-item:last-child { border-bottom: none; }
|
.menu-item:last-child { border-bottom: none; }
|
||||||
.menu-text { font-size: 30rpx; color: #333; }
|
.menu-text { font-size: 30rpx; color: #333; }
|
||||||
.menu-arrow { font-size: 28rpx; color: #ccc; }
|
.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; }
|
.dev-tools { margin-top: 20rpx; background-color: #fff; border-radius: 16rpx; overflow: hidden; }
|
||||||
@@ -507,4 +702,5 @@ page { height: 100%; background-color: #fff; }
|
|||||||
border: 2rpx solid #2979ff;
|
border: 2rpx solid #2979ff;
|
||||||
border-radius: 40rpx;
|
border-radius: 40rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
@@ -67,6 +67,12 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
|
// 退出登录后跳转过来,清除标记,停留在扫码页
|
||||||
|
if (uni.getStorageSync('__logout_flag')) {
|
||||||
|
uni.removeStorageSync('__logout_flag');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 1. 检查 JWT(App.vue 已处理首次跳转,这里兜底)
|
// 1. 检查 JWT(App.vue 已处理首次跳转,这里兜底)
|
||||||
const token = uni.getStorageSync('token');
|
const token = uni.getStorageSync('token');
|
||||||
if (!token) {
|
if (!token) {
|
||||||
@@ -101,7 +107,25 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
handleScan() {
|
handleScan() {
|
||||||
// #ifdef H5
|
// #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
|
// #endif
|
||||||
|
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
|
|||||||
@@ -0,0 +1,469 @@
|
|||||||
|
<template>
|
||||||
|
<view class="detail-page">
|
||||||
|
<!-- 顶部导航 -->
|
||||||
|
<view class="nav-bar">
|
||||||
|
<view class="nav-back" @click="goBack">
|
||||||
|
<text class="back-arrow">‹</text>
|
||||||
|
</view>
|
||||||
|
<text class="nav-title">订单详情</text>
|
||||||
|
<view class="nav-placeholder"></view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 内容区域 -->
|
||||||
|
<scroll-view class="detail-scroll" scroll-y>
|
||||||
|
<view v-if="loading" class="loading-state">
|
||||||
|
<text class="loading-text">加载中...</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view v-else-if="order" class="detail-body">
|
||||||
|
<!-- 状态卡片 -->
|
||||||
|
<view class="status-card">
|
||||||
|
<view class="status-icon-row">
|
||||||
|
<view class="status-dot" :class="statusDotClass"></view>
|
||||||
|
<text class="status-main">{{ orderStatusText(order.order_status) }}</text>
|
||||||
|
</view>
|
||||||
|
<text class="status-sub">{{ payStatusText(order.payment_status) }}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 商品信息 -->
|
||||||
|
<view class="section-card">
|
||||||
|
<view class="section-title">商品信息</view>
|
||||||
|
<view
|
||||||
|
class="product-item"
|
||||||
|
v-for="(product, idx) in order.products"
|
||||||
|
:key="idx"
|
||||||
|
>
|
||||||
|
<image class="product-img" :src="product.image" mode="aspectFill" />
|
||||||
|
<view class="product-info">
|
||||||
|
<text class="product-name">{{ product.name }}</text>
|
||||||
|
<view class="product-bottom">
|
||||||
|
<text class="product-price">¥{{ getDecimal(product.unit_price) }}</text>
|
||||||
|
<text class="product-qty">x{{ product.qty }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 订单信息 -->
|
||||||
|
<view class="section-card">
|
||||||
|
<view class="section-title">订单信息</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="info-label">订单编号</text>
|
||||||
|
<text class="info-value" @click="copyText(order.order_id)">{{ order.order_id }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="info-label">下单时间</text>
|
||||||
|
<text class="info-value">{{ formatTime(order.createdAt) }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="info-label">设备编号</text>
|
||||||
|
<text class="info-value">{{ order.device_id }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="info-label">订单来源</text>
|
||||||
|
<text class="info-value">{{ orderSourceText(order.order_source) }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="info-label">商品数量</text>
|
||||||
|
<text class="info-value">{{ order.total_qty }} 件</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 金额信息 -->
|
||||||
|
<view class="section-card">
|
||||||
|
<view class="section-title">金额信息</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="info-label">商品总额</text>
|
||||||
|
<text class="info-value">¥{{ getDecimal(order.total_amount) }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row" v-if="getDecimal(order.discount_amount) !== '0'">
|
||||||
|
<text class="info-label">优惠金额</text>
|
||||||
|
<text class="info-value discount">-¥{{ getDecimal(order.discount_amount) }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row total">
|
||||||
|
<text class="info-label">实付金额</text>
|
||||||
|
<text class="info-value price">¥{{ getDecimal(order.paid_amount) }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 退款信息 -->
|
||||||
|
<view class="section-card" v-if="order.has_refund && order.refund_info">
|
||||||
|
<view class="section-title">退款信息</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="info-label">退款状态</text>
|
||||||
|
<text class="info-value refunded">已退款</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view v-else class="empty-state">
|
||||||
|
<text class="empty-text">订单不存在</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="bottom-spacer"></view>
|
||||||
|
</scroll-view>
|
||||||
|
|
||||||
|
<!-- 底部操作栏 -->
|
||||||
|
<view class="bottom-bar" v-if="order">
|
||||||
|
<view
|
||||||
|
v-if="order.payment_status === 'PENDING'"
|
||||||
|
class="btn-action btn-pay"
|
||||||
|
@click="handlePay"
|
||||||
|
>
|
||||||
|
立即支付
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
v-else-if="order.payment_status === 'PAID' && !order.has_refund"
|
||||||
|
class="btn-action btn-refund"
|
||||||
|
@click="handleRefund"
|
||||||
|
>
|
||||||
|
申请退款
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { get } from '@/utils/request.js';
|
||||||
|
import { checkLoginWithPrompt } from '@/utils/auth-guard.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
orderId: '',
|
||||||
|
order: null,
|
||||||
|
loading: false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
statusDotClass() {
|
||||||
|
if (!this.order) return '';
|
||||||
|
const s = this.order.order_status;
|
||||||
|
if (s === 'COMPLETED') return 'dot-success';
|
||||||
|
if (s === 'CANCELLED') return 'dot-grey';
|
||||||
|
return 'dot-blue';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLoad(options) {
|
||||||
|
this.orderId = options.order_id || '';
|
||||||
|
// 优先从缓存读取(订单列表/交易完成页跳转时已存入)
|
||||||
|
const cached = uni.getStorageSync('__order_detail_cache');
|
||||||
|
if (cached) {
|
||||||
|
this.order = cached;
|
||||||
|
this.orderId = cached.order_id || this.orderId;
|
||||||
|
uni.removeStorageSync('__order_detail_cache');
|
||||||
|
} else if (this.orderId) {
|
||||||
|
this.fetchOrder();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async fetchOrder() {
|
||||||
|
this.loading = true;
|
||||||
|
try {
|
||||||
|
const res = await get('/user/orders', {
|
||||||
|
page: 1,
|
||||||
|
limit: 1,
|
||||||
|
filter: JSON.stringify({ order_id: this.orderId })
|
||||||
|
});
|
||||||
|
|
||||||
|
const ret = res.data || {};
|
||||||
|
if (ret.code === 0 && Array.isArray(ret.data) && ret.data.length > 0) {
|
||||||
|
this.order = ret.data[0];
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
uni.showToast({ title: '获取订单失败', icon: 'none' });
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getDecimal(val) {
|
||||||
|
if (!val) return '0.00';
|
||||||
|
if (val.$numberDecimal) return val.$numberDecimal;
|
||||||
|
return String(val);
|
||||||
|
},
|
||||||
|
|
||||||
|
formatTime(iso) {
|
||||||
|
if (!iso) return '';
|
||||||
|
const d = new Date(iso);
|
||||||
|
const pad = n => String(n).padStart(2, '0');
|
||||||
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||||
|
},
|
||||||
|
|
||||||
|
orderStatusText(status) {
|
||||||
|
const map = { PROCESSING: '处理中', COMPLETED: '已完成', CANCELLED: '已取消' };
|
||||||
|
return map[status] || status;
|
||||||
|
},
|
||||||
|
payStatusText(status) {
|
||||||
|
const map = { PENDING: '待支付', PAID: '已支付', REFUNDED: '已退款', PARTIAL_REFUND: '部分退款' };
|
||||||
|
return map[status] || status;
|
||||||
|
},
|
||||||
|
orderSourceText(source) {
|
||||||
|
const map = { SCAN: '扫码开门', APP: 'APP下单' };
|
||||||
|
return map[source] || source;
|
||||||
|
},
|
||||||
|
|
||||||
|
copyText(text) {
|
||||||
|
uni.setClipboardData({
|
||||||
|
data: text,
|
||||||
|
success: () => uni.showToast({ title: '已复制', icon: 'success' })
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
handlePay() {
|
||||||
|
uni.showModal({
|
||||||
|
title: '立即支付',
|
||||||
|
content: `确认支付¥${this.getDecimal(this.order.total_amount)}?`,
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
uni.showToast({ title: '支付功能开发中', icon: 'none' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleRefund() {
|
||||||
|
uni.showModal({
|
||||||
|
title: '申请退款',
|
||||||
|
content: '确认申请退款?',
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
uni.showToast({ title: '退款功能开发中', icon: 'none' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
goBack() {
|
||||||
|
uni.navigateBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
page {
|
||||||
|
height: 100%;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100vh;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 导航栏 */
|
||||||
|
.nav-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0 24rpx;
|
||||||
|
height: 88rpx;
|
||||||
|
background: #fff;
|
||||||
|
padding-top: constant(safe-area-inset-top);
|
||||||
|
padding-top: env(safe-area-inset-top);
|
||||||
|
}
|
||||||
|
.nav-back {
|
||||||
|
width: 60rpx;
|
||||||
|
height: 60rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.back-arrow {
|
||||||
|
font-size: 48rpx;
|
||||||
|
color: #333;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
.nav-title {
|
||||||
|
font-size: 34rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.nav-placeholder {
|
||||||
|
width: 60rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 内容区域 */
|
||||||
|
.detail-scroll {
|
||||||
|
flex: 1;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 状态卡片 */
|
||||||
|
.status-card {
|
||||||
|
background: linear-gradient(135deg, #2979ff, #1e60e0);
|
||||||
|
padding: 40rpx 32rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12rpx;
|
||||||
|
}
|
||||||
|
.status-icon-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12rpx;
|
||||||
|
}
|
||||||
|
.status-dot {
|
||||||
|
width: 16rpx;
|
||||||
|
height: 16rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
.dot-blue { background: #fff; }
|
||||||
|
.dot-success { background: #52c41a; }
|
||||||
|
.dot-grey { background: #999; }
|
||||||
|
.status-main {
|
||||||
|
font-size: 36rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.status-sub {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: rgba(255, 255, 255, 0.75);
|
||||||
|
padding-left: 28rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 通用卡片 */
|
||||||
|
.section-card {
|
||||||
|
background: #fff;
|
||||||
|
margin: 20rpx;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
padding: 24rpx 28rpx;
|
||||||
|
}
|
||||||
|
.section-title {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
padding-bottom: 16rpx;
|
||||||
|
border-bottom: 1rpx solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 商品项 */
|
||||||
|
.product-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 16rpx 0;
|
||||||
|
}
|
||||||
|
.product-item + .product-item {
|
||||||
|
border-top: 1rpx solid #f5f5f5;
|
||||||
|
}
|
||||||
|
.product-img {
|
||||||
|
width: 120rpx;
|
||||||
|
height: 120rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
background: #f0f0f0;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.product-info {
|
||||||
|
flex: 1;
|
||||||
|
margin-left: 20rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
min-height: 120rpx;
|
||||||
|
}
|
||||||
|
.product-name {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
font-weight: 500;
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.product-bottom {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.product-price {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.product-qty {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 信息行 */
|
||||||
|
.info-row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 16rpx 0;
|
||||||
|
}
|
||||||
|
.info-row + .info-row {
|
||||||
|
border-top: 1rpx solid #f5f5f5;
|
||||||
|
}
|
||||||
|
.info-row.total {
|
||||||
|
border-top: 1rpx solid #f0f0f0;
|
||||||
|
margin-top: 8rpx;
|
||||||
|
padding-top: 20rpx;
|
||||||
|
}
|
||||||
|
.info-label {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
.info-value {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.info-value.discount {
|
||||||
|
color: #ff6b6b;
|
||||||
|
}
|
||||||
|
.info-value.price {
|
||||||
|
font-size: 32rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #e4393c;
|
||||||
|
}
|
||||||
|
.info-value.refunded {
|
||||||
|
color: #ff6b6b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 加载/空状态 */
|
||||||
|
.loading-state, .empty-state {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
padding: 120rpx 0;
|
||||||
|
}
|
||||||
|
.loading-text, .empty-text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 底部操作栏 */
|
||||||
|
.bottom-bar {
|
||||||
|
background: #fff;
|
||||||
|
padding: 16rpx 30rpx;
|
||||||
|
padding-bottom: calc(16rpx + constant(safe-area-inset-bottom));
|
||||||
|
padding-bottom: calc(16rpx + env(safe-area-inset-bottom));
|
||||||
|
box-shadow: 0 -2rpx 12rpx rgba(0, 0, 0, 0.06);
|
||||||
|
}
|
||||||
|
.btn-action {
|
||||||
|
width: 100%;
|
||||||
|
height: 88rpx;
|
||||||
|
border-radius: 44rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.btn-pay {
|
||||||
|
background: linear-gradient(135deg, #2979ff, #1e60e0);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.btn-refund {
|
||||||
|
background: #fff;
|
||||||
|
border: 2rpx solid #2979ff;
|
||||||
|
color: #2979ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 底部占位 */
|
||||||
|
.bottom-spacer {
|
||||||
|
height: 40rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
+237
-143
@@ -2,24 +2,24 @@
|
|||||||
<view class="order-page">
|
<view class="order-page">
|
||||||
<!-- 顶部Tab切换 -->
|
<!-- 顶部Tab切换 -->
|
||||||
<view class="tab-header">
|
<view class="tab-header">
|
||||||
<view
|
<view
|
||||||
class="tab-item"
|
class="tab-item"
|
||||||
:class="{ active: currentTab === 'all' }"
|
:class="{ active: currentTab === 'all' }"
|
||||||
@click="switchTab('all')"
|
@click="switchTab('all')"
|
||||||
>
|
>
|
||||||
<text class="tab-text">全部订单</text>
|
<text class="tab-text">全部订单</text>
|
||||||
<view class="tab-line" v-if="currentTab === 'all'"></view>
|
<view class="tab-line" v-if="currentTab === 'all'"></view>
|
||||||
</view>
|
</view>
|
||||||
<view
|
<view
|
||||||
class="tab-item"
|
class="tab-item"
|
||||||
:class="{ active: currentTab === 'paid' }"
|
:class="{ active: currentTab === 'paid' }"
|
||||||
@click="switchTab('paid')"
|
@click="switchTab('paid')"
|
||||||
>
|
>
|
||||||
<text class="tab-text">已支付</text>
|
<text class="tab-text">已支付</text>
|
||||||
<view class="tab-line" v-if="currentTab === 'paid'"></view>
|
<view class="tab-line" v-if="currentTab === 'paid'"></view>
|
||||||
</view>
|
</view>
|
||||||
<view
|
<view
|
||||||
class="tab-item"
|
class="tab-item"
|
||||||
:class="{ active: currentTab === 'unpaid' }"
|
:class="{ active: currentTab === 'unpaid' }"
|
||||||
@click="switchTab('unpaid')"
|
@click="switchTab('unpaid')"
|
||||||
>
|
>
|
||||||
@@ -43,34 +43,39 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 订单列表 -->
|
<!-- 订单列表 -->
|
||||||
<scroll-view class="order-scroll" scroll-y>
|
<scroll-view class="order-scroll" scroll-y @scrolltolower="loadMore">
|
||||||
<view class="order-list">
|
<view class="order-list">
|
||||||
<view
|
<view
|
||||||
class="order-card"
|
class="order-card"
|
||||||
v-for="(order, index) in filteredOrders"
|
v-for="order in filteredOrders"
|
||||||
:key="index"
|
:key="order._id"
|
||||||
>
|
>
|
||||||
<!-- 第一行: 日期 + 状态 -->
|
<!-- 第一行: 日期 + 状态 -->
|
||||||
<view class="order-header">
|
<view class="order-header">
|
||||||
<text class="order-date">{{ order.create_time }}</text>
|
<text class="order-date">{{ formatTime(order.createdAt) }}</text>
|
||||||
<text class="order-status" :class="{ paid: order.status === 'paid', unpaid: order.status === 'unpaid' }">
|
<view class="status-tags">
|
||||||
{{ order.status === 'paid' ? '已支付' : '未支付' }}
|
<text class="order-status" :class="orderStatusClass(order.order_status)">
|
||||||
</text>
|
{{ orderStatusText(order.order_status) }}
|
||||||
|
</text>
|
||||||
|
<text class="pay-status" :class="payStatusClass(order.payment_status)">
|
||||||
|
{{ payStatusText(order.payment_status) }}
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="divider"></view>
|
<view class="divider"></view>
|
||||||
|
|
||||||
<!-- 商品列表(整体可点击跳转) -->
|
<!-- 商品列表 -->
|
||||||
<view class="product-section" @click="goToDetail(order)">
|
<view class="product-section" @click="goToDetail(order)">
|
||||||
<view class="product-list">
|
<view class="product-list">
|
||||||
<view
|
<view
|
||||||
class="product-item"
|
class="product-item"
|
||||||
v-for="(product, pIndex) in order.products"
|
v-for="(product, pIndex) in order.products"
|
||||||
:key="pIndex"
|
:key="pIndex"
|
||||||
>
|
>
|
||||||
<image class="product-img" :src="product.image" mode="aspectFill" />
|
<image class="product-img" :src="product.image" mode="aspectFill" />
|
||||||
<view class="product-info">
|
<view class="product-info">
|
||||||
<text class="product-name">{{ product.name }}</text>
|
<text class="product-name">{{ product.name }}</text>
|
||||||
<text class="product-price-qty">¥{{ product.price }} x {{ product.quantity }}</text>
|
<text class="product-price-qty">¥{{ getDecimal(product.unit_price) }} x {{ product.qty }}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -81,27 +86,44 @@
|
|||||||
|
|
||||||
<!-- 总计 -->
|
<!-- 总计 -->
|
||||||
<view class="order-total">
|
<view class="order-total">
|
||||||
<text class="total-qty">共{{ order.totalQuantity }}件</text>
|
<text class="total-qty">共{{ order.total_qty }}件</text>
|
||||||
<view class="total-amount">
|
<view class="total-amount">
|
||||||
<text class="total-label">总计:</text>
|
<text class="total-label">总计:</text>
|
||||||
<text class="total-price">¥{{ order.totalAmount }}</text>
|
<text class="total-price">¥{{ getDecimal(order.total_amount) }}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 操作按钮 -->
|
<!-- 操作按钮 -->
|
||||||
<view class="order-action">
|
<view class="order-action">
|
||||||
<view
|
<view
|
||||||
class="action-btn"
|
v-if="order.payment_status === 'PENDING'"
|
||||||
:class="{ 'pay-btn': order.status === 'unpaid', 'refund-btn': order.status === 'paid' }"
|
class="action-btn pay-btn"
|
||||||
@click="handleAction(order)"
|
@click="handlePay(order)"
|
||||||
>
|
>
|
||||||
{{ order.status === 'unpaid' ? '立即支付' : '申请退款' }}
|
立即支付
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
v-else-if="order.payment_status === 'PAID' && !order.has_refund"
|
||||||
|
class="action-btn refund-btn"
|
||||||
|
@click="handleRefund(order)"
|
||||||
|
>
|
||||||
|
申请退款
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 加载状态 -->
|
||||||
|
<view class="loading-state" v-if="loading">
|
||||||
|
<text class="loading-text">加载中...</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 加载更多 / 没有更多 -->
|
||||||
|
<view class="load-more" v-if="!loading && orderList.length > 0 && total > limit">
|
||||||
|
<text class="load-more-text">{{ hasNext ? '上拉加载更多' : '没有更多了' }}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
<!-- 空状态 -->
|
<!-- 空状态 -->
|
||||||
<view class="empty-state" v-if="filteredOrders.length === 0">
|
<view class="empty-state" v-if="!loading && filteredOrders.length === 0">
|
||||||
<text class="empty-text">暂无订单</text>
|
<text class="empty-text">暂无订单</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -118,11 +140,7 @@
|
|||||||
<view class="sidebar-content">
|
<view class="sidebar-content">
|
||||||
<view class="date-row">
|
<view class="date-row">
|
||||||
<text class="date-label">开始时间</text>
|
<text class="date-label">开始时间</text>
|
||||||
<picker
|
<picker mode="date" :value="tempStartTime" @change="onStartTimeChange">
|
||||||
mode="date"
|
|
||||||
:value="tempStartTime"
|
|
||||||
@change="onStartTimeChange"
|
|
||||||
>
|
|
||||||
<view class="date-picker">
|
<view class="date-picker">
|
||||||
<text class="date-value">{{ tempStartTime || '请选择' }}</text>
|
<text class="date-value">{{ tempStartTime || '请选择' }}</text>
|
||||||
</view>
|
</view>
|
||||||
@@ -130,11 +148,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="date-row">
|
<view class="date-row">
|
||||||
<text class="date-label">结束时间</text>
|
<text class="date-label">结束时间</text>
|
||||||
<picker
|
<picker mode="date" :value="tempEndTime" @change="onEndTimeChange">
|
||||||
mode="date"
|
|
||||||
:value="tempEndTime"
|
|
||||||
@change="onEndTimeChange"
|
|
||||||
>
|
|
||||||
<view class="date-picker">
|
<view class="date-picker">
|
||||||
<text class="date-value">{{ tempEndTime || '请选择' }}</text>
|
<text class="date-value">{{ tempEndTime || '请选择' }}</text>
|
||||||
</view>
|
</view>
|
||||||
@@ -164,7 +178,8 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import PageNavBar from '@/components/page-nav-bar/page-nav-bar.vue';
|
import PageNavBar from '@/components/page-nav-bar/page-nav-bar.vue';
|
||||||
import { checkLoginWithPrompt } from '@/utils/auth-guard.js';
|
import { get } from '@/utils/request.js';
|
||||||
|
import { checkLoginWithPrompt, getCachedUserInfo } from '@/utils/auth-guard.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { PageNavBar },
|
components: { PageNavBar },
|
||||||
@@ -176,99 +191,92 @@ export default {
|
|||||||
tempEndTime: '',
|
tempEndTime: '',
|
||||||
filterStartTime: '',
|
filterStartTime: '',
|
||||||
filterEndTime: '',
|
filterEndTime: '',
|
||||||
// 模拟订单数据
|
orderList: [],
|
||||||
orderList: [
|
loading: false,
|
||||||
{
|
page: 1,
|
||||||
id: 1,
|
limit: 10,
|
||||||
create_time: '2026-04-30 10:25:30',
|
hasNext: true,
|
||||||
status: 'paid',
|
total: 0
|
||||||
products: [
|
|
||||||
{ name: '君乐宝450ml悦鲜活', price: 0.01, quantity: 2, image: '/static/c1.png' },
|
|
||||||
{ name: '可口可乐330ml', price: 3.00, quantity: 1, image: '/static/c4.png' }
|
|
||||||
],
|
|
||||||
totalQuantity: 3,
|
|
||||||
totalAmount: '0.04'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
create_time: '2026-04-29 15:12:45',
|
|
||||||
status: 'unpaid',
|
|
||||||
products: [
|
|
||||||
{ name: '农夫山泉550ml', price: 2.00, quantity: 3, image: '/static/c5.png' }
|
|
||||||
],
|
|
||||||
totalQuantity: 3,
|
|
||||||
totalAmount: '6.00'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
create_time: '2026-04-28 09:30:00',
|
|
||||||
status: 'paid',
|
|
||||||
products: [
|
|
||||||
{ name: '乐事薯片原味75g', price: 7.50, quantity: 1, image: '/static/c6.png' },
|
|
||||||
{ name: '白桔(0.0.0.0-5.5.5)', price: 0.05, quantity: 5, image: '/static/c3.png' }
|
|
||||||
],
|
|
||||||
totalQuantity: 6,
|
|
||||||
totalAmount: '1.00'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
create_time: '2026-04-27 18:45:20',
|
|
||||||
status: 'unpaid',
|
|
||||||
products: [
|
|
||||||
{ name: '白红(0.0.0.0-9.9.9)', price: 0.06, quantity: 10, image: '/static/c2.png' }
|
|
||||||
],
|
|
||||||
totalQuantity: 10,
|
|
||||||
totalAmount: '0.60'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
create_time: '2026-04-25 12:00:00',
|
|
||||||
status: 'paid',
|
|
||||||
products: [
|
|
||||||
{ name: '君乐宝450ml悦鲜活', price: 0.01, quantity: 1, image: '/static/c1.png' }
|
|
||||||
],
|
|
||||||
totalQuantity: 1,
|
|
||||||
totalAmount: '0.01'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
filteredOrders() {
|
filteredOrders() {
|
||||||
let list = this.orderList;
|
let list = this.orderList;
|
||||||
|
|
||||||
// Tab筛选
|
|
||||||
if (this.currentTab === 'paid') {
|
if (this.currentTab === 'paid') {
|
||||||
list = list.filter(o => o.status === 'paid');
|
list = list.filter(o => o.payment_status === 'PAID');
|
||||||
} else if (this.currentTab === 'unpaid') {
|
} else if (this.currentTab === 'unpaid') {
|
||||||
list = list.filter(o => o.status === 'unpaid');
|
list = list.filter(o => o.payment_status === 'PENDING');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 日期筛选
|
|
||||||
if (this.filterStartTime) {
|
|
||||||
list = list.filter(o => o.create_time >= this.filterStartTime);
|
|
||||||
}
|
|
||||||
if (this.filterEndTime) {
|
|
||||||
list = list.filter(o => o.create_time.split(' ')[0] <= this.filterEndTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
// 进入订单页需要登录
|
|
||||||
if (!checkLoginWithPrompt('order')) return;
|
if (!checkLoginWithPrompt('order')) return;
|
||||||
|
this.fetchOrders();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// 拉取订单列表
|
||||||
|
async fetchOrders(append = false) {
|
||||||
|
if (this.loading) return;
|
||||||
|
this.loading = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userInfo = getCachedUserInfo();
|
||||||
|
const userId = userInfo && userInfo.user_id;
|
||||||
|
if (!userId) {
|
||||||
|
uni.showToast({ title: '无法获取用户信息', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filter = { user_id: userId };
|
||||||
|
if (this.filterStartTime) filter.start_time = this.filterStartTime;
|
||||||
|
if (this.filterEndTime) filter.end_time = this.filterEndTime;
|
||||||
|
|
||||||
|
const res = await get('/user/orders', {
|
||||||
|
page: this.page,
|
||||||
|
limit: this.limit,
|
||||||
|
filter: JSON.stringify(filter)
|
||||||
|
});
|
||||||
|
|
||||||
|
const ret = res.data || {};
|
||||||
|
if (ret.code === 0) {
|
||||||
|
const list = Array.isArray(ret.data) ? ret.data : [];
|
||||||
|
const meta = ret.meta || {};
|
||||||
|
|
||||||
|
if (append) {
|
||||||
|
this.orderList = this.orderList.concat(list);
|
||||||
|
} else {
|
||||||
|
this.orderList = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.total = meta.total || list.length;
|
||||||
|
this.hasNext = !!meta.hasNext;
|
||||||
|
} else {
|
||||||
|
uni.showToast({ title: ret.message || '获取订单失败', icon: 'none' });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
uni.showToast({ title: '网络请求失败', icon: 'none' });
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 上拉加载更多
|
||||||
|
loadMore() {
|
||||||
|
if (!this.hasNext || this.loading) return;
|
||||||
|
this.page++;
|
||||||
|
this.fetchOrders(true);
|
||||||
|
},
|
||||||
|
|
||||||
switchTab(tab) {
|
switchTab(tab) {
|
||||||
this.currentTab = tab;
|
this.currentTab = tab;
|
||||||
},
|
},
|
||||||
onStartTimeChange(e) {
|
|
||||||
this.tempStartTime = e.detail.value;
|
// 筛选
|
||||||
},
|
onStartTimeChange(e) { this.tempStartTime = e.detail.value; },
|
||||||
onEndTimeChange(e) {
|
onEndTimeChange(e) { this.tempEndTime = e.detail.value; },
|
||||||
this.tempEndTime = e.detail.value;
|
|
||||||
},
|
|
||||||
resetFilter() {
|
resetFilter() {
|
||||||
this.tempStartTime = '';
|
this.tempStartTime = '';
|
||||||
this.tempEndTime = '';
|
this.tempEndTime = '';
|
||||||
@@ -277,39 +285,83 @@ export default {
|
|||||||
this.filterStartTime = this.tempStartTime;
|
this.filterStartTime = this.tempStartTime;
|
||||||
this.filterEndTime = this.tempEndTime;
|
this.filterEndTime = this.tempEndTime;
|
||||||
this.showFilterSidebar = false;
|
this.showFilterSidebar = false;
|
||||||
|
this.page = 1;
|
||||||
|
this.hasNext = true;
|
||||||
|
this.fetchOrders();
|
||||||
},
|
},
|
||||||
clearFilter() {
|
clearFilter() {
|
||||||
this.filterStartTime = '';
|
this.filterStartTime = '';
|
||||||
this.filterEndTime = '';
|
this.filterEndTime = '';
|
||||||
|
this.page = 1;
|
||||||
|
this.hasNext = true;
|
||||||
|
this.fetchOrders();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 格式化时间
|
||||||
|
formatTime(iso) {
|
||||||
|
if (!iso) return '';
|
||||||
|
const d = new Date(iso);
|
||||||
|
const pad = n => String(n).padStart(2, '0');
|
||||||
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 解析 MongoDB Decimal128
|
||||||
|
getDecimal(val) {
|
||||||
|
if (!val) return '0.00';
|
||||||
|
if (val.$numberDecimal) return val.$numberDecimal;
|
||||||
|
return String(val);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 订单状态
|
||||||
|
orderStatusText(status) {
|
||||||
|
const map = { PROCESSING: '处理中', COMPLETED: '已完成', CANCELLED: '已取消' };
|
||||||
|
return map[status] || status;
|
||||||
|
},
|
||||||
|
orderStatusClass(status) {
|
||||||
|
if (status === 'COMPLETED') return 'paid';
|
||||||
|
if (status === 'CANCELLED') return 'cancelled';
|
||||||
|
return 'processing';
|
||||||
|
},
|
||||||
|
|
||||||
|
// 支付状态
|
||||||
|
payStatusText(status) {
|
||||||
|
const map = { PENDING: '待支付', PAID: '已支付', REFUNDED: '已退款', PARTIAL_REFUND: '部分退款' };
|
||||||
|
return map[status] || status;
|
||||||
|
},
|
||||||
|
payStatusClass(status) {
|
||||||
|
if (status === 'PAID') return 'paid';
|
||||||
|
if (status === 'PENDING') return 'unpaid';
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
|
||||||
goToDetail(order) {
|
goToDetail(order) {
|
||||||
uni.showToast({ title: '订单详情开发中', icon: 'none' });
|
uni.setStorageSync('__order_detail_cache', order);
|
||||||
|
uni.navigateTo({ url: `/pages/order/detail?order_id=${order.order_id}` });
|
||||||
},
|
},
|
||||||
handleAction(order) {
|
handlePay(order) {
|
||||||
if (order.status === 'unpaid') {
|
if (!checkLoginWithPrompt('pay')) return;
|
||||||
// 支付需要登录
|
uni.showModal({
|
||||||
if (!checkLoginWithPrompt('pay')) return;
|
title: '立即支付',
|
||||||
uni.showModal({
|
content: `确认支付¥${this.getDecimal(order.total_amount)}?`,
|
||||||
title: '立即支付',
|
success: (res) => {
|
||||||
content: `确认支付¥${order.totalAmount}?`,
|
if (res.confirm) {
|
||||||
success: (res) => {
|
uni.showToast({ title: '支付功能开发中', icon: 'none' });
|
||||||
if (res.confirm) {
|
|
||||||
uni.showToast({ title: '支付成功', icon: 'success' });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} else {
|
});
|
||||||
uni.showModal({
|
|
||||||
title: '申请退款',
|
|
||||||
content: '确认申请退款?',
|
|
||||||
success: (res) => {
|
|
||||||
if (res.confirm) {
|
|
||||||
uni.showToast({ title: '退款申请已提交', icon: 'success' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
handleRefund(order) {
|
||||||
|
uni.showModal({
|
||||||
|
title: '申请退款',
|
||||||
|
content: '确认申请退款?',
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
uni.showToast({ title: '退款功能开发中', icon: 'none' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
handleNavPrev() {
|
handleNavPrev() {
|
||||||
uni.navigateBack({ fail: () => { uni.switchTab({ url: '/pages/index/index' }); } });
|
uni.navigateBack({ fail: () => { uni.switchTab({ url: '/pages/index/index' }); } });
|
||||||
},
|
},
|
||||||
@@ -426,16 +478,36 @@ page { height: 100%; background-color: #f5f5f5; }
|
|||||||
font-size: 26rpx;
|
font-size: 26rpx;
|
||||||
color: #666;
|
color: #666;
|
||||||
}
|
}
|
||||||
.order-status {
|
.status-tags {
|
||||||
font-size: 26rpx;
|
display: flex;
|
||||||
font-weight: bold;
|
gap: 12rpx;
|
||||||
|
}
|
||||||
|
.order-status, .pay-status {
|
||||||
|
font-size: 22rpx;
|
||||||
|
padding: 4rpx 14rpx;
|
||||||
|
border-radius: 6rpx;
|
||||||
|
}
|
||||||
|
.order-status.processing {
|
||||||
|
background: #e8f4ff;
|
||||||
|
color: #2979ff;
|
||||||
}
|
}
|
||||||
.order-status.paid {
|
.order-status.paid {
|
||||||
|
background: #e8faf0;
|
||||||
color: #19be6b;
|
color: #19be6b;
|
||||||
}
|
}
|
||||||
.order-status.unpaid {
|
.order-status.cancelled {
|
||||||
|
background: #f5f5f5;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
.pay-status.paid {
|
||||||
|
background: #e8faf0;
|
||||||
|
color: #19be6b;
|
||||||
|
}
|
||||||
|
.pay-status.unpaid {
|
||||||
|
background: #fff0f0;
|
||||||
color: #e4393c;
|
color: #e4393c;
|
||||||
}
|
}
|
||||||
|
|
||||||
.divider {
|
.divider {
|
||||||
height: 1rpx;
|
height: 1rpx;
|
||||||
background: #f0f0f0;
|
background: #f0f0f0;
|
||||||
@@ -554,6 +626,28 @@ page { height: 100%; background-color: #f5f5f5; }
|
|||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 加载状态 */
|
||||||
|
.loading-state {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 40rpx 0;
|
||||||
|
}
|
||||||
|
.loading-text {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 加载更多 */
|
||||||
|
.load-more {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 30rpx 0;
|
||||||
|
}
|
||||||
|
.load-more-text {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
/* 筛选侧边栏 */
|
/* 筛选侧边栏 */
|
||||||
.filter-sidebar-mask {
|
.filter-sidebar-mask {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@@ -645,4 +739,4 @@ page { height: 100%; background-color: #f5f5f5; }
|
|||||||
.bottom-spacer {
|
.bottom-spacer {
|
||||||
height: 120rpx;
|
height: 120rpx;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -69,6 +69,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { gatewayPost } from '@/utils/request.js';
|
import { gatewayPost } from '@/utils/request.js';
|
||||||
|
import config from '@/config/env.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@@ -153,7 +154,7 @@ export default {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
},
|
},
|
||||||
|
|
||||||
// 注册
|
// 注册(Mock 模式也走真实接口)
|
||||||
async handleRegister() {
|
async handleRegister() {
|
||||||
if (!this.canSubmit) return;
|
if (!this.canSubmit) return;
|
||||||
|
|
||||||
@@ -182,10 +183,31 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const ret = res.data || {};
|
const ret = res.data || {};
|
||||||
|
console.log('[register] 注册响应:', JSON.stringify(ret, null, 2));
|
||||||
|
|
||||||
if (ret.code === 0 && ret.data) {
|
if (ret.code === 0 && ret.data) {
|
||||||
// 保存 token 和用户信息
|
// 保存 token
|
||||||
uni.setStorageSync('token', ret.data.token);
|
uni.setStorageSync('token', ret.data.token);
|
||||||
uni.setStorageSync('user_info', ret.data.user_info);
|
|
||||||
|
// 存储 user_info(接口返回 user_info.user_id 和 phone)
|
||||||
|
const existing = uni.getStorageSync('user_info') || {};
|
||||||
|
const apiUserInfo = ret.data.user_info || {};
|
||||||
|
const userInfo = {
|
||||||
|
user_id: apiUserInfo.user_id || existing.user_id || '',
|
||||||
|
phone: apiUserInfo.phone || this.phone || existing.phone || '',
|
||||||
|
nickname: existing.nickname || '',
|
||||||
|
avatar: existing.avatar || '',
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mock 模式下补充 mock 数据
|
||||||
|
if (config.mockWechatLogin) {
|
||||||
|
const mockInfo = config.mockUser.user_info;
|
||||||
|
userInfo.nickname = userInfo.nickname || mockInfo.nickname;
|
||||||
|
userInfo.avatar = userInfo.avatar || mockInfo.avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.setStorageSync('user_info', userInfo);
|
||||||
|
console.log('[register] 存储 user_info:', userInfo);
|
||||||
|
|
||||||
// 清除临时数据
|
// 清除临时数据
|
||||||
uni.removeStorageSync('temp_token');
|
uni.removeStorageSync('temp_token');
|
||||||
@@ -193,14 +215,7 @@ export default {
|
|||||||
|
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
uni.showToast({ title: '注册成功', icon: 'success' });
|
uni.showToast({ title: '注册成功', icon: 'success' });
|
||||||
|
setTimeout(() => this.navigateToTarget(), 1500);
|
||||||
// 跳转首页
|
|
||||||
setTimeout(() => {
|
|
||||||
const url = this.deviceId
|
|
||||||
? `/pages/index/index?device_id=${this.deviceId}`
|
|
||||||
: '/pages/index/index';
|
|
||||||
uni.redirectTo({ url });
|
|
||||||
}, 1500);
|
|
||||||
} else {
|
} else {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
uni.showToast({ title: ret.message || '注册失败', icon: 'none' });
|
uni.showToast({ title: ret.message || '注册失败', icon: 'none' });
|
||||||
@@ -211,6 +226,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) {
|
showAgreement(type) {
|
||||||
const title = type === 'user' ? '用户协议' : '隐私政策';
|
const title = type === 'user' ? '用户协议' : '隐私政策';
|
||||||
uni.showToast({ title: title + '开发中', icon: 'none' });
|
uni.showToast({ title: title + '开发中', icon: 'none' });
|
||||||
@@ -349,10 +377,8 @@ page {
|
|||||||
|
|
||||||
/* 底部协议 */
|
/* 底部协议 */
|
||||||
.agreement {
|
.agreement {
|
||||||
position: absolute;
|
margin-top: 80rpx;
|
||||||
bottom: 80rpx;
|
padding-bottom: env(safe-area-inset-bottom);
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
@@ -72,7 +72,9 @@ export function logout() {
|
|||||||
*/
|
*/
|
||||||
export function getCachedUserInfo() {
|
export function getCachedUserInfo() {
|
||||||
try {
|
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 {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -6,9 +6,9 @@
|
|||||||
// app_no 编码表:platform + terminalType → app_no
|
// app_no 编码表:platform + terminalType → app_no
|
||||||
const APP_NO_MAP = {
|
const APP_NO_MAP = {
|
||||||
'wechat_h5': '60000001102001',
|
'wechat_h5': '60000001102001',
|
||||||
'wechat_mp': '600102101',
|
'wechat_mp': '60000001102101',
|
||||||
'alipay_h5': '600112001',
|
'alipay_h5': '60000001112001',
|
||||||
'alipay_mp': '600112101',
|
'alipay_mp': '60000001112101',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -40,10 +40,11 @@ export function request(options = {}) {
|
|||||||
// 公开接口(授权/登录/注册相关)不带 Authorization,避免 CORS 预检和 JWT 拦截
|
// 公开接口(授权/登录/注册相关)不带 Authorization,避免 CORS 预检和 JWT 拦截
|
||||||
const publicPaths = [
|
const publicPaths = [
|
||||||
'/api/v1/user/auth/url',
|
'/api/v1/user/auth/url',
|
||||||
'/api/v1/user/auth/callback',
|
'/api/v1/user/auth/exchange',
|
||||||
'/api/v1/user/login',
|
'/api/v1/user/login',
|
||||||
'/api/v1/user/register',
|
'/api/v1/user/register',
|
||||||
'/api/v1/user/sms/send',
|
'/api/v1/user/sms/send',
|
||||||
|
'/api/v1/user/info',
|
||||||
];
|
];
|
||||||
const isPublic = publicPaths.some((p) => url.includes(p));
|
const isPublic = publicPaths.some((p) => url.includes(p));
|
||||||
|
|
||||||
|
|||||||
+29
-1
@@ -1,8 +1,35 @@
|
|||||||
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()],
|
||||||
|
// 将构建时的 DEPLOY_ENV 环境变量注入到客户端代码中
|
||||||
|
define: {
|
||||||
|
'process.env.DEPLOY_ENV': JSON.stringify(process.env.DEPLOY_ENV || ''),
|
||||||
|
},
|
||||||
css: {
|
css: {
|
||||||
preprocessorOptions: {
|
preprocessorOptions: {
|
||||||
scss: {
|
scss: {
|
||||||
@@ -10,4 +37,5 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
publicDir: 'public',
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user