Files
happy-life-star/docs/superpowers/specs/2026-06-23-remove-mock-data-from-profile-and-script-library-design.md

82 lines
2.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
author: Peanut
created_at: 2026-06-23
purpose: 去除编辑资料页默认昵称和剧本列表中的 mock/兜底数据
---
# 去除编辑资料页与剧本列表中的 mock/兜底数据
## 背景
项目代码中存在两处违反「禁止 mock 与兜底规则」的问题:
1. 编辑资料页面(`mini-program/src/pages/onboarding/index.vue`)顶部预览卡片在没有昵称时,默认显示假名「Zoey」。
2. 剧本列表页面(`mini-program/src/pages/main/ScriptLibraryView.vue`)在 `store.scripts` 为空时,使用 `fallbackScripts` 数组展示 6 条写死 demo 数据;同时多个工具函数在无数据时返回固定的默认标签、字数、日期、进度等假值。
## 目标
- 没有昵称时,编辑资料页面顶部显示「未设置昵称」。
- 剧本列表没有数据时,不显示任何假数据,直接展示空状态。
- 清理剧本列表工具函数中的兜底默认值,确保「没有就是没有」。
## 改动点
### 1. 编辑资料页昵称空状态
**文件**`mini-program/src/pages/onboarding/index.vue:22`
**修改前**
```vue
<text class="hero-name">{{ form.nickname || 'Zoey' }}</text>
```
**修改后**
```vue
<text class="hero-name">{{ form.nickname || '未设置昵称' }}</text>
```
### 2. 剧本列表删除 mock 数据与兜底值
**文件**`mini-program/src/pages/main/ScriptLibraryView.vue`
#### 2.1 删除 `fallbackScripts` 数组
删除第 178249 行的 `fallbackScripts` 常量及其 6 条 demo 数据。
#### 2.2 修改 `scripts` computed
**修改前**
```javascript
const scripts = computed(() => {
const list = store.scripts || []
return list.length ? list : fallbackScripts
})
```
**修改后**
```javascript
const scripts = computed(() => store.scripts || [])
```
#### 2.3 清理工具函数默认值
| 函数 | 修改前 | 修改后 |
|---|---|---|
| `getTags` | `return [script.style || '逆袭成长', '都市', '事业', '热血']` | `return []` |
| `getWordCount` | `if (!count) return '3.1万字'` | 删除该分支,直接走后续逻辑(返回 `'0字'` |
| `getDateText` | 各分支使用 `|| '2025.05.10'``|| '2025.05.08'``|| '今天 21:30'` | 去掉兜底日期,返回空字符串 `''` |
| `getProgress` | `Number(script.progress || 28)` | `Number(script.progress || 0)` |
| `getChapterCount` | `script.chapterCount || script.chapters || Math.max(1, Math.round((script.wordCount || 30000) / 4500))` | `script.chapterCount || script.chapters || 0` |
## 验证标准
1. 进入编辑资料页面,昵称输入框为空时,顶部预览卡片显示「未设置昵称」。
2. 剧本列表为空时,页面显示「还没有人生剧本」空状态,不展示任何 demo 剧本。
3. 剧本列表中的真实剧本数据展示不受影响(有数据时仍正常显示标题、标签、字数、日期、进度等)。
4. H5 模式下浏览器 Console 无新增报错。
5. 运行 `npm run build:h5` 编译通过。