全局MOCK脚本

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
const code = [
{
key: 100200,
value: '服务端数据查询成功'
},
{
key: 100400,
value: '服务端数据查询成功'
},
{
key: 100401,
value: '无权限(令牌或者密码错误)'
},
{
key: 100404,
value: '当前接口不存在或者已删除'
},
{
key: 100500,
value: '服务端发生未知错误'
}
]
delay = 800 // 默认响应延时,单位为 ms
// 默认格式
mockJson = {
code: code[0].key,
msg: code[0].value,
data: null
}


const { mock_status_code } = params

if (mock_status_code && mock_status_code.length > 0) {
// mockJson.code = mock_status_code
const findIndex = code.findIndex(i => i.key == mock_status_code)
if (findIndex !== -1) {
mockJson.code = code[findIndex].key
mockJson.msg = code[findIndex].value
} else {
mockJson.code = mock_status_code
mockJson.msg = '当前调试状态码已删除或者不存在,请依据开发文档确认是否书写错误!'
}
}