master
old易 2025-07-28 15:08:25 +08:00
parent cea025ecdd
commit 14c947c1f9
2 changed files with 159 additions and 35 deletions

View File

@ -760,10 +760,11 @@
{ {
"method": "GET", "method": "GET",
"path": "/api/lesson/list", "path": "/api/lesson/list",
"query": {"type": "1"},
"response": { "response": {
"category": "推荐", "category": "推荐",
"total": 4, "total": 4,
"items": [ "data": [
{ {
"id": "lesson001", "id": "lesson001",
"title": "隶属的古法用笔技巧", "title": "隶属的古法用笔技巧",
@ -798,41 +799,154 @@
"learnCount": 6525 "learnCount": 6525
} }
] ]
}, }
"swagger": { },
"summary": "获取课程学习列表", {
"description": "返回推荐课程列表数据(包含课程封面、价格、节数、学习人数等)", "method": "GET",
"responses": { "path": "/api/lesson/list",
"200": { "query": {"type": "2"},
"description": "课程数据", "response": {
"content": { "category": "手机电脑",
"application/json": { "total": 5,
"schema": { "data": [
"type": "object", {
"properties": { "id": "lesson001",
"category": { "type": "string" }, "title": "4个设置让手机更顺手",
"total": { "type": "integer" }, "image": "https://res.klyj.jinzejk.com/lesson/phone1.png",
"items": { "price": 0.0,
"type": "array", "chapterCount": 7,
"items": { "learnCount": 6525,
"type": "object", "label": "免费"
"properties": { },
"id": { "type": "string" }, {
"title": { "type": "string" }, "id": "lesson002",
"image": { "type": "string" }, "title": "手机桌面之老年机篇",
"price": { "type": "number" }, "image": "https://res.klyj.jinzejk.com/lesson/phone2.png",
"chapterCount": { "type": "integer" }, "price": 9.9,
"learnCount": { "type": "integer" }, "chapterCount": 3,
"label": { "type": "string" } "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
}
]
} }
}, },
{ {

View File

@ -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 匹配 // 精确 query 匹配
if (query) { if (query) {