diff --git a/mock/_util.ts b/mock/_util.ts index 97c87564f..de4d55844 100644 --- a/mock/_util.ts +++ b/mock/_util.ts @@ -1,8 +1,9 @@ // Interface data format used to return a unified format +import { ResultEnum } from '/@/enums/httpEnum'; export function resultSuccess(result: T, { message = 'ok' } = {}) { return { - code: 0, + code: ResultEnum.SUCCESS, result, message, type: 'success', @@ -26,7 +27,10 @@ export function resultPageSuccess( }; } -export function resultError(message = 'Request failed', { code = -1, result = null } = {}) { +export function resultError( + message = 'Request failed', + { code = ResultEnum.ERROR, result = null } = {}, +) { return { code, result, @@ -37,11 +41,9 @@ export function resultError(message = 'Request failed', { code = -1, result = nu export function pagination(pageNo: number, pageSize: number, array: T[]): T[] { const offset = (pageNo - 1) * Number(pageSize); - const ret = - offset + Number(pageSize) >= array.length - ? array.slice(offset, array.length) - : array.slice(offset, offset + Number(pageSize)); - return ret; + return offset + Number(pageSize) >= array.length + ? array.slice(offset, array.length) + : array.slice(offset, offset + Number(pageSize)); } export interface requestParams { diff --git a/src/enums/httpEnum.ts b/src/enums/httpEnum.ts index 61a944a1c..c7548cce9 100644 --- a/src/enums/httpEnum.ts +++ b/src/enums/httpEnum.ts @@ -3,7 +3,7 @@ */ export enum ResultEnum { SUCCESS = 0, - ERROR = 1, + ERROR = -1, TIMEOUT = 401, TYPE = 'success', }