mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-24 10:33:50 +08:00
fix: 使用枚举属性表示mock的响应状态 (#2062)
This commit is contained in:
parent
6981b73ef6
commit
baa42a57fd
@ -1,8 +1,9 @@
|
||||
// Interface data format used to return a unified format
|
||||
import { ResultEnum } from '/@/enums/httpEnum';
|
||||
|
||||
export function resultSuccess<T = Recordable>(result: T, { message = 'ok' } = {}) {
|
||||
return {
|
||||
code: 0,
|
||||
code: ResultEnum.SUCCESS,
|
||||
result,
|
||||
message,
|
||||
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 {
|
||||
code,
|
||||
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[] {
|
||||
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 {
|
||||
|
@ -3,7 +3,7 @@
|
||||
*/
|
||||
export enum ResultEnum {
|
||||
SUCCESS = 0,
|
||||
ERROR = 1,
|
||||
ERROR = -1,
|
||||
TIMEOUT = 401,
|
||||
TYPE = 'success',
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user