feat: 对接真实数据并移除前端假数据

本次提交完成多模块真实数据对接,移除前端硬编码假数据:
- 新增后端接口:区域列表、未读消息数、详情页评价列表、最低提现金额
- 前端对应修改:移除首页/列表/详情页硬编码区域选项、未读消息数、评价内容,分销页最低提现金额
- 修复登录页微信授权不伪造code、营业执照不伪造文件名,避免绕过校验
- 新增集成测试用例,验证真实数据对接正确性
这个提交包含在:
2026-10-19 11:48:41 +08:00
父节点 63fdfe87d7
当前提交 81a48feaad
共有 25 个文件被更改,包括 383 次插入 和 40 次删除

查看文件

@@ -16,7 +16,7 @@ class Distribution extends V1
{
/**
* D1 分销概览
* GET /api/v1/distribution/overview → {totalCommission,settled,withdrawable,todayCommission,teamCount,l1Count,l2Count,inviteCode,posterUrl}
* GET /api/v1/distribution/overview → {totalCommission,settled,withdrawable,todayCommission,teamCount,l1Count,l2Count,inviteCode,posterUrl,minWithdraw}
*/
public function overview()
{
@@ -48,6 +48,8 @@ class Distribution extends V1
'l2Count' => $l2,
'inviteCode' => (string)$ext['invite_code'],
'posterUrl' => '',
// 最低提现金额(后台「分销设置」下发,替代前端写死的 50)
'minWithdraw' => (float)$this->cfg('dist.minWithdraw', 50),
]);
}

查看文件

@@ -11,6 +11,7 @@ use think\Db;
* GET /api/v1/home/categories H2 分类导航
* GET /api/v1/home/search/hot H3 热门搜索
* GET /api/v1/home/feed H4 信息流(支持 lat/lng + sort=nearby 距离排序)
* GET /api/v1/home/areas H5 区域列表(用户端下拉筛选,读后台「区域管理」)
*/
class Home extends V1
{
@@ -81,6 +82,26 @@ class Home extends V1
$this->ok(array_values($keywords));
}
/**
* H5 区域列表(用户端筛选用)
* GET /api/v1/home/areas → [string]
* 规则:仅 enabled=1,按 sort asc;与后台「区域管理」(fc_area) 同源,
* 前端首页/信息列表/发布页的「区域」选项均由此下发,不再前端写死。
*/
public function areas()
{
$rows = Db::name('fc_area')
->where('enabled', 1)
->order('sort asc')
->select();
$list = [];
foreach ($rows as $row) {
$list[] = (string)$row['name'];
}
$this->ok($list);
}
/**
* H4 信息流
* GET /api/v1/home/feed {categoryId?,keyword?,area?,sort?,lat?,lng?,page,size}

查看文件

@@ -9,6 +9,7 @@ use think\Db;
* 路由:
* GET /api/v1/message/list M1 消息列表
* POST /api/v1/message/:id/read M2 标记已读
* GET /api/v1/message/unread-count M3 未读消息数(首页角标)
*
* 说明:user_id=0 表示全体广播消息,用户可见。
*/
@@ -68,4 +69,23 @@ class Message extends V1
$this->ok(['read' => true]);
}
/**
* M3 未读消息数(首页消息角标)
* GET /api/v1/message/unread-count → {count}
* 规则:统计当前用户可见(user_id = 本人 或 0 广播)且 isread=0 的消息条数,
* 替代前端原先写死的角标数字。
*/
public function unreadCount()
{
$user = $this->auth();
$uid = (int)$user['id'];
$count = (int)Db::name('fc_message')
->where('user_id', 'in', [$uid, 0])
->where('isread', 0)
->count();
$this->ok(['count' => $count]);
}
}

查看文件

