fix: 使用枚举属性表示mock的响应状态 (#2062)

This commit is contained in:
Henry 2022-07-10 18:29:21 +08:00 committed by GitHub
parent 6981b73ef6
commit baa42a57fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View File

@ -1,8 +1,9 @@
// Interface data format used to return a unified format // Interface data format used to return a unified format
import { ResultEnum } from '/@/enums/httpEnum';
export function resultSuccess<T = Recordable>(result: T, { message = 'ok' } = {}) { export function resultSuccess<T = Recordable>(result: T, { message = 'ok' } = {}) {
return { return {
code: 0, code: ResultEnum.SUCCESS,
result, result,
message, message,
type: 'success', type: 'success',
@ -26,7 +27,10 @@ export function resultPageSuccess<T = any>(
}; };
} }
export function resultError(message = 'Request failed', { code = -1, result = null } = {}) { export function resultError(
message = 'Request failed',
{ code = ResultEnum.ERROR, result = null } = {},
) {
return { return {
code, code,
result, result,
@ -37,11 +41,9 @@ export function resultError(message = 'Request failed', { code = -1, result = nu
export function pagination<T = any>(pageNo: number, pageSize: number, array: T[]): T[] { export function pagination<T = any>(pageNo: number, pageSize: number, array: T[]): T[] {
const offset = (pageNo - 1) * Number(pageSize); const offset = (pageNo - 1) * Number(pageSize);
const ret = return offset + Number(pageSize) >= array.length
offset + Number(pageSize) >= array.length ? array.slice(offset, array.length)
? array.slice(offset, array.length) : array.slice(offset, offset + Number(pageSize));
: array.slice(offset, offset + Number(pageSize));
return ret;
} }
export interface requestParams { export interface requestParams {

View File

@ -3,7 +3,7 @@
*/ */
export enum ResultEnum { export enum ResultEnum {
SUCCESS = 0, SUCCESS = 0,
ERROR = 1, ERROR = -1,
TIMEOUT = 401, TIMEOUT = 401,
TYPE = 'success', TYPE = 'success',
} }