From baa42a57fdd4661a915a02f6dbb8391c26c43b53 Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 10 Jul 2022 18:29:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E8=A1=A8=E7=A4=BAmock=E7=9A=84=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E7=8A=B6=E6=80=81=20(#2062)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/_util.ts | 16 +++++++++------- src/enums/httpEnum.ts | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) 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', }