|
@@ -1,249 +0,0 @@
|
1
|
|
-import Mock from 'mockjs'
|
2
|
|
-import { SUCCESS_CODE } from '@/constants'
|
3
|
|
-import { toAnyString } from '@/utils'
|
4
|
|
-
|
5
|
|
-const timeout = 1000
|
6
|
|
-const count = 100
|
7
|
|
-
|
8
|
|
-const baseContent =
|
9
|
|
- '<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'
|
10
|
|
-
|
11
|
|
-interface ListProps {
|
12
|
|
- id: string
|
13
|
|
- author: string
|
14
|
|
- title: string
|
15
|
|
- content: string
|
16
|
|
- importance: number
|
17
|
|
- display_time: any
|
18
|
|
- pageviews: number
|
19
|
|
- image_uri: string
|
20
|
|
- video_uri?: string
|
21
|
|
-}
|
22
|
|
-
|
23
|
|
-interface TreeListProps {
|
24
|
|
- id: string
|
25
|
|
- author: string
|
26
|
|
- title: string
|
27
|
|
- content: string
|
28
|
|
- importance: number
|
29
|
|
- display_time: any
|
30
|
|
- image_uri: string
|
31
|
|
- pageviews: number
|
32
|
|
- video_uri?: string
|
33
|
|
- children?: TreeListProps[]
|
34
|
|
-}
|
35
|
|
-
|
36
|
|
-let List: ListProps[] = []
|
37
|
|
-
|
38
|
|
-for (let i = 0; i < count; i++) {
|
39
|
|
- List.push(
|
40
|
|
- Mock.mock({
|
41
|
|
- id: toAnyString(),
|
42
|
|
- // timestamp: +Mock.Random.date('T'),
|
43
|
|
- author: '@first',
|
44
|
|
- title: '@title(5, 10)',
|
45
|
|
- content: baseContent,
|
46
|
|
- importance: '@integer(1, 3)',
|
47
|
|
- display_time: '@datetime',
|
48
|
|
- pageviews: '@integer(100, 500)',
|
49
|
|
- image_uri: Mock.Random.image('@integer(100, 500)x@integer(100, 500)'),
|
50
|
|
- video_uri:
|
51
|
|
- '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4'
|
52
|
|
- })
|
53
|
|
- )
|
54
|
|
-}
|
55
|
|
-
|
56
|
|
-const treeList: TreeListProps[] = []
|
57
|
|
-
|
58
|
|
-for (let i = 0; i < count; i++) {
|
59
|
|
- treeList.push(
|
60
|
|
- Mock.mock({
|
61
|
|
- id: toAnyString(),
|
62
|
|
- // timestamp: +Mock.Random.date('T'),
|
63
|
|
- author: '@first',
|
64
|
|
- title: '@title(5, 10)',
|
65
|
|
- content: baseContent,
|
66
|
|
- importance: '@integer(1, 3)',
|
67
|
|
- display_time: '@datetime',
|
68
|
|
- pageviews: '@integer(300, 5000)',
|
69
|
|
- image_uri: Mock.Random.image('@integer(100, 500)x@integer(100, 500)'),
|
70
|
|
- // image_uri
|
71
|
|
- })
|
72
|
|
- )
|
73
|
|
-}
|
74
|
|
-
|
75
|
|
-const cardList = [
|
76
|
|
- {
|
77
|
|
- logo: 'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png',
|
78
|
|
- name: 'Alipay',
|
79
|
|
- desc: '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。'
|
80
|
|
- },
|
81
|
|
- {
|
82
|
|
- logo: 'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png',
|
83
|
|
- name: 'Angular',
|
84
|
|
- desc: '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。'
|
85
|
|
- },
|
86
|
|
- {
|
87
|
|
- logo: 'https://gw.alipayobjects.com/zos/rmsportal/siCrBXXhmvTQGWPNLBow.png',
|
88
|
|
- name: 'Bootstrap',
|
89
|
|
- desc: '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。'
|
90
|
|
- },
|
91
|
|
- {
|
92
|
|
- logo: 'https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png',
|
93
|
|
- name: 'React',
|
94
|
|
- desc: '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。'
|
95
|
|
- },
|
96
|
|
- {
|
97
|
|
- logo: 'https://gw.alipayobjects.com/zos/rmsportal/ComBAopevLwENQdKWiIn.png',
|
98
|
|
- name: 'Vue',
|
99
|
|
- desc: '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。'
|
100
|
|
- },
|
101
|
|
- {
|
102
|
|
- logo: 'https://gw.alipayobjects.com/zos/rmsportal/nxkuOJlFJuAUhzlMTCEe.png',
|
103
|
|
- name: 'Webpack',
|
104
|
|
- desc: '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。'
|
105
|
|
- }
|
106
|
|
-]
|
107
|
|
-
|
108
|
|
-export default [
|
109
|
|
- // 树形列表接口
|
110
|
|
- {
|
111
|
|
- url: '/mock/example/treeList',
|
112
|
|
- method: 'get',
|
113
|
|
- timeout,
|
114
|
|
- response: ({ query }) => {
|
115
|
|
- const { title, pageIndex, pageSize } = query
|
116
|
|
- const mockList = treeList.filter((item) => {
|
117
|
|
- if (title && item.title.indexOf(title) < 0) return false
|
118
|
|
- return true
|
119
|
|
- })
|
120
|
|
- const pageList = mockList.filter(
|
121
|
|
- (_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
|
122
|
|
- )
|
123
|
|
- return {
|
124
|
|
- code: SUCCESS_CODE,
|
125
|
|
- data: {
|
126
|
|
- total: mockList.length,
|
127
|
|
- list: pageList
|
128
|
|
- }
|
129
|
|
- }
|
130
|
|
- }
|
131
|
|
- },
|
132
|
|
- // 列表接口
|
133
|
|
- {
|
134
|
|
- url: '/mock/example/list',
|
135
|
|
- method: 'get',
|
136
|
|
- timeout,
|
137
|
|
- response: ({ query }) => {
|
138
|
|
- const { title, pageIndex, pageSize } = query
|
139
|
|
- const mockList = List.filter((item) => {
|
140
|
|
- if (title && item.title.indexOf(title) < 0) return false
|
141
|
|
- return true
|
142
|
|
- })
|
143
|
|
- const pageList = mockList.filter(
|
144
|
|
- (_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
|
145
|
|
- )
|
146
|
|
- return {
|
147
|
|
- code: SUCCESS_CODE,
|
148
|
|
- data: {
|
149
|
|
- total: mockList.length,
|
150
|
|
- list: pageList
|
151
|
|
- }
|
152
|
|
- }
|
153
|
|
- }
|
154
|
|
- },
|
155
|
|
- // 保存接口
|
156
|
|
- {
|
157
|
|
- url: '/mock/example/save',
|
158
|
|
- method: 'post',
|
159
|
|
- timeout,
|
160
|
|
- response: ({ body }) => {
|
161
|
|
- if (!body.id) {
|
162
|
|
- List = [
|
163
|
|
- Object.assign(body, {
|
164
|
|
- id: toAnyString()
|
165
|
|
- })
|
166
|
|
- ].concat(List)
|
167
|
|
- return {
|
168
|
|
- code: SUCCESS_CODE,
|
169
|
|
- data: 'success'
|
170
|
|
- }
|
171
|
|
- } else {
|
172
|
|
- List.map((item) => {
|
173
|
|
- if (item.id === body.id) {
|
174
|
|
- for (const key in item) {
|
175
|
|
- item[key] = body[key]
|
176
|
|
- }
|
177
|
|
- }
|
178
|
|
- })
|
179
|
|
- return {
|
180
|
|
- code: SUCCESS_CODE,
|
181
|
|
- data: 'success'
|
182
|
|
- }
|
183
|
|
- }
|
184
|
|
- }
|
185
|
|
- },
|
186
|
|
- // 详情接口
|
187
|
|
- {
|
188
|
|
- url: '/mock/example/detail',
|
189
|
|
- method: 'get',
|
190
|
|
- response: ({ query }) => {
|
191
|
|
- const { id } = query
|
192
|
|
- for (const example of List) {
|
193
|
|
- if (example.id === id) {
|
194
|
|
- return {
|
195
|
|
- code: SUCCESS_CODE,
|
196
|
|
- data: example
|
197
|
|
- }
|
198
|
|
- }
|
199
|
|
- }
|
200
|
|
- }
|
201
|
|
- },
|
202
|
|
- // 删除接口
|
203
|
|
- {
|
204
|
|
- url: '/mock/example/delete',
|
205
|
|
- method: 'post',
|
206
|
|
- response: ({ body }) => {
|
207
|
|
- const ids = body.ids
|
208
|
|
- if (!ids) {
|
209
|
|
- return {
|
210
|
|
- code: 500,
|
211
|
|
- message: '请选择需要删除的数据'
|
212
|
|
- }
|
213
|
|
- } else {
|
214
|
|
- let i = List.length
|
215
|
|
- while (i--) {
|
216
|
|
- if (ids.indexOf(List[i].id) !== -1) {
|
217
|
|
- List.splice(i, 1)
|
218
|
|
- }
|
219
|
|
- }
|
220
|
|
- return {
|
221
|
|
- code: SUCCESS_CODE,
|
222
|
|
- data: 'success'
|
223
|
|
- }
|
224
|
|
- }
|
225
|
|
- }
|
226
|
|
- },
|
227
|
|
- {
|
228
|
|
- url: '/mock/card/list',
|
229
|
|
- method: 'get',
|
230
|
|
- timeout,
|
231
|
|
- response: ({ query }) => {
|
232
|
|
- const { name, pageIndex, pageSize } = query
|
233
|
|
- const mockList = cardList.filter((item) => {
|
234
|
|
- if (name && item.name.indexOf(name) < 0) return false
|
235
|
|
- return true
|
236
|
|
- })
|
237
|
|
- const pageList = mockList.filter(
|
238
|
|
- (_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
|
239
|
|
- )
|
240
|
|
- return {
|
241
|
|
- code: SUCCESS_CODE,
|
242
|
|
- data: {
|
243
|
|
- total: mockList.length,
|
244
|
|
- list: pageList
|
245
|
|
- }
|
246
|
|
- }
|
247
|
|
- }
|
248
|
|
- }
|
249
|
|
-]
|