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