update Page and Response T

This commit is contained in:
Timi
2025-12-25 15:43:47 +08:00
parent e20d2ea351
commit 05e354f148
4 changed files with 10 additions and 8 deletions

View File

@ -22,6 +22,7 @@
], ],
"exports": { "exports": {
".": { ".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/timi-web.mjs", "import": "./dist/timi-web.mjs",
"require": "./dist/timi-web.umd.js" "require": "./dist/timi-web.umd.js"
}, },

View File

@ -53,7 +53,7 @@ export type CommentReplyView = {
export type CommentPage = { export type CommentPage = {
bizType?: CommentBizType; bizType?: CommentBizType;
bizId?: number; bizId?: number;
} & Page; } & Page<Comment>;
export enum CommentReplyBizType { export enum CommentReplyBizType {
@ -67,7 +67,7 @@ export enum CommentReplyBizType {
export type CommentReplyPage = { export type CommentReplyPage = {
bizType: CommentReplyBizType bizType: CommentReplyBizType
bizId?: number bizId?: number
} & Page; } & Page<Comment>;
export enum CommentBizType { export enum CommentBizType {
ARTICLE = "ARTICLE", ARTICLE = "ARTICLE",

View File

@ -13,17 +13,18 @@ export type Model = {
deletedAt?: number; deletedAt?: number;
} }
export type Response = { export type Response<T> = {
code: number; code: number;
msg?: string; msg?: string;
data: object; data: T;
} }
export type Page = { export type Page<T> = {
index: number; index: number;
size: number; size: number;
orderMap?: { [key: string]: OrderType }; orderMap?: { [key: string]: OrderType };
likeMap?: { [key: string]: string | undefined | null }; equalsExample?: T;
likesExample?: T;
} }
export enum OrderType { export enum OrderType {

View File

@ -2,7 +2,7 @@ import axios, { InternalAxiosRequestConfig } from "axios";
import { Response } from "~/types/Model"; import { Response } from "~/types/Model";
import { Cooker, Time, userStore } from "~/index"; import { Cooker, Time, userStore } from "~/index";
type ErrorCallback = (response: Response) => void; type ErrorCallback = (response: Response<any>) => void;
let globalErrorCallback: ErrorCallback | null = null; let globalErrorCallback: ErrorCallback | null = null;
@ -36,7 +36,7 @@ axios.defaults.withCredentials = true;
axios.interceptors.response.use((axiosResp: any) => { axios.interceptors.response.use((axiosResp: any) => {
if (!axiosResp.config.responseType) { if (!axiosResp.config.responseType) {
// 服务端返回 // 服务端返回
const serverResp = axiosResp.data as Response; const serverResp = axiosResp.data as Response<any>;
if (serverResp.code < 40000) { if (serverResp.code < 40000) {
// 200 或 300 HTTP 状态段视为成功 // 200 或 300 HTTP 状态段视为成功
return serverResp.data; return serverResp.data;