docs: add mp CRM product confirm dialog implementation plan.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3138666ae2
commit
f404592d44
1 file changed
+500
@@ -0,0 +1,500 @@
|
||||
# 产品管理确认弹窗美化 Implementation Plan
|
||||
|
||||
> **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:** 产品管理 WebView 确认弹窗:删除用方案 B(红确认 + 警示),上架/下架用方案 A(绿确认),消灭纵向堆叠默认丑态。
|
||||
|
||||
**Architecture:** 抽出纯函数 `buildProductConfirmOptions` 统一 Dialog 参数(className / allowHtml / 确认色 / 文案);`product.scss` 仅覆盖 `.mp-product-dialog`(含 `--danger`),避免误伤客户等其它页;三个页面调用点改为走该 helper。禁止 `theme: 'round-button'`。
|
||||
|
||||
**Tech Stack:** Vue 3 + Vant 4 `showConfirmDialog`;SCSS;node:test;可选 DOM 契约脚本。
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-10-18-mp-crm-product-confirm-dialog-design.md`
|
||||
|
||||
**Demo:** `bak/mobile-ui/shanxia-mp-crm-product-delete-confirm-demo.html`
|
||||
|
||||
---
|
||||
|
||||
## File map
|
||||
|
||||
| File | Responsibility |
|
||||
|------|----------------|
|
||||
| `web-admin/src/utils/mp-crm-product-confirm.ts` | 纯函数构建 Dialog options;可选薄封装 `showProductConfirmDialog` |
|
||||
| `web-admin/src/utils/mp-crm-product-confirm.test.ts` | A/B 参数契约单测 |
|
||||
| `web-admin/src/views/m/crm/product/product.scss` | `.mp-product-dialog` / `--danger` 视觉覆盖 |
|
||||
| `web-admin/src/views/m/crm/product/index.vue` | 删除 B、上下架 A |
|
||||
| `web-admin/src/views/m/crm/product/detail.vue` | 同上 |
|
||||
| `web-admin/src/views/m/crm/product/categories.vue` | 删除分类 B |
|
||||
| `web-admin/scripts/test-mp-crm-product-confirm-dom.mjs` | 源码契约:三页调用 + scss 选择器 |
|
||||
|
||||
---
|
||||
|
||||
### Task 1: 单测驱动 — `buildProductConfirmOptions`
|
||||
|
||||
**Files:**
|
||||
- Create: `web-admin/src/utils/mp-crm-product-confirm.test.ts`
|
||||
- Create: `web-admin/src/utils/mp-crm-product-confirm.ts`
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
```ts
|
||||
import assert from 'node:assert/strict'
|
||||
import { describe, it } from 'node:test'
|
||||
import { buildProductConfirmOptions } from './mp-crm-product-confirm'
|
||||
|
||||
describe('buildProductConfirmOptions', () => {
|
||||
it('builds scheme A for non-delete confirms', () => {
|
||||
const opts = buildProductConfirmOptions({
|
||||
kind: 'default',
|
||||
title: '下架产品',
|
||||
message: '确认下架该产品?'
|
||||
})
|
||||
assert.equal(opts.title, '下架产品')
|
||||
assert.equal(opts.message, '确认下架该产品?')
|
||||
assert.equal(opts.allowHtml, false)
|
||||
assert.equal(opts.className, 'mp-product-dialog')
|
||||
assert.equal(opts.confirmButtonText, '确认')
|
||||
assert.equal(opts.confirmButtonColor, '#0a9f6d')
|
||||
assert.equal(opts.theme, undefined)
|
||||
})
|
||||
|
||||
it('builds scheme B for delete confirms with warn html', () => {
|
||||
const opts = buildProductConfirmOptions({
|
||||
kind: 'danger',
|
||||
title: '删除产品',
|
||||
message: '确认删除该产品?删除后不可恢复。'
|
||||
})
|
||||
assert.equal(opts.title, '删除产品')
|
||||
assert.equal(opts.allowHtml, true)
|
||||
assert.equal(opts.className, 'mp-product-dialog mp-product-dialog--danger')
|
||||
assert.equal(opts.confirmButtonText, '确认删除')
|
||||
assert.equal(opts.confirmButtonColor, '#dc2626')
|
||||
assert.match(String(opts.message), /mp-product-dialog__warn/)
|
||||
assert.match(String(opts.message), /确认删除该产品?删除后不可恢复。/)
|
||||
assert.doesNotMatch(String(opts.message), /<script/)
|
||||
assert.equal(opts.theme, undefined)
|
||||
})
|
||||
|
||||
it('escapes html in danger message body', () => {
|
||||
const opts = buildProductConfirmOptions({
|
||||
kind: 'danger',
|
||||
title: '删除产品',
|
||||
message: 'a <b>x</b> & "y"'
|
||||
})
|
||||
assert.match(String(opts.message), /a <b>x<\/b> & "y"/)
|
||||
})
|
||||
|
||||
it('allows override confirmButtonText', () => {
|
||||
const opts = buildProductConfirmOptions({
|
||||
kind: 'default',
|
||||
title: '上架产品',
|
||||
message: '确认上架该产品?',
|
||||
confirmButtonText: '立即上架'
|
||||
})
|
||||
assert.equal(opts.confirmButtonText, '立即上架')
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 跑测试确认失败**
|
||||
|
||||
Run:
|
||||
|
||||
```bash
|
||||
cd web-admin && node --import tsx --test src/utils/mp-crm-product-confirm.test.ts
|
||||
```
|
||||
|
||||
Expected: FAIL(模块不存在)
|
||||
|
||||
- [ ] **Step 3: 最小实现**
|
||||
|
||||
创建 `web-admin/src/utils/mp-crm-product-confirm.ts`:
|
||||
|
||||
```ts
|
||||
import { showConfirmDialog, type DialogOptions } from 'vant'
|
||||
|
||||
export type ProductConfirmKind = 'default' | 'danger'
|
||||
|
||||
export type BuildProductConfirmInput = {
|
||||
kind: ProductConfirmKind
|
||||
title: string
|
||||
message: string
|
||||
confirmButtonText?: string
|
||||
}
|
||||
|
||||
function escapeHtml(text: string): string {
|
||||
return text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
}
|
||||
|
||||
function dangerMessageHtml(message: string): string {
|
||||
return (
|
||||
`<div class="mp-product-dialog__warn"><span class="mp-product-dialog__warn-icon">!</span></div>` +
|
||||
`<div class="mp-product-dialog__msg">${escapeHtml(message)}</div>`
|
||||
)
|
||||
}
|
||||
|
||||
export function buildProductConfirmOptions(input: BuildProductConfirmInput): DialogOptions {
|
||||
const isDanger = input.kind === 'danger'
|
||||
return {
|
||||
title: input.title,
|
||||
message: isDanger ? dangerMessageHtml(input.message) : input.message,
|
||||
allowHtml: isDanger,
|
||||
className: isDanger ? 'mp-product-dialog mp-product-dialog--danger' : 'mp-product-dialog',
|
||||
confirmButtonText: input.confirmButtonText ?? (isDanger ? '确认删除' : '确认'),
|
||||
confirmButtonColor: isDanger ? '#dc2626' : '#0a9f6d'
|
||||
}
|
||||
}
|
||||
|
||||
export function showProductConfirmDialog(input: BuildProductConfirmInput) {
|
||||
return showConfirmDialog(buildProductConfirmOptions(input))
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 4: 跑测试确认通过**
|
||||
|
||||
Run:
|
||||
|
||||
```bash
|
||||
cd web-admin && node --import tsx --test src/utils/mp-crm-product-confirm.test.ts
|
||||
```
|
||||
|
||||
Expected: PASS(4 tests)
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add web-admin/src/utils/mp-crm-product-confirm.ts web-admin/src/utils/mp-crm-product-confirm.test.ts
|
||||
git commit -m "$(cat <<'EOF'
|
||||
feat(web-admin): add product confirm dialog option builder for scheme A/B.
|
||||
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: `product.scss` — Dialog 视觉覆盖
|
||||
|
||||
**Files:**
|
||||
- Modify: `web-admin/src/views/m/crm/product/product.scss`
|
||||
|
||||
- [ ] **Step 1: 在文件末尾追加样式**(对齐 Demo A/B;只命中 `.mp-product-dialog`)
|
||||
|
||||
```scss
|
||||
/* ── 确认弹窗:方案 A / B(挂到 body,须用 className 限定)── */
|
||||
body .van-dialog.mp-product-dialog {
|
||||
overflow: hidden;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 16px 40px rgb(15 40 30 / 22%);
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog .van-dialog__header {
|
||||
padding-top: 20px;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: #1f2a26;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog .van-dialog__content {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog .van-dialog__message {
|
||||
padding: 10px 20px 4px;
|
||||
font-size: 14px;
|
||||
line-height: 1.55;
|
||||
color: #6b7b74;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog .mp-product-dialog__warn {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 4px 0 10px;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog .mp-product-dialog__warn-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
color: #dc2626;
|
||||
background: #fef2f2;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog .mp-product-dialog__msg {
|
||||
color: #6b7b74;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog .van-dialog__footer {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
padding: 16px;
|
||||
border-top: none !important;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog .van-dialog__footer::after,
|
||||
body .van-dialog.mp-product-dialog .van-hairline--left::after,
|
||||
body .van-dialog.mp-product-dialog .van-hairline--top::after {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog .van-dialog__cancel,
|
||||
body .van-dialog.mp-product-dialog .van-dialog__confirm {
|
||||
flex: 1;
|
||||
height: 40px !important;
|
||||
min-height: 40px !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 10px !important;
|
||||
font-size: 14px !important;
|
||||
font-weight: 600 !important;
|
||||
line-height: 40px !important;
|
||||
border-radius: 10px !important;
|
||||
border: 1px solid #dcebe4 !important;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog .van-dialog__cancel {
|
||||
color: #1f2a26 !important;
|
||||
background: #fff !important;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog .van-dialog__confirm {
|
||||
color: #fff !important;
|
||||
background: #0a9f6d !important;
|
||||
border-color: #0a9f6d !important;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog.mp-product-dialog--danger .van-dialog__confirm {
|
||||
background: #dc2626 !important;
|
||||
border-color: #dc2626 !important;
|
||||
}
|
||||
|
||||
body .van-dialog.mp-product-dialog.mp-product-dialog--danger .van-dialog__header {
|
||||
padding-top: 12px;
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 目视核对**(可选)打开 Demo 与样式注释对照;确认无 `#10b981`。
|
||||
|
||||
- [ ] **Step 3: Commit**
|
||||
|
||||
```bash
|
||||
git add web-admin/src/views/m/crm/product/product.scss
|
||||
git commit -m "$(cat <<'EOF'
|
||||
style(web-admin): style product confirm dialog for scheme A/B.
|
||||
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 3: 接入列表 / 详情 / 分类调用点
|
||||
|
||||
**Files:**
|
||||
- Modify: `web-admin/src/views/m/crm/product/index.vue`
|
||||
- Modify: `web-admin/src/views/m/crm/product/detail.vue`
|
||||
- Modify: `web-admin/src/views/m/crm/product/categories.vue`
|
||||
|
||||
- [ ] **Step 1: `index.vue`**
|
||||
|
||||
将 `showConfirmDialog` 导入改为:
|
||||
|
||||
```ts
|
||||
import { showFailToast, showSuccessToast } from 'vant'
|
||||
import { showProductConfirmDialog } from '@/utils/mp-crm-product-confirm'
|
||||
```
|
||||
|
||||
`toggleStatus` 内:
|
||||
|
||||
```ts
|
||||
await showProductConfirmDialog({
|
||||
kind: 'default',
|
||||
title: `${label}产品`,
|
||||
message: `确认${label}该产品?`
|
||||
})
|
||||
```
|
||||
|
||||
`deleteCard` 内:
|
||||
|
||||
```ts
|
||||
await showProductConfirmDialog({
|
||||
kind: 'danger',
|
||||
title: '删除产品',
|
||||
message: '确认删除该产品?删除后不可恢复。'
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 2: `detail.vue`**
|
||||
|
||||
同样替换导入;`toggleStatus` / `onDelete` 与列表相同参数(标题「上架产品」/「下架产品」/「删除产品」)。
|
||||
|
||||
- [ ] **Step 3: `categories.vue`**
|
||||
|
||||
替换导入;`onActionDelete`:
|
||||
|
||||
```ts
|
||||
await showProductConfirmDialog({
|
||||
kind: 'danger',
|
||||
title: '删除分类',
|
||||
message: '是否确认删除该产品分类?'
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 4: 确认三文件均无 `showConfirmDialog(` 残留**
|
||||
|
||||
Run:
|
||||
|
||||
```bash
|
||||
rg "showConfirmDialog" web-admin/src/views/m/crm/product
|
||||
```
|
||||
|
||||
Expected: 无匹配(或仅注释;调用应全部为 `showProductConfirmDialog`)
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add web-admin/src/views/m/crm/product/index.vue web-admin/src/views/m/crm/product/detail.vue web-admin/src/views/m/crm/product/categories.vue
|
||||
git commit -m "$(cat <<'EOF'
|
||||
feat(web-admin): wire product pages to scheme A/B confirm dialogs.
|
||||
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 4: DOM / 源码契约测试
|
||||
|
||||
**Files:**
|
||||
- Create: `web-admin/scripts/test-mp-crm-product-confirm-dom.mjs`
|
||||
|
||||
- [ ] **Step 1: 写契约脚本**
|
||||
|
||||
```js
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
|
||||
const root = new URL('../src/views/m/crm/product/', import.meta.url)
|
||||
const util = await readFile(new URL('../src/utils/mp-crm-product-confirm.ts', import.meta.url), 'utf8')
|
||||
const scss = await readFile(new URL('product.scss', root), 'utf8')
|
||||
const list = await readFile(new URL('index.vue', root), 'utf8')
|
||||
const detail = await readFile(new URL('detail.vue', root), 'utf8')
|
||||
const categories = await readFile(new URL('categories.vue', root), 'utf8')
|
||||
|
||||
assert.match(util, /kind: 'danger'/, 'helper 必须支持 danger')
|
||||
assert.match(util, /mp-product-dialog--danger/, 'helper 必须带 danger className')
|
||||
assert.match(util, /#dc2626/, '删除确认色必须为危险红')
|
||||
assert.match(util, /#0a9f6d/, '普通确认色必须为三墙绿')
|
||||
assert.doesNotMatch(util, /round-button/, '禁止 round-button 主题')
|
||||
assert.doesNotMatch(util, /#10b981/, '禁止 Fresh Mint')
|
||||
|
||||
assert.match(scss, /body \.van-dialog\.mp-product-dialog/, 'scss 必须限定产品 Dialog')
|
||||
assert.match(scss, /mp-product-dialog--danger/, 'scss 必须覆盖危险确认键')
|
||||
assert.match(scss, /mp-product-dialog__warn-icon/, 'scss 必须有警示图标')
|
||||
assert.doesNotMatch(scss, /#10b981/, 'scss 禁止 Fresh Mint')
|
||||
|
||||
for (const [name, src] of [
|
||||
['index', list],
|
||||
['detail', detail],
|
||||
['categories', categories]
|
||||
]) {
|
||||
assert.match(src, /showProductConfirmDialog/, `${name} 必须使用 showProductConfirmDialog`)
|
||||
assert.doesNotMatch(src, /showConfirmDialog\s*\(/, `${name} 不得直接调用 showConfirmDialog`)
|
||||
}
|
||||
|
||||
assert.match(list, /kind:\s*'danger'/, '列表删除必须 danger')
|
||||
assert.match(list, /kind:\s*'default'/, '列表上下架必须 default')
|
||||
assert.match(detail, /kind:\s*'danger'/, '详情删除必须 danger')
|
||||
assert.match(detail, /kind:\s*'default'/, '详情上下架必须 default')
|
||||
assert.match(categories, /kind:\s*'danger'/, '分类删除必须 danger')
|
||||
assert.match(categories, /删除分类/, '分类删除标题须为删除分类')
|
||||
|
||||
console.log('mp-crm-product-confirm-dom: ok')
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 跑脚本**
|
||||
|
||||
```bash
|
||||
cd web-admin && node scripts/test-mp-crm-product-confirm-dom.mjs
|
||||
```
|
||||
|
||||
Expected: `mp-crm-product-confirm-dom: ok`
|
||||
|
||||
- [ ] **Step 3: 再跑 helper 单测**
|
||||
|
||||
```bash
|
||||
cd web-admin && node --import tsx --test src/utils/mp-crm-product-confirm.test.ts
|
||||
```
|
||||
|
||||
Expected: PASS
|
||||
|
||||
- [ ] **Step 4: Commit**
|
||||
|
||||
```bash
|
||||
git add web-admin/scripts/test-mp-crm-product-confirm-dom.mjs
|
||||
git commit -m "$(cat <<'EOF'
|
||||
test(web-admin): add product confirm dialog source contract checks.
|
||||
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 5: 图谱更新 + 手工验收清单
|
||||
|
||||
**Files:**
|
||||
- 无业务代码(跑脚本)
|
||||
|
||||
- [ ] **Step 1: 更新前端图谱**
|
||||
|
||||
```bash
|
||||
./scripts/update-graph.sh frontend
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 手工验收(本地 WebView / H5)**
|
||||
|
||||
1. 产品列表点「删除」→ 警示图标 + 红「确认删除」+ 横排;取消不删。
|
||||
2. 产品列表点「下架」→ 绿「确认」+ 横排;无红、无警示图标。
|
||||
3. 产品详情删除 / 上下架同上。
|
||||
4. 产品分类删除 → 标题「删除分类」、方案 B。
|
||||
5. 与 Demo 方案 A/B 目视一致;无纵向堆叠。
|
||||
|
||||
- [ ] **Step 3: 若图谱有 diff 则提交**
|
||||
|
||||
```bash
|
||||
git add web-admin/graphify-out/
|
||||
git commit -m "$(cat <<'EOF'
|
||||
chore: update web-admin graphify after product confirm dialog.
|
||||
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
(无变更则跳过)
|
||||
|
||||
---
|
||||
|
||||
## Spec coverage checklist
|
||||
|
||||
| Spec 要求 | Task |
|
||||
|-----------|------|
|
||||
| 删除 = B(红 + 警示) | Task 1–3 |
|
||||
| 上下架 = A(绿) | Task 1–3 |
|
||||
| 分类删除 = B | Task 3 |
|
||||
| 横排、禁 round-button | Task 1–2 |
|
||||
| className 限定防误伤 | Task 1–2 |
|
||||
| Demo 对齐 | Task 2 + Task 5 手工 |
|
||||
| 禁 `#10b981` | Task 4 契约 |
|
||||
| 验收标准 | Task 5 |
|
||||
Reference in new issue
Block a user