Files
medical-mall/doc_mall/consumer/backup_doc_full/TEAM_COLLABORATION_GUIDE.md

10 KiB
Raw Permalink Blame History

多人协作多端开发方案

一、问题分析

1.1 当前协作场景

团队成员分工:
├── 开发者A → 消费者端 (consumer)
├── 开发者B → 商家端 (merchant)
├── 开发者C → 管理端 (admin)
├── 开发者D → 分析端 (analytics)
└── 开发者E → 配送端 (delivery)

1.2 潜在冲突问题

如果每个人都在 manifest.jsonpages.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 创建端专用配置目录

# 创建配置目录结构
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

{
  "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

{
  "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

#!/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

#!/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 配置

# 编译产物
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

{
  "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 有公共页面更新,需要同步到各端的配置文件:

# 同步公共页面配置
./scripts/sync-common-pages.sh

7.3 冲突处理

如果发生配置冲突:

  1. 优先保留各端专用配置
  2. 合并公共配置
  3. 团队沟通确认

八、总结

推荐方案

端专用配置文件 + 构建脚本

核心优势

优势 说明
无冲突 每个开发者只修改自己端的配置
体积可控 每个端只编译自己需要的页面
独立发布 各端可独立发布小程序
代码共享 页面代码仍在同一仓库

目录结构

config/
├── consumer/     # 消费者端配置开发者A维护
├── merchant/     # 商家端配置开发者B维护
├── admin/        # 管理端配置开发者C维护
├── analytics/    # 分析端配置开发者D维护
└── delivery/     # 配送端配置开发者E维护