Commit baa42a57fdd4661a915a02f6dbb8391c26c43b53
Committed by
GitHub
1 parent
6981b73e
fix: 使用枚举属性表示mock的响应状态 (#2062)
Showing
2 changed files
with
10 additions
and
8 deletions
mock/_util.ts
1 | 1 | // Interface data format used to return a unified format |
2 | +import { ResultEnum } from '/@/enums/httpEnum'; | |
2 | 3 | |
3 | 4 | export function resultSuccess<T = Recordable>(result: T, { message = 'ok' } = {}) { |
4 | 5 | return { |
5 | - code: 0, | |
6 | + code: ResultEnum.SUCCESS, | |
6 | 7 | result, |
7 | 8 | message, |
8 | 9 | type: 'success', |
... | ... | @@ -26,7 +27,10 @@ export function resultPageSuccess<T = any>( |
26 | 27 | }; |
27 | 28 | } |
28 | 29 | |
29 | -export function resultError(message = 'Request failed', { code = -1, result = null } = {}) { | |
30 | +export function resultError( | |
31 | + message = 'Request failed', | |
32 | + { code = ResultEnum.ERROR, result = null } = {}, | |
33 | +) { | |
30 | 34 | return { |
31 | 35 | code, |
32 | 36 | result, |
... | ... | @@ -37,11 +41,9 @@ export function resultError(message = 'Request failed', { code = -1, result = nu |
37 | 41 | |
38 | 42 | export function pagination<T = any>(pageNo: number, pageSize: number, array: T[]): T[] { |
39 | 43 | const offset = (pageNo - 1) * Number(pageSize); |
40 | - const ret = | |
41 | - offset + Number(pageSize) >= array.length | |
42 | - ? array.slice(offset, array.length) | |
43 | - : array.slice(offset, offset + Number(pageSize)); | |
44 | - return ret; | |
44 | + return offset + Number(pageSize) >= array.length | |
45 | + ? array.slice(offset, array.length) | |
46 | + : array.slice(offset, offset + Number(pageSize)); | |
45 | 47 | } |
46 | 48 | |
47 | 49 | export interface requestParams { | ... | ... |