提交 | 用户 | age
|
3ac5f2
|
1 |
// 引入mockjs |
J |
2 |
import Mock from 'mockjs' |
|
3 |
const Random = Mock.Random |
|
4 |
// 项目域名 |
|
5 |
import config from './config' |
|
6 |
|
|
7 |
const delay = 500 // 模拟请求时长 |
|
8 |
|
|
9 |
// const config = 'http://192.168.1.163:8080/sk_anchor_pc/' |
|
10 |
const res = { status: 0, errMsg: '' } |
|
11 |
// var Req = require('@/libs/request') |
|
12 |
// var OPTIONS = Req.OPTIONS || Req.default.OPTIONS |
|
13 |
|
|
14 |
const commonReturn = {res, inf: {}} // 通用返回 |
|
15 |
const imgUrl = 'static/imgs/headimg.jpg' // 通用示例图片 |
|
16 |
// const videoUrl = 'https://vjs.zencdn.net/v/oceans.mp4' // 通用示例视频 |
|
17 |
|
|
18 |
var mockJson = { |
|
19 |
commSuc: commonReturn, |
|
20 |
// 获取key |
|
21 |
'weixin!ajaxGetInfoByCode': { |
|
22 |
res, |
|
23 |
inf: { |
|
24 |
"key": "123", |
|
25 |
"nickname": "昵称", |
|
26 |
"imgUrl": imgUrl, |
|
27 |
"shareImg": imgUrl, |
|
28 |
"shareTitle": "分享标题" |
|
29 |
} |
|
30 |
}, |
|
31 |
|
|
32 |
// 获取OSS参数 |
|
33 |
'oss!ajaxGetAccess': { |
|
34 |
res, |
|
35 |
"inf": { |
|
36 |
"accessId": "", |
|
37 |
"policy": "", |
|
38 |
"signature": "", |
|
39 |
"dir": "", |
|
40 |
"host": "", |
|
41 |
"expire": "" |
|
42 |
} |
|
43 |
}, |
|
44 |
|
|
45 |
// ticket |
|
46 |
'weixin!ajaxGetJsTicket': { |
|
47 |
res, |
|
48 |
inf: { |
|
49 |
ticket: '123' |
|
50 |
} |
|
51 |
} |
|
52 |
} |
|
53 |
/** |
|
54 |
* 生成回调函数 |
|
55 |
* @param {object|function} data mockJson 对应项 |
|
56 |
*/ |
|
57 |
function createCallback (data) { |
|
58 |
return function () { |
|
59 |
if (typeof data === 'function') { |
|
60 |
return data() |
|
61 |
} else { |
|
62 |
return data |
|
63 |
} |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
// 设置延迟响应,模拟向后端请求数据 |
|
68 |
Mock.setup({timeout: delay}) |
|
69 |
for (var key in mockJson) { |
|
70 |
var obj = mockJson[key] |
|
71 |
var url = key |
|
72 |
Mock.mock(config.domain + url, createCallback(obj)) |
|
73 |
} |
|
74 |
// Mock.mock( url, post/get , 返回的数据); |
|
75 |
// Mock.mock('/news/index', 'post', {}); |