@@ -17,6 +17,7 @@ use think\Db;
* GET /api/v1/post/:id P5 信息详情
* POST /api/v1/post/:id/pay-view P6 付费查看联系方式
* POST /api/v1/post/:id/comment P7 发表评价
* GET /api/v1/post/:id/comments P10 评价列表(详情页「用户评价」)
*
* 计费口径(后台「发布与费用配置」维护,真源=fc_config);
* 金额一律由服务端按配置计算,**不接受客户端传入金额**;
@@ -809,6 +810,42 @@ class Post extends V1
$this->ok(['commentId' => $commentId]);
}
/**
* P10 评价列表(详情页「用户评价」)
* GET /api/v1/post/:id/comments → [{id,user,score,content,reply,createdAt}]
* 规则:仅 status=1(正常/审核通过)的评价;置顶优先,其余按时间倒序。
* 替代前端详情页原先写死的两条假评价。
*/
public function comments()
{
$id = $this->routeId();
if ($id <= 0) {
$this->fail('信息不存在', 404);
}
$rows = Db::name('fc_comment')->alias('co')
->join('user u', 'u.id = co.user_id', 'LEFT')
->where('co.post_id', $id)
->where('co.status', 1)
->field('co.id, co.score, co.content, co.reply, co.top, co.createtime, u.nickname AS nickname')
->order('co.top desc, co.id desc')
->select();
$list = [];
foreach ($rows as $row) {
$list[] = [
'id' => (int)$row['id'],
'user' => (string)$row['nickname'],
'score' => (int)$row['score'],
'content' => (string)$row['content'],
'reply' => (string)$row['reply'],
'createdAt' => $this->iso($row['createtime']),
];
}
$this->ok($list);
}
/**
* 读取路由 :id 参数(兼容 POST 体/查询串传入)
* @return int

查看文件

@@ -41,10 +41,12 @@ return [
'api/v1/home/categories' => 'api/Home/categories',
'api/v1/home/search/hot' => 'api/Home/hotKeywords',
'api/v1/home/feed' => 'api/Home/feed',
'api/v1/home/areas' => 'api/Home/areas',
/* =============== 三、用户端 · 信息发布与详情(长路径优先) =============== */
'api/v1/post/:id/pay-view' => 'api/Post/payView',
'api/v1/post/:id/comment' => 'api/Post/comment',
'api/v1/post/:id/comments' => 'api/Post/comments',
'api/v1/post/create' => 'api/Post/create',
'api/v1/post/mine' => 'api/Post/mine',
'api/v1/post/publish-config' => 'api/Post/publishConfig',
@@ -80,6 +82,7 @@ return [
/* =============== 六、用户端 · 消息中心(Module-MESSAGE) =============== */
'api/v1/message/list' => 'api/Message/list',
'api/v1/message/unread-count' => 'api/Message/unreadCount',
'api/v1/message/:id/read' => 'api/Message/read',
/* =============== 六·B、用户端 · 交易与支付(充值 / 微信支付 / 优惠券) ===============

二进制
docs/原始功能需求/1.png 普通文件

二进制文件未显示。

之后

宽度:  |  高度:  |  大小: 278 KiB

二进制
docs/原始功能需求/2.png 普通文件

二进制文件未显示。

之后

宽度:  |  高度:  |  大小: 199 KiB

二进制
docs/原始功能需求/3.png 普通文件

二进制文件未显示。

之后

宽度:  |  高度:  |  大小: 23 KiB

查看文件

@@ -11,8 +11,8 @@
| --- | --- | --- |
| **① 功能模块清单(PM)** | [`docs/01-产品功能模块清单.md`](docs/01-产品功能模块清单.md) | 用户端 + 后台管理端模块清单、优先级、业务规则、接口映射 |
| **② UI 设计规范(UI)** | [`docs/02-UI设计规范.md`](docs/02-UI设计规范.md) | 春绿设计令牌、排版、组件、动效规范 |
| **③ 接口文档(前后端)** | [`docs/03-接口文档.md`](docs/03-接口文档.md) | 73 个接口(用户端 41 + 后台 32)字段级契约 + Mock 兜底机制 + 联调清单 |
| **④ 全链路测试报告(QA)** | [`docs/04-全链路测试用例与报告.md`](docs/04-全链路测试用例与报告.md) | 167 条用例、15 步 E2E、15 个缺陷记录与修复 |
| **③ 接口文档(前后端)** | [`docs/03-接口文档.md`](docs/03-接口文档.md) | 75 个接口(用户端 43 + 后台 32)字段级契约 + Mock 兜底机制 + 联调清单 |
| **④ 全链路测试报告(QA)** | [`docs/04-全链路测试用例与报告.md`](docs/04-全链路测试用例与报告.md) | 179 条用例、15 步 E2E、15 个缺陷记录与修复 |
## 二、目录结构
@@ -44,7 +44,7 @@ fenleixinxi/
│ ├── api/ # auth/home/post/member/distribution/message/favorite/report/order/pay/coupon/setting/admin
│ ├── constants/report.js # 举报原因字典(report.js,v1.1.0)
│ ├── assets/ # 图标注册表(icons.js)+ 轮播取图与主题护栏(banners.js)
│ ├── mock/ # 77 条 mock 路由 + 数据集(离线可跑)
│ ├── mock/ # 79 条 mock 路由 + 数据集(离线可跑)
│ ├── constants/ui.js # 状态/图标映射
│ └── store/index.js # 轻量全局状态
├── static/ # 74 枚图标 + 3 张轮播插画(banners/)+ LOGO
@@ -152,7 +152,7 @@ sh tests/run.sh
# 等价于依次执行:
# 1) node tests/validate.mjs 项目结构校验(路由/.vue 标签/SCSS 括号/import 依赖)
# 2) node tools/check-scss.cjs 用 dart-sass 编译全部 SCSS
# 3) node tests/run.mjs 全链路接口测试(167 例)
# 3) node tests/run.mjs 全链路接口测试(179 例)
```
## 七、设计主色调(春绿 · Spring Green)
@@ -186,10 +186,11 @@ node tools/preview-theme.mjs --render # 首页仿真 + 全量令牌色板;
```
[1/3] 项目结构校验 : 错误 0,警告 0
[2/3] SCSS 编译校验 : 通过 19 个,失败 0(dart-sass)
[3/3] 全链路接口测试 : 用例总数 167 通过 167 失败 0 (通过率 100%)
[3/3] 全链路接口测试 : 用例总数 179 通过 179 失败 0 (通过率 100%)
—— 含 配图完整性与后台自定义闭环 16 例 + 轮播配图与主题护栏 17 例
—— 含 v1.0.7 新增:我的发布 / 发布配置与计费 / 后台置顶闭环 14 例
—— 含 v1.1.0 新增:支付 / 上传 / LBS / 收藏关注 / 举报 / 充值 / 优惠券 28 例
—— 含 v1.1.1 新增:真实数据对接回归 12 例(区域/未读/详情评价/最低提现/去 mock_code 等)
```
| 视觉资源 | 状态 |

查看文件

@@ -18,6 +18,8 @@ export const homeApi = {
feed: (params = {}) => get('/home/feed', params, { silent: true }),
/** 热门搜索词 */
hotKeywords: () => get('/home/search/hot', {}, { silent: true }),
/** 区域列表(后台「区域管理」下发,供首页/列表/发布页筛选项使用) → [string] */
areas: () => get('/home/areas', {}, { silent: true }),
}
export default homeApi

查看文件

@@ -7,6 +7,8 @@ import { get, post } from '../utils/request.js'
export const messageApi = {
/** 消息列表(type: system / interact) */
list: (params = {}) => get('/message/list', params, { silent: true }),
/** 未读消息数(首页角标) → { count } */
unreadCount: () => get('/message/unread-count', {}, { silent: true }),
/** 标记已读 */
read: (id) => post(`/message/${id}/read`, {}, { silent: true }),
}

查看文件

@@ -63,6 +63,8 @@ export const postApi = {
payView: (id, payload) => post(`/post/${id}/pay-view`, payload, { silent: true }),
/** 发表评价(评分 + 图文) */
comment: (id, payload) => post(`/post/${id}/comment`, payload, { silent: true }),
/** 评价列表(详情页「用户评价」,替代前端写死的假评价) */
comments: (id) => get(`/post/${id}/comments`, {}, { silent: true }),
}
export default postApi

查看文件

@@ -242,6 +242,7 @@ export const datasets = {
l2Count: 16,
inviteCode: 'TC8A9K',
posterUrl: '',
minWithdraw: 50,
},
/** 分销团队 */

查看文件

@@ -188,6 +188,14 @@ export const mockRoutes = {
return ok(paginate(list, data && data.page, data && data.size))
},
'GET /home/search/hot': () => ok(datasets.hotKeywords),
// 区域列表:与后台「区域管理」同源,仅下发启用项并按 sort 升序(返回名称数组)
'GET /home/areas': () =>
ok(
datasets.areas
.filter((a) => a.enabled)
.sort((a, b) => (a.sort || 0) - (b.sort || 0))
.map((a) => a.name)
),
// ==================== 用户端 · 信息发布 ====================
'POST /post/upload': ({ data }) => {
@@ -359,6 +367,20 @@ export const mockRoutes = {
if (data.score && (data.score < 1 || data.score > 5)) fail('评分需在 1-5 之间')
return ok({ commentId: Date.now(), ...data })
},
// 评价列表(与后端 Post::comments 出参对齐:仅展示字段,按置顶+时间倒序)
'GET /post/:id/comments': ({ params }) =>
ok(
datasets.comments
.filter((c) => String(c.postId) === String(params.id))
.map((c) => ({
id: c.id,
user: c.user,
score: c.score,
content: c.content,
reply: c.reply,
createdAt: c.createdAt,
}))
),
// ==================== 用户端 · 会员中心 ====================
'GET /member/plans': () => ok(datasets.memberPlans),
@@ -547,6 +569,8 @@ export const mockRoutes = {
return ok(paginate(list, data && data.page, data && data.size))
},
'POST /message/:id/read': () => ok({ read: true }),
'GET /message/unread-count': () =>
ok({ count: datasets.messages.filter((m) => !m.read).length }),
// ==================== 后台管理端 · 数据总览 ====================
'GET /admin/dashboard/overview': () => ok(datasets.dashboard.overview),

查看文件

@@ -11,7 +11,8 @@ const state = reactive({
token: storage.get(config.storageKeys.token, ''),
userInfo: storage.get(config.storageKeys.userInfo, null),
userType: Number(storage.get(config.storageKeys.userType, config.constants.USER_TYPE.PERSON)),
unread: 2,
// 未读消息数由 /message/unread-count 实时拉取,不在此写死
unread: 0,
})
export const useUserStore = () => {

查看文件

@@ -4,7 +4,7 @@
> 网关地址:`https://fenleixinxi.gzyakj.com.cn/api`
> 版本前缀:`/api/v1`
> 版本:v1.0.0 编制日期:2026-10-15(v1.1.0 增补日期:2026-10-17)
> **接口总数:73 条**(用户端 41 + 后台 32,以 `application/route.php` 实际登记条目为准;v1.1.0 新增用户端 11 条)
> **接口总数:76 条**(用户端 44 + 后台 32,以 `application/route.php` 实际登记条目为准;v1.1.0 新增用户端 11 条)
---
@@ -91,6 +91,7 @@
| GET | `/home/categories` | — | `[{ id, name, icon, color, count }]` |
| GET | `/home/feed` | `{ page, size, categoryId?, keyword?, area?, sort?, lat?, lng? }` | 分页 `list:[Post]`(含 `isTop`、`distance`) |
| GET | `/home/search/hot` | — | `[string]` |
| GET | `/home/areas` | — | `[string]`(仅启用区域,按 `sort` 升序;与后台「区域管理」同源) |
- `sort` 枚举:`new`(默认,按发布时间)/ `hot`(按浏览量)/ `price`(按价格升序)/ **`nearby`(v1.1.0,按距离升序)**
- **LBS 距离(v1.1.0)**:传入 `lat`/`lng`(gcj02,可与 `categoryId`/`keyword`/`area` 组合)后,列表项新增 `distance`(number|**km,一位小数**;请求未带坐标或信息未定位时为 `null`)。
@@ -121,6 +122,7 @@
| GET | `/post/{id}` | — | `Post`(含 `publisher`、`commentCount`、`lat`、`lng`、`distance`、`faved`、`followed`、`favoriteCount`、`media`) |
| POST | `/post/{id}/pay-view` | `{ payType: 'wxpay'\|'balance' }` | 微信:`{ order: { orderNo, amount, payType, status: 'pending' } }`;余额:`{ unlocked, contact: { phone, wechat } }` |
| POST | `/post/{id}/comment` | `{ score:1-5, content }` | `{ commentId }` |
| GET | `/post/{id}/comments` | — | `[{ id, user, score, content, reply, createdAt }]`(仅 `status=1`,置顶优先+时间倒序) |
**业务规则**:标题/内容必填;`payType` 仅支持 `wxpay`/`balance`;`score` 必须 1–5。
@@ -164,7 +166,7 @@
| 方法 | 路径 | 入参 | 返回 |
| --- | --- | --- | --- |
| GET | `/distribution/overview` | — | `{ totalCommission, settled, withdrawable, todayCommission, teamCount, l1Count, l2Count, inviteCode }` |
| GET | `/distribution/overview` | — | `{ totalCommission, settled, withdrawable, todayCommission, teamCount, l1Count, l2Count, inviteCode, minWithdraw }` |
| GET | `/distribution/team` | `{ level?, page, size }` | 分页 `[{ id, nickname, level, performance, commission, joinedAt }]` |
| POST | `/distribution/withdraw` | `{ amount, channel }` | `{ withdrawNo, status }` |
| GET | `/distribution/withdraw-records` | — | `[{ withdrawNo, amount, status, createdAt }]` |
@@ -176,6 +178,7 @@
| 方法 | 路径 | 入参 | 返回 |
| --- | --- | --- | --- |
| GET | `/message/list` | `{ type: 'system'\|'interact', page, size }` | 分页 `[{ id, type, title, content, read, createdAt }]` |
| GET | `/message/unread-count` | — | `{ count }`(当前用户可见且未读的消息数,驱动首页角标) |
| POST | `/message/{id}/read` | — | `{ read: true }` |
### 2.7 交易与支付(v1.1.0)`common/api/{order,pay,coupon}.js`
@@ -348,7 +351,7 @@ LOGO = logo(后台自定义) || '/static/logo.png'(内置)
| 真实请求失败(超时/断网)且 `enableMockFallback = true` | 自动降级到同名 mock 路由 |
| mock 无匹配路由 | 抛出原始网络异常 |
- Mock 路由表:`common/mock/index.js`(**77 条**路由,覆盖上表全部接口,含 v1.0.7 的 `/post/mine`、`/post/publish-config`、服务端定价模拟,v1.0.8 的 `/auth/wx-phone`,以及 v1.1.0 的 `/post/upload`、`/report`、`/favorite/*`、`/follow/toggle`、`/order/recharge`、`/pay/*`、`/coupon/*` 与 `home/feed` 的 LBS)
- Mock 路由表:`common/mock/index.js`(**80 条**路由,覆盖上表全部接口,含 v1.0.7 的 `/post/mine`、`/post/publish-config`、服务端定价模拟,v1.0.8 的 `/auth/wx-phone`,以及 v1.1.0 的 `/post/upload`、`/report`、`/favorite/*`、`/follow/toggle`、`/order/recharge`、`/pay/*`、`/coupon/*` 与 `home/feed` 的 LBS;另含真实数据对接新增的 `/home/areas`、`/message/unread-count`、`/post/:id/comments`)
- Mock 数据集:`common/mock/data.js`
- 切换真实后端:确保 `common/config/index.js` 中 `forceMock = false`、`enableMockFallback = false`(生产建议关闭降级以暴露真实问题)

查看文件

@@ -12,7 +12,7 @@
| 项 | 说明 |
| --- | --- |
| 被测对象 | ① 统一请求层 `common/utils/request.js` ② API 模块 `common/api/*.js`(认证/首页/发布/会员/分销/消息/收藏/举报/订单/支付/优惠券/设置/后台) ③ Mock 路由表 `common/mock`(作为接口契约参照) ④ 工具函数 `common/utils/format.js` |
| 覆盖接口 | `application/route.php` 实际 **73 条**路由(用户端 41 + 后台 32);Mock 路由表 **77 条** |
| 覆盖接口 | `application/route.php` 实际 **76 条**路由(用户端 44 + 后台 32);Mock 路由表 **80 条** |
| 测试层级 | 单元(工具/请求层)→ 集成(API 模块 ↔ Mock 契约)→ 端到端(用户端 8 步 + 后台端 7 步业务闭环) |
| 测试手段 | 断言响应结构、业务规则拦截、异常分支、分页边界、精度校验 |
| 缺陷判定 | 用例失败即缺陷;已发现并修复 15 个缺陷(详见第五章) |
@@ -310,17 +310,17 @@
```
=========== 全链路接口测试报告 ===========
用例总数: 167 通过: 167 失败: 0
用例总数: 179 通过: 179 失败: 0
🎉 全部用例通过,前后端接口契约与业务规则校验一致。
```
| 指标 | 数值 |
| --- | --- |
| 用例总数 | 167(原 139 + v1.1.0 新增 28) |
| 通过 | 167 |
| 用例总数 | 179(原 167 + 真实数据对接新增 12) |
| 通过 | 179 |
| 失败 | 0 |
| 通过率 | **100%** |
| 覆盖接口 | `route.php` 73 条路由(用户端 41 + 后台 32);Mock 路由表 77 条 |
| 覆盖接口 | `route.php` 76 条路由(用户端 44 + 后台 32);Mock 路由表 80 条 |
| 覆盖业务规则 | 16 / 16(BR-01 ~ BR-16,含 v1.1.0 新增 BR-16 折扣计价) |
| 内置配图完整性 | 74 / 74(PNG 魔数 + 透明通道 + 尺寸一致) |
| 轮播配图完整性 | 3 / 3(192×192 + 真实透明 + 白色插画 + 合计 6.0KB) |

查看文件

@@ -62,6 +62,7 @@
<script>
import { useUserStore } from '@/common/store/index.js'
import authApi from '@/common/api/auth.js'
import postApi from '@/common/api/post.js'
import config from '@/common/config/index.js'
import { iconUrl, logoUrl, loadUiConfig, uiState } from '@/common/store/ui.js'
@@ -70,7 +71,9 @@ export default {
return {
statusBarHeight: 20,
userType: config.constants.USER_TYPE.PERSON,
// license 仅用于展示文件名;licenseTemp 保存本地临时路径,登录拿到 token 后再上传
license: '',
licenseTemp: '',
loading: false,
// 微信资料(可选):昵称 + 头像临时路径(登录拿到 token 后再上传落库)
nickname: '',
@@ -107,18 +110,20 @@ export default {
uni.chooseImage({
count: 1,
success: (res) => {
const f = (res.tempFilePaths && res.tempFilePaths[0]) || 'license.jpg'
this.license = String(f).split('/').pop()
const f = (res.tempFilePaths && res.tempFilePaths[0]) || ''
if (!f) return
// 保存本地临时路径,登录后上传为持久化 URL;显示仅取文件名
this.licenseTemp = f
this.license = String(f).split('/').pop() || '营业执照'
uni.showToast({ title: '已选择资质文件', icon: 'none' })
},
fail: () => {
this.license = '营业执照.jpg'
},
// 用户取消选择:不伪造文件名(原先会写入假的「营业执照.jpg」,可绕过资质校验)
fail: () => {},
})
},
async onLogin() {
if (this.loading) return
if (this.userType === config.constants.USER_TYPE.BUSINESS && !this.license) {
if (this.userType === config.constants.USER_TYPE.BUSINESS && !this.licenseTemp && !this.license) {
uni.showToast({ title: '商家用户请先上传营业执照', icon: 'none' })
return
}
@@ -140,7 +145,14 @@ export default {
if (this.nickname || this.pendingAvatar) {
await store.fetchProfile()
}
const res = await store.switchType(this.userType, this.license)
// 商家营业执照:登录拿到 token 后把本地图片上传为可持久化 URL,再提交资质认证
let license = this.license
if (this.userType === config.constants.USER_TYPE.BUSINESS && this.licenseTemp) {
const up = await postApi.uploadMedia(this.licenseTemp, 'image')
license = (up && up.url) || ''
if (!license) throw new Error('营业执照上传失败,请重试')
}
const res = await store.switchType(this.userType, license)
uni.showToast({ title: res.needAudit ? '已提交资质,等待审核' : '登录成功', icon: 'none' })
setTimeout(() => {
uni.reLaunch({ url: '/pages/index/index' })
@@ -152,18 +164,21 @@ export default {
}
},
getWxCode() {
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
const fail = () => reject(new Error('微信授权失败,请重试'))
try {
if (typeof uni !== 'undefined' && uni.login) {
uni.login({
provider: 'weixin',
success: (r) => resolve(r.code || 'mock_code'),
fail: () => resolve('mock_code'),
success: (r) => (r && r.code ? resolve(r.code) : fail()),
fail,
})
return
}
} catch (e) {}
resolve('mock_code')
// 非微信小程序环境(H5/Node)无 uni.login,无法换取真实 code:
// 不再伪造 'mock_code'(否则线上所有失败用户会派生到同一个 openid 账号)
fail()
})
},
/** 选择微信头像(官方组件回调,返回的是本地临时文件) */

查看文件

@@ -239,10 +239,13 @@ export default {
try {
const res = await postApi.detail(this.id)
this.post = res
this.comments = [
{ id: 5001, user: '小王同学', score: 5, content: '联系很及时,沟通顺畅。', reply: '' },
{ id: 5002, user: '果果', score: 4, content: '信息真实,价格合理。', reply: '感谢支持~' },
]
// 用户评价:来自后端 /post/:id/comments(原先写死两条假评价)
try {
const cs = await postApi.comments(this.id)
this.comments = Array.isArray(cs) ? cs : []
} catch (e) {
this.comments = []
}
this.contact = { phone: maskPhone(res.contact), wechat: '' }
// 契约:详情出参已带 faved/followed,先用返回值回显;
// 兼容旧后端:缺失时再用 /favorite/status 批量回显。
@@ -327,8 +330,12 @@ export default {
}
try {
await postApi.comment(this.id, { score: this.score, content: this.commentText })
this.comments.unshift({ id: Date.now(), user: '我', score: this.score, content: this.commentText, reply: '' })
this.commentText = ''
// 重新拉取评价列表,确保展示后台真实数据(含昵称)
try {
const cs = await postApi.comments(this.id)
this.comments = Array.isArray(cs) ? cs : this.comments
} catch (e) {}
this.showComment = false
uni.showToast({ title: '评价成功', icon: 'none' })
} catch (e) {

查看文件

@@ -132,6 +132,7 @@ export default {
level: 0,
showWithdraw: false,
withdrawAmount: '',
// 最低提现金额由后台「分销设置」经 /distribution/overview 下发(加载前用 50 兜底)
minWithdraw: 50,
levelTabs: [
{ label: '全部', value: 0 },
@@ -159,6 +160,10 @@ export default {
this.overview = overview
this.team = team.list
this.records = records
// 最低提现金额以后台配置为准(未下发时保持默认 50)
if (overview && overview.minWithdraw != null) {
this.minWithdraw = Number(overview.minWithdraw) || 0
}
} catch (e) {
uni.showToast({ title: '分销数据加载失败', icon: 'none' })
}
@@ -195,6 +200,10 @@ export default {
uni.showToast({ title: '请输入正确的提现金额', icon: 'none' })
return
}
if (this.minWithdraw > 0 && amount < this.minWithdraw) {
uni.showToast({ title: `最低提现 ¥${this.minWithdraw}`, icon: 'none' })
return
}
try {
await distributionApi.withdraw({ amount, channel: 'wxpay' })
this.showWithdraw = false

查看文件

@@ -7,7 +7,7 @@
<image class="fc-logo fc-logo--sm" :src="logoUrl()" mode="aspectFit" />
<view class="home__location" @click="onLocation">
<image class="fc-icon fc-icon--sm" :src="iconUrl('home-location')" mode="aspectFit" />
<text class="home__location-text fc-ellipsis">{{ location }}</text>
<text class="home__location-text fc-ellipsis">{{ location || '当前定位' }}</text>
<text class="home__location-arrow">▾</text>
</view>
<view class="home__msg" @click="go('/pages/message/index')">
@@ -77,8 +77,8 @@
<view class="home__vip-left">
<image class="fc-icon fc-icon--md" :src="iconUrl('home-crown')" mode="aspectFit" />
<view class="home__vip-texts">
<text class="home__vip-title">{{ isMember ? '会员权益已生效' : '开通会员,发布 8 折' }}</text>
<text class="home__vip-sub">{{ isMember ? '每日免费查看 20 条联系方式' : '超值月卡 ¥19.9 起' }}</text>
<text class="home__vip-title">{{ vipTitle }}</text>
<text class="home__vip-sub">{{ vipSub }}</text>
</view>
</view>
<view class="home__vip-btn">{{ isMember ? '查看权益' : '立即开通' }}</view>
@@ -142,6 +142,8 @@ import FcPostCard from '@/components/fc-post-card/fc-post-card.vue'
import FcTabbar from '@/components/fc-tabbar/fc-tabbar.vue'
import FcEmpty from '@/components/fc-empty/fc-empty.vue'
import homeApi from '@/common/api/home.js'
import memberApi from '@/common/api/member.js'
import messageApi from '@/common/api/message.js'
import { useUserStore } from '@/common/store/index.js'
import { iconUrl, logoUrl, categoryIconUrl, loadUiConfig } from '@/common/store/ui.js'
import { bannerArtUrl, bannerHasValue, bannerBg } from '@/common/assets/banners.js'
@@ -151,8 +153,9 @@ export default {
data() {
return {
statusBarHeight: 20,
location: '贵阳 · 观山湖区',
unread: 2,
// 顶栏定位文案:由真实定位/区域选择驱动,不再写死具体区(原为「贵阳 · 观山湖区」)
location: '',
unread: 0,
banners: [],
categories: [],
list: [],
@@ -165,7 +168,11 @@ export default {
lat: null,
lng: null,
showAreaPicker: false,
areaOptions: ['云岩区', '南明区', '观山湖区', '花溪区'],
// 区域选项由后台「区域管理」下发(/home/areas),不再前端写死
areaOptions: [],
// 会员权益 / 套餐(/member/benefits、/member/plans),用于下方会员引导条
benefits: {},
plans: [],
sorts: [
{ label: '最新', value: 'new' },
{ label: '最热', value: 'hot' },
@@ -182,6 +189,24 @@ export default {
return false
}
},
/** 会员引导条主标题:折扣文案来自 /member/benefits(无则退回通用文案) */
vipTitle() {
if (this.isMember) return '会员权益已生效'
const discount = this.benefits && this.benefits.postDiscount
return discount ? `开通会员,发布${discount}` : '开通会员,享专属特权'
},
/** 会员引导条副标题:免费查看条数来自 /member/benefits,价格取 /member/plans 最低价 */
vipSub() {
if (this.isMember) {
const freeView = Number(this.benefits && this.benefits.freeView)
return freeView > 0 ? `每日免费查看 ${freeView} 条联系方式` : '尊享会员专属权益'
}
const prices = (this.plans || [])
.map((p) => Number(p.price))
.filter((n) => n > 0)
const min = prices.length ? Math.min.apply(null, prices) : 0
return min > 0 ? `超值月卡 ¥${min} 起` : '超值会员权益,立即开通'
},
},
onLoad() {
try {
@@ -198,6 +223,8 @@ export default {
// 必须重启小程序才生效,表现为「后台改了前端不变」。
onShow() {
loadUiConfig(true)
// 登录状态可能在别处变化(如从登录页返回),回首页时同步未读角标
this.loadUnread()
},
onPullDownRefresh() {
this.page = 1
@@ -229,9 +256,49 @@ export default {
} catch (e) {
console.warn('首页基础数据加载失败', e)
}
// 区域 / 会员引导 / 未读角标:各自静默加载,任一失败都不阻塞首页
this.loadAreas()
this.loadMemberCard()
this.loadUnread()
await this.fetchFeed(true)
this.loading = false
},
/** 区域选项(后台「区域管理」下发) */
async loadAreas() {
try {
const areas = await homeApi.areas()
if (Array.isArray(areas) && areas.length) this.areaOptions = areas
} catch (e) {}
},
/** 会员权益与套餐(首页会员引导条) */
async loadMemberCard() {
try {
const [benefits, plans] = await Promise.all([memberApi.benefits(), memberApi.plans()])
this.benefits = benefits || {}
this.plans = Array.isArray(plans) ? plans : []
} catch (e) {}
},
/**
* 未读消息数(首页消息角标)。
* /message/unread-count 需要登录态,未登录时直接置 0,
* 避免走 request.js 的 401 处理把游客强制跳转到登录页。
*/
async loadUnread() {
let logged = false
try {
logged = !!useUserStore().isLogin.value
} catch (e) {}
if (!logged) {
this.unread = 0
return
}
try {
const res = await messageApi.unreadCount()
this.unread = Number((res && res.count) || 0)
} catch (e) {
this.unread = 0
}
},
/**
* 取用户坐标(gcj02,与后端 LBS 口径一致)。
* 失败静默降级:不弹提示、不阻塞首页,仅本次请求不带 lat/lng。

查看文件

@@ -148,6 +148,8 @@ export default {
return {
categories: [],
drafts: [],
// 区域选项由后台「区域管理」下发(/home/areas),用于定位失败时的兜底选择
areas: [],
submitting: false,
uploading: false,
draftTimer: null,
@@ -271,6 +273,11 @@ export default {
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
}
// 区域选项(后台「区域管理」下发),失败静默 —— 仅兜底定位失败时使用
try {
const areas = await homeApi.areas()
if (Array.isArray(areas) && areas.length) this.areas = areas
} catch (e) {}
this.loadPublish()
},
/** 读取后台发布的「发布模式 / 价格 / 我的剩余额度」 */
@@ -358,10 +365,15 @@ export default {
this.autoSave()
},
fail: () => {
// 定位/选点失败时,用后台下发的区域列表兜底手选
if (!this.areas.length) {
uni.showToast({ title: '暂无可选区域,请填写详细地址', icon: 'none' })
return
}
uni.showActionSheet({
itemList: ['云岩区', '南明区', '观山湖区', '花溪区'],
itemList: this.areas,
success: (r) => {
this.form.address = ['云岩区', '南明区', '观山湖区', '花溪区'][r.tapIndex]
this.form.address = this.areas[r.tapIndex]
this.autoSave()
},
fail: () => {},

查看文件

@@ -75,7 +75,8 @@ export default {
sort: 'new',
area: '',
showArea: false,
areaOptions: ['云岩区', '南明区', '观山湖区', '花溪区'],
// 区域选项由后台「区域管理」下发(/home/areas)
areaOptions: [],
sorts: [
{ label: '最新', value: 'new' },
{ label: '最热', value: 'hot' },
@@ -103,6 +104,11 @@ export default {
try {
this.categories = await homeApi.categories()
} catch (e) {}
// 区域筛选项:后台「区域管理」下发,失败静默(不影响信息流)
try {
const areas = await homeApi.areas()
if (Array.isArray(areas) && areas.length) this.areaOptions = areas
} catch (e) {}
this.fetch(true)
},
async fetch(reset = false) {

查看文件

@@ -0,0 +1,107 @@
/**
* 真实数据对接回归(消除前端写死的假数据)
*
* 覆盖:
* ① GET /home/areas —— 区域选项由后台「区域管理」下发
* ② GET /message/unread-count —— 首页消息角标由后端未读数驱动
* ③ GET /distribution/overview —— 最低提现金额由后台「分销设置」下发
* ④ 源码断言:登录不再伪造 mock_code / 营业执照假文件名;首页不再写死会员文案、角标与区域
*/
import fs from 'node:fs'
import path from 'node:path'
import url from 'node:url'
import { describe, it, expect } from './harness.mjs'
import { homeApi, messageApi, distributionApi, postApi } from '../common/api/index.js'
import { datasets } from '../common/mock/data.js'
const ROOT = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..')
const read = (p) => fs.readFileSync(path.join(ROOT, p), 'utf8')
describe('对接 · 区域选项来自后台', () => {
it('GET /home/areas 仅返回启用区域,按 sort 升序', async () => {
const areas = await homeApi.areas()
expect(areas).toBeArray()
const enabled = datasets.areas
.filter((a) => a.enabled)
.sort((a, b) => a.sort - b.sort)
.map((a) => a.name)
expect(areas).toEqual(enabled)
expect(areas).toContain('云岩区')
})
})
describe('对接 · 首页未读角标来自后台', () => {
it('GET /message/unread-count 返回未读消息数', async () => {
const res = await messageApi.unreadCount()
expect(res.count).toBe(datasets.messages.filter((m) => !m.read).length)
})
})
describe('对接 · 最低提现金额来自后台', () => {
it('GET /distribution/overview 含 minWithdraw', async () => {
const res = await distributionApi.overview()
expect(res.minWithdraw).toBeDefined()
expect(res.minWithdraw).toBe(50)
})
})
describe('对接 · 详情页评价来自后台', () => {
it('GET /post/:id/comments 仅返回该信息的评价', async () => {
const list = await postApi.comments(101)
expect(list).toBeArray()
const expected = datasets.comments.filter((c) => String(c.postId) === '101')
expect(list.length).toBe(expected.length)
if (list.length) {
expect(list[0].user).toBe(expected[0].user)
expect(list[0].content).toBe(expected[0].content)
}
})
it('详情页不再写死假评价', () => {
const src = read('pages/detail/detail.vue')
expect(src.includes("user: '小王同学'")).toBe(false)
expect(src.includes("user: '果果'")).toBe(false)
})
})
describe('去假数据 · 源码断言', () => {
it('登录页不再伪造微信 code(mock_code)', () => {
const src = read('pages/auth/login.vue')
expect(src.includes("resolve('mock_code')")).toBe(false)
expect(src.includes("r.code || 'mock_code'")).toBe(false)
})
it('登录页不再伪造营业执照文件名', () => {
expect(read('pages/auth/login.vue').includes("license = '营业执照.jpg'")).toBe(false)
})
it('首页不再写死会员文案与未读角标', () => {
const src = read('pages/index/index.vue')
expect(src.includes('每日免费查看 20 条联系方式')).toBe(false)
expect(src.includes('超值月卡 ¥19.9 起')).toBe(false)
expect(src.includes('unread: 2')).toBe(false)
})
it('首页区域选项不再写死', () => {
expect(read('pages/index/index.vue').includes("['云岩区', '南明区', '观山湖区', '花溪区']")).toBe(false)
})
it('首页不再写死定位区名', () => {
expect(read('pages/index/index.vue').includes("location: '贵阳 · 观山湖区'")).toBe(false)
})
it('信息列表区域选项不再写死', () => {
expect(read('pages/post/list.vue').includes("['云岩区', '南明区', '观山湖区', '花溪区']")).toBe(false)
})
it('首页未读角标调用前有登录态守卫,避免游客被 401 跳登录页', () => {
const src = read('pages/index/index.vue')
// loadUnread 内部必须先判断 isLogin,再调用需要鉴权的接口
const body = src.slice(src.indexOf('async loadUnread()'))
const guardAt = body.indexOf('isLogin')
const callAt = body.indexOf('messageApi.unreadCount()')
expect(guardAt).toBeGreaterThan(-1)
expect(callAt).toBeGreaterThan(-1)
expect(guardAt < callAt).toBe(true)
})
})

查看文件

@@ -15,5 +15,6 @@ await import('./api.admin.contract.test.mjs')
await import('./publish.test.mjs')
await import('./e2e.flow.test.mjs')
await import('./v110.test.mjs')
await import('./integration.test.mjs')
await run()