-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock.js
137 lines (132 loc) · 3.14 KB
/
mock.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* mock.js 提供应用截获ajax请求,为脱离后台测试使用
* 模拟查询更改内存中mockData,并返回数据
*/
import { fetch } from 'edf-utils'
import { debug } from 'util';
import Mock from 'mockjs'
const mockproxy = '/v1/testTools/ttk-hook-app-init'
function filter(list, index, value) {
return list.filter(item => {
return String(item[index]).indexOf(value) >= 0
})
}
// fetch.mock(`${mockproxy}/subTreeData`, (option) => {
// const data = Mock.mock({
// 'list|15': [{
// functioinId: "@integer(-100000, 100000)",
// name: "@cname",
// url: "#",
// parentId: "1",
// 'subNodeFlag|1': ["0", "1"],
// }]
// })
// return {
// result: true,
// value: data.list
// }
// })
fetch.mock(`${mockproxy}/thead`, (option) => {
return {
result: true,
value: [{
dataIndex: 'userId',
title: '用户ID'
}, {
title: '用户类型',
dataIndex: 'userType',
}, {
title: '服务号码',
dataIndex: 'encode'
}, {
title: '用户名称',
dataIndex: 'userName'
}, {
title: '邮箱',
dataIndex: 'email'
}, {
title: '手机号',
dataIndex: 'mobilePhone'
}, {
title: '启用',
dataIndex: 'isValid'
}, {
title: '部门',
dataIndex: 'channel'
}, {
title: '创建者ID',
dataIndex: 'createUser'
}, {
title: '所属部门',
dataIndex: 'depName'
}, {
title: '所属部门ID',
dataIndex: 'depId'
}, {
title: '用户岗位',
dataIndex: 'dutiesName'
}]
}
})
// mock(url, function), function必须返回你要的值
fetch.mock(`${mockproxy}/tableBody`, (option) => {
const { pageIndex, pageSize } = option.pager
const { userName } = option.entity
let list = mockList().list
if (userName !== '')
list = filter(list, 'userName', userName)
const recordCount = list.length
const pageCount = Math.ceil(recordCount / pageSize)
const data = list.slice((pageIndex - 1) * pageSize, pageIndex * pageSize)
return {
result: true,
value: {
pager: {
pageIndex,
pageSize,
recordCount,
pageCount
},
data
}
}
})
function mockList() {
return Mock.mock({
'list|101': [{
userId: "@integer(-100000, 100000)",
userType: "@ctitle(4)",
encode: "@increment",
userName: "@name",
email: "[email protected]",
mobilePhone: "15800003248",
isValid: "@cparagraph(1, 2)",
channel: "win",
createUser: "1",
createDate: "@datetime(yyyy-MM-dd)",
updateUser: "1",
updateDate: "@datetime",
depName: "@cparagraph(4)",
depId: "1",
dutiesName: "@ctitle(12)",
depUserId: "0ec47f6cd1c54c0dbed81255d4f84ce6"
}]
})
}
// mock(url, function), function必须返回你要的值
fetch.mock(`${mockproxy}/attributeForm`, (option) => {
const { name, sortNo } = option
let result = true
if (Number(sortNo) != 1)
result = false
return {
result,
error:{
code:303,
message: 'mock接口设置了只有排序等于1时才能提交成功。'
},
value: {
...option
}
}
})