update Page and Response T
This commit is contained in:
@ -22,6 +22,7 @@
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/src/index.d.ts",
|
||||
"import": "./dist/timi-web.mjs",
|
||||
"require": "./dist/timi-web.umd.js"
|
||||
},
|
||||
|
||||
@ -53,7 +53,7 @@ export type CommentReplyView = {
|
||||
export type CommentPage = {
|
||||
bizType?: CommentBizType;
|
||||
bizId?: number;
|
||||
} & Page;
|
||||
} & Page<Comment>;
|
||||
|
||||
export enum CommentReplyBizType {
|
||||
|
||||
@ -67,7 +67,7 @@ export enum CommentReplyBizType {
|
||||
export type CommentReplyPage = {
|
||||
bizType: CommentReplyBizType
|
||||
bizId?: number
|
||||
} & Page;
|
||||
} & Page<Comment>;
|
||||
|
||||
export enum CommentBizType {
|
||||
ARTICLE = "ARTICLE",
|
||||
|
||||
@ -13,17 +13,18 @@ export type Model = {
|
||||
deletedAt?: number;
|
||||
}
|
||||
|
||||
export type Response = {
|
||||
export type Response<T> = {
|
||||
code: number;
|
||||
msg?: string;
|
||||
data: object;
|
||||
data: T;
|
||||
}
|
||||
|
||||
export type Page = {
|
||||
export type Page<T> = {
|
||||
index: number;
|
||||
size: number;
|
||||
orderMap?: { [key: string]: OrderType };
|
||||
likeMap?: { [key: string]: string | undefined | null };
|
||||
equalsExample?: T;
|
||||
likesExample?: T;
|
||||
}
|
||||
|
||||
export enum OrderType {
|
||||
|
||||
@ -2,7 +2,7 @@ import axios, { InternalAxiosRequestConfig } from "axios";
|
||||
import { Response } from "~/types/Model";
|
||||
import { Cooker, Time, userStore } from "~/index";
|
||||
|
||||
type ErrorCallback = (response: Response) => void;
|
||||
type ErrorCallback = (response: Response<any>) => void;
|
||||
|
||||
let globalErrorCallback: ErrorCallback | null = null;
|
||||
|
||||
@ -36,7 +36,7 @@ axios.defaults.withCredentials = true;
|
||||
axios.interceptors.response.use((axiosResp: any) => {
|
||||
if (!axiosResp.config.responseType) {
|
||||
// 服务端返回
|
||||
const serverResp = axiosResp.data as Response;
|
||||
const serverResp = axiosResp.data as Response<any>;
|
||||
if (serverResp.code < 40000) {
|
||||
// 200 或 300 HTTP 状态段视为成功
|
||||
return serverResp.data;
|
||||
|
||||
Reference in New Issue
Block a user