From 14c947c1f9ad96c763d6b67373895093b763c97c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?old=E6=98=93?= <156663459@qq.com> Date: Mon, 28 Jul 2025 15:08:25 +0800 Subject: [PATCH] ww --- mock-config.json | 184 ++++++++++++++++++++++++++++++++++++++--------- server.js | 10 +++ 2 files changed, 159 insertions(+), 35 deletions(-) diff --git a/mock-config.json b/mock-config.json index 93ee81b..af33b8c 100644 --- a/mock-config.json +++ b/mock-config.json @@ -760,10 +760,11 @@ { "method": "GET", "path": "/api/lesson/list", + "query": {"type": "1"}, "response": { "category": "推荐", "total": 4, - "items": [ + "data": [ { "id": "lesson001", "title": "隶属的古法用笔技巧", @@ -798,41 +799,154 @@ "learnCount": 6525 } ] - }, - "swagger": { - "summary": "获取课程学习列表", - "description": "返回推荐课程列表数据(包含课程封面、价格、节数、学习人数等)", - "responses": { - "200": { - "description": "课程数据", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "category": { "type": "string" }, - "total": { "type": "integer" }, - "items": { - "type": "array", - "items": { - "type": "object", - "properties": { - "id": { "type": "string" }, - "title": { "type": "string" }, - "image": { "type": "string" }, - "price": { "type": "number" }, - "chapterCount": { "type": "integer" }, - "learnCount": { "type": "integer" }, - "label": { "type": "string" } - } - } - } - } - } - } - } + } +}, +{ + "method": "GET", + "path": "/api/lesson/list", + "query": {"type": "2"}, + "response": { + "category": "手机电脑", + "total": 5, + "data": [ + { + "id": "lesson001", + "title": "4个设置让手机更顺手", + "image": "https://res.klyj.jinzejk.com/lesson/phone1.png", + "price": 0.0, + "chapterCount": 7, + "learnCount": 6525, + "label": "免费" + }, + { + "id": "lesson002", + "title": "手机桌面之老年机篇", + "image": "https://res.klyj.jinzejk.com/lesson/phone2.png", + "price": 9.9, + "chapterCount": 3, + "learnCount": 6525 + }, + { + "id": "lesson003", + "title": "如何学习使用微信", + "image": "https://res.klyj.jinzejk.com/lesson/phone3.png", + "price": 9.9, + "chapterCount": 3, + "learnCount": 6525 + }, + { + "id": "lesson004", + "title": "用上iPad老年机更大", + "image": "https://res.klyj.jinzejk.com/lesson/phone4.png", + "price": 9.9, + "chapterCount": 3, + "learnCount": 6525 + }, + { + "id": "lesson005", + "title": "手机桌面之老年机篇", + "image": "https://res.klyj.jinzejk.com/lesson/phone5.png", + "price": 9.9, + "chapterCount": 3, + "learnCount": 6525 } - } + ] + } +}, +{ + "method": "GET", + "path": "/api/lesson/list", + "query": {"type": "3"}, + "response": { + "category": "书法学习", + "total": 4, + "data": [ + { + "id": "lesson101", + "title": "隶属的古法用笔技巧", + "image": "https://res.klyj.jinzejk.com/lesson/calligraphy-1.png", + "price": 0.0, + "chapterCount": 7, + "learnCount": 6525, + "label": "免费" + }, + { + "id": "lesson102", + "title": "六十三个常用行书字", + "image": "https://res.klyj.jinzejk.com/lesson/calligraphy-2.png", + "price": 9.9, + "chapterCount": 3, + "learnCount": 6525 + }, + { + "id": "lesson103", + "title": "隶书入门教学", + "image": "https://res.klyj.jinzejk.com/lesson/calligraphy-3.png", + "price": 9.9, + "chapterCount": 3, + "learnCount": 6525 + }, + { + "id": "lesson104", + "title": "易道字体教学", + "image": "https://res.klyj.jinzejk.com/lesson/calligraphy-4.png", + "price": 9.9, + "chapterCount": 3, + "learnCount": 6525 + }, + { + "id": "lesson105", + "title": "隶书古法教学", + "image": "https://res.klyj.jinzejk.com/lesson/calligraphy-5.png", + "price": 9.9, + "chapterCount": 3, + "learnCount": 6525 + } + ] + } +}, +{ + "method": "GET", + "path": "/api/lesson/list", + "query": {"type": "4"}, + "response": { + "category": "乐器弹奏", + "total": 3, + "data": [ + { + "id": "lesson201", + "title": "二胡学习技法", + "image": "https://res.klyj.jinzejk.com/lesson/music-1.png", + "price": 0.0, + "chapterCount": 7, + "learnCount": 6525, + "label": "免费" + }, + { + "id": "lesson202", + "title": "吹管开启夕阳红🎷", + "image": "https://res.klyj.jinzejk.com/lesson/music-2.png", + "price": 9.9, + "chapterCount": 3, + "learnCount": 6525 + }, + { + "id": "lesson203", + "title": "建议中老年人学下乐器", + "image": "https://res.klyj.jinzejk.com/lesson/music-3.png", + "price": 9.9, + "chapterCount": 3, + "learnCount": 6525 + }, + { + "id": "lesson204", + "title": "二胡三玄映月", + "image": "https://res.klyj.jinzejk.com/lesson/music-4.png", + "price": 9.9, + "chapterCount": 3, + "learnCount": 6525 + } + ] } }, { diff --git a/server.js b/server.js index 6b3066f..cad7fd9 100644 --- a/server.js +++ b/server.js @@ -52,6 +52,16 @@ function registerMockApi(config) { } } + if (path === '/api/lesson/list' && Object.keys(req.query).length === 0) { + const defaultConfig = global.mockConfigs.find(c => + c.path === path + ); + if (defaultConfig) { + console.log(`[MOCK] Fallback to default (home)`); + return res.json(formatResponse(defaultConfig.response)); + } + } + // 精确 query 匹配 if (query) {