--- change: weapp-capsule-safearea design-doc: docs/superpowers/specs/2026-06-24-weapp-capsule-safearea-design.md base-ref: fe7ae882ea6905abf5f97f370efe8ffee9a7134f archived-with: 2026-06-24-weapp-capsule-safearea --- # 微信小程序胶囊安全区适配实施计划 > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. **Goal:** 创建全局胶囊安全区组件,改造 `TopBar` 自动避让微信小程序右上角胶囊按钮,并修复首页、任务页、排班页的胶囊遮挡问题。 **Architecture:** 新增纯展示组件 `CapsuleSafeArea.vue` 计算胶囊安全宽度并包裹右侧操作按钮;改造 `TopBar.vue` 在右侧 slot 外层自动包裹 `CapsuleSafeArea`;三个首页从自定义 header 改为使用 `TopBar`,任务页和排班页将操作按钮移入 `TopBar` 的 right slot。 **Tech Stack:** Vue 3 + uni-app + TypeScript + Tailwind CSS ## Global Constraints - 微信小程序:使用 `uni.getMenuButtonBoundingClientRect()` + `uni.getSystemInfoSync()` 动态计算安全宽度。 - H5 / App / 其他平台:安全宽度返回 `0`,布局保持不变。 - API 调用失败:使用基于 `screenWidth` 的保守估算值兜底(约为屏幕宽度的 28%)。 - `CapsuleSafeArea` 为纯展示组件,无外部状态依赖,无 props,仅提供默认 slot。 - 安全宽度在 `onMounted` 中计算一次,不监听窗口尺寸变化。 - 标题区使用 `flex-1 min-w-0 truncate`,避免左侧内容过长或右侧安全区挤压导致标题溢出。 - 保持 H5/App 等非微信环境下的正常显示(graceful fallback)。 - 不处理胶囊以外的系统 UI(如灵动岛、底部横条)。 - 不做横屏/旋转后的实时安全区重算。 - 无新增 npm 依赖,无后端接口变更。 ## 文件结构 | 文件 | 操作 | 职责 | |------|------|------| | `src/components/common/CapsuleSafeArea.vue` | 新增 | 计算微信小程序胶囊安全宽度,以 wrapper 形式给默认 slot 内容添加左侧间距 | | `src/components/common/TopBar.vue` | 修改 | 右侧 `` 外层自动包裹 ``;标题区使用 `flex-1 min-w-0 truncate` | | `src/components/home/DispatchHome.vue` | 修改 | 自定义 header 改为使用 `TopBar`,左侧放头像+欢迎语,右侧放通知铃铛 | | `src/components/home/SalesHome.vue` | 修改 | 同上 | | `src/components/home/ConstructionHome.vue` | 修改 | 同上 | | `src/components/task/TaskListView.vue` | 修改 | 顶部自定义标题栏改为 ``,右侧放发布/新增按钮;筛选标签保留在 TopBar 下方 | | `src/components/dispatch/ScheduleView.vue` | 修改 | 右侧 slot 同时放入「今天」和「新增排班」两个按钮;月份切换行右侧清空 | archived-with: 2026-06-24-weapp-capsule-safearea --- ### Task 1: 创建 CapsuleSafeArea.vue 组件 **Files:** - Create: `src/components/common/CapsuleSafeArea.vue` **Interfaces:** - Consumes: 无 - Produces: 默认 slot wrapper,内部通过 `marginLeft` 为 slot 内容添加胶囊安全区左侧间距 - 内部状态: `safeWidth` (ref),微信小程序下为 `screenWidth - menuButton.left + 8`,其他平台为 `0` - [x] **Step 1: 创建组件文件** 创建 `src/components/common/CapsuleSafeArea.vue`,内容如下: ```vue ``` - [x] **Step 2: 验证文件创建** 确认文件存在且内容正确: ```bash cat src/components/common/CapsuleSafeArea.vue ``` - [x] **Step 3: Commit** ```bash git add src/components/common/CapsuleSafeArea.vue git commit -m "feat: add CapsuleSafeArea component for weapp capsule button safe area" ``` archived-with: 2026-06-24-weapp-capsule-safearea --- ### Task 2: 改造 TopBar.vue 集成 CapsuleSafeArea **Files:** - Modify: `src/components/common/TopBar.vue` **Interfaces:** - Consumes: `CapsuleSafeArea.vue`(默认 slot wrapper) - Produces: 右侧 `` 自动被 `CapsuleSafeArea` 包裹,页面无需感知胶囊安全区 - [x] **Step 1: 修改模板结构** 将 `src/components/common/TopBar.vue` 的 `