重构:移动源码到 src/ 目录,支持 CLI 构建

This commit is contained in:
kk
2026-06-26 17:55:48 +08:00
parent a85117cca7
commit 437764c9d2
348 changed files with 8914 additions and 40210 deletions
+487
View File
@@ -0,0 +1,487 @@
<template>
<view class="app-container">
<!-- ========== 首页内容 ========== -->
<view v-if="currentTab === 'home'" class="page-content home-page">
<scroll-view
class="product-area"
scroll-y
>
<!-- 热销商品标题 + 装饰 -->
<view class="section-title-wrap">
<view class="section-title">热销商品</view>
<view class="title-decoration">
<view class="deco-dot"></view>
<view class="deco-line"></view>
</view>
</view>
<!-- 分类 Tab 横向滚动 -->
<scroll-view class="category-tabs" scroll-x>
<view class="tabs-inner">
<view class="tab-item" :class="{ active: activeCategory === 'all' }" @click="switchCategory('all')">
<text class="tab-text">全部商品</text>
<view class="tab-underline"></view>
</view>
<view
v-for="(cat, idx) in categoryList"
:key="idx"
class="tab-item"
:class="{ active: activeCategory === cat.category }"
@click="switchCategory(cat.category)"
>
<text class="tab-text">{{ cat.category }}</text>
<view class="tab-underline"></view>
</view>
</view>
</scroll-view>
<!-- 商品网格 -->
<view class="product-grid">
<view
v-for="(item, idx) in displayProducts"
:key="idx"
class="product-card"
>
<image class="product-img" :src="item.image" mode="aspectFill" />
<view class="product-name">{{ item.name }}</view>
<view class="product-price">
<text class="price-yen">¥</text>
<text class="price-num">{{ getDisplayPrice(item) }}</text>
</view>
</view>
</view>
<!-- 无商品时 -->
<view v-if="categoryList.length === 0 && !loading" class="empty-tip">
<text>暂无商品</text>
</view>
<!-- loading -->
<view v-if="loading" class="loading-tip">
<text>加载中...</text>
</view>
<!-- 底部占位 -->
<view class="bottom-spacer"></view>
</scroll-view>
<!-- 底部导航栏 -->
<view class="tab-bar">
<view class="tab-item" :class="{ active: currentTab === 'home' }" @click="switchTab('home')">
<view class="home-icon">
<view class="home-roof"></view>
<view class="home-body"></view>
</view>
<text class="tab-text">首页</text>
</view>
<view class="door-btn-wrapper" @click="handleOpenDoor">
<view class="door-btn">开门</view>
</view>
<view class="tab-item" :class="{ active: currentTab === 'mine' }" @click="switchTab('mine')">
<view class="mine-icon">
<view class="mine-head"></view>
<view class="mine-body"></view>
</view>
<text class="tab-text">我的</text>
</view>
</view>
</view>
<!-- ========== 我的内容 ========== -->
<view v-if="currentTab === 'mine'" class="page-content mine-page">
<!-- 蓝色个人信息区域 -->
<view class="user-header">
<view class="user-info">
<view class="avatar-wrapper">
<image class="avatar" :src="userInfo.avatar || '/static/default-avatar.png'" mode="aspectFill" />
</view>
<view class="user-detail">
<text class="nickname">{{ userInfo.nickname || '未登录' }}</text>
<text class="phone">{{ maskedPhone }}</text>
</view>
</view>
</view>
<!-- 菜单列表 -->
<view class="content-area">
<view class="menu-list">
<view class="menu-item" v-for="(item, index) in menuList" :key="index" @click="handleMenuClick(item)">
<text class="menu-text">{{ item.title }}</text>
<text class="menu-arrow">></text>
</view>
</view>
<!-- 开发调试工具仅开发环境显示 -->
<view v-if="isDev" class="dev-tools">
<view class="dev-tools-title">开发工具</view>
<view class="menu-item">
<text class="menu-text">vConsole 调试</text>
<switch :checked="vconsoleEnabled" color="#2979ff" @change="onVConsoleChange" />
</view>
</view>
</view>
<!-- 底部左右箭头导航条 -->
<page-nav-bar
:hasPrev="true"
:hasNext="false"
@prev="handleNavPrev"
@next="handleNavNext"
/>
<!-- 公众号二维码弹窗 -->
<view v-if="showQrcodePopup" class="qrcode-popup-mask" @click="showQrcodePopup = false">
<view class="qrcode-popup-content" @click.stop>
<view class="qrcode-popup-title">关注公众号</view>
<image class="qrcode-img" src="/static/qrcode.png" mode="aspectFit" />
<view class="qrcode-popup-tip">扫码关注获取更多优惠信息</view>
<view class="qrcode-popup-close" @click="showQrcodePopup = false">关闭</view>
</view>
</view>
</view>
</view>
</template>
<script>
import PageNavBar from '@/components/page-nav-bar/page-nav-bar.vue';
import config from '@/config/env.js';
import { get } from '@/utils/request.js';
import { checkLoginWithPrompt, getCachedUserInfo } from '@/utils/auth-guard.js';
import { isVConsoleEnabled, showVConsole, hideVConsole } from '@/utils/vconsole';
export default {
components: { PageNavBar },
data() {
return {
deviceId: '',
currentTab: 'home',
showQrcodePopup: false,
loading: false,
categoryList: [],
activeCategory: 'all',
userInfo: { nickname: '', phone: '', avatar: '' },
menuList: [
{ title: '我的订单', action: 'order' },
{ title: '常见问题', action: 'faq' },
{ title: '联系客服', action: 'call' },
{ title: '公众号信息', action: 'qrcode' }
],
servicePhone: config.servicePhone,
isDev: process.env.NODE_ENV === 'development',
vconsoleEnabled: false
};
},
computed: {
maskedPhone() {
const p = this.userInfo.phone;
return p ? p.substring(0,3) + '****' + p.substring(7) : '';
},
// 全部商品:合并所有分类下的商品
allProducts() {
let all = [];
this.categoryList.forEach(cat => {
if (cat.products) all = all.concat(cat.products);
});
return all;
},
// 当前显示的商品列表(根据选中的分类 tab)
displayProducts() {
if (this.activeCategory === 'all') return this.allProducts;
const cat = this.categoryList.find(c => c.category === this.activeCategory);
return cat ? cat.products || [] : [];
}
},
onLoad(options) {
// 支持通过 tab 参数切换到"我的"页面
if (options.tab === 'mine') {
this.currentTab = 'mine';
}
if (options.device_id) {
this.deviceId = options.device_id;
this.fetchProducts();
} else if (!options.tab) {
// 无设备编号且非 tab 跳转,跳回扫码页
uni.redirectTo({ url: '/pages/index/scan' });
}
// 加载缓存的用户信息
this.loadUserInfo();
// 初始化 vConsole 状态
this.vconsoleEnabled = isVConsoleEnabled();
},
onShow() {
// 每次显示页面时刷新用户信息(授权回调后可能已更新)
this.loadUserInfo();
},
onReady() {
// 页面渲染完成后再次检查状态
this.vconsoleEnabled = isVConsoleEnabled();
},
methods: {
switchTab(tab) {
// 切换到"我的"Tab 时检查登录
if (tab === 'mine' && !checkLoginWithPrompt('mine')) return;
this.currentTab = tab;
},
switchCategory(cat) { this.activeCategory = cat; },
getDisplayPrice(item) {
// 优先显示促销价,没有促销价则显示销售价
if (item.promotion_price != null) return item.promotion_price;
return item.sale_price;
},
// 从缓存加载用户信息
loadUserInfo() {
const cached = getCachedUserInfo();
if (cached) {
this.userInfo = { ...this.userInfo, ...cached };
} else {
this.userInfo = { nickname: '', phone: '', avatar: '' };
}
},
async fetchProducts() {
this.loading = true;
try {
const res = await get('/device-product/getProductList', {
device_id: this.deviceId,
});
const ret = res.data || {};
if (ret.code === 0 && Array.isArray(ret.data)) {
this.categoryList = ret.data;
} else {
uni.showToast({ title: ret.message || '获取商品失败', icon: 'none' });
}
} catch (e) {
uni.showToast({ title: '网络请求失败', icon: 'none' });
} finally {
this.loading = false;
}
},
handleOpenDoor() {
uni.showModal({
title: '开门',
content: '确认打开柜门?',
success: r => r.confirm && uni.showToast({ title: '柜门已打开', icon: 'success' })
});
},
handleMenuClick(item) {
switch (item.action) {
case 'order':
// 查看订单需要登录
if (!checkLoginWithPrompt('order')) return;
uni.navigateTo({ url: '/pages/order/order' });
break;
case 'faq':
uni.navigateTo({ url: '/pages/faq/faq' });
break;
case 'call':
uni.makePhoneCall({ phoneNumber: this.servicePhone, fail: () => {} });
break;
case 'qrcode':
this.showQrcodePopup = true;
break;
}
},
handleNavPrev() { this.currentTab = 'home'; },
handleNavNext() { uni.showToast({ title: '暂无下一页', icon: 'none' }); },
onVConsoleChange(e) {
const enabled = e.detail.value;
if (enabled) {
showVConsole();
} else {
hideVConsole();
}
this.vconsoleEnabled = enabled;
}
}
};
</script>
<style scoped>
page { height: 100%; background-color: #fff; }
.app-container { display: flex; flex-direction: column; height: 100vh; background-color: #fff; }
.page-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; position: relative; }
/* ====== 首页样式 ====== */
.home-page { display: flex; flex-direction: column; height: 100%; }
.product-area { flex: 1; overflow-y: auto; height: 0; }
/* 热销商品标题 + 装饰 */
.section-title-wrap { display: flex; align-items: center; padding: 24rpx 28rpx 16rpx; }
.section-title { font-size: 36rpx; font-weight: bold; color: #333; }
.title-decoration { display: flex; align-items: center; margin-left: 16rpx; }
.deco-dot { width: 12rpx; height: 12rpx; background: #ff6b6b; border-radius: 50%; }
.deco-line { width: 40rpx; height: 6rpx; background: linear-gradient(90deg, #ff6b6b, transparent); margin-left: 6rpx; border-radius: 3rpx; }
/* 分类 Tab 横向滚动 */
.category-tabs { white-space: nowrap; padding: 0 20rpx; border-bottom: 1rpx solid #f0f0f0; }
.tabs-inner { display: inline-flex; padding: 0 8rpx; }
.tab-item { display: inline-flex; flex-direction: column; align-items: center; padding: 20rpx 24rpx; position: relative; }
.tab-text { font-size: 28rpx; color: #666; transition: color 0.2s; }
.tab-item.active .tab-text { color: #2979ff; font-weight: bold; }
.tab-underline { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 0; height: 4rpx; background: #2979ff; border-radius: 2rpx; transition: width 0.2s; }
.tab-item.active .tab-underline { width: 48rpx; }
/* 商品网格 */
.product-grid { display: flex; flex-wrap: wrap; padding: 12rpx; gap: 12rpx; }
.product-card { width: calc((100% - 24rpx) / 3); text-align: center; }
.product-img { width: 100%; height: 220rpx; border-radius: 8rpx; background-color: #fff; }
.product-name { font-size: 24rpx; color: #333; padding: 10rpx 8rpx 6rpx; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-price { font-size: 30rpx; font-weight: bold; color: #e4393c; padding: 0 8rpx 16rpx; }
.price-yen { font-size: 22rpx; }
.price-num { font-size: 32rpx; }
/* 底部占位 */
.bottom-spacer { height: 160rpx; }
/* 底部导航栏 */
.tab-bar { position: absolute; bottom: 0; left: 0; right: 0; height: 120rpx; background: #fff; display: flex; align-items: center; justify-content: space-around; box-shadow: 0 -2rpx 16rpx rgba(0,0,0,0.08); z-index: 999; padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); }
.tab-bar .tab-item { flex: 1; display: flex; align-items: center; justify-content: center; height: 100%; }
.tab-bar .tab-text { font-size: 28rpx; color: #999; font-weight: normal; }
.tab-bar .tab-item.active .tab-text { color: #2979ff; }
/* 首页图标 */
.tab-bar .home-icon {
width: 40rpx;
height: 36rpx;
position: relative;
margin-bottom: 6rpx;
}
.tab-bar .home-roof {
width: 0;
height: 0;
border-left: 22rpx solid transparent;
border-right: 22rpx solid transparent;
border-bottom: 18rpx solid #999;
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
}
.tab-bar .home-body {
width: 30rpx;
height: 18rpx;
background-color: #999;
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
border-radius: 0 0 3rpx 3rpx;
}
.tab-bar .tab-item.active .home-roof {
border-bottom-color: #2979ff;
}
.tab-bar .tab-item.active .home-body {
background-color: #2979ff;
}
/* 我的图标(与扫一扫页共用) */
.tab-bar .mine-icon {
width: 40rpx;
height: 36rpx;
position: relative;
margin-bottom: 6rpx;
}
.tab-bar .mine-head {
width: 16rpx;
height: 16rpx;
border-radius: 50%;
background-color: #999;
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
}
.tab-bar .mine-body {
width: 28rpx;
height: 16rpx;
border-radius: 14rpx 14rpx 0 0;
background-color: #999;
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
.tab-bar .tab-item.active .mine-head,
.tab-bar .tab-item.active .mine-body {
background-color: #2979ff;
}
.door-btn-wrapper { position: relative; display: flex; align-items: center; justify-content: center; margin-top: -80rpx; }
.door-btn { width: 160rpx; height: 160rpx; border-radius: 50%; background: linear-gradient(135deg, #2979ff, #1e60e0); color: #fff; font-size: 38rpx; font-weight: bold; display: flex; align-items: center; justify-content: center; box-shadow: 0 10rpx 36rpx rgba(41,121,255,0.55); }
/* 空状态 / Loading */
.empty-tip, .loading-tip { text-align: center; padding: 60rpx; color: #999; font-size: 28rpx; }
/* ====== 我的页面样式 ====== */
.mine-page { background-color: #f5f5f5; position: relative; overflow-y: auto; }
.user-header { background: linear-gradient(135deg, #2979ff, #1e60e0); padding: 60rpx 40rpx; }
.user-info { display: flex; align-items: center; }
.avatar { width: 120rpx; height: 120rpx; border-radius: 50%; border: 4rpx solid rgba(255,255,255,0.8); background-color: #e0e0e0; }
.avatar-wrapper { margin-right: 30rpx; }
.user-detail { display: flex; flex-direction: column; flex: 1; }
.nickname { font-size: 36rpx; font-weight: bold; color: #fff; margin-bottom: 12rpx; }
.phone { font-size: 28rpx; color: rgba(255,255,255,0.9); }
.content-area { padding: 20rpx; padding-bottom: 140rpx; }
.menu-list { background-color: #fff; border-radius: 16rpx; overflow: hidden; }
.menu-item { display: flex; justify-content: space-between; padding: 32rpx 28rpx; border-bottom: 1rpx solid #f0f0f0; }
.menu-item:last-child { border-bottom: none; }
.menu-text { font-size: 30rpx; color: #333; }
.menu-arrow { font-size: 28rpx; color: #ccc; }
/* 开发工具区域 */
.dev-tools { margin-top: 20rpx; background-color: #fff; border-radius: 16rpx; overflow: hidden; }
.dev-tools-title { padding: 20rpx 28rpx 10rpx; font-size: 24rpx; color: #999; }
.dev-tools .menu-item { align-items: center; }
.dev-tools switch { transform: scale(0.8); }
/* ====== 公众号二维码弹窗 ====== */
.qrcode-popup-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.55);
z-index: 2000;
display: flex;
align-items: center;
justify-content: center;
}
.qrcode-popup-content {
width: 560rpx;
background: #fff;
border-radius: 20rpx;
padding: 48rpx 40rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.qrcode-popup-title {
font-size: 34rpx;
font-weight: bold;
color: #333;
margin-bottom: 32rpx;
}
.qrcode-img {
width: 400rpx;
height: 400rpx;
margin-bottom: 24rpx;
}
.qrcode-popup-tip {
font-size: 26rpx;
color: #999;
margin-bottom: 32rpx;
}
.qrcode-popup-close {
font-size: 28rpx;
color: #2979ff;
padding: 16rpx 60rpx;
border: 2rpx solid #2979ff;
border-radius: 40rpx;
}
</style>
+310
View File
@@ -0,0 +1,310 @@
<template>
<view class="scan-page">
<!-- 顶部品牌 -->
<view class="brand-area">
<text class="brand-name">智联方舟</text>
</view>
<!-- 中间扫一扫按钮 -->
<view class="scan-area">
<view class="scan-btn" @click="handleScan">
<!-- 二维码图标 -->
<view class="qr-icon">
<view class="qr-row">
<view class="qr-block"></view>
<view class="qr-block"></view>
<view class="qr-space"></view>
<view class="qr-block"></view>
</view>
<view class="qr-row">
<view class="qr-block"></view>
<view class="qr-space"></view>
<view class="qr-block"></view>
<view class="qr-space"></view>
</view>
<view class="qr-row">
<view class="qr-space"></view>
<view class="qr-block"></view>
<view class="qr-space"></view>
<view class="qr-block"></view>
</view>
<view class="qr-row">
<view class="qr-block"></view>
<view class="qr-block"></view>
<view class="qr-block"></view>
<view class="qr-space"></view>
</view>
</view>
<text class="scan-text">扫一扫</text>
</view>
<text class="scan-tip">扫描货柜上的二维码开始购物</text>
</view>
<!-- 我的入口 -->
<view class="mine-entry" @click="goMine">
<view class="mine-icon">
<view class="mine-head"></view>
<view class="mine-body"></view>
</view>
<text class="mine-text">我的</text>
</view>
<!-- 底部客服电话 -->
<view class="footer">
<text class="footer-text">客服电话</text>
<text class="footer-phone" @click="callService">{{ servicePhone }}</text>
</view>
</view>
</template>
<script>
import config from '@/config/env.js';
export default {
data() {
return {
servicePhone: config.servicePhone,
};
},
onLoad(options) {
// 1. query 参数中携带设备编号
if (options.device_id) {
uni.redirectTo({
url: '/pages/index/index?device_id=' + options.device_id,
});
return;
}
// #ifdef H5
// 2. URL 路径中携带设备编号(如 http://xxx/A1036
const path = window.location.pathname;
const segments = path.split('/').filter(Boolean);
if (segments.length > 0) {
const last = segments[segments.length - 1];
if (/^[A-Z][A-Z0-9]+$/.test(last)) {
uni.redirectTo({
url: '/pages/index/index?device_id=' + last,
});
return;
}
}
// #endif
},
methods: {
handleScan() {
// #ifdef H5
uni.showToast({ title: 'H5 环境暂不支持扫码', icon: 'none' });
// #endif
// #ifdef MP-WEIXIN
uni.scanCode({
onlyFromCamera: false,
success: (res) => {
this.parseScanResult(res.result);
},
fail: () => {
uni.showToast({ title: '扫码取消', icon: 'none' });
},
});
// #endif
},
parseScanResult(result) {
// 解析扫码结果,提取 device_id
// 预期格式:https://domain/A1036 或 device_id=A1036
let deviceId = '';
try {
const url = new URL(result);
// 取路径最后一段作为设备编号
const pathParts = url.pathname.split('/').filter(Boolean);
if (pathParts.length > 0) {
deviceId = pathParts[pathParts.length - 1];
}
} catch {
// 非 URL 格式,尝试直接匹配
if (/^[A-Z][A-Z0-9]+$/.test(result)) {
deviceId = result;
}
}
if (deviceId) {
uni.redirectTo({
url: '/pages/index/index?device_id=' + deviceId,
});
} else {
uni.showToast({ title: '无效的二维码', icon: 'none' });
}
},
goMine() {
uni.navigateTo({ url: '/pages/index/index?tab=mine' });
},
callService() {
// #ifdef H5
window.location.href = 'tel:' + this.servicePhone;
// #endif
// #ifndef H5
uni.makePhoneCall({ phoneNumber: this.servicePhone, fail: () => {} });
// #endif
},
},
};
</script>
<style scoped>
page {
height: 100%;
background-color: #fff;
}
.scan-page {
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
background-color: #fff;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
}
/* 品牌区域 */
.brand-area {
margin-top: 200rpx;
margin-bottom: 80rpx;
}
.brand-name {
font-size: 96rpx;
font-weight: bold;
color: #000;
letter-spacing: 12rpx;
}
/* 扫一扫按钮 */
.scan-area {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 80rpx;
}
.scan-btn {
width: 360rpx;
height: 360rpx;
border-radius: 50%;
background: linear-gradient(135deg, #2979ff, #1e60e0);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
box-shadow: 0 20rpx 60rpx rgba(41, 121, 255, 0.4);
}
/* 二维码图标 */
.qr-icon {
width: 120rpx;
height: 120rpx;
margin-bottom: 20rpx;
}
.qr-row {
display: flex;
margin-bottom: 6rpx;
}
.qr-row:last-child {
margin-bottom: 0;
}
.qr-block {
width: 24rpx;
height: 24rpx;
background-color: #fff;
margin-right: 6rpx;
border-radius: 4rpx;
}
.qr-space {
width: 24rpx;
height: 24rpx;
margin-right: 6rpx;
}
.scan-text {
font-size: 40rpx;
font-weight: bold;
color: #fff;
}
.scan-tip {
font-size: 26rpx;
color: #999;
margin-top: 40rpx;
}
/* 我的入口 */
.mine-entry {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 140rpx;
}
.mine-icon {
width: 60rpx;
height: 54rpx;
position: relative;
margin-bottom: 12rpx;
}
.mine-head {
width: 24rpx;
height: 24rpx;
border-radius: 50%;
background-color: #999;
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
}
.mine-body {
width: 44rpx;
height: 26rpx;
border-radius: 22rpx 22rpx 0 0;
background-color: #999;
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
.mine-text {
font-size: 28rpx;
color: #999;
}
/* 底部客服 */
.footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
padding: 32rpx 0;
padding-bottom: calc(32rpx + constant(safe-area-inset-bottom));
padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
}
.footer-text {
font-size: 26rpx;
color: #999;
}
.footer-phone {
font-size: 26rpx;
color: #2979ff;
}
</style>