consumer模块完成度95%,优化安卓端界面和小程序测试3
14
.hbuilderx/external-commands.json
Normal file
@@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"name": "切换到消费者端配置",
|
||||
"command": "D:\\companyproject\\mall\\scripts\\build-consumer.bat",
|
||||
"type": "shell",
|
||||
"workingDir": "D:\\companyproject\\mall"
|
||||
},
|
||||
{
|
||||
"name": "恢复公共配置",
|
||||
"command": "D:\\companyproject\\mall\\scripts\\restore-config.bat",
|
||||
"type": "shell",
|
||||
"workingDir": "D:\\companyproject\\mall"
|
||||
}
|
||||
]
|
||||
@@ -1,16 +1,38 @@
|
||||
{
|
||||
"version" : "1.0",
|
||||
"version" : "0.0.1",
|
||||
"configurations" : [
|
||||
{
|
||||
"customPlaygroundType" : "device",
|
||||
"localRepoPath" : "D:/companyproject/mall",
|
||||
"packageName" : "com.huawei.hisuite",
|
||||
"playground" : "standard",
|
||||
"type" : "uni-app:app-android"
|
||||
"name" : "消费者端-微信小程序",
|
||||
"platform" : "mp-weixin",
|
||||
"postDebugTask" : "restore-config",
|
||||
"preLaunchTask" : "build-consumer-config",
|
||||
"type" : "uni-app"
|
||||
},
|
||||
{
|
||||
"name" : "消费者端-Android App",
|
||||
"platform" : "app-android",
|
||||
"type" : "uni-app"
|
||||
},
|
||||
{
|
||||
"playground" : "standard",
|
||||
"type" : "uni-app:app-ios"
|
||||
"type" : "uni-app:app-android"
|
||||
}
|
||||
]
|
||||
],
|
||||
"tasks" : {
|
||||
"version" : "0.0.1",
|
||||
"tasks" : [
|
||||
{
|
||||
"label" : "build-consumer-config",
|
||||
"type" : "shell",
|
||||
"command" : "${workspaceFolder}/scripts/build-consumer.bat",
|
||||
"problemMatcher" : []
|
||||
},
|
||||
{
|
||||
"label" : "restore-config",
|
||||
"type" : "shell",
|
||||
"command" : "${workspaceFolder}/scripts/restore-config.bat",
|
||||
"problemMatcher" : []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
151
config/consumer/README.md
Normal file
@@ -0,0 +1,151 @@
|
||||
# 消费者端专用配置说明
|
||||
|
||||
## 一、配置文件结构
|
||||
|
||||
```
|
||||
mall/
|
||||
├── pages.json # 公共配置(保持不变)
|
||||
├── manifest.json # 公共配置(保持不变)
|
||||
│
|
||||
├── config/
|
||||
│ └── consumer/ # 消费者端专用配置
|
||||
│ ├── pages.json # 消费者端页面配置
|
||||
│ ├── manifest.json # 消费者端应用配置
|
||||
│ └── README.md # 本文档
|
||||
│
|
||||
└── scripts/ # 构建脚本
|
||||
├── build-consumer.bat # 应用消费者端配置
|
||||
└── restore-config.bat # 恢复公共配置
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 二、快速使用
|
||||
|
||||
### 方式一:一键切换(推荐)
|
||||
|
||||
在 HBuilderX 中打开项目,使用 **外部命令** 功能:
|
||||
|
||||
1. 菜单:**工具 → 外部命令 → 自定义外部命令**
|
||||
2. 添加以下命令:
|
||||
|
||||
```
|
||||
名称: 切换到消费者端配置
|
||||
命令: scripts\build-consumer.bat
|
||||
工作目录: ${projectPath}
|
||||
|
||||
名称: 恢复公共配置
|
||||
命令: scripts\restore-config.bat
|
||||
工作目录: ${projectPath}
|
||||
```
|
||||
|
||||
3. 以后通过菜单 **工具 → 外部命令** 一键切换
|
||||
|
||||
### 方式二:手动运行脚本
|
||||
|
||||
在项目目录下双击运行:
|
||||
- `scripts\build-consumer.bat` - 切换到消费者端配置
|
||||
- `scripts\restore-config.bat` - 恢复公共配置
|
||||
|
||||
---
|
||||
|
||||
## 三、开发流程
|
||||
|
||||
### 3.1 开发消费者端小程序
|
||||
|
||||
```
|
||||
1. 运行 build-consumer.bat(切换配置)
|
||||
2. HBuilderX 编译微信小程序
|
||||
3. 开发调试
|
||||
4. 运行 restore-config.bat(恢复配置)
|
||||
5. 提交代码
|
||||
```
|
||||
|
||||
### 3.2 开发消费者端 App
|
||||
|
||||
直接在 HBuilderX 中编译 Android App,无需切换配置。
|
||||
|
||||
---
|
||||
|
||||
## 四、配置文件说明
|
||||
|
||||
### 4.1 pages.json
|
||||
|
||||
消费者端专用页面配置:
|
||||
|
||||
**主包页面(核心页面)**:
|
||||
- 登录注册:login, register, forgot-password
|
||||
- 主要功能:index, category, cart, profile
|
||||
|
||||
**分包页面(次级页面)**:
|
||||
- 商品:product-detail, shop-detail, search
|
||||
- 订单:checkout, payment, orders, order-detail
|
||||
- 用户:settings, wallet, favorites, address-list
|
||||
- 会员:member/index, points/*, coupons
|
||||
|
||||
### 4.2 manifest.json
|
||||
|
||||
消费者端专用应用配置:
|
||||
- 应用名称:商城消费者端
|
||||
- 小程序 AppID(需填写)
|
||||
- 分包优化配置
|
||||
|
||||
---
|
||||
|
||||
## 五、添加新页面
|
||||
|
||||
### 5.1 添加消费者端页面
|
||||
|
||||
1. 创建页面文件:`pages/mall/consumer/new-page.uvue`
|
||||
2. 编辑 `config/consumer/pages.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"path": "new-page",
|
||||
"style": {
|
||||
"navigationBarTitleText": "新页面"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5.2 添加公共页面
|
||||
|
||||
同时更新:
|
||||
- `config/consumer/pages.json`
|
||||
- 根目录 `pages.json`
|
||||
|
||||
---
|
||||
|
||||
## 六、Git 提交规范
|
||||
|
||||
```bash
|
||||
# 只提交消费者端配置
|
||||
git add config/consumer/
|
||||
git commit -m "feat(consumer): 添加新页面配置"
|
||||
|
||||
# 只提交消费者端代码
|
||||
git add pages/mall/consumer/
|
||||
git commit -m "feat(consumer): 添加会员功能"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 七、常见问题
|
||||
|
||||
### Q1: 编译时提示找不到页面?
|
||||
检查 `config/consumer/pages.json` 中的页面路径。
|
||||
|
||||
### Q2: 忘记恢复配置怎么办?
|
||||
直接运行 `restore-config.bat` 即可。
|
||||
|
||||
### Q3: 如何查看当前使用的是哪个配置?
|
||||
查看根目录 `pages.json` 的内容,或检查是否存在 `.bak` 备份文件。
|
||||
|
||||
---
|
||||
|
||||
## 八、注意事项
|
||||
|
||||
- ✅ 只修改 `config/consumer/` 目录下的文件
|
||||
- ❌ 不要修改根目录的 `pages.json` 和 `manifest.json`
|
||||
- ✅ 编译小程序前运行 `build-consumer.bat`
|
||||
- ✅ 编译完成后运行 `restore-config.bat`
|
||||
82
config/consumer/manifest.json
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"name": "商城消费者端",
|
||||
"appid": "__UNI__CONSUMER",
|
||||
"description": "商城消费者端 - 购物、订单、会员等功能",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": "100",
|
||||
"transformPx": false,
|
||||
"app-plus": {
|
||||
"usingComponents": true,
|
||||
"nvueStyleCompiler": "uni-app",
|
||||
"compilerVersion": 3,
|
||||
"splashscreen": {
|
||||
"alwaysShowBeforeRender": true,
|
||||
"waiting": true,
|
||||
"autoclose": true,
|
||||
"delay": 0
|
||||
},
|
||||
"modules": {},
|
||||
"distribute": {
|
||||
"android": {
|
||||
"permissions": [
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.INTERNET\"/>"
|
||||
]
|
||||
},
|
||||
"ios": {},
|
||||
"sdkConfigs": {}
|
||||
}
|
||||
},
|
||||
"quickapp": {},
|
||||
"mp-weixin": {
|
||||
"appid": "",
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
"es6": true,
|
||||
"postcss": true,
|
||||
"minified": true,
|
||||
"enhance": true
|
||||
},
|
||||
"usingComponents": true,
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
},
|
||||
"lazyCodeLoading": "requiredComponents"
|
||||
},
|
||||
"mp-alipay": {
|
||||
"appid": "",
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-baidu": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-toutiao": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"vueVersion": "3",
|
||||
"uni-app-x": {},
|
||||
"h5": {
|
||||
"title": "商城消费者端",
|
||||
"router": {
|
||||
"mode": "hash",
|
||||
"base": "./"
|
||||
}
|
||||
},
|
||||
"app-android": {
|
||||
"distribute": {
|
||||
"modules": {},
|
||||
"android": {
|
||||
"usesCleartextTraffic": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
248
config/consumer/pages.json
Normal file
@@ -0,0 +1,248 @@
|
||||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/user/login",
|
||||
"style": {
|
||||
"navigationBarTitleText": "用户登录",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/main/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "首页",
|
||||
"navigationStyle": "custom",
|
||||
"enablePullDownRefresh": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/main/category",
|
||||
"style": {
|
||||
"navigationBarTitleText": "分类",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/main/cart",
|
||||
"style": {
|
||||
"navigationBarTitleText": "购物车",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/main/profile",
|
||||
"style": {
|
||||
"navigationBarTitleText": "我的",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
}
|
||||
],
|
||||
"subPackages": [
|
||||
{
|
||||
"root": "pages/mall/consumer",
|
||||
"pages": [
|
||||
{
|
||||
"path": "settings",
|
||||
"style": { "navigationBarTitleText": "设置" }
|
||||
},
|
||||
{
|
||||
"path": "wallet",
|
||||
"style": { "navigationBarTitleText": "我的钱包" }
|
||||
},
|
||||
{
|
||||
"path": "withdraw",
|
||||
"style": { "navigationBarTitleText": "余额提现" }
|
||||
},
|
||||
{
|
||||
"path": "search",
|
||||
"style": { "navigationBarTitleText": "搜索", "navigationStyle": "custom" }
|
||||
},
|
||||
{
|
||||
"path": "product-detail",
|
||||
"style": { "navigationBarTitleText": "商品详情" }
|
||||
},
|
||||
{
|
||||
"path": "shop-detail",
|
||||
"style": { "navigationBarTitleText": "店铺详情" }
|
||||
},
|
||||
{
|
||||
"path": "coupons",
|
||||
"style": { "navigationBarTitleText": "我的优惠券" }
|
||||
},
|
||||
{
|
||||
"path": "favorites",
|
||||
"style": { "navigationBarTitleText": "我的收藏" }
|
||||
},
|
||||
{
|
||||
"path": "footprint",
|
||||
"style": { "navigationBarTitleText": "我的足迹" }
|
||||
},
|
||||
{
|
||||
"path": "address-list",
|
||||
"style": { "navigationBarTitleText": "收货地址" }
|
||||
},
|
||||
{
|
||||
"path": "address-edit",
|
||||
"style": { "navigationBarTitleText": "编辑地址" }
|
||||
},
|
||||
{
|
||||
"path": "checkout",
|
||||
"style": { "navigationBarTitleText": "确认订单" }
|
||||
},
|
||||
{
|
||||
"path": "payment",
|
||||
"style": { "navigationBarTitleText": "收银台" }
|
||||
},
|
||||
{
|
||||
"path": "payment-success",
|
||||
"style": { "navigationBarTitleText": "支付成功", "navigationStyle": "custom" }
|
||||
},
|
||||
{
|
||||
"path": "orders",
|
||||
"style": { "navigationBarTitleText": "我的订单", "enablePullDownRefresh": true }
|
||||
},
|
||||
{
|
||||
"path": "order-detail",
|
||||
"style": { "navigationBarTitleText": "订单详情" }
|
||||
},
|
||||
{
|
||||
"path": "logistics",
|
||||
"style": { "navigationBarTitleText": "物流详情" }
|
||||
},
|
||||
{
|
||||
"path": "review",
|
||||
"style": { "navigationBarTitleText": "评价晒单" }
|
||||
},
|
||||
{
|
||||
"path": "refund",
|
||||
"style": { "navigationBarTitleText": "退款/售后" }
|
||||
},
|
||||
{
|
||||
"path": "apply-refund",
|
||||
"style": { "navigationBarTitleText": "申请售后" }
|
||||
},
|
||||
{
|
||||
"path": "refund-review",
|
||||
"style": { "navigationBarTitleText": "服务评价" }
|
||||
},
|
||||
{
|
||||
"path": "chat",
|
||||
"style": { "navigationBarTitleText": "客服聊天", "navigationStyle": "custom" }
|
||||
},
|
||||
{
|
||||
"path": "subscription/followed-shops",
|
||||
"style": { "navigationBarTitleText": "关注店铺" }
|
||||
},
|
||||
{
|
||||
"path": "points/index",
|
||||
"style": { "navigationBarTitleText": "积分管理" }
|
||||
},
|
||||
{
|
||||
"path": "points/signin",
|
||||
"style": { "navigationBarTitleText": "每日签到" }
|
||||
},
|
||||
{
|
||||
"path": "points/exchange",
|
||||
"style": { "navigationBarTitleText": "积分兑换" }
|
||||
},
|
||||
{
|
||||
"path": "points/exchange-records",
|
||||
"style": { "navigationBarTitleText": "兑换记录" }
|
||||
},
|
||||
{
|
||||
"path": "product-reviews",
|
||||
"style": { "navigationBarTitleText": "商品评价" }
|
||||
},
|
||||
{
|
||||
"path": "my-reviews",
|
||||
"style": { "navigationBarTitleText": "我的评价" }
|
||||
},
|
||||
{
|
||||
"path": "balance/index",
|
||||
"style": { "navigationBarTitleText": "我的余额" }
|
||||
},
|
||||
{
|
||||
"path": "share/index",
|
||||
"style": { "navigationBarTitleText": "我的分享" }
|
||||
},
|
||||
{
|
||||
"path": "share/detail",
|
||||
"style": { "navigationBarTitleText": "分享详情" }
|
||||
},
|
||||
{
|
||||
"path": "member/index",
|
||||
"style": { "navigationBarTitleText": "会员中心" }
|
||||
},
|
||||
{
|
||||
"path": "message-detail",
|
||||
"style": { "navigationBarTitleText": "消息详情" }
|
||||
},
|
||||
{
|
||||
"path": "red-packets/index",
|
||||
"style": { "navigationBarTitleText": "我的红包" }
|
||||
},
|
||||
{
|
||||
"path": "bank-cards/index",
|
||||
"style": { "navigationBarTitleText": "银行卡管理" }
|
||||
},
|
||||
{
|
||||
"path": "bank-cards/add",
|
||||
"style": { "navigationBarTitleText": "添加银行卡" }
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarTitleText": "商城",
|
||||
"navigationBarBackgroundColor": "#ffffff",
|
||||
"backgroundColor": "#f5f5f5"
|
||||
},
|
||||
"tabBar": {
|
||||
"color": "#999999",
|
||||
"selectedColor": "#ff5000",
|
||||
"borderStyle": "black",
|
||||
"backgroundColor": "#ffffff",
|
||||
"list": [
|
||||
{
|
||||
"pagePath": "pages/main/index",
|
||||
"text": "首页",
|
||||
"iconPath": "static/tabbar/home.png",
|
||||
"selectedIconPath": "static/tabbar/home-active.png"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/main/category",
|
||||
"text": "分类",
|
||||
"iconPath": "static/tabbar/category.png",
|
||||
"selectedIconPath": "static/tabbar/category.png"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/main/cart",
|
||||
"text": "购物车",
|
||||
"iconPath": "static/tabbar/cart.png",
|
||||
"selectedIconPath": "static/tabbar/cart.png"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/main/profile",
|
||||
"text": "我的",
|
||||
"iconPath": "static/tabbar/user.png",
|
||||
"selectedIconPath": "static/tabbar/user.png"
|
||||
}
|
||||
]
|
||||
},
|
||||
"preloadRule": {
|
||||
"pages/main/index": {
|
||||
"network": "all",
|
||||
"packages": ["pages/mall/consumer"]
|
||||
}
|
||||
},
|
||||
"easycom": {
|
||||
"autoscan": true,
|
||||
"custom": {
|
||||
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
|
||||
}
|
||||
},
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
# 多端分包与体积优化方案
|
||||
|
||||
## 一、问题分析
|
||||
|
||||
### 1.1 当前项目结构问题
|
||||
|
||||
当前 `pages.json` 包含了所有端的页面配置:
|
||||
|
||||
```
|
||||
pages/
|
||||
├── user/ # 公共用户页面
|
||||
├── main/ # 公共主页面
|
||||
├── mall/
|
||||
│ ├── consumer/ # 消费者端 (约 40+ 页面)
|
||||
│ ├── merchant/ # 商家端 (约 20+ 页面)
|
||||
│ ├── admin/ # 管理端 (约 50+ 页面)
|
||||
│ ├── analytics/ # 分析端 (约 15+ 页面)
|
||||
│ ├── delivery/ # 配送端 (约 15+ 页面)
|
||||
│ └── service/ # 服务端 (约 5+ 页面)
|
||||
```
|
||||
|
||||
### 1.2 小程序包体积限制
|
||||
|
||||
| 平台 | 主包限制 | 分包限制 | 总限制 |
|
||||
|------|---------|---------|--------|
|
||||
| 微信小程序 | 2MB | 2MB/个 | 20MB |
|
||||
| 支付宝小程序 | 2MB | 2MB/个 | 20MB |
|
||||
| 百度小程序 | 2MB | 2MB/个 | 20MB |
|
||||
|
||||
**问题**: 如果所有端的页面都打包进小程序,会严重超出限制!
|
||||
|
||||
---
|
||||
|
||||
## 二、解决方案
|
||||
|
||||
### 方案 A:条件编译 + 独立 pages.json(推荐)
|
||||
|
||||
**核心思路**: 使用 uni-app x 的条件编译功能,为不同端编译不同的页面配置。
|
||||
|
||||
#### 2.1 创建端专用 pages.json
|
||||
|
||||
```
|
||||
pages/
|
||||
├── pages-consumer.json # 消费者端页面配置
|
||||
├── pages-merchant.json # 商家端页面配置
|
||||
├── pages-admin.json # 管理端页面配置
|
||||
├── pages-analytics.json # 分析端页面配置
|
||||
└── pages-delivery.json # 配送端页面配置
|
||||
```
|
||||
|
||||
#### 2.2 pages-consumer.json 示例
|
||||
|
||||
```json
|
||||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/user/login",
|
||||
"style": { "navigationBarTitleText": "登录" }
|
||||
},
|
||||
{
|
||||
"path": "pages/main/index",
|
||||
"style": { "navigationBarTitleText": "首页" }
|
||||
},
|
||||
{
|
||||
"path": "pages/main/category",
|
||||
"style": { "navigationBarTitleText": "分类" }
|
||||
},
|
||||
{
|
||||
"path": "pages/main/cart",
|
||||
"style": { "navigationBarTitleText": "购物车" }
|
||||
},
|
||||
{
|
||||
"path": "pages/main/profile",
|
||||
"style": { "navigationBarTitleText": "我的" }
|
||||
}
|
||||
],
|
||||
"subPackages": [
|
||||
{
|
||||
"root": "pages/mall/consumer",
|
||||
"pages": [
|
||||
{ "path": "product-detail", "style": { "navigationBarTitleText": "商品详情" } },
|
||||
{ "path": "checkout", "style": { "navigationBarTitleText": "结算" } },
|
||||
{ "path": "orders", "style": { "navigationBarTitleText": "订单" } },
|
||||
{ "path": "payment", "style": { "navigationBarTitleText": "支付" } }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### 2.3 编译脚本配置
|
||||
|
||||
在 `package.json` 中添加编译脚本:
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"dev:mp-weixin:consumer": "uni -p mp-weixin --pages pages-consumer.json",
|
||||
"build:mp-weixin:consumer": "uni build -p mp-weixin --pages pages-consumer.json",
|
||||
"dev:mp-weixin:merchant": "uni -p mp-weixin --pages pages-merchant.json",
|
||||
"build:mp-weixin:merchant": "uni build -p mp-weixin --pages pages-merchant.json"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 方案 B:条件编译页面级别(备选)
|
||||
|
||||
**核心思路**: 在单个 `pages.json` 中使用条件编译注释。
|
||||
|
||||
```json
|
||||
{
|
||||
"pages": [
|
||||
// 公共页面
|
||||
{ "path": "pages/user/login", "style": {} },
|
||||
|
||||
// #ifdef PLATFORM_CONSUMER
|
||||
// 消费者端页面
|
||||
{ "path": "pages/main/index", "style": {} },
|
||||
{ "path": "pages/main/cart", "style": {} },
|
||||
// #endif
|
||||
|
||||
// #ifdef PLATFORM_MERCHANT
|
||||
// 商家端页面
|
||||
{ "path": "pages/mall/merchant/index", "style": {} },
|
||||
// #endif
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**注意**: 此方案需要自定义平台标识,uni-app x 默认不支持。
|
||||
|
||||
---
|
||||
|
||||
### 方案 C:多项目共享核心(备选)
|
||||
|
||||
**核心思路**: 创建多个小程序项目,共享核心代码。
|
||||
|
||||
```
|
||||
mall/
|
||||
├── core/ # 共享核心代码
|
||||
│ ├── components/
|
||||
│ ├── utils/
|
||||
│ ├── api/
|
||||
│ └── types/
|
||||
├── projects/
|
||||
│ ├── consumer/ # 消费者端项目
|
||||
│ │ ├── pages/
|
||||
│ │ ├── pages.json
|
||||
│ │ └── manifest.json
|
||||
│ ├── merchant/ # 商家端项目
|
||||
│ │ ├── pages/
|
||||
│ │ ├── pages.json
|
||||
│ │ └── manifest.json
|
||||
│ └── admin/ # 管理端项目
|
||||
│ ├── pages/
|
||||
│ ├── pages.json
|
||||
│ └── manifest.json
|
||||
└── shared/ # 共享资源
|
||||
├── static/
|
||||
└── uni_modules/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 三、推荐方案实施
|
||||
|
||||
### 3.1 采用方案 A 的实施步骤
|
||||
|
||||
#### 步骤 1:创建消费者端专用配置
|
||||
|
||||
创建 `pages-consumer.json`,仅包含消费者端需要的页面。
|
||||
|
||||
#### 步骤 2:修改 manifest.json
|
||||
|
||||
```json
|
||||
{
|
||||
"mp-weixin": {
|
||||
"appid": "消费者端小程序AppID",
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 步骤 3:配置分包
|
||||
|
||||
```json
|
||||
{
|
||||
"subPackages": [
|
||||
{
|
||||
"root": "pages/mall/consumer",
|
||||
"pages": [
|
||||
// 消费者端次级页面
|
||||
]
|
||||
}
|
||||
],
|
||||
"preloadRule": {
|
||||
"pages/main/index": {
|
||||
"network": "all",
|
||||
"packages": ["pages/mall/consumer"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 步骤 4:排除其他端代码
|
||||
|
||||
在 `manifest.json` 中配置排除:
|
||||
|
||||
```json
|
||||
{
|
||||
"mp-weixin": {
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
},
|
||||
"exclude": [
|
||||
"pages/mall/merchant/**",
|
||||
"pages/mall/admin/**",
|
||||
"pages/mall/analytics/**",
|
||||
"pages/mall/delivery/**",
|
||||
"pages/mall/service/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 四、体积优化建议
|
||||
|
||||
### 4.1 图片资源优化
|
||||
|
||||
```
|
||||
static/
|
||||
├── images/
|
||||
│ ├── consumer/ # 消费者端图片
|
||||
│ ├── merchant/ # 商家端图片
|
||||
│ └── common/ # 公共图片
|
||||
```
|
||||
|
||||
- 使用 CDN 托管图片
|
||||
- 小图片使用 base64 内联
|
||||
- 使用 WebP 格式
|
||||
|
||||
### 4.2 组件按需加载
|
||||
|
||||
```uts
|
||||
// 动态导入组件
|
||||
const ProductDetail = () => import('@/pages/mall/consumer/product-detail.uvue')
|
||||
```
|
||||
|
||||
### 4.3 代码分割
|
||||
|
||||
```
|
||||
utils/
|
||||
├── consumer/ # 消费者端专用工具
|
||||
├── merchant/ # 商家端专用工具
|
||||
├── admin/ # 管理端专用工具
|
||||
└── common/ # 公共工具
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 五、各端小程序独立发布
|
||||
|
||||
### 5.1 发布矩阵
|
||||
|
||||
| 端 | 小程序名称 | AppID | 用途 |
|
||||
|---|-----------|-------|------|
|
||||
| 消费者端 | XX商城 | wx_xxx | 消费者购物 |
|
||||
| 商家端 | XX商家 | wx_xxx | 商家管理 |
|
||||
| 配送端 | XX配送 | wx_xxx | 配送员接单 |
|
||||
|
||||
### 5.2 独立配置
|
||||
|
||||
每个端使用独立的:
|
||||
- `manifest.json` 配置(AppID、权限等)
|
||||
- `pages.json` 页面配置
|
||||
- 图标和启动页
|
||||
|
||||
---
|
||||
|
||||
## 六、总结
|
||||
|
||||
### 推荐方案
|
||||
**方案 A:条件编译 + 独立 pages.json**
|
||||
|
||||
### 核心优势
|
||||
1. **体积可控**: 每个端只编译自己需要的页面
|
||||
2. **维护简单**: 代码仍在同一仓库,便于共享和同步
|
||||
3. **发布灵活**: 各端可独立发布和更新
|
||||
|
||||
### 实施优先级
|
||||
1. 创建 `pages-consumer.json`(消费者端)
|
||||
2. 配置分包和排除规则
|
||||
3. 测试编译体积
|
||||
4. 逐步为其他端创建配置
|
||||
|
||||
### 预期效果
|
||||
- 消费者端小程序主包 < 1.5MB
|
||||
- 分包 < 500KB
|
||||
- 总体积 < 3MB
|
||||
534
doc_mall/consumer/backup_doc_full/MULTI_PLATFORM_SOLUTION.md
Normal file
@@ -0,0 +1,534 @@
|
||||
# 消费者端多端适配方案
|
||||
|
||||
## 一、项目现状分析
|
||||
|
||||
### 1.1 当前技术栈
|
||||
- **框架**: uni-app x (Vue 3 + UTS)
|
||||
- **已支持平台**:
|
||||
- Android App (已验证)
|
||||
- 微信小程序 (已验证)
|
||||
- H5 (配置已就绪)
|
||||
- 其他小程序平台 (支付宝、百度、头条等配置已就绪)
|
||||
|
||||
### 1.2 项目结构
|
||||
```
|
||||
pages/mall/consumer/ # 消费者端页面
|
||||
├── doc/ # 文档目录
|
||||
├── index.uvue # 首页
|
||||
├── category.uvue # 分类页
|
||||
├── product-detail.uvue # 商品详情
|
||||
├── cart.uvue # 购物车
|
||||
├── checkout.uvue # 结算页
|
||||
├── orders.uvue # 订单列表
|
||||
├── profile.uvue # 个人中心
|
||||
└── ...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 二、多端适配方案对比
|
||||
|
||||
### 方案一:单项目多端编译(推荐)
|
||||
|
||||
**核心思路**: 一套代码,通过条件编译和平台判断,编译到不同平台。
|
||||
|
||||
**优点**:
|
||||
- 代码复用率高,维护成本低
|
||||
- 统一的技术栈和开发流程
|
||||
- Bug修复一次,全平台生效
|
||||
- 符合 uni-app x 的设计理念
|
||||
|
||||
**缺点**:
|
||||
- 需要处理各平台差异
|
||||
- 部分平台特性需要条件编译
|
||||
- 小程序包体积限制需要注意
|
||||
|
||||
**实现方式**:
|
||||
```uts
|
||||
// 条件编译示例
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序特有代码
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-ANDROID
|
||||
// Android App 特有代码
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
// H5 特有代码
|
||||
// #endif
|
||||
```
|
||||
|
||||
### 方案二:多项目独立开发
|
||||
|
||||
**核心思路**: 为每个平台创建独立项目,共享核心业务逻辑。
|
||||
|
||||
**优点**:
|
||||
- 各端可独立优化
|
||||
- 不受其他平台限制
|
||||
- 可针对平台特性深度定制
|
||||
|
||||
**缺点**:
|
||||
- 维护成本高,代码重复
|
||||
- Bug需要多端修复
|
||||
- 开发周期长
|
||||
|
||||
**适用场景**:
|
||||
- 各端差异极大
|
||||
- 需要深度定制平台特性
|
||||
- 有充足的开发资源
|
||||
|
||||
### 方案三:核心库 + 平台适配层
|
||||
|
||||
**核心思路**: 抽离核心业务逻辑为共享库,各平台实现适配层。
|
||||
|
||||
**优点**:
|
||||
- 核心逻辑统一
|
||||
- 平台适配灵活
|
||||
- 便于团队协作
|
||||
|
||||
**缺点**:
|
||||
- 架构复杂度高
|
||||
- 需要良好的抽象设计
|
||||
- 初期开发成本较高
|
||||
|
||||
---
|
||||
|
||||
## 三、推荐方案:单项目多端编译
|
||||
|
||||
基于项目现状,**推荐采用方案一**,原因如下:
|
||||
|
||||
1. **uni-app x 天然支持多端编译**
|
||||
2. **当前代码已具备良好的跨端基础**
|
||||
3. **维护成本最低,开发效率最高**
|
||||
|
||||
---
|
||||
|
||||
## 四、具体实施步骤
|
||||
|
||||
### 4.1 平台配置
|
||||
|
||||
#### 4.1.1 微信小程序配置
|
||||
```json
|
||||
// manifest.json
|
||||
{
|
||||
"mp-weixin": {
|
||||
"appid": "你的微信小程序AppID",
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
"es6": true,
|
||||
"postcss": true,
|
||||
"minified": true
|
||||
},
|
||||
"usingComponents": true,
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 4.1.2 支付宝小程序配置
|
||||
```json
|
||||
// manifest.json
|
||||
{
|
||||
"mp-alipay": {
|
||||
"appid": "你的支付宝小程序AppID",
|
||||
"usingComponents": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 4.1.3 H5 配置
|
||||
```json
|
||||
// manifest.json
|
||||
{
|
||||
"h5": {
|
||||
"title": "商城消费者端",
|
||||
"router": {
|
||||
"mode": "history",
|
||||
"base": "/consumer/"
|
||||
},
|
||||
"devServer": {
|
||||
"port": 8080,
|
||||
"proxy": {
|
||||
"/api": {
|
||||
"target": "https://your-api.com",
|
||||
"changeOrigin": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4.2 条件编译处理
|
||||
|
||||
#### 4.2.1 平台判断工具类
|
||||
```uts
|
||||
// utils/platform.uts
|
||||
|
||||
// 平台类型
|
||||
export type PlatformType = 'android' | 'ios' | 'weixin' | 'alipay' | 'h5' | 'unknown'
|
||||
|
||||
// 获取当前平台
|
||||
export function getCurrentPlatform(): PlatformType {
|
||||
// #ifdef APP-ANDROID
|
||||
return 'android'
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-IOS
|
||||
return 'ios'
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
return 'weixin'
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-ALIPAY
|
||||
return 'alipay'
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
return 'h5'
|
||||
// #endif
|
||||
|
||||
return 'unknown'
|
||||
}
|
||||
|
||||
// 判断是否为小程序环境
|
||||
export function isMiniProgram(): boolean {
|
||||
const platform = getCurrentPlatform()
|
||||
return platform === 'weixin' || platform === 'alipay'
|
||||
}
|
||||
|
||||
// 判断是否为 App 环境
|
||||
export function isApp(): boolean {
|
||||
const platform = getCurrentPlatform()
|
||||
return platform === 'android' || platform === 'ios'
|
||||
}
|
||||
```
|
||||
|
||||
#### 4.2.2 API 适配层
|
||||
```uts
|
||||
// utils/apiAdapter.uts
|
||||
|
||||
import { getCurrentPlatform, isMiniProgram, isApp } from './platform.uts'
|
||||
|
||||
// 支付适配
|
||||
export function requestPayment(orderId: string, amount: number): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序支付
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay',
|
||||
timeStamp: '',
|
||||
nonceStr: '',
|
||||
package: '',
|
||||
signType: 'MD5',
|
||||
paySign: '',
|
||||
success: (res) => resolve(res),
|
||||
fail: (err) => reject(err)
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-ALIPAY
|
||||
// 支付宝小程序支付
|
||||
my.tradePay({
|
||||
tradeNO: orderId,
|
||||
success: (res) => resolve(res),
|
||||
fail: (err) => reject(err)
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-ANDROID || APP-IOS
|
||||
// App 支付
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay', // 或 'alipay'
|
||||
orderInfo: orderId,
|
||||
success: (res) => resolve(res),
|
||||
fail: (err) => reject(err)
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
// H5 支付(跳转到支付页面)
|
||||
window.location.href = `/payment?orderId=${orderId}`
|
||||
resolve({})
|
||||
// #endif
|
||||
})
|
||||
}
|
||||
|
||||
// 登录适配
|
||||
export function platformLogin(): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序登录
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: (res) => resolve(res),
|
||||
fail: (err) => reject(err)
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-ALIPAY
|
||||
// 支付宝小程序登录
|
||||
my.getAuthCode({
|
||||
scopes: 'auth_user',
|
||||
success: (res) => resolve(res),
|
||||
fail: (err) => reject(err)
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-ANDROID || APP-IOS
|
||||
// App 登录(使用账号密码或第三方登录)
|
||||
// 跳转到登录页面
|
||||
uni.navigateTo({ url: '/pages/user/login' })
|
||||
resolve({})
|
||||
// #endif
|
||||
})
|
||||
}
|
||||
|
||||
// 分享适配
|
||||
export function shareProduct(productId: string, title: string, imageUrl: string): void {
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序分享(通过 onShareAppMessage)
|
||||
// 在页面中定义 onShareAppMessage 即可
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-ALIPAY
|
||||
// 支付宝小程序分享
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-ANDROID || APP-IOS
|
||||
// App 分享
|
||||
uni.share({
|
||||
provider: 'weixin',
|
||||
scene: 'WXSceneSession',
|
||||
type: 0,
|
||||
title: title,
|
||||
imageUrl: imageUrl,
|
||||
success: () => console.log('分享成功'),
|
||||
fail: (err) => console.error('分享失败', err)
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
```
|
||||
|
||||
### 4.3 样式适配
|
||||
|
||||
#### 4.3.1 响应式样式
|
||||
```css
|
||||
/* 基础样式 */
|
||||
.container {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
/* 小程序适配 */
|
||||
/* #ifdef MP-WEIXIN || MP-ALIPAY */
|
||||
.container {
|
||||
padding: 30rpx; /* 小程序通常需要更大的间距 */
|
||||
}
|
||||
/* #endif */
|
||||
|
||||
/* H5 适配 */
|
||||
/* #ifdef H5 */
|
||||
.container {
|
||||
max-width: 750rpx;
|
||||
margin: 0 auto;
|
||||
}
|
||||
/* #endif */
|
||||
|
||||
/* 电脑端适配 */
|
||||
@media screen and (min-width: 1025px) {
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
padding: 40rpx;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 4.3.2 安全区域适配
|
||||
```css
|
||||
/* 底部安全区域 */
|
||||
.safe-area-bottom {
|
||||
padding-bottom: constant(safe-area-inset-bottom);
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
|
||||
/* 顶部安全区域 */
|
||||
.safe-area-top {
|
||||
padding-top: constant(safe-area-inset-top);
|
||||
padding-top: env(safe-area-inset-top);
|
||||
}
|
||||
```
|
||||
|
||||
### 4.4 功能差异处理
|
||||
|
||||
#### 4.4.1 小程序特有功能
|
||||
```uts
|
||||
// 小程序特有功能封装
|
||||
export function initMiniProgramFeatures(): void {
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序更新检查
|
||||
const updateManager = uni.getUpdateManager()
|
||||
updateManager.onUpdateReady(() => {
|
||||
uni.showModal({
|
||||
title: '更新提示',
|
||||
content: '新版本已经准备好,是否重启应用?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
updateManager.applyUpdate()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
```
|
||||
|
||||
#### 4.4.2 App 特有功能
|
||||
```uts
|
||||
// App 特有功能封装
|
||||
export function initAppFeatures(): void {
|
||||
// #ifdef APP-ANDROID || APP-IOS
|
||||
// 检查 App 更新
|
||||
checkAppUpdate()
|
||||
|
||||
// 推送通知初始化
|
||||
initPushNotification()
|
||||
// #endif
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 五、小程序分包策略
|
||||
|
||||
### 5.1 分包配置
|
||||
```json
|
||||
// pages.json
|
||||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/main/index",
|
||||
"style": { "navigationBarTitleText": "首页" }
|
||||
},
|
||||
{
|
||||
"path": "pages/main/category",
|
||||
"style": { "navigationBarTitleText": "分类" }
|
||||
},
|
||||
{
|
||||
"path": "pages/main/cart",
|
||||
"style": { "navigationBarTitleText": "购物车" }
|
||||
},
|
||||
{
|
||||
"path": "pages/user/center",
|
||||
"style": { "navigationBarTitleText": "我的" }
|
||||
}
|
||||
],
|
||||
"subPackages": [
|
||||
{
|
||||
"root": "pages/mall/consumer",
|
||||
"pages": [
|
||||
{
|
||||
"path": "product-detail",
|
||||
"style": { "navigationBarTitleText": "商品详情" }
|
||||
},
|
||||
{
|
||||
"path": "checkout",
|
||||
"style": { "navigationBarTitleText": "结算" }
|
||||
},
|
||||
{
|
||||
"path": "orders",
|
||||
"style": { "navigationBarTitleText": "订单" }
|
||||
},
|
||||
{
|
||||
"path": "payment",
|
||||
"style": { "navigationBarTitleText": "支付" }
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"preloadRule": {
|
||||
"pages/main/index": {
|
||||
"network": "all",
|
||||
"packages": ["pages/mall/consumer"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5.2 分包原则
|
||||
1. **主包**: 仅包含首页、分类、购物车、个人中心等核心页面
|
||||
2. **分包**: 包含商品详情、订单、支付等次级页面
|
||||
3. **预加载**: 在首页预加载分包,提升用户体验
|
||||
|
||||
---
|
||||
|
||||
## 六、测试策略
|
||||
|
||||
### 6.1 测试环境配置
|
||||
|
||||
| 平台 | 测试工具 | 测试要点 |
|
||||
|------|---------|---------|
|
||||
| Android App | 真机调试 | 性能、兼容性、权限 |
|
||||
| iOS App | 真机调试 | 性能、兼容性、权限 |
|
||||
| 微信小程序 | 微信开发者工具 | 功能、样式、API |
|
||||
| 支付宝小程序 | 支付宝开发者工具 | 功能、样式、API |
|
||||
| H5 | Chrome DevTools | 响应式、兼容性 |
|
||||
|
||||
### 6.2 自动化测试
|
||||
```typescript
|
||||
// 测试用例示例
|
||||
describe('多端适配测试', () => {
|
||||
it('登录功能各端一致', async () => {
|
||||
// 测试登录逻辑在各端表现一致
|
||||
})
|
||||
|
||||
it('支付功能各端可用', async () => {
|
||||
// 测试支付功能在各端可用
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 七、发布流程
|
||||
|
||||
### 7.1 发布检查清单
|
||||
|
||||
- [ ] 条件编译代码正确
|
||||
- [ ] 各端样式适配完成
|
||||
- [ ] API 调用正常
|
||||
- [ ] 支付功能测试通过
|
||||
- [ ] 分包配置正确
|
||||
- [ ] 包体积符合要求
|
||||
|
||||
### 7.2 发布渠道
|
||||
|
||||
| 平台 | 发布渠道 | 审核周期 |
|
||||
|------|---------|---------|
|
||||
| Android App | 应用商店 / 自有渠道 | 1-3天 |
|
||||
| iOS App | App Store | 3-7天 |
|
||||
| 微信小程序 | 微信审核 | 1-3天 |
|
||||
| 支付宝小程序 | 支付宝审核 | 1-3天 |
|
||||
| H5 | 自有服务器 | 即时 |
|
||||
|
||||
---
|
||||
|
||||
## 八、总结
|
||||
|
||||
### 推荐方案
|
||||
**单项目多端编译**,利用 uni-app x 的跨端能力,通过条件编译处理平台差异。
|
||||
|
||||
### 关键点
|
||||
1. 使用条件编译处理平台差异
|
||||
2. 封装平台适配层统一 API 调用
|
||||
3. 合理使用分包控制包体积
|
||||
4. 建立完善的多端测试流程
|
||||
|
||||
### 后续优化
|
||||
1. 持续优化各端性能
|
||||
2. 完善自动化测试
|
||||
3. 建立多端 CI/CD 流程
|
||||
386
doc_mall/consumer/backup_doc_full/TEAM_COLLABORATION_GUIDE.md
Normal file
@@ -0,0 +1,386 @@
|
||||
# 多人协作多端开发方案
|
||||
|
||||
## 一、问题分析
|
||||
|
||||
### 1.1 当前协作场景
|
||||
|
||||
```
|
||||
团队成员分工:
|
||||
├── 开发者A → 消费者端 (consumer)
|
||||
├── 开发者B → 商家端 (merchant)
|
||||
├── 开发者C → 管理端 (admin)
|
||||
├── 开发者D → 分析端 (analytics)
|
||||
└── 开发者E → 配送端 (delivery)
|
||||
```
|
||||
|
||||
### 1.2 潜在冲突问题
|
||||
|
||||
如果每个人都在 `manifest.json` 或 `pages.json` 中修改配置:
|
||||
- ❌ Git 合并冲突频繁
|
||||
- ❌ 互相覆盖配置
|
||||
- ❌ 影响其他端的编译
|
||||
|
||||
---
|
||||
|
||||
## 二、推荐方案:端专用配置文件
|
||||
|
||||
### 2.1 核心思路
|
||||
|
||||
**不修改公共配置文件,而是创建端专用的配置文件**
|
||||
|
||||
```
|
||||
mall/
|
||||
├── pages.json # 主配置(保持不变,供 App 端使用)
|
||||
├── manifest.json # 主配置(保持不变)
|
||||
│
|
||||
├── config/ # 端专用配置目录
|
||||
│ ├── consumer/ # 消费者端配置
|
||||
│ │ ├── pages.json # 消费者端页面配置
|
||||
│ │ └── manifest.json # 消费者端小程序配置
|
||||
│ │
|
||||
│ ├── merchant/ # 商家端配置
|
||||
│ │ ├── pages.json
|
||||
│ │ └── manifest.json
|
||||
│ │
|
||||
│ ├── admin/ # 管理端配置
|
||||
│ │ ├── pages.json
|
||||
│ │ └── manifest.json
|
||||
│ │
|
||||
│ ├── analytics/ # 分析端配置
|
||||
│ │ ├── pages.json
|
||||
│ │ └── manifest.json
|
||||
│ │
|
||||
│ └── delivery/ # 配送端配置
|
||||
│ ├── pages.json
|
||||
│ └── manifest.json
|
||||
│
|
||||
└── scripts/ # 构建脚本
|
||||
├── build-consumer.sh # 消费者端构建脚本
|
||||
├── build-merchant.sh # 商家端构建脚本
|
||||
└── ...
|
||||
```
|
||||
|
||||
### 2.2 优势
|
||||
|
||||
| 优势 | 说明 |
|
||||
|------|------|
|
||||
| ✅ 无冲突 | 每个开发者只修改自己端的配置文件 |
|
||||
| ✅ 独立发布 | 各端可独立编译和发布 |
|
||||
| ✅ 代码共享 | 页面代码仍在同一仓库,便于共享 |
|
||||
| ✅ 向后兼容 | 主配置文件保持不变,不影响 App 端 |
|
||||
|
||||
---
|
||||
|
||||
## 三、具体实施
|
||||
|
||||
### 3.1 创建端专用配置目录
|
||||
|
||||
```bash
|
||||
# 创建配置目录结构
|
||||
mkdir -p config/consumer
|
||||
mkdir -p config/merchant
|
||||
mkdir -p config/admin
|
||||
mkdir -p config/analytics
|
||||
mkdir -p config/delivery
|
||||
```
|
||||
|
||||
### 3.2 消费者端配置示例
|
||||
|
||||
#### config/consumer/pages.json
|
||||
|
||||
```json
|
||||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/user/login",
|
||||
"style": { "navigationBarTitleText": "登录" }
|
||||
},
|
||||
{
|
||||
"path": "pages/main/index",
|
||||
"style": { "navigationBarTitleText": "首页", "navigationStyle": "custom" }
|
||||
},
|
||||
{
|
||||
"path": "pages/main/category",
|
||||
"style": { "navigationBarTitleText": "分类", "navigationStyle": "custom" }
|
||||
},
|
||||
{
|
||||
"path": "pages/main/cart",
|
||||
"style": { "navigationBarTitleText": "购物车", "navigationStyle": "custom" }
|
||||
},
|
||||
{
|
||||
"path": "pages/main/profile",
|
||||
"style": { "navigationBarTitleText": "我的", "navigationStyle": "custom" }
|
||||
}
|
||||
],
|
||||
"subPackages": [
|
||||
{
|
||||
"root": "pages/mall/consumer",
|
||||
"pages": [
|
||||
{ "path": "product-detail", "style": { "navigationBarTitleText": "商品详情" } },
|
||||
{ "path": "shop-detail", "style": { "navigationBarTitleText": "店铺详情" } },
|
||||
{ "path": "search", "style": { "navigationBarTitleText": "搜索" } },
|
||||
{ "path": "checkout", "style": { "navigationBarTitleText": "结算" } },
|
||||
{ "path": "payment", "style": { "navigationBarTitleText": "支付" } },
|
||||
{ "path": "orders", "style": { "navigationBarTitleText": "订单" } },
|
||||
{ "path": "order-detail", "style": { "navigationBarTitleText": "订单详情" } },
|
||||
{ "path": "favorites", "style": { "navigationBarTitleText": "收藏" } },
|
||||
{ "path": "coupons", "style": { "navigationBarTitleText": "优惠券" } },
|
||||
{ "path": "address-list", "style": { "navigationBarTitleText": "地址管理" } },
|
||||
{ "path": "address-edit", "style": { "navigationBarTitleText": "编辑地址" } },
|
||||
{ "path": "chat", "style": { "navigationBarTitleText": "客服" } },
|
||||
{ "path": "points/index", "style": { "navigationBarTitleText": "积分" } },
|
||||
{ "path": "member/index", "style": { "navigationBarTitleText": "会员" } },
|
||||
{ "path": "wallet", "style": { "navigationBarTitleText": "钱包" } },
|
||||
{ "path": "settings", "style": { "navigationBarTitleText": "设置" } }
|
||||
]
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarTitleText": "商城",
|
||||
"navigationBarBackgroundColor": "#ffffff",
|
||||
"backgroundColor": "#f5f5f5"
|
||||
},
|
||||
"tabBar": {
|
||||
"color": "#999999",
|
||||
"selectedColor": "#ff5000",
|
||||
"borderStyle": "black",
|
||||
"backgroundColor": "#ffffff",
|
||||
"list": [
|
||||
{ "pagePath": "pages/main/index", "text": "首页", "iconPath": "static/tabbar/home.png", "selectedIconPath": "static/tabbar/home-active.png" },
|
||||
{ "pagePath": "pages/main/category", "text": "分类", "iconPath": "static/tabbar/category.png", "selectedIconPath": "static/tabbar/category-active.png" },
|
||||
{ "pagePath": "pages/main/cart", "text": "购物车", "iconPath": "static/tabbar/cart.png", "selectedIconPath": "static/tabbar/cart-active.png" },
|
||||
{ "pagePath": "pages/main/profile", "text": "我的", "iconPath": "static/tabbar/profile.png", "selectedIconPath": "static/tabbar/profile-active.png" }
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### config/consumer/manifest.json
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "商城消费者端",
|
||||
"appid": "__UNI__CONSUMER",
|
||||
"description": "商城消费者端小程序",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": "100",
|
||||
"mp-weixin": {
|
||||
"appid": "wx_consumer_appid",
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
"es6": true,
|
||||
"postcss": true,
|
||||
"minified": true
|
||||
},
|
||||
"usingComponents": true,
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3.3 构建脚本
|
||||
|
||||
#### scripts/build-consumer.sh
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# 消费者端小程序构建脚本
|
||||
|
||||
# 复制消费者端配置到根目录
|
||||
cp config/consumer/pages.json pages.json
|
||||
cp config/consumer/manifest.json manifest.json
|
||||
|
||||
# 执行编译
|
||||
uni build -p mp-weixin
|
||||
|
||||
# 编译完成后恢复原配置(可选)
|
||||
# git checkout pages.json manifest.json
|
||||
|
||||
echo "消费者端小程序构建完成!"
|
||||
```
|
||||
|
||||
#### scripts/dev-consumer.sh
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# 消费者端开发脚本
|
||||
|
||||
# 复制消费者端配置到根目录
|
||||
cp config/consumer/pages.json pages.json
|
||||
cp config/consumer/manifest.json manifest.json
|
||||
|
||||
# 启动开发服务器
|
||||
uni -p mp-weixin
|
||||
|
||||
echo "消费者端开发环境已启动!"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 四、Git 协作策略
|
||||
|
||||
### 4.1 .gitignore 配置
|
||||
|
||||
```gitignore
|
||||
# 编译产物
|
||||
unpackage/
|
||||
|
||||
# 临时配置文件(可选)
|
||||
# 如果不想提交临时替换的配置,可以忽略
|
||||
# pages.json
|
||||
# manifest.json
|
||||
```
|
||||
|
||||
### 4.2 分支策略
|
||||
|
||||
```
|
||||
main # 主分支(稳定版本)
|
||||
├── develop # 开发分支
|
||||
│ ├── feature/consumer # 消费者端功能分支
|
||||
│ ├── feature/merchant # 商家端功能分支
|
||||
│ ├── feature/admin # 管理端功能分支
|
||||
│ └── ...
|
||||
└── release/consumer # 消费者端发布分支
|
||||
```
|
||||
|
||||
### 4.3 提交规范
|
||||
|
||||
```
|
||||
feat(consumer): 添加会员功能
|
||||
fix(merchant): 修复订单列表bug
|
||||
docs(admin): 更新管理端文档
|
||||
style(analytics): 优化分析端样式
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 五、HBuilderX 配置(推荐)
|
||||
|
||||
### 5.1 创建多个运行配置
|
||||
|
||||
在 HBuilderX 中,可以为每个端创建独立的运行配置:
|
||||
|
||||
**运行 → 运行到小程序模拟器 → 消费者端微信小程序**
|
||||
|
||||
配置文件:`.hbuilderx/launch.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "0.0.1",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "消费者端-微信小程序",
|
||||
"type": "uni-app",
|
||||
"platform": "mp-weixin",
|
||||
"args": {
|
||||
"pages": "config/consumer/pages.json",
|
||||
"manifest": "config/consumer/manifest.json"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "商家端-微信小程序",
|
||||
"type": "uni-app",
|
||||
"platform": "mp-weixin",
|
||||
"args": {
|
||||
"pages": "config/merchant/pages.json",
|
||||
"manifest": "config/merchant/manifest.json"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 六、团队协作流程
|
||||
|
||||
### 6.1 开发流程
|
||||
|
||||
```
|
||||
1. 拉取最新代码
|
||||
git pull origin develop
|
||||
|
||||
2. 创建功能分支
|
||||
git checkout -b feature/consumer/member-function
|
||||
|
||||
3. 开发(只修改消费者端相关文件)
|
||||
- 修改 pages/mall/consumer/*.uvue
|
||||
- 修改 config/consumer/pages.json(如需添加新页面)
|
||||
|
||||
4. 提交代码
|
||||
git add .
|
||||
git commit -m "feat(consumer): 添加会员功能"
|
||||
|
||||
5. 推送并创建 PR
|
||||
git push origin feature/consumer/member-function
|
||||
```
|
||||
|
||||
### 6.2 编译发布流程
|
||||
|
||||
```
|
||||
1. 切换到发布分支
|
||||
git checkout release/consumer
|
||||
|
||||
2. 执行构建脚本
|
||||
./scripts/build-consumer.sh
|
||||
|
||||
3. 上传小程序代码
|
||||
微信开发者工具 → 上传
|
||||
|
||||
4. 提交审核
|
||||
微信公众平台 → 提交审核
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 七、注意事项
|
||||
|
||||
### 7.1 共享代码修改
|
||||
|
||||
如果修改了共享代码(如 `utils/`、`components/`、`types/`),需要:
|
||||
1. 通知相关开发者
|
||||
2. 确保不影响其他端
|
||||
3. 在 PR 中详细说明
|
||||
|
||||
### 7.2 配置文件同步
|
||||
|
||||
如果主 `pages.json` 有公共页面更新,需要同步到各端的配置文件:
|
||||
```bash
|
||||
# 同步公共页面配置
|
||||
./scripts/sync-common-pages.sh
|
||||
```
|
||||
|
||||
### 7.3 冲突处理
|
||||
|
||||
如果发生配置冲突:
|
||||
1. 优先保留各端专用配置
|
||||
2. 合并公共配置
|
||||
3. 团队沟通确认
|
||||
|
||||
---
|
||||
|
||||
## 八、总结
|
||||
|
||||
### 推荐方案
|
||||
**端专用配置文件 + 构建脚本**
|
||||
|
||||
### 核心优势
|
||||
| 优势 | 说明 |
|
||||
|------|------|
|
||||
| ✅ 无冲突 | 每个开发者只修改自己端的配置 |
|
||||
| ✅ 体积可控 | 每个端只编译自己需要的页面 |
|
||||
| ✅ 独立发布 | 各端可独立发布小程序 |
|
||||
| ✅ 代码共享 | 页面代码仍在同一仓库 |
|
||||
|
||||
### 目录结构
|
||||
```
|
||||
config/
|
||||
├── consumer/ # 消费者端配置(开发者A维护)
|
||||
├── merchant/ # 商家端配置(开发者B维护)
|
||||
├── admin/ # 管理端配置(开发者C维护)
|
||||
├── analytics/ # 分析端配置(开发者D维护)
|
||||
└── delivery/ # 配送端配置(开发者E维护)
|
||||
```
|
||||
@@ -0,0 +1,216 @@
|
||||
# 微信小程序审核优化方案
|
||||
|
||||
## 一、问题分析
|
||||
|
||||
### 1.1 审核未通过项
|
||||
|
||||
| 问题 | 说明 | 限制 |
|
||||
|------|------|------|
|
||||
| 主包尺寸 | 主包体积超过限制 | ≤ 2MB |
|
||||
| 组件按需注入 | 未启用组件按需注入 | 需要配置 |
|
||||
| 图片音频资源 | 静态资源过大 | 建议使用 CDN |
|
||||
|
||||
---
|
||||
|
||||
## 二、优化方案
|
||||
|
||||
### 2.1 主包尺寸优化
|
||||
|
||||
#### 当前问题
|
||||
主包包含了太多页面,需要进一步分包。
|
||||
|
||||
#### 解决方案:进一步分包
|
||||
|
||||
修改 `config/consumer/pages.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"pages": [
|
||||
// 只保留最核心的页面在主包
|
||||
{ "path": "pages/user/login" },
|
||||
{ "path": "pages/main/index" }
|
||||
],
|
||||
"subPackages": [
|
||||
{
|
||||
"root": "pagesub/user",
|
||||
"pages": [
|
||||
{ "path": "register" },
|
||||
{ "path": "forgot-password" },
|
||||
{ "path": "profile" },
|
||||
{ "path": "center" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"root": "pagesub/main",
|
||||
"pages": [
|
||||
{ "path": "category" },
|
||||
{ "path": "cart" },
|
||||
{ "path": "profile" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"root": "pages/mall/consumer",
|
||||
"pages": [
|
||||
// 消费者端所有页面
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 2.2 启用组件按需注入
|
||||
|
||||
修改 `config/consumer/pages.json`,添加:
|
||||
|
||||
```json
|
||||
{
|
||||
"easycom": {
|
||||
"autoscan": true,
|
||||
"custom": {
|
||||
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
|
||||
}
|
||||
},
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
修改 `config/consumer/manifest.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"mp-weixin": {
|
||||
"appid": "",
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
"es6": true,
|
||||
"postcss": true,
|
||||
"minified": true,
|
||||
"enhance": true
|
||||
},
|
||||
"usingComponents": true,
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
},
|
||||
"lazyCodeLoading": "requiredComponents"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.3 图片资源优化
|
||||
|
||||
#### 方案 A:使用 CDN 托管图片
|
||||
|
||||
1. 将 `static/` 目录下的图片上传到 CDN
|
||||
2. 代码中使用 CDN 链接
|
||||
|
||||
```javascript
|
||||
// 修改前
|
||||
<image src="/static/images/default-product.png" />
|
||||
|
||||
// 修改后
|
||||
<image src="https://cdn.your-domain.com/images/default-product.png" />
|
||||
```
|
||||
|
||||
#### 方案 B:压缩图片
|
||||
|
||||
使用工具压缩图片:
|
||||
- TinyPNG: https://tinypng.com/
|
||||
- 智图: https://zhitu.isux.us/
|
||||
|
||||
#### 方案 C:使用 WebP 格式
|
||||
|
||||
微信小程序支持 WebP 格式,体积更小。
|
||||
|
||||
---
|
||||
|
||||
## 三、具体修改
|
||||
|
||||
### 3.1 修改 manifest.json
|
||||
|
||||
```json
|
||||
{
|
||||
"mp-weixin": {
|
||||
"appid": "",
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
"es6": true,
|
||||
"postcss": true,
|
||||
"minified": true,
|
||||
"enhance": true
|
||||
},
|
||||
"usingComponents": true,
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
},
|
||||
"lazyCodeLoading": "requiredComponents"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3.2 修改 pages.json
|
||||
|
||||
添加优化配置:
|
||||
|
||||
```json
|
||||
{
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 四、优化检查清单
|
||||
|
||||
### 4.1 主包优化
|
||||
- [ ] 只保留登录页和首页在主包
|
||||
- [ ] 其他页面移到分包
|
||||
- [ ] 检查主包体积 < 2MB
|
||||
|
||||
### 4.2 组件优化
|
||||
- [ ] 启用 `lazyCodeLoading`
|
||||
- [ ] 启用 `enhance`
|
||||
- [ ] 检查组件按需加载
|
||||
|
||||
### 4.3 资源优化
|
||||
- [ ] 图片使用 CDN
|
||||
- [ ] 压缩图片
|
||||
- [ ] 移除未使用的资源
|
||||
|
||||
---
|
||||
|
||||
## 五、快速修复
|
||||
|
||||
### 5.1 修改 manifest.json(启用组件按需注入)
|
||||
|
||||
在 `mp-weixin` 配置中添加:
|
||||
```json
|
||||
"lazyCodeLoading": "requiredComponents"
|
||||
```
|
||||
|
||||
### 5.2 图片优化
|
||||
|
||||
1. 删除未使用的图片
|
||||
2. 压缩现有图片
|
||||
3. 考虑使用 CDN
|
||||
|
||||
---
|
||||
|
||||
## 六、预期效果
|
||||
|
||||
| 优化项 | 优化前 | 优化后 |
|
||||
|--------|--------|--------|
|
||||
| 主包体积 | 可能 > 2MB | < 1.5MB |
|
||||
| 组件加载 | 全量加载 | 按需加载 |
|
||||
| 图片资源 | 本地存储 | CDN 托管 |
|
||||
|
||||
---
|
||||
|
||||
## 七、注意事项
|
||||
|
||||
1. 分包后页面路径会变化,需要更新跳转逻辑
|
||||
2. CDN 图片需要确保域名已备案
|
||||
3. 测试分包后功能是否正常
|
||||
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.5 MiB |
|
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 142 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
167
manifest.json
@@ -1,87 +1,82 @@
|
||||
{
|
||||
"name": "mall",
|
||||
"appid": "__UNI__EC68BC3",
|
||||
"description": "A multi-role e-commerce application.",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": "100",
|
||||
"transformPx": false,
|
||||
"app-plus": {
|
||||
"usingComponents": true,
|
||||
"nvueStyleCompiler": "uni-app",
|
||||
"compilerVersion": 3,
|
||||
"splashscreen": {
|
||||
"alwaysShowBeforeRender": true,
|
||||
"waiting": true,
|
||||
"autoclose": true,
|
||||
"delay": 0
|
||||
},
|
||||
"modules": {},
|
||||
"distribute": {
|
||||
"android": {
|
||||
"permissions": [
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
||||
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.INTERNET\"/>"
|
||||
]
|
||||
},
|
||||
"ios": {},
|
||||
"sdkConfigs": {}
|
||||
}
|
||||
},
|
||||
"quickapp": {},
|
||||
"mp-weixin": {
|
||||
"appid": "",
|
||||
"setting": {
|
||||
"urlCheck": false
|
||||
},
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-alipay": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-baidu": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-toutiao": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"vueVersion": "3",
|
||||
"uni-app-x": {},
|
||||
"h5": {
|
||||
"title": "mall",
|
||||
"router": {
|
||||
"mode": "hash",
|
||||
"base": "./"
|
||||
}
|
||||
},
|
||||
"app-android": {
|
||||
"distribute": {
|
||||
"modules": {},
|
||||
"android": {
|
||||
"usesCleartextTraffic": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"web": {
|
||||
"router": {
|
||||
"mode": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
"name": "商城消费者端",
|
||||
"appid": "__UNI__CONSUMER",
|
||||
"description": "商城消费者端 - 购物、订单、会员等功能",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": "100",
|
||||
"transformPx": false,
|
||||
"app-plus": {
|
||||
"usingComponents": true,
|
||||
"nvueStyleCompiler": "uni-app",
|
||||
"compilerVersion": 3,
|
||||
"splashscreen": {
|
||||
"alwaysShowBeforeRender": true,
|
||||
"waiting": true,
|
||||
"autoclose": true,
|
||||
"delay": 0
|
||||
},
|
||||
"modules": {},
|
||||
"distribute": {
|
||||
"android": {
|
||||
"permissions": [
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.INTERNET\"/>"
|
||||
]
|
||||
},
|
||||
"ios": {},
|
||||
"sdkConfigs": {}
|
||||
}
|
||||
},
|
||||
"quickapp": {},
|
||||
"mp-weixin": {
|
||||
"appid": "",
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
"es6": true,
|
||||
"postcss": true,
|
||||
"minified": true,
|
||||
"enhance": true
|
||||
},
|
||||
"usingComponents": true,
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
},
|
||||
"lazyCodeLoading": "requiredComponents"
|
||||
},
|
||||
"mp-alipay": {
|
||||
"appid": "",
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-baidu": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-toutiao": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"vueVersion": "3",
|
||||
"uni-app-x": {},
|
||||
"h5": {
|
||||
"title": "商城消费者端",
|
||||
"router": {
|
||||
"mode": "hash",
|
||||
"base": "./"
|
||||
}
|
||||
},
|
||||
"app-android": {
|
||||
"distribute": {
|
||||
"modules": {},
|
||||
"android": {
|
||||
"usesCleartextTraffic": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
83
manifest.json.bak
Normal file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"name": "商城消费者端",
|
||||
"appid": "__UNI__CONSUMER",
|
||||
"description": "商城消费者端 - 购物、订单、会员等功能",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": "100",
|
||||
"transformPx": false,
|
||||
"app-plus": {
|
||||
"usingComponents": true,
|
||||
"nvueStyleCompiler": "uni-app",
|
||||
"compilerVersion": 3,
|
||||
"splashscreen": {
|
||||
"alwaysShowBeforeRender": true,
|
||||
"waiting": true,
|
||||
"autoclose": true,
|
||||
"delay": 0
|
||||
},
|
||||
"modules": {},
|
||||
"distribute": {
|
||||
"android": {
|
||||
"permissions": [
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.INTERNET\"/>"
|
||||
]
|
||||
},
|
||||
"ios": {},
|
||||
"sdkConfigs": {}
|
||||
}
|
||||
},
|
||||
"quickapp": {},
|
||||
"mp-weixin": {
|
||||
"appid": "",
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
"es6": true,
|
||||
"postcss": true,
|
||||
"minified": true,
|
||||
"enhance": true
|
||||
},
|
||||
"usingComponents": true,
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
},
|
||||
"lazyCodeLoading": "requiredComponents",
|
||||
"runmode": "liberate"
|
||||
},
|
||||
"mp-alipay": {
|
||||
"appid": "",
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-baidu": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-toutiao": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"vueVersion": "3",
|
||||
"uni-app-x": {},
|
||||
"h5": {
|
||||
"title": "商城消费者端",
|
||||
"router": {
|
||||
"mode": "hash",
|
||||
"base": "./"
|
||||
}
|
||||
},
|
||||
"app-android": {
|
||||
"distribute": {
|
||||
"modules": {},
|
||||
"android": {
|
||||
"usesCleartextTraffic": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
884
pages.json
248
pages.json.bak
Normal file
@@ -0,0 +1,248 @@
|
||||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/user/login",
|
||||
"style": {
|
||||
"navigationBarTitleText": "用户登录",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/main/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "首页",
|
||||
"navigationStyle": "custom",
|
||||
"enablePullDownRefresh": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/main/category",
|
||||
"style": {
|
||||
"navigationBarTitleText": "分类",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/main/cart",
|
||||
"style": {
|
||||
"navigationBarTitleText": "购物车",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/main/profile",
|
||||
"style": {
|
||||
"navigationBarTitleText": "我的",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
}
|
||||
],
|
||||
"subPackages": [
|
||||
{
|
||||
"root": "pages/mall/consumer",
|
||||
"pages": [
|
||||
{
|
||||
"path": "settings",
|
||||
"style": { "navigationBarTitleText": "设置" }
|
||||
},
|
||||
{
|
||||
"path": "wallet",
|
||||
"style": { "navigationBarTitleText": "我的钱包" }
|
||||
},
|
||||
{
|
||||
"path": "withdraw",
|
||||
"style": { "navigationBarTitleText": "余额提现" }
|
||||
},
|
||||
{
|
||||
"path": "search",
|
||||
"style": { "navigationBarTitleText": "搜索", "navigationStyle": "custom" }
|
||||
},
|
||||
{
|
||||
"path": "product-detail",
|
||||
"style": { "navigationBarTitleText": "商品详情" }
|
||||
},
|
||||
{
|
||||
"path": "shop-detail",
|
||||
"style": { "navigationBarTitleText": "店铺详情" }
|
||||
},
|
||||
{
|
||||
"path": "coupons",
|
||||
"style": { "navigationBarTitleText": "我的优惠券" }
|
||||
},
|
||||
{
|
||||
"path": "favorites",
|
||||
"style": { "navigationBarTitleText": "我的收藏" }
|
||||
},
|
||||
{
|
||||
"path": "footprint",
|
||||
"style": { "navigationBarTitleText": "我的足迹" }
|
||||
},
|
||||
{
|
||||
"path": "address-list",
|
||||
"style": { "navigationBarTitleText": "收货地址" }
|
||||
},
|
||||
{
|
||||
"path": "address-edit",
|
||||
"style": { "navigationBarTitleText": "编辑地址" }
|
||||
},
|
||||
{
|
||||
"path": "checkout",
|
||||
"style": { "navigationBarTitleText": "确认订单" }
|
||||
},
|
||||
{
|
||||
"path": "payment",
|
||||
"style": { "navigationBarTitleText": "收银台" }
|
||||
},
|
||||
{
|
||||
"path": "payment-success",
|
||||
"style": { "navigationBarTitleText": "支付成功", "navigationStyle": "custom" }
|
||||
},
|
||||
{
|
||||
"path": "orders",
|
||||
"style": { "navigationBarTitleText": "我的订单", "enablePullDownRefresh": true }
|
||||
},
|
||||
{
|
||||
"path": "order-detail",
|
||||
"style": { "navigationBarTitleText": "订单详情" }
|
||||
},
|
||||
{
|
||||
"path": "logistics",
|
||||
"style": { "navigationBarTitleText": "物流详情" }
|
||||
},
|
||||
{
|
||||
"path": "review",
|
||||
"style": { "navigationBarTitleText": "评价晒单" }
|
||||
},
|
||||
{
|
||||
"path": "refund",
|
||||
"style": { "navigationBarTitleText": "退款/售后" }
|
||||
},
|
||||
{
|
||||
"path": "apply-refund",
|
||||
"style": { "navigationBarTitleText": "申请售后" }
|
||||
},
|
||||
{
|
||||
"path": "refund-review",
|
||||
"style": { "navigationBarTitleText": "服务评价" }
|
||||
},
|
||||
{
|
||||
"path": "chat",
|
||||
"style": { "navigationBarTitleText": "客服聊天", "navigationStyle": "custom" }
|
||||
},
|
||||
{
|
||||
"path": "subscription/followed-shops",
|
||||
"style": { "navigationBarTitleText": "关注店铺" }
|
||||
},
|
||||
{
|
||||
"path": "points/index",
|
||||
"style": { "navigationBarTitleText": "积分管理" }
|
||||
},
|
||||
{
|
||||
"path": "points/signin",
|
||||
"style": { "navigationBarTitleText": "每日签到" }
|
||||
},
|
||||
{
|
||||
"path": "points/exchange",
|
||||
"style": { "navigationBarTitleText": "积分兑换" }
|
||||
},
|
||||
{
|
||||
"path": "points/exchange-records",
|
||||
"style": { "navigationBarTitleText": "兑换记录" }
|
||||
},
|
||||
{
|
||||
"path": "product-reviews",
|
||||
"style": { "navigationBarTitleText": "商品评价" }
|
||||
},
|
||||
{
|
||||
"path": "my-reviews",
|
||||
"style": { "navigationBarTitleText": "我的评价" }
|
||||
},
|
||||
{
|
||||
"path": "balance/index",
|
||||
"style": { "navigationBarTitleText": "我的余额" }
|
||||
},
|
||||
{
|
||||
"path": "share/index",
|
||||
"style": { "navigationBarTitleText": "我的分享" }
|
||||
},
|
||||
{
|
||||
"path": "share/detail",
|
||||
"style": { "navigationBarTitleText": "分享详情" }
|
||||
},
|
||||
{
|
||||
"path": "member/index",
|
||||
"style": { "navigationBarTitleText": "会员中心" }
|
||||
},
|
||||
{
|
||||
"path": "message-detail",
|
||||
"style": { "navigationBarTitleText": "消息详情" }
|
||||
},
|
||||
{
|
||||
"path": "red-packets/index",
|
||||
"style": { "navigationBarTitleText": "我的红包" }
|
||||
},
|
||||
{
|
||||
"path": "bank-cards/index",
|
||||
"style": { "navigationBarTitleText": "银行卡管理" }
|
||||
},
|
||||
{
|
||||
"path": "bank-cards/add",
|
||||
"style": { "navigationBarTitleText": "添加银行卡" }
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarTitleText": "商城",
|
||||
"navigationBarBackgroundColor": "#ffffff",
|
||||
"backgroundColor": "#f5f5f5"
|
||||
},
|
||||
"tabBar": {
|
||||
"color": "#999999",
|
||||
"selectedColor": "#ff5000",
|
||||
"borderStyle": "black",
|
||||
"backgroundColor": "#ffffff",
|
||||
"list": [
|
||||
{
|
||||
"pagePath": "pages/main/index",
|
||||
"text": "首页",
|
||||
"iconPath": "static/tabbar/home.png",
|
||||
"selectedIconPath": "static/tabbar/home-active.png"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/main/category",
|
||||
"text": "分类",
|
||||
"iconPath": "static/tabbar/category.png",
|
||||
"selectedIconPath": "static/tabbar/category.png"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/main/cart",
|
||||
"text": "购物车",
|
||||
"iconPath": "static/tabbar/cart.png",
|
||||
"selectedIconPath": "static/tabbar/cart.png"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/main/profile",
|
||||
"text": "我的",
|
||||
"iconPath": "static/tabbar/user.png",
|
||||
"selectedIconPath": "static/tabbar/user.png"
|
||||
}
|
||||
]
|
||||
},
|
||||
"preloadRule": {
|
||||
"pages/main/index": {
|
||||
"network": "all",
|
||||
"packages": ["pages/mall/consumer"]
|
||||
}
|
||||
},
|
||||
"easycom": {
|
||||
"autoscan": true,
|
||||
"custom": {
|
||||
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
|
||||
}
|
||||
},
|
||||
"optimization": {
|
||||
"subPackages": true
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<view class="cart-page">
|
||||
<!-- 智能顶部导航栏 - 与消息页保持一致 -->
|
||||
<view class="smart-navbar" :style="{ paddingTop: statusBarHeight + 'px' }">
|
||||
<view class="nav-container">
|
||||
<view class="nav-container" :style="{ paddingRight: navBarRight + 'px' }">
|
||||
<text class="nav-title">购物车</text>
|
||||
<view class="nav-actions">
|
||||
<view class="action-btn" @click="toggleManageMode">
|
||||
@@ -245,6 +245,20 @@ const statusBarHeight = ref(0)
|
||||
const isManageMode = ref(false)
|
||||
const updatingItems = ref<Set<string>>(new Set()) // Track items being updated to prevent race conditions
|
||||
|
||||
// 小程序胶囊按钮信息类型
|
||||
type CapsuleButtonInfo = {
|
||||
left: number,
|
||||
top: number,
|
||||
right: number,
|
||||
bottom: number,
|
||||
width: number,
|
||||
height: number
|
||||
}
|
||||
|
||||
// 小程序胶囊按钮信息
|
||||
const capsuleButtonInfo = ref<CapsuleButtonInfo | null>(null)
|
||||
const navBarRight = ref(0) // 导航栏右侧预留空间
|
||||
|
||||
// 计算属性
|
||||
const cartGroups = computed<CartGroup[]>(() => {
|
||||
console.log('[cartGroups] 计算购物车分组, cartItems count:', cartItems.value.length)
|
||||
@@ -326,6 +340,27 @@ const toggleManageMode = () => {
|
||||
const initPage = () => {
|
||||
const systemInfo = uni.getSystemInfoSync()
|
||||
statusBarHeight.value = systemInfo.statusBarHeight ?? 0
|
||||
|
||||
// 获取小程序胶囊按钮信息
|
||||
// #ifdef MP-WEIXIN
|
||||
try {
|
||||
const menuButton = uni.getMenuButtonBoundingClientRect()
|
||||
if (menuButton != null) {
|
||||
capsuleButtonInfo.value = {
|
||||
left: menuButton.left,
|
||||
top: menuButton.top,
|
||||
right: menuButton.right,
|
||||
bottom: menuButton.bottom,
|
||||
width: menuButton.width,
|
||||
height: menuButton.height
|
||||
}
|
||||
navBarRight.value = (systemInfo.screenWidth - menuButton.left) + 10
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('获取胶囊按钮信息失败', e)
|
||||
navBarRight.value = 90
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
// 生命周期
|
||||
@@ -863,7 +898,7 @@ const navigateToProduct = (product: any) => {
|
||||
const name = productJson.getString('name') ?? ''
|
||||
paramsArr.push('name=' + encodeURIComponent(name))
|
||||
|
||||
const image = productJson.getString('image') ?? '/static/product1.jpg'
|
||||
const image = productJson.getString('image') ?? '/static/images/default-product.png'
|
||||
paramsArr.push('image=' + encodeURIComponent(image))
|
||||
|
||||
const url = `/pages/mall/consumer/product-detail?${paramsArr.join('&')}`
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<view class="category-page">
|
||||
<!-- 顶部搜索栏 -->
|
||||
<view class="search-bar" :style="{ paddingTop: statusBarHeight + 'px' }">
|
||||
<view class="search-container">
|
||||
<view class="search-container" :style="{ paddingRight: navBarRight + 'px' }">
|
||||
<view class="search-box" @click="navigateToSearch" :style="{ height: '30px' }">
|
||||
<!-- 模拟输入框 -->
|
||||
<text class="search-placeholder">请输入商品名称、店铺</text>
|
||||
@@ -139,6 +139,21 @@ type LocalCategory = {
|
||||
// 响应式数据
|
||||
const statusBarHeight = ref(0)
|
||||
const headerHeight = ref(44)
|
||||
|
||||
// 小程序胶囊按钮信息类型
|
||||
type CapsuleButtonInfo = {
|
||||
left: number,
|
||||
top: number,
|
||||
right: number,
|
||||
bottom: number,
|
||||
width: number,
|
||||
height: number
|
||||
}
|
||||
|
||||
// 小程序胶囊按钮信息
|
||||
const capsuleButtonInfo = ref<CapsuleButtonInfo | null>(null)
|
||||
const navBarRight = ref(0) // 导航栏右侧预留空间
|
||||
|
||||
const primaryCategories = ref<LocalCategory[]>([])
|
||||
const subCategories = ref<LocalCategory[]>([]) // 二级分类列表
|
||||
const productList = ref<Product[]>([])
|
||||
@@ -547,6 +562,28 @@ onShow(() => {
|
||||
onLoad((options: any) => {
|
||||
const systemInfo = uni.getSystemInfoSync()
|
||||
statusBarHeight.value = systemInfo.statusBarHeight
|
||||
|
||||
// 获取小程序胶囊按钮信息
|
||||
// #ifdef MP-WEIXIN
|
||||
try {
|
||||
const menuButton = uni.getMenuButtonBoundingClientRect()
|
||||
if (menuButton != null) {
|
||||
capsuleButtonInfo.value = {
|
||||
left: menuButton.left,
|
||||
top: menuButton.top,
|
||||
right: menuButton.right,
|
||||
bottom: menuButton.bottom,
|
||||
width: menuButton.width,
|
||||
height: menuButton.height
|
||||
}
|
||||
navBarRight.value = (systemInfo.screenWidth - menuButton.left) + 10
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('获取胶囊按钮信息失败', e)
|
||||
navBarRight.value = 90
|
||||
}
|
||||
// #endif
|
||||
|
||||
console.log('=== category页面onLoad被调用 ===')
|
||||
|
||||
let categoryId = ''
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
transform: showNavbar ? 'translateY(0)' : 'translateY(-100%)'
|
||||
}"
|
||||
>
|
||||
<view class="search-container">
|
||||
<view class="search-container" :style="{ paddingRight: navBarRight + 'px' }">
|
||||
<view class="search-box" @click="navigateToSearch" :style="{ height: '30px' }">
|
||||
<!-- 模拟输入框 -->
|
||||
<text class="search-placeholder">请输入商品名称、店铺</text>
|
||||
@@ -287,6 +287,20 @@ const activeFilter = ref('recommend')
|
||||
const currentPage = ref(1)
|
||||
const priceAscending = ref(true) // 价格排序方向:true=升序,false=降序
|
||||
|
||||
// 小程序胶囊按钮信息类型
|
||||
type CapsuleButtonInfo = {
|
||||
left: number,
|
||||
top: number,
|
||||
right: number,
|
||||
bottom: number,
|
||||
width: number,
|
||||
height: number
|
||||
}
|
||||
|
||||
// 小程序胶囊按钮信息
|
||||
const capsuleButtonInfo = ref<CapsuleButtonInfo | null>(null)
|
||||
const navBarRight = ref(0) // 导航栏右侧预留空间
|
||||
|
||||
// 数据源
|
||||
const hotProducts = ref<Product[]>([])
|
||||
const recommendedProducts = ref<Product[]>([])
|
||||
@@ -629,6 +643,24 @@ const initPage = () => {
|
||||
const systemInfo = uni.getSystemInfoSync()
|
||||
statusBarHeight.value = systemInfo.statusBarHeight
|
||||
|
||||
// 获取小程序胶囊按钮信息
|
||||
// #ifdef MP-WEIXIN
|
||||
try {
|
||||
capsuleButtonInfo.value = uni.getMenuButtonBoundingClientRect()
|
||||
if (capsuleButtonInfo.value != null) {
|
||||
// 计算导航栏右侧需要预留的空间(胶囊按钮宽度 + 左右边距)
|
||||
navBarRight.value = (systemInfo.screenWidth - capsuleButtonInfo.value.left) + 10
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('获取胶囊按钮信息失败', e)
|
||||
navBarRight.value = 90 // 默认预留空间
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifndef MP-WEIXIN
|
||||
navBarRight.value = 0 // 非小程序不需要预留空间
|
||||
// #endif
|
||||
|
||||
// 计算滚动区域高度 - 不再需要手动计算,使用 Flex 布局自动撑开
|
||||
// scrollHeight.value = windowHeight - 50
|
||||
|
||||
@@ -985,7 +1017,7 @@ const navigateToProduct = (product: any) => {
|
||||
const productId = prodObj.getString('productId') ?? prodObj.getString('id') ?? ''
|
||||
const name = prodObj.getString('name') ?? ''
|
||||
// 使用 main_image_url
|
||||
const image = prodObj.getString('main_image_url') ?? prodObj.getString('image') ?? '/static/product1.jpg'
|
||||
const image = prodObj.getString('main_image_url') ?? prodObj.getString('image') ?? '/static/images/default-product.png'
|
||||
const price = (prodObj.getNumber('base_price') ?? prodObj.getNumber('price') ?? 0).toString()
|
||||
const marketPrice = prodObj.getNumber('market_price') ?? prodObj.getNumber('original_price') ?? (parseFloat(price) * 1.2)
|
||||
const originalPrice = marketPrice.toString()
|
||||
|
||||
@@ -413,7 +413,7 @@ const loadMessages = async () => {
|
||||
time: formatTime(room.last_message_at ?? ''),
|
||||
read: room.unread_count === 0,
|
||||
type: 'service',
|
||||
avatar: room.shop_logo ?? '/static/icons/shop-default.png',
|
||||
avatar: room.shop_logo ?? '/static/icons/customer-service.png',
|
||||
online: true,
|
||||
unreadCount: room.unread_count,
|
||||
tags: [] as string[],
|
||||
@@ -442,7 +442,7 @@ const loadMessages = async () => {
|
||||
time: '刚刚',
|
||||
read: true,
|
||||
type: 'service',
|
||||
avatar: '/static/icons/service-avatar.png',
|
||||
avatar: '/static/icons/customer-service.png',
|
||||
online: true,
|
||||
unreadCount: 0,
|
||||
tags: ['自动回复'],
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
<!-- 基础用户信息:头像和昵称 -->
|
||||
<view class="nav-user-basic" @click="editProfile">
|
||||
<image
|
||||
:src="userInfo.avatar_url != '' ? userInfo.avatar_url : '/static/default-avatar.png'"
|
||||
:src="userInfo.avatar_url != '' ? userInfo.avatar_url : '/static/images/default-product.png'"
|
||||
class="nav-avatar"
|
||||
/>
|
||||
<text class="nav-user-name">{{ userInfo.nickname != '' ? userInfo.nickname : userInfo.phone }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 用户资产横向排列 (积分、余额、优惠券) -->
|
||||
<view class="nav-user-stats">
|
||||
<view class="nav-user-stats" :style="{ marginRight: navBarRight + 'px' }">
|
||||
<view class="nav-stat-item" @click="goToPoints">
|
||||
<text class="nav-stat-label">积分</text>
|
||||
<text class="nav-stat-value">{{ userStats.points }}</text>
|
||||
@@ -371,6 +371,7 @@ export default {
|
||||
save_amount: 0
|
||||
} as ConsumptionStatsType,
|
||||
statusBarHeight: 0,
|
||||
navBarRight: 0, // 导航栏右侧预留空间(小程序胶囊按钮)
|
||||
currentOrderTab: 'all' as string,
|
||||
allOrders: [] as Array<OrderItemType>
|
||||
}
|
||||
@@ -529,6 +530,19 @@ export default {
|
||||
initPage() {
|
||||
const systemInfo = uni.getSystemInfoSync()
|
||||
this.statusBarHeight = systemInfo.statusBarHeight ?? 0
|
||||
|
||||
// 获取小程序胶囊按钮信息
|
||||
// #ifdef MP-WEIXIN
|
||||
try {
|
||||
const menuButton = uni.getMenuButtonBoundingClientRect()
|
||||
if (menuButton != null) {
|
||||
this.navBarRight = (systemInfo.screenWidth - menuButton.left) + 10
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('获取胶囊按钮信息失败', e)
|
||||
this.navBarRight = 90
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
async loadUserProfile() {
|
||||
try {
|
||||
@@ -570,7 +584,7 @@ export default {
|
||||
phone: uPhone,
|
||||
email: uEmail,
|
||||
nickname: uNickname != '' ? uNickname : '微信用户',
|
||||
avatar_url: uAvatar != '' ? uAvatar : '/static/default-avatar.png',
|
||||
avatar_url: uAvatar != '' ? uAvatar : '/static/images/default-product.png',
|
||||
gender: uGender,
|
||||
user_type: 1,
|
||||
status: 1,
|
||||
@@ -929,20 +943,20 @@ export default {
|
||||
|
||||
getOrderMainImage(order: OrderItemType): string {
|
||||
const itemsRaw = order.ml_order_items
|
||||
if (itemsRaw == null) return '/static/product1.jpg'
|
||||
if (itemsRaw == null) return '/static/images/default-product.png'
|
||||
const items = itemsRaw as any[]
|
||||
if (items.length > 0) {
|
||||
const firstItem = items[0]
|
||||
const itemStr = JSON.stringify(firstItem)
|
||||
const itemParsed = JSON.parse(itemStr)
|
||||
if (itemParsed == null) return '/static/product1.jpg'
|
||||
if (itemParsed == null) return '/static/images/default-product.png'
|
||||
const itemObj = itemParsed as UTSJSONObject
|
||||
const imgUrl = itemObj.getString('image_url')
|
||||
const prodImg = itemObj.getString('product_image')
|
||||
const img = (imgUrl != null && imgUrl !== '') ? imgUrl : prodImg
|
||||
if (img != null && img !== '') return img
|
||||
}
|
||||
return '/static/product1.jpg'
|
||||
return '/static/images/default-product.png'
|
||||
},
|
||||
|
||||
getOrderTitle(order: OrderItemType): string {
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
</view>
|
||||
<image
|
||||
class="avatar me"
|
||||
src="/static/default-avatar.png"
|
||||
src="/static/images/default-product.png"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
</view>
|
||||
<image
|
||||
class="avatar me"
|
||||
:src="userAvatar || '/static/default-avatar.png'"
|
||||
:src="userAvatar || '/static/images/default-product.png'"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
软件订阅(consumer)
|
||||
|
||||
入口:
|
||||
- 用户中心 -> 软件订阅
|
||||
|
||||
页面:
|
||||
- plan-list.uvue:展示可用订阅方案(ml_subscription_plans)
|
||||
- plan-detail.uvue:展示某个订阅方案详情
|
||||
- subscribe-checkout.uvue:确认支付并创建订阅(写入 ml_user_subscriptions)
|
||||
|
||||
依赖表(示例名称,可按实际后端调整):
|
||||
- ml_subscription_plans(id, plan_code, name, description, features jsonb, price numeric, currency text, billing_period text, trial_days int, is_active bool, sort_order int, created_at, updated_at)
|
||||
- ml_user_subscriptions(id, user_id, plan_id, status text, start_date timestamptz, end_date timestamptz, next_billing_date timestamptz, auto_renew bool, cancel_at_period_end bool, metadata jsonb, created_at, updated_at)
|
||||
|
||||
注意:
|
||||
- 本实现使用 uni-app-x 兼容组件与 supaClient。实际支付请替换为你们的支付网关,并在后端完成对账与签名校验。
|
||||
@@ -99,7 +99,7 @@ const userStats = ref<UserStatsType>({
|
||||
streak: 0
|
||||
} as UserStatsType)
|
||||
const currentLocale = ref<string>('zh-CN')
|
||||
const userAvatar = ref<string>('/static/default-avatar.png')
|
||||
const userAvatar = ref<string>('/static/images/default-product.png')
|
||||
|
||||
const toggleLanguage = (): void => {
|
||||
if (currentLocale.value === 'zh-CN') {
|
||||
|
||||
10
scripts/build-consumer.bat
Normal file
@@ -0,0 +1,10 @@
|
||||
@echo off
|
||||
chcp 65001 >nul 2>&1
|
||||
|
||||
if exist pages.json copy /y pages.json pages.json.bak >nul 2>&1
|
||||
if exist manifest.json copy /y manifest.json manifest.json.bak >nul 2>&1
|
||||
|
||||
copy /y config\consumer\pages.json pages.json >nul 2>&1
|
||||
copy /y config\consumer\manifest.json manifest.json >nul 2>&1
|
||||
|
||||
echo 消费者端配置已应用,可以编译小程序了
|
||||
35
scripts/build-consumer.sh
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
# 消费者端小程序构建脚本 (Linux/Mac)
|
||||
|
||||
echo "========================================"
|
||||
echo "消费者端小程序构建脚本"
|
||||
echo "========================================"
|
||||
echo ""
|
||||
|
||||
echo "[1/3] 备份原配置文件..."
|
||||
if [ -f "pages.json" ]; then
|
||||
cp pages.json pages.json.bak
|
||||
echo " 已备份 pages.json -> pages.json.bak"
|
||||
fi
|
||||
if [ -f "manifest.json" ]; then
|
||||
cp manifest.json manifest.json.bak
|
||||
echo " 已备份 manifest.json -> manifest.json.bak"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "[2/3] 复制消费者端配置文件..."
|
||||
cp config/consumer/pages.json pages.json
|
||||
echo " 已复制 config/consumer/pages.json -> pages.json"
|
||||
cp config/consumer/manifest.json manifest.json
|
||||
echo " 已复制 config/consumer/manifest.json -> manifest.json"
|
||||
echo ""
|
||||
|
||||
echo "[3/3] 配置完成!"
|
||||
echo ""
|
||||
echo "========================================"
|
||||
echo "现在可以在 HBuilderX 中编译小程序了"
|
||||
echo "编译目标: 微信小程序"
|
||||
echo "========================================"
|
||||
echo ""
|
||||
echo "提示: 编译完成后,运行 restore-config.sh 恢复原配置"
|
||||
echo ""
|
||||
10
scripts/restore-config.bat
Normal file
@@ -0,0 +1,10 @@
|
||||
@echo off
|
||||
chcp 65001 >nul 2>&1
|
||||
|
||||
if exist pages.json.bak copy /y pages.json.bak pages.json >nul 2>&1
|
||||
if exist manifest.json.bak copy /y manifest.json.bak manifest.json >nul 2>&1
|
||||
|
||||
if exist pages.json.bak del pages.json.bak >nul 2>&1
|
||||
if exist manifest.json.bak del manifest.json.bak >nul 2>&1
|
||||
|
||||
echo 公共配置已恢复
|
||||
25
scripts/restore-config.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
# 恢复原配置文件 (Linux/Mac)
|
||||
|
||||
echo "========================================"
|
||||
echo "恢复原配置文件"
|
||||
echo "========================================"
|
||||
echo ""
|
||||
|
||||
echo "[1/2] 恢复配置文件..."
|
||||
if [ -f "pages.json.bak" ]; then
|
||||
cp pages.json.bak pages.json
|
||||
rm pages.json.bak
|
||||
echo " 已恢复 pages.json"
|
||||
fi
|
||||
if [ -f "manifest.json.bak" ]; then
|
||||
cp manifest.json.bak manifest.json
|
||||
rm manifest.json.bak
|
||||
echo " 已恢复 manifest.json"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "[2/2] 完成!"
|
||||
echo ""
|
||||
echo "配置文件已恢复到原始状态"
|
||||
echo ""
|
||||