123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- import mockjs from 'mockjs';
- import { format, delay } from 'roadhog-api-doc';
- import config from './src/utils/config';
- import Logger from './src/utils/logger';
- import { imageDatabase, videoDatabase } from './mock/resource';
- import { tagList, wareList, lessonList, courseList, supportList } from './mock/product';
- import { itemList } from './mock/item';
- const logger = Logger.getLogger('RoadhogMock');
- // 是否禁用代理
- const noProxy = process.env.NO_PROXY === 'true';
- // 测试API
- const OFFLINE_API_URL = 'http://192.168.199.119:8100';
- // 代码中会兼容本地 service mock 以及部署站点的静态数据
- const proxy = {
- [`GET ${config.api.resourceList}`]: (req, res) => {
- let params = req.query;
- if (!params || !params.type) {
- res.send({
- code: '401',
- message: '请求参数不完整!'
- });
- }
- else {
- let dataset = [];
- if (parseInt(params.type) === config.RESOURCE_TYPE_IMAGE) {
- dataset = imageDatabase;
- }
- else if (parseInt(params.type) === config.RESOURCE_TYPE_VIDEO) {
- dataset = videoDatabase;
- }
- let type = params.type;
- let pageSize = params.pageSize ? parseInt(params.pageSize) : 10;
- let pageNo = params.pageNo ? parseInt(params.pageNo) : 1;
- let totalSize = dataset.length;
- let totalNo = Math.floor(dataset.length / pageSize) + 1;
- let start = pageNo * pageSize;
- let list = dataset.slice(start, start + pageSize);
- res.send({
- code: '200',
- message: 'Request success!',
- data: { pageNo, pageSize, totalSize, list }
- });
- }
- },
- [`GET ${config.api.wareList}`]: (req, res) => {
- let params = req.query;
- let dataset = wareList;
- logger.info('【WareList Request】: ', params);
- let pageSize = params.pageSize ? parseInt(params.pageSize) : 10;
- let pageNo = params.pageNo ? parseInt(params.pageNo) : 1;
- let totalSize = dataset.length;
- let start = pageNo * pageSize;
- let list = dataset.slice(start, start + pageSize);
- res.send({
- code: '200',
- message: 'Request success!',
- data: { pageNo, pageSize, totalSize, list }
- });
- },
- [`GET ${config.api.lessonList}`]: (req, res) => {
- let params = req.query;
- let dataset = lessonList;
- logger.info('【LessonList Request】: ', params);
- let pageSize = params.pageSize ? parseInt(params.pageSize) : 10;
- let pageNo = params.pageNo ? parseInt(params.pageNo) : 1;
- let totalSize = dataset.length;
- let start = pageNo * pageSize;
- let list = dataset.slice(start, start + pageSize);
- res.send({
- code: '200',
- message: 'Request success!',
- data: { pageNo, pageSize, totalSize, list }
- });
- },
- [`GET ${config.api.lessonItem}`]: (req, res) => {
- logger.info('【LessonItem】:', req.params);
- res.send({
- "code": 200,
- "success": true,
- "message": null,
- "data": {
- "id": 1511504034666794,
- "code": "K-test-310",
- "name": "小学310",
- "digest": "霍冬冬是个大傻蛋,这是一句很中肯的话,不要狡辩!",
- "sort": null,
- "status": "NORMAL",
- "gmtCreated": null,
- "gmtModified": null,
- "wareList": [{
- "id": 1511425213814978,
- "code": "J-test-310",
- "name": "小学310",
- "digest": null,
- "type": "SINGLE",
- "playUrl": null,
- "imgUrls": [
- "http://www.xxx.c/img.jpg",
- ],
- "sort": null,
- "status": "NORMAL",
- "gmtCreated": 1511264969000,
- "gmtModified": 1511264969000
- }]
- }
- });
- },
- [`POST ${config.api.lessonItemAdd}`]: (req, res) => {
- logger.info('【LessonItemAdd】:', req.body);
- res.send({
- code: 200,
- message: '新建课成功',
- data: {},
- });
- },
- [`PUT ${config.api.lessonItemUpdate}`]: (req, res) => {
- logger.info('【LessonItemUpdate】:', req.body);
- res.send({
- code: 200,
- message: '更新课成功',
- data: {},
- });
- },
- [`DELETE ${config.api.lessonItemDel}`]: (req, res) => {
- logger.info('【LessonItemDelete】:', req.body);
- res.send({
- code: 200,
- message: '删除课成功',
- data: {},
- });
- },
- [`GET ${config.api.courseList}`]: (req, res) => {
- let params = req.query;
- let dataset = courseList;
- logger.info('【CourseList Request】: ', params);
- let pageSize = params.pageSize ? parseInt(params.pageSize) : 10;
- let pageNo = params.pageNo ? parseInt(params.pageNo) : 1;
- let totalSize = dataset.length;
- let start = pageNo * pageSize;
- let list = dataset.slice(start, start + pageSize);
- res.send({
- code: '200',
- message: 'Request success!',
- data: { pageNo, pageSize, totalSize, list }
- });
- },
- [`GET ${config.api.courseItem}`]: (req, res) => {
- logger.info('【CourseItem】:', req.params);
- res.send({
- "code": 200,
- "success": true,
- "message": null,
- "data": {
- "id": 1511767193919357,
- "code": "C-test-311",
- "name": "小学311",
- "title": null,
- "digest": null,
- "detail": null,
- "keyword": null,
- "cvImgIds": null,
- "bgImgIds": null,
- "status": null,
- "gmtCreated": null,
- "gmtModified": null,
- "subItemList": [{
- "id": 1511509291305739,
- "code": "K-test-311",
- "name": "小学310",
- "digest": null,
- "type": "LESSON",
- "status": null,
- "gmtCreated": null,
- "gmtModified": null
- }],
- "supportList": [{
- "id": 1511835822190182,
- "code": "S-test-310",
- "name": "小学310",
- "title": null,
- "digest": null,
- "detail": null,
- "imgIds": null,
- "status": null,
- "gmtCreated": null,
- "gmtModified": null
- }]
- }
- })
- },
- [`POST ${config.api.courseItemAdd}`]: (req, res) => {
- logger.info('【CourseItemAdd】:', req.body);
- res.send({
- code: 200,
- message: '新建课程成功',
- data: {},
- });
- },
- [`PUT ${config.api.courseItemUpdate}`]: (req, res) => {
- logger.info('【CourseItemUpdate】:', req.body);
- res.send({
- code: 200,
- message: '更新课程成功',
- data: {},
- });
- },
- [`DELETE ${config.api.courseItemDel}`]: (req, res) => {
- logger.info('【CourseItemDelete】:', req.body);
- res.send({
- code: 200,
- message: '删除课程成功',
- data: {},
- });
- },
- [`GET ${config.api.supportList}`]: (req, res) => {
- let params = req.query;
- let dataset = supportList;
- logger.info('【SupportList Request】: ', params);
- let pageSize = params.pageSize ? parseInt(params.pageSize) : 10;
- let pageNo = params.pageNo ? parseInt(params.pageNo) : 1;
- let totalSize = dataset.length;
- let start = pageNo * pageSize;
- let list = dataset.slice(start, start + pageSize);
- res.send({
- code: '200',
- message: 'Request success!',
- data: { pageNo, pageSize, totalSize, list }
- });
- },
- [`GET ${config.api.supportItem}`]: (req, res) => {
- logger.info('【SupportItem】:', req.params);
- res.send({
- "code": 200,
- "success": true,
- "message": null,
- "data": {
- "id": 1,
- "code": "S-test-310",
- "name": "先学急用的汉字1",
- "digest": "周边描述周边描述周边描述周边描述周边描述周边描述周边描述周边描述周边描述",
- "tags": [{tagId: 15, tagName:'EQ情商教育-15'}, {tagId:17, tagName:'EQ情商教育-2'}],
- "status": "NORMAL",
- "cpId": 1,
- "cpName": "贝尔安亲",
- "gmtCreated": null,
- "gmtModified": null,
- "playUrl": 'http://www.baidu.com',
- "imgUrls": ['http://www.baidu.com'],
- "supportArr": [{
- "id": 2,
- "code": "S-test-311",
- "name": "先学急用的汉字2",
- "digest": "周边描述周边描述周边描述周边描述周边描述周边描述周边描述周边描述周边描述",
- "tags": [{15: 'EQ情商教育-15'}, {17: 'EQ情商教育-17'}],
- "status": "NORMAL",
- "cpId": 1,
- "cpName": "贝尔安亲",
- "playUrl": 'http://www.baidu.com',
- "imgUrls": ['http://www.baidu.com'],
- "gmtCreated": null,
- "gmtModified": null,
- }]
- }
- });
- },
- [`POST ${config.api.supportItemAdd}`]: (req, res) => {
- logger.info('【SupportItemAdd】:', req.body);
- res.send({
- code: 200,
- message: '新建周边成功',
- data: {},
- });
- },
- [`PUT ${config.api.supportItemUpdate}`]: (req, res) => {
- logger.info('【SupportItemUpdate】:', req.body);
- res.send({
- code: 200,
- message: '更新周边成功',
- data: {},
- });
- },
- [`DELETE ${config.api.supportItemDel}`]: (req, res) => {
- logger.info('【SupportItemDelete】:', req.body);
- res.send({
- code: 200,
- message: '删除周边成功',
- data: {},
- });
- },
- [`GET ${config.api.itemList}`]: (req, res) => {
- let params = req.query;
- let dataset = itemList;
- logger.info('【ItemList Request】: ', params);
- let pageSize = params.pageSize ? parseInt(params.pageSize) : 10;
- let pageNo = params.pageNo ? parseInt(params.pageNo) : 1;
- let totalSize = dataset.length;
- let start = pageNo * pageSize;
- let list = dataset.slice(start, start + pageSize);
- res.send({
- code: '200',
- message: 'Request success!',
- data: { pageNo, pageSize, totalSize, list }
- });
- },
- [`GET ${config.api.itemItem}`]: (req, res) => {
- logger.info('【ItemItem Request】: ', req.params);
- res.send({
- code: 200,
- message: null,
- data: { ...itemList[0] },
- });
- },
- [`POST ${config.api.itemItemAdd}`]: (req, res) => {
- logger.info('【ItemItemAdd】:', req.body);
- res.send({
- code: 200,
- message: '新建商品成功',
- data: {},
- });
- },
- [`PUT ${config.api.itemItemUpdate}`]: (req, res) => {
- logger.info('【ItemItemUpdate】:', req.body);
- res.send({
- code: 200,
- message: '更新商品信息成功',
- data: {},
- });
- },
- [`DELETE ${config.api.itemItemDel}`]: (req, res) => {
- logger.info('【ItemItemDelete】:', req.body);
- res.send({
- code: 200,
- message: '删除商品成功',
- data: {},
- });
- },
- [`POST ${config.api.wareItemAdd}`]: (req, res) => {
- logger.info('【WareItemAdd】:', req.body);
- res.send({
- code: 200,
- message: '新建课件成功',
- data: {},
- });
- },
- [`PUT ${config.api.wareItemUpdate}`]: (req, res) => {
- logger.info('【WareItemUpdate】:', req.body);
- res.send({
- code: 200,
- message: '更新课件成功',
- data: {},
- });
- },
- [`DELETE ${config.api.wareItemDel}`]: (req, res) => {
- logger.info('【WareItemDelete】:', req.body);
- res.send({
- code: 200,
- message: '删除课件成功',
- data: {},
- });
- },
- [`GET ${config.api.tagList}`]: (req, res) => {
- let params = req.query;
- let dataset = tagList;
- logger.info('【TagList Request】: ', params);
- let pageSize = params.pageSize ? parseInt(params.pageSize) : 10;
- let pageNo = params.pageNo ? parseInt(params.pageNo) : 1;
- let totalSize = dataset.length;
- let start = pageNo * pageSize;
- let list = dataset.slice(start, start + pageSize);
- res.send({
- code: '200',
- message: 'Request success!',
- data: { pageNo, pageSize, totalSize, list }
- });
- },
- [`GET ${config.api.tagItem}`]: (req, res) => {
- logger.info('【TagItem】:', req.params);
- res.send({
- "code": 200,
- "success": true,
- "message": null,
- "data": {
- "tagId": 1511767193919357,
- "tagName": "EQ情商教育",
- "status": null,
- "type": 0,
- "gmtCreated": null,
- "gmtModified": null,
- "merchantId": 0,
- "merchantName": "贝尔安亲",
- }
- })
- },
- [`POST ${config.api.tagItemAdd}`]: (req, res) => {
- logger.info('【tagItemAdd】:', req.body);
- res.send({
- code: 200,
- message: '新建标签成功',
- data: {},
- });
- },
- [`PUT ${config.api.tagItemUpdate}`]: (req, res) => {
- logger.info('【TagItemUpdate】:', req.body);
- res.send({
- code: 200,
- message: '更新标签成功',
- data: {},
- });
- },
- [`DELETE ${config.api.tagItemDel}`]: (req, res) => {
- logger.info('【TagItemDelete】:', req.body);
- res.send({
- code: 200,
- message: '删除标签成功',
- data: {},
- });
- },
- [`GET ${config.api.merchantList}`]: {
- code: 200,
- message: 'Request success',
- success: true,
- data: {
- list:[
- {
- merchantId: 0,
- merchantName: '贝尔安亲',
- },{
- merchantId: 1,
- merchantName: '昂乐教育',
- },{
- merchantId: 2,
- merchantName: '好托管',
- },{
- merchantId: 3,
- merchantName: '红黄蓝',
- },{
- merchantId: 4,
- merchantName: '英乐教育',
- }
- ]
- }
- },
- [`GET ${config.api.cpList}`]: {
- code: 200,
- message: 'Request success',
- success: true,
- data: {
- list:[
- {
- cpId: 0,
- cpName: '贝尔安亲',
- },{
- cpId: 1,
- cpName: '昂乐教育',
- },{
- cpId: 2,
- cpName: '鲨鱼公园',
- }
- ]
- }
- },
- [`GET /api/v1/oss/upload`]: {
- "code": 200,
- "success": true,
- "message": null,
- "data": {
- "accessid": "LTAIUFvd17IXLBQ4",
- "policy": "eyJleHBpcmF0aW9uIjoiMjAxNy0xMS0yMlQwMzoyNTo0Mi41NjFaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF0sWyJzdGFydHMtd2l0aCIsIiRrZXkiLCJyZXNvdXJjZXMiXV19",
- "signature": "YxqziyjItL6F4F0OzfxaBOTg6Ok=",
- "expire": "1511321142",
- "dir": "resources",
- "path": "a/b/001.png",
- // "host": "http://efunimgs.oss-cn-beijing-internal.aliyuncs.com"
- "host": "http://localhost:8000/oss/upload"
- }
- },
- [`GET /oss/upload`]: {
- "code": 200,
- "success": true,
- "message": null,
- "data": {
- "fileName": "a-b-c.png",
- "path": "user-dir",
- "size": 80,
- }
- }
- };
- export default noProxy ? {} : delay(proxy, 1000);
- // export default {
- // [`GET ${config.apiPrefix}/(.*)`]: `${OFFLINE_API_URL}`,
- // }
|