docs(audit): add mock-data and unimplemented APIs
Add two audit reports covering static mock data residue and hidden/unimplemented interfaces and logic.
This commit is contained in:
+344
@@ -0,0 +1,344 @@
|
||||
# 隐蔽未实现接口与逻辑清单
|
||||
|
||||
本报告聚焦于"看起来已实现、实际未接通或存在断层"的功能点。这些问题在 mock 演示阶段不易察觉,切换真实后端后会表现为数据丢失、页面空态、交互无效等事故。
|
||||
|
||||
与第一份报告(《静态模拟数据残留审计报告》)互补,本报告不再重复 mock 数据源、store 初始化、伪 API 层等已知问题。
|
||||
|
||||
---
|
||||
|
||||
## 一、登录态与持久化缺失
|
||||
|
||||
### 1.1 记住登录状态 — 纯展示控件
|
||||
|
||||
登录页渲染了"记住登录状态"复选框,但该控件未被表单注册,无任何读取或写入逻辑。
|
||||
|
||||
| 位置 | 内容 |
|
||||
| ------------------------------ | -------------------------------------------------------------------------- |
|
||||
| `app/(auth)/login/page.tsx:86` | `<Checkbox id="remember" />` — 未绑定 `register("remember")` 或 `useState` |
|
||||
|
||||
### 1.2 登录态无持久化 — 刷新即丢
|
||||
|
||||
全仓库未发现 `localStorage`、`sessionStorage`、`cookie` 写入,也未使用 `zustand/middleware` 的 `persist`。`store/auth.ts` 的 `login()` 仅写内存态,页面刷新后回到未登录状态。
|
||||
|
||||
**影响**:切真实后端后,如果前端仍依赖 Zustand 内存态判断登录,刷新会导致用户被踢出。
|
||||
|
||||
---
|
||||
|
||||
## 二、身份与实体模型错位
|
||||
|
||||
### 2.1 当前用户与店铺/打手 ID 不匹配 — 后台大面积空态
|
||||
|
||||
登录固定为 `mockUsers[0]`(id=`u1`),但 mock 数据中的店铺 owner 是 `u10`/`u11`/`u12`,打手是 `u5`/`u6` 起。
|
||||
|
||||
| 位置 | 内容 |
|
||||
| -------------------------------------- | ---------------------------------------------- |
|
||||
| `lib/mock/users.ts:119` | `currentUser = mockUsers[0]` — 固定 `u1` |
|
||||
| `lib/mock/shops.ts:7` 起 | 店铺 owner 为 `u10`、`u11`、`u12` |
|
||||
| `lib/mock/players.ts:7` 起 | 打手 user 从 `u5` 开始 |
|
||||
| `lib/domain/resolve-current-shop.ts:5` | `shops.find(shop => shop.owner.id === userId)` |
|
||||
|
||||
**结果**:用户切换到店主身份后,`resolveOwnerShop` 始终返回 `null`,以下页面全部显示"当前账号没有可管理的店铺":
|
||||
|
||||
- `app/(dashboard)/dashboard/shop/employees/page.tsx:67`
|
||||
- `app/(dashboard)/dashboard/shop/rules/page.tsx:29`
|
||||
- `app/(dashboard)/dashboard/shop/income/page.tsx:28`
|
||||
- `app/(dashboard)/dashboard/shop/page.tsx` 同理
|
||||
- `app/(dashboard)/dashboard/shop/templates/page.tsx` 同理
|
||||
- `app/(dashboard)/dashboard/shop/orders/page.tsx` 同理
|
||||
|
||||
### 2.2 打手主页链接指向不存在的打手
|
||||
|
||||
导航栏在 player 身份下跳转 `/player/${user.id}`(`components/header.tsx:88`),但 `user.id` 是 `u1`,`mockPlayers` 中没有 id 为 `u1` 的打手,会触发 `notFound()`(`app/(main)/player/[id]/page.tsx:25`)。
|
||||
|
||||
---
|
||||
|
||||
## 三、用户动作无持久化 — 刷新即回退
|
||||
|
||||
以下交互在前端有即时反馈,但数据仅存在于 Zustand 内存态,刷新页面或换设备后全部丢失。
|
||||
|
||||
### 3.1 点赞
|
||||
|
||||
| 位置 | 行为 |
|
||||
| --------------------------------------- | --------------------------------------------------------------------- |
|
||||
| `components/post-like-button.tsx:21-32` | 调用 `togglePostLike` → `store/posts.ts:50-61` 本地翻转 `liked` 并 ±1 |
|
||||
|
||||
### 3.2 评论
|
||||
|
||||
| 位置 | 行为 |
|
||||
| ------------------------------------- | ------------------------------------------------ |
|
||||
| `components/post-comments.tsx:29-52` | 调用 `addComment` → `store/comments.ts` 本地追加 |
|
||||
| `components/post-comment-count.tsx:3` | 读 `useCommentStore` 本地计数 |
|
||||
|
||||
### 3.3 收藏
|
||||
|
||||
| 位置 | 行为 |
|
||||
| -------------------------------------- | ----------------------------------------------------- |
|
||||
| `components/favorite-button.tsx:29-33` | 调用 `toggleFavorite` → `store/favorites.ts` 本地增删 |
|
||||
|
||||
### 3.4 通知已读
|
||||
|
||||
| 位置 | 行为 |
|
||||
| -------------------------------------- | ----------------------------------------------------------------------- |
|
||||
| `app/(account)/notifications/page.tsx` | 调用 `markAsRead` / `markAllAsRead` → `store/notifications.ts` 本地标记 |
|
||||
| `components/header.tsx:81-83` | 未读数通过 `.filter(n => !n.read).length` 本地计算 |
|
||||
|
||||
### 3.5 设置保存
|
||||
|
||||
| 位置 | 行为 |
|
||||
| --------------------------------- | ---------------------------------------------------- |
|
||||
| `app/(account)/settings/page.tsx` | 昵称、简介、通知偏好等修改仅写 `useAuthStore` 内存态 |
|
||||
|
||||
---
|
||||
|
||||
## 四、上传功能 — 占位或 Object URL
|
||||
|
||||
所有"上传"操作要么是纯占位 UI,要么使用 `URL.createObjectURL` 生成本地临时链接,刷新后失效。
|
||||
|
||||
### 4.1 头像上传
|
||||
|
||||
| 位置 | 行为 |
|
||||
| ------------------------------------ | ------------------------------------------------------------- |
|
||||
| `app/(account)/settings/page.tsx:75` | `setAvatar(URL.createObjectURL(file))` — 本地预览,无上传请求 |
|
||||
|
||||
### 4.2 聊天图片发送
|
||||
|
||||
| 位置 | 行为 |
|
||||
| ------------------------------------ | --------------------------------------------------------------------------------- |
|
||||
| `app/(order)/chat/[id]/page.tsx:152` | `sendImageMessage(session.id, URL.createObjectURL(file))` — blob URL 作为消息内容 |
|
||||
|
||||
### 4.3 争议证据上传
|
||||
|
||||
| 位置 | 行为 |
|
||||
| --------------------------------------- | ------------------------------------------------------------------------------- |
|
||||
| `app/(order)/dispute/[id]/page.tsx:88` | `URL.createObjectURL(file)` 生成预览,提交时传入 store |
|
||||
| `app/(order)/dispute/[id]/page.tsx:102` | `URL.revokeObjectURL` 移除时释放 — 说明开发者意识到了临时性,但未替换为真实上传 |
|
||||
|
||||
### 4.4 身份认证证明材料 — 纯占位
|
||||
|
||||
| 位置 | 行为 |
|
||||
| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `app/(account)/verify/page.tsx:170-181` | 三个 `<div>` 占位块(身份证正面/反面/游戏截图),有 `cursor-pointer` 样式但无 `<input type="file">`、无 `onClick`、无状态绑定 |
|
||||
|
||||
### 4.5 发帖图片 — 假计数 + 固定路径
|
||||
|
||||
| 位置 | 行为 |
|
||||
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `app/(main)/post/new/page.tsx:46` | `imageCount` 状态仅做数字加减 |
|
||||
| `app/(main)/post/new/page.tsx:84` | 提交时 `images: Array.from({ length: imageCount }).map(() => "/posts/p1-1.jpg")` — 无论"上传"几张,全部指向同一张固定图片 |
|
||||
|
||||
---
|
||||
|
||||
## 五、客户端与服务端数据隔离
|
||||
|
||||
部分页面是 Server Component(或在服务端执行的函数),通过 `lib/api/*` 读取数据;而写入操作发生在客户端 Zustand store。在 Next.js 的 SSR/RSC 模式下,服务端无法读取客户端 store 的最新状态。
|
||||
|
||||
### 5.1 发帖 → 帖子详情
|
||||
|
||||
| 写入 | 读取 |
|
||||
| ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
|
||||
| `app/(main)/post/new/page.tsx:79` → `store/posts.ts:44` (client) | `app/(main)/post/[id]/page.tsx:17` → `lib/api/posts.ts:10` → `usePostStore.getState()` (server?) |
|
||||
|
||||
### 5.2 店铺模板保存 → 店铺主页
|
||||
|
||||
| 写入 | 读取 |
|
||||
| ----------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
||||
| `app/(dashboard)/dashboard/shop/templates/page.tsx:120` → `store/shops.ts` (client) | `app/(main)/shop/[id]/page.tsx:29` → `shop.templateConfig.sections` (server) |
|
||||
|
||||
### 5.3 服务发布 → 打手详情页
|
||||
|
||||
| 写入 | 读取 |
|
||||
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `app/(dashboard)/dashboard/services/new/page.tsx:132` → `store/services.ts` (client) | `app/(main)/player/[id]/page.tsx:29-32` — 优先读 `player.services`(mock 内嵌数据),仅当为空时才 fallback 到 `listServicesByPlayer` |
|
||||
|
||||
**特别注意**:打手详情页的 `player.services && player.services.length > 0` 判断(`app/(main)/player/[id]/page.tsx:30`)意味着只要 mock 数据中打手自带了 services,新发布的服务就永远不会显示。这是一个数据遮蔽问题,不仅仅是隔离问题。
|
||||
|
||||
---
|
||||
|
||||
## 六、纯前端筛选/排序/统计
|
||||
|
||||
以下逻辑在前端内存中对全量数据做 filter/sort/slice,mock 阶段数据量小时体验正常,接后端引入分页、权限、跨端一致性后会出现偏差。
|
||||
|
||||
### 6.1 社区列表 — 内存排序与筛选
|
||||
|
||||
| 位置 | 行为 |
|
||||
| ------------------------------------- | ---------------------------------------------------------- |
|
||||
| `app/(main)/community/page.tsx:22-34` | 全量 `posts.filter().sort()` 实现"最新/最热"和游戏标签筛选 |
|
||||
|
||||
### 6.2 订单列表 — 内存角色过滤 + Tab 过滤
|
||||
|
||||
| 位置 | 行为 |
|
||||
| ------------------------------------ | ----------------------------------------------------------------- |
|
||||
| `app/(order)/orders/page.tsx:91-103` | 先按 `consumerId/playerId/shopId` 过滤角色视角,再按 tab 过滤状态 |
|
||||
|
||||
### 6.3 管理后台概览 — 硬取首项 + 截断
|
||||
|
||||
| 位置 | 行为 |
|
||||
| --------------------------------------- | --------------------------------------------------------- |
|
||||
| `app/(dashboard)/dashboard/page.tsx:17` | `listPlayers()[0]` — 始终取第一个打手的数据作为"我的"数据 |
|
||||
| `app/(dashboard)/dashboard/page.tsx:18` | `listShops()[0]` — 始终取第一个店铺 |
|
||||
| `app/(dashboard)/dashboard/page.tsx:19` | `listOrders().slice(0, 3)` — 最近订单截前 3 条 |
|
||||
|
||||
### 6.4 首页推荐 — 全量渲染
|
||||
|
||||
| 位置 | 行为 |
|
||||
| --------------------------- | ---------------------------------------------------------------------- |
|
||||
| `app/(main)/page.tsx:12-14` | `listPlayers()` / `listShops()` 全量获取后直接渲染,无推荐算法、无分页 |
|
||||
|
||||
### 6.5 收入统计 — 正则匹配交易描述关联订单
|
||||
|
||||
| 位置 | 行为 |
|
||||
| ------------------------------------------------------ | -------------------------------------------------------------------- |
|
||||
| `app/(dashboard)/dashboard/shop/income/page.tsx:51-53` | `transaction.description.match(/ord[-\d]+/)` 从描述文本中提取订单 ID |
|
||||
|
||||
**风险**:后端描述格式变化时,统计数据会静默丢失,不报错。应由后端提供结构化的 `orderId` 字段。
|
||||
|
||||
---
|
||||
|
||||
## 七、消息列表未按用户过滤
|
||||
|
||||
| 位置 | 行为 |
|
||||
| -------------------------------------- | ----------------------------------------------------------- |
|
||||
| `app/(order)/chat/page.tsx:12` | `sessions` 直接全量渲染,未过滤当前用户是否为参与者 |
|
||||
| `app/(order)/chat/page.tsx:21-23` | 仅用 `participant.id !== userId` 找"对方",但不排除无关会话 |
|
||||
| `app/(order)/chat/[id]/page.tsx:52-59` | 会话详情页才做参与者校验 |
|
||||
|
||||
**结果**:列表页会展示当前用户不参与的会话,点进去才提示无权查看。
|
||||
|
||||
---
|
||||
|
||||
## 八、店铺规则 — 可保存但不执行
|
||||
|
||||
### 8.1 规则字段仅做展示
|
||||
|
||||
| 字段 | 保存位置 | 执行位置 |
|
||||
| ------------------------------------ | ----------------------------------------------------------------- | ----------------------------------------------------- |
|
||||
| `allowMultiShop` | `app/(dashboard)/dashboard/shop/rules/page.tsx:50` → `updateShop` | 无 — 未发现任何校验逻辑 |
|
||||
| `allowIndependentOrders` | 同上 | 无 — 未发现任何校验逻辑 |
|
||||
| `dispatchMode` | 同上 | `store/orders.ts:407` — 仅影响前端自动派单模拟 |
|
||||
| `commissionType` / `commissionValue` | 同上 | `lib/domain/income.ts:22-31` — 仅影响前端收入计算展示 |
|
||||
|
||||
### 8.2 员工邀请 — 无校验直接重绑定
|
||||
|
||||
| 位置 | 行为 |
|
||||
| --------------------------------------------------------- | --------------------------------------------------------- |
|
||||
| `app/(dashboard)/dashboard/shop/employees/page.tsx:74-79` | 点击"邀请打手"直接调用 `assignToShop` + `playerCount + 1` |
|
||||
| `store/players.ts:13-17` | `assignToShop` 仅修改 `shopId`/`shopName` 字段,无校验 |
|
||||
|
||||
**缺失**:未检查打手是否已属于其他店铺、是否符合 `allowMultiShop` 规则、是否需要打手同意。
|
||||
|
||||
### 8.3 公告编辑 — `window.prompt` 无审计
|
||||
|
||||
| 位置 | 行为 |
|
||||
| --------------------------------------------- | ------------------------------------------ |
|
||||
| `app/(dashboard)/dashboard/shop/page.tsx:157` | `window.prompt("", announcement)` 编辑公告 |
|
||||
| `app/(dashboard)/dashboard/shop/page.tsx:175` | `window.prompt("", "")` 新增公告 |
|
||||
|
||||
---
|
||||
|
||||
## 九、社区列表的点赞/评论入口缺失
|
||||
|
||||
| 位置 | 行为 |
|
||||
| --------------------------------------- | -------------------------------------------------------------- |
|
||||
| `app/(main)/community/page.tsx:145-154` | 点赞和评论图标是 `<span>` 内的纯展示元素,无 `onClick`,无链接 |
|
||||
|
||||
帖子详情页(`components/post-like-button.tsx`、`components/post-comments.tsx`)有完整的点赞和评论交互,但社区列表页的卡片上这些图标仅做数字展示,用户无法在列表页直接操作。
|
||||
|
||||
---
|
||||
|
||||
## 十、置顶/精选 — 有字段和展示,无操作入口
|
||||
|
||||
| 位置 | 内容 |
|
||||
| ----------------------------------- | ------------------------------------------------------------------------------------------- |
|
||||
| `lib/types.ts:177` | `Post` 类型定义 `pinned: boolean` |
|
||||
| `lib/mock/posts.ts:17` 等 | mock 帖子中有 `pinned: true` |
|
||||
| `app/(main)/community/page.tsx:104` | 展示 `<Pin>` 图标 |
|
||||
| `store/posts.ts:40` | `createPost` 强制 `pinned: false` |
|
||||
| `store/posts.ts:17-22` | store 接口仅有 `createPost` / `togglePostLike` / `incrementCommentCount`,无 pin/unpin 方法 |
|
||||
|
||||
`PLAN.md:141` 规划了"用户自己置顶,最多 N 条",但目前无任何操作路径可以改变 `pinned` 状态。
|
||||
|
||||
---
|
||||
|
||||
## 十一、关注与推送 — 文案存在,实现缺席
|
||||
|
||||
### 11.1 关注
|
||||
|
||||
| 位置 | 内容 |
|
||||
| ------------------------------------- | ------------------------------- |
|
||||
| `PLAN.md:9` | "消费者可以收藏/关注打手或店铺" |
|
||||
| `app/(account)/settings/page.tsx:234` | 通知偏好文案"点赞、评论、关注" |
|
||||
|
||||
全仓库未发现 `follow`/`关注` 相关的 store、api、页面动作。
|
||||
|
||||
### 11.2 浏览器推送
|
||||
|
||||
| 位置 | 内容 |
|
||||
| ------------- | ------------------------------- |
|
||||
| `PLAN.md:216` | "站内通知 + 用户可选浏览器推送" |
|
||||
|
||||
全仓库未发现 `Notification.requestPermission`、`serviceWorker`、`PushSubscription`、`pushManager` 等 Web Push 相关代码。现有通知体系仅为本地生成 + 本地已读。
|
||||
|
||||
---
|
||||
|
||||
## 十二、硬编码展示值
|
||||
|
||||
这些数值直接写在 JSX 中,不来自任何 store 或 API 计算。
|
||||
|
||||
| 位置 | 内容 |
|
||||
| --------------------------------------- | -------------------------------------------------------- |
|
||||
| `app/(account)/wallet/page.tsx:154` | `¥1,280.00`(本月收入) |
|
||||
| `app/(account)/wallet/page.tsx:158` | `¥320.00`(待结算) |
|
||||
| `app/(account)/wallet/page.tsx:162` | `¥5,400.00`(已提现) |
|
||||
| `app/(dashboard)/dashboard/page.tsx:79` | `¥12,800`(店主本月收入) |
|
||||
| `app/(auth)/layout.tsx:4-8` | `12,000+` 认证打手 / `98.6%` 好评率 / `50,000+` 完成订单 |
|
||||
| `app/(order)/dispute/[id]/page.tsx:377` | UI 文案含"模拟处理结果"字样 |
|
||||
|
||||
---
|
||||
|
||||
## 十三、未使用的基础设施
|
||||
|
||||
### 13.1 `requestWithAuth` — 定义未调用
|
||||
|
||||
| 位置 | 内容 |
|
||||
| --------------------- | ----------------------------------------------- |
|
||||
| `lib/api/client.ts:9` | 定义了 `requestWithAuth<T>(executor, options?)` |
|
||||
| 全仓库 | `rg "requestWithAuth("` 命中 0 处调用 |
|
||||
|
||||
### 13.2 `usePlayerStatusStore` — 定义未调用
|
||||
|
||||
| 位置 | 内容 |
|
||||
| --------------------------- | ----------------------------------------------------------- |
|
||||
| `store/player-status.ts:11` | 定义了 `usePlayerStatusStore`,含 `statuses` 和 `setStatus` |
|
||||
| 全仓库 | `rg "usePlayerStatusStore"` 仅命中定义处 |
|
||||
|
||||
`PLAN.md:107` 规划了"打手有并发接单上限,搜索结果和打手详情页展示'可接单/忙碌'状态",该 store 疑似为此功能的未完成基础设施。
|
||||
|
||||
---
|
||||
|
||||
## 迁移优先级建议
|
||||
|
||||
### P0 — 上线前必须解决(数据安全/业务正确性)
|
||||
|
||||
1. 登录态持久化(刷新丢失 = 用户无法正常使用)
|
||||
2. 身份与实体 ID 对齐(否则后台全部空态)
|
||||
3. 所有用户写入动作接入后端持久化(点赞/评论/收藏/设置/通知已读)
|
||||
4. 上传功能替换为真实文件上传(头像/聊天图片/争议证据/认证材料/发帖图片)
|
||||
5. 移除 UI 中的"模拟"字样(`dispute/[id]/page.tsx:377`)
|
||||
|
||||
### P1 — 切后端时必须改造(数据一致性)
|
||||
|
||||
6. 消息列表按当前用户过滤会话
|
||||
7. 筛选/排序/统计改为后端分页查询(社区/订单/首页推荐/收入统计)
|
||||
8. 打手详情页移除 `player.services` 优先读取逻辑,统一从服务列表查询
|
||||
9. 店铺规则执行逻辑落地(`allowMultiShop`/`allowIndependentOrders` 校验)
|
||||
10. 员工邀请增加校验流程
|
||||
11. 收入统计改用结构化字段关联订单
|
||||
|
||||
### P2 — 功能补齐或明确下线
|
||||
|
||||
12. 记住登录状态功能实现或移除控件
|
||||
13. 置顶/精选操作入口
|
||||
14. 关注功能
|
||||
15. 浏览器推送
|
||||
16. 打手在线状态(`usePlayerStatusStore` 接入或移除)
|
||||
17. 公告编辑替换 `window.prompt` 为正式表单
|
||||
+260
@@ -0,0 +1,260 @@
|
||||
# 静态模拟数据残留审计报告
|
||||
|
||||
## 总体结论
|
||||
|
||||
项目当前没有任何真实后端 HTTP 请求。全仓库仅 1 处 `fetch(`(`lib/api/search.ts:34`),请求的是本地 Next.js Route `/api/search`,而该 Route 本身也以 mock 数据为源。`@tanstack/react-query` 的 `QueryClientProvider` 已挂载(`app/providers.tsx`),但全仓库 0 处 `useQuery`/`useMutation` 调用。无 `.env` 文件,无 mock/real 环境切换开关。
|
||||
|
||||
---
|
||||
|
||||
## 一、静态实体数据源 `lib/mock/*.ts`
|
||||
|
||||
15 个文件,定义了全部业务实体的硬编码数组,是整个模拟体系的根:
|
||||
|
||||
| 文件 | 导出 | 实体类型 |
|
||||
| ------------------------------ | --------------------------------------- | ------------ |
|
||||
| `lib/mock/users.ts:3` | `mockUsers: User[]` | 用户 |
|
||||
| `lib/mock/users.ts:119` | `currentUser = mockUsers[0]` | 当前登录用户 |
|
||||
| `lib/mock/games.ts:3` | `mockGames: Game[]` | 游戏 |
|
||||
| `lib/mock/services.ts:3` | `mockServices: PlayerService[]` | 陪玩服务 |
|
||||
| `lib/mock/players.ts:5` | `mockPlayers: Player[]` | 打手 |
|
||||
| `lib/mock/shops.ts:4` | `mockShops: Shop[]` | 店铺 |
|
||||
| `lib/mock/orders.ts:4` | `mockOrders: Order[]` | 订单 |
|
||||
| `lib/mock/disputes.ts:3` | `mockDisputes: Dispute[]` | 争议 |
|
||||
| `lib/mock/reviews.ts:3` | `mockReviews: Review[]` | 评价 |
|
||||
| `lib/mock/posts.ts:4` | `mockPosts: Post[]` | 帖子 |
|
||||
| `lib/mock/comments.ts:4` | `mockComments: Comment[]` | 评论 |
|
||||
| `lib/mock/chat.ts:3` | `mockChatSessions: ChatSession[]` | 聊天会话 |
|
||||
| `lib/mock/chat.ts:95` | `mockChatMessages: ChatMessage[]` | 聊天消息 |
|
||||
| `lib/mock/favorites.ts:3` | `mockFavorites: Favorite[]` | 收藏 |
|
||||
| `lib/mock/notifications.ts:3` | `mockNotifications: Notification[]` | 通知 |
|
||||
| `lib/mock/transactions.ts:3` | `mockTransactions: WalletTransaction[]` | 交易流水 |
|
||||
| `lib/mock/transactions.ts:139` | `walletBalance = 275` | 钱包余额 |
|
||||
|
||||
聚合出口:`lib/mock/index.ts`
|
||||
|
||||
---
|
||||
|
||||
## 二、Store 层 — mock 初始化 + 前端本地状态机
|
||||
|
||||
12 个 Zustand store 全部以 mock 数据初始化,运行时在前端内存中增删改查并生成 ID/时间戳:
|
||||
|
||||
| Store 文件 | 初始化行 | mock 来源 |
|
||||
| --------------------------- | -------------------------------------------------------- | ------------------------------------------------------------ |
|
||||
| `store/shops.ts:14` | `shops: mockShops` | `mockShops` |
|
||||
| `store/players.ts:12` | `players: mockPlayers` | `mockPlayers` |
|
||||
| `store/services.ts:14` | `services: mockServices` | `mockServices` |
|
||||
| `store/orders.ts:315` | `orders: mockOrders` | `mockOrders` |
|
||||
| `store/disputes.ts:203` | `disputes: mockDisputes.map(asRecord)` | `mockDisputes` |
|
||||
| `store/reviews.ts:51` | `reviews: mockReviews` | `mockReviews` + `mockUsers`(:24) |
|
||||
| `store/posts.ts:25` | `posts: mockPosts` | `mockPosts` |
|
||||
| `store/comments.ts:13` | `comments: mockComments` | `mockComments` |
|
||||
| `store/chat.ts:23-24` | `sessions: mockChatSessions, messages: mockChatMessages` | `mockChatSessions` + `mockChatMessages` + `mockUsers`(:15) |
|
||||
| `store/favorites.ts:14` | `favorites: mockFavorites` | `mockFavorites` |
|
||||
| `store/notifications.ts:21` | `notifications: mockNotifications` | `mockNotifications` |
|
||||
| `store/wallet.ts:20-21` | `balance: walletBalance, transactions: mockTransactions` | `walletBalance` + `mockTransactions` |
|
||||
|
||||
所有 store 还通过 `generateId()` 在前端本地生成实体 ID(`store/orders.ts:318,350`、`store/services.ts:21`、`store/wallet.ts:29,45,71,102,132`、`store/disputes.ts:231` 等),切后端后 ID 应由服务端分配。
|
||||
|
||||
---
|
||||
|
||||
## 三、伪 API 层 `lib/api/*.ts`
|
||||
|
||||
15 个模块名义上是 API 层,实际全部是同步读写本地 store 或直接返回 mock:
|
||||
|
||||
| 文件 | 实际行为 | 风险 |
|
||||
| ---------------------------- | -------------------------------------------------- | --------------------------- |
|
||||
| `lib/api/users.ts:1,4,8,12` | 直接 `import { currentUser, mockUsers }` 并 return | 高 — 直接返回 mock |
|
||||
| `lib/api/games.ts:1,4,8` | 直接 `import { mockGames }` 并 return | 高 — 直接返回 mock |
|
||||
| `lib/api/orders.ts:11` | `useOrderStore.getState().orders` | 中 — 读本地 store |
|
||||
| `lib/api/services.ts:4` | `useServiceStore.getState().services` | 中 — 读本地 store |
|
||||
| `lib/api/players.ts:4` | `usePlayerStore.getState().players` | 中 — 读本地 store |
|
||||
| `lib/api/shops.ts:4` | `useShopStore.getState().shops` | 中 — 读本地 store |
|
||||
| `lib/api/posts.ts:7` | `usePostStore.getState().posts` | 中 — 读写本地 store |
|
||||
| `lib/api/comments.ts:8` | `useCommentStore.getState().comments` | 中 — 读写本地 store |
|
||||
| `lib/api/chat.ts:6` | `useChatStore.getState().sessions` | 中 — 读写本地 store |
|
||||
| `lib/api/favorites.ts:4` | `useFavoriteStore.getState().favorites` | 中 — 读本地 store |
|
||||
| `lib/api/notifications.ts:7` | `useNotificationStore.getState().notifications` | 中 — 读写本地 store |
|
||||
| `lib/api/transactions.ts:4` | `useWalletStore.getState().transactions` | 中 — 读本地 store |
|
||||
| `lib/api/reviews.ts:6` | `useReviewStore.getState().reviews` | 中 — 读写本地 store |
|
||||
| `lib/api/disputes.ts:6` | `useDisputeStore.getState().disputes` | 中 — 读写本地 store |
|
||||
| `lib/api/search.ts:34` | `fetch('/api/search?...')` | 唯一 fetch,但后端仍是 mock |
|
||||
| `lib/api/client.ts:9` | `requestWithAuth` 仅包装执行器做未登录拦截 | 无网络请求 |
|
||||
|
||||
---
|
||||
|
||||
## 四、唯一 HTTP 链路 — 搜索
|
||||
|
||||
```
|
||||
lib/api/search.ts:34 → fetch(`/api/search?${params}`)
|
||||
app/api/search/route.ts:1 → import { mockPlayers, mockServices, mockShops } from "@/lib/mock"
|
||||
app/api/search/route.ts:51 → players: mockPlayers, shops: mockShops, services: mockServices
|
||||
```
|
||||
|
||||
搜索是项目里唯一走了 HTTP 请求的链路,但 Next.js Route Handler 的数据源仍然是 mock。
|
||||
|
||||
---
|
||||
|
||||
## 五、前端状态自动推进(Demo 定时器)
|
||||
|
||||
这是切后端时事故概率最高的部分 — 前端 `setTimeout` 自动推进业务状态,真实后端应由服务端事件驱动。
|
||||
|
||||
**定时常量:**
|
||||
```
|
||||
lib/config/demo-timers.ts:1 ORDER_ACCEPT_TIMEOUT_MS = 30_000
|
||||
lib/config/demo-timers.ts:2 ORDER_CLOSE_TIMEOUT_MS = 30_000
|
||||
lib/config/demo-timers.ts:3 ORDER_REVIEW_TIMEOUT_MS = 30_000
|
||||
lib/config/demo-timers.ts:5 DISPUTE_TO_REVIEWING_MS = 5_000
|
||||
lib/config/demo-timers.ts:6 DISPUTE_TO_RESOLVED_MS = 10_000
|
||||
```
|
||||
|
||||
**订单自动流转:**
|
||||
| 位置 | 行为 |
|
||||
| ------------------------- | ------------------------------------------------------------------------------------------------------------ |
|
||||
| `store/orders.ts:172-206` | `scheduleOrderTimeout` — 订单进入 pending_accept/pending_close/pending_review 后启动 setTimeout 自动超时流转 |
|
||||
| `store/orders.ts:405-413` | 自动派单模拟 — 当店铺 `dispatchMode === "auto"` 时,`setTimeout(3000)` 自动调用 `acceptOrder` |
|
||||
|
||||
**争议自动推进:**
|
||||
| 位置 | 行为 |
|
||||
| --------------------------- | ----------------------------------------------------------------------------------- |
|
||||
| `store/disputes.ts:142-163` | `setTimeout(DISPUTE_TO_REVIEWING_MS)` — 自动将争议从 open → reviewing |
|
||||
| `store/disputes.ts:165-197` | `setTimeout(DISPUTE_TO_RESOLVED_MS)` — 自动将争议从 reviewing → resolved 并回写订单 |
|
||||
|
||||
---
|
||||
|
||||
## 六、认证/表单流程模拟
|
||||
|
||||
| 位置 | 行为 |
|
||||
| ---------------------------------------- | --------------------------------------------------------------------------------------- |
|
||||
| `app/(auth)/login/page.tsx:35-36` | `await new Promise(r => setTimeout(r, 500))` + `login(getCurrentUserForLogin(), ...)` |
|
||||
| `app/(auth)/register/page.tsx:50-51` | 同上 |
|
||||
| `components/login-dialog.tsx:44-45` | 同上 |
|
||||
| `app/(auth)/forgot-password/page.tsx:27` | `await new Promise(r => setTimeout(r, 500))` + toast |
|
||||
| `app/(account)/verify/page.tsx:41-52` | `submitWithMockApproval` — 提交认证后 `setTimeout(3000)` 自动调用 `approveVerification` |
|
||||
|
||||
`getCurrentUserForLogin()` 最终来自 `lib/api/users.ts:12` → `lib/mock/users.ts:119` 的 `currentUser = mockUsers[0]`,即无论输入什么账号密码,登录的永远是同一个硬编码用户。
|
||||
|
||||
---
|
||||
|
||||
## 七、硬编码展示值
|
||||
|
||||
| 位置 | 内容 |
|
||||
| --------------------------------------- | -------------------------------------------------------------------------- |
|
||||
| `app/(account)/wallet/page.tsx:154` | `¥1,280.00`(本月收入,写死) |
|
||||
| `app/(account)/wallet/page.tsx:158` | `¥320.00`(待结算,写死) |
|
||||
| `app/(account)/wallet/page.tsx:162` | `¥5,400.00`(已提现,写死) |
|
||||
| `app/(auth)/layout.tsx:4-8` | `12,000+` 认证打手 / `98.6%` 好评率 / `50,000+` 完成订单(营销数字,写死) |
|
||||
| `app/(order)/dispute/[id]/page.tsx:377` | UI 文案含"模拟处理结果"字样 |
|
||||
|
||||
---
|
||||
|
||||
## 八、页面数据源分类(34 个页面)
|
||||
|
||||
**Store Only(14 个)— 完全不经过 lib/api,直接读写 store:**
|
||||
```
|
||||
app/(account)/notifications/page.tsx
|
||||
app/(account)/settings/page.tsx
|
||||
app/(account)/verify/page.tsx [含 setTimeout 模拟]
|
||||
app/(account)/wallet/page.tsx
|
||||
app/(dashboard)/dashboard/services/page.tsx
|
||||
app/(dashboard)/dashboard/shop/employees/page.tsx
|
||||
app/(dashboard)/dashboard/shop/orders/page.tsx
|
||||
app/(dashboard)/dashboard/shop/page.tsx
|
||||
app/(dashboard)/dashboard/shop/rules/page.tsx
|
||||
app/(dashboard)/dashboard/shop/templates/page.tsx [含 setTimeout]
|
||||
app/(main)/post/new/page.tsx
|
||||
app/(order)/chat/page.tsx
|
||||
app/(order)/order/[id]/page.tsx
|
||||
app/(order)/orders/page.tsx
|
||||
```
|
||||
|
||||
**API + Store 混合(9 个)— 经过 lib/api 但 lib/api 本身也是读 store:**
|
||||
```
|
||||
app/(auth)/login/page.tsx [含 setTimeout 模拟登录]
|
||||
app/(auth)/register/page.tsx [含 setTimeout 模拟注册]
|
||||
app/(dashboard)/dashboard/page.tsx
|
||||
app/(dashboard)/dashboard/services/new/page.tsx
|
||||
app/(dashboard)/dashboard/shop/income/page.tsx
|
||||
app/(order)/chat/[id]/page.tsx
|
||||
app/(order)/dispute/[id]/page.tsx
|
||||
app/(order)/order/new/page.tsx [含 setTimeout]
|
||||
app/(order)/review/[id]/page.tsx
|
||||
```
|
||||
|
||||
**API Only(7 个)— 仅经过 lib/api,但 lib/api 底层仍是本地数据:**
|
||||
```
|
||||
app/(main)/page.tsx
|
||||
app/(main)/community/page.tsx
|
||||
app/(main)/player/[id]/page.tsx
|
||||
app/(main)/post/[id]/page.tsx
|
||||
app/(main)/search/page.tsx [唯一真正 fetch 的页面]
|
||||
app/(main)/shop/[id]/page.tsx
|
||||
app/(main)/user/[id]/page.tsx
|
||||
```
|
||||
|
||||
**无 API/Store(4 个)— 纯静态或纯前端模拟:**
|
||||
```
|
||||
app/(auth)/forgot-password/page.tsx [setTimeout 模拟]
|
||||
app/(main)/help/page.tsx [纯静态内容]
|
||||
app/(main)/privacy/page.tsx [纯静态内容]
|
||||
app/(main)/terms/page.tsx [纯静态内容]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 九、组件层直接读写业务 Store(绕过 lib/api)
|
||||
|
||||
除 `useAuthStore`/`useLoginDialogStore` 外,以下共享组件直接操作业务 store:
|
||||
|
||||
| 组件 | 直接引用的 store |
|
||||
| ------------------------------------- | ----------------------------------------------- |
|
||||
| `components/order-actions.tsx:14-16` | `useChatStore`, `useOrderStore`, `useShopStore` |
|
||||
| `components/favorite-button.tsx:6` | `useFavoriteStore` |
|
||||
| `components/post-like-button.tsx:5` | `usePostStore` |
|
||||
| `components/post-comments.tsx:5` | `useCommentStore` |
|
||||
| `components/post-comment-count.tsx:3` | `useCommentStore` |
|
||||
| `components/header.tsx:19-20` | `useNotificationStore`, `useShopStore` |
|
||||
|
||||
---
|
||||
|
||||
## 十、已排除项(确认不存在)
|
||||
|
||||
- 无 `.env` / `.env.local` / `.env.development` 等环境配置文件
|
||||
- 无 mock/real 环境切换开关(`NEXT_PUBLIC_*MOCK*`、`USE_MOCK` 等)
|
||||
- 无运行时 MSW 拦截代码(`msw` 仅作为 `@vitest/mocker` 的 peer dep 出现在 lockfile)
|
||||
- 无 `axios`、`axios-mock-adapter`、`json-server`、`miragejs` 使用
|
||||
- 无运行时 `.json` 文件作为数据源导入
|
||||
- 无 `Promise.resolve` 模拟异步返回
|
||||
- 无 Next.js `rewrites`/`redirects`/proxy 配置
|
||||
- `useQuery`/`useMutation`/`useSWR` 全仓库 0 处调用
|
||||
|
||||
---
|
||||
|
||||
## 十一、隐蔽未实现接口(更像真功能,实际仍在前端自转)
|
||||
|
||||
这些条目即使去掉了明显的 mock 字样,也会在切真实后端后造成严重偏差:UI 提示可用或可保存,实际没有任何可被后端接入的请求/数据契约/权限边界。
|
||||
|
||||
| 类型 | 现象 | 关键证据(单行) | 切后端后常见失败模式 |
|
||||
| ------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------- |
|
||||
| Client Store 与 Server Component 断层 | 管理页或发布页写入 Zustand 后,跳转到详情/公开页看不到改动 | `app/(main)/post/new/page.tsx:79`(createPost 写前端 store) / `app/(main)/post/[id]/page.tsx:17`(详情页从 server 侧读 getPostById) | 新创建内容在列表可见,详情页 404 或展示旧数据;店铺模板预览不反映保存结果 |
|
||||
| 图片/文件上传未落到接口 | 多处上传只生成本地 blob URL 或占位图,刷新或换设备即失效 | `app/(account)/settings/page.tsx:75`、`app/(order)/chat/[id]/page.tsx:152`、`app/(order)/dispute/[id]/page.tsx:88`、`app/(main)/post/new/page.tsx:84`、`app/(account)/verify/page.tsx:170` | 后端接入后出现上传缺字段、图片无法复现、消息图片仅本机可见 |
|
||||
| 会话列表未按参与者过滤 | 消息列表直接渲染全部会话,只在详情页才做参与者校验 | `app/(order)/chat/page.tsx:12` | 列表出现无关会话,后端接入时需要补齐按用户查询与分页 |
|
||||
| 店铺规则字段缺少业务约束 | 规则页可保存 allowMultiShop 等字段,员工邀请直接改归属,不存在申请/同意流 | `app/(dashboard)/dashboard/shop/rules/page.tsx:48` / `app/(dashboard)/dashboard/shop/employees/page.tsx:75` / `store/players.ts:13` | 规则与权限不生效,导致运营规则与实际行为脱节 |
|
||||
| 智能派单与流程推进为固定定时器 | 自动派单固定 3 秒自动接单;待接单/结单/评价自动超时推进;争议自动进入 reviewing/resolved | `store/orders.ts:186`、`store/orders.ts:408`、`store/disputes.ts:142` | 与真实状态机/消息队列/人工审核不一致,产生错误状态与资金流偏差 |
|
||||
| 交易明细与订单关联靠字符串解析 | 收入统计用正则从 transaction.description 里提取 ord id | `app/(dashboard)/dashboard/shop/income/page.tsx:51` | 后端字段结构化后该逻辑失效,统计漏算或误算 |
|
||||
| 身份切换与实体模型不对齐 | 登录永远是固定用户 u1(consumer),UI 允许切换到 player/owner;导航用 user.id 直接拼 player/shop 路由 | `app/(auth)/login/page.tsx:36` / `lib/mock/users.ts:119` / `components/header.tsx:85` / `lib/mock/players.ts:7` / `lib/mock/shops.ts:7` | 打手/店主页面长期空态或 404;店铺后台永远提示无可管理店铺 |
|
||||
| 看似走 API,实际仍为 mock | `/search` 会发起 fetch,但 `/api/search` 路由以 mockPlayers/mockShops/mockServices 作为数据源 | `lib/api/search.ts:34` / `app/api/search/route.ts:1` | 接真实后端时容易遗漏替换点,导致线上仍走假数据 |
|
||||
|
||||
---
|
||||
|
||||
## 复扫命令
|
||||
|
||||
后续持续监控可用以下 6 条命令覆盖主要信号:
|
||||
|
||||
```bash
|
||||
rg -n '@/lib/mock' app lib store components
|
||||
rg -n '\bfetch\(' app lib store components
|
||||
rg -n 'setTimeout\(' app lib store components
|
||||
rg -n 'from "@/store/' app components
|
||||
rg -n 'URL\.createObjectURL' app components
|
||||
rg -n 'window\.prompt' app
|
||||
```
|
||||
Reference in New Issue
Block a user