From 37de79fba66f826044932b7cbc3ad9c53c3676e7 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Wed, 10 Dec 2025 13:23:37 +0800 Subject: [PATCH] fix: json for query --- .npmrc | 1 - package.json | 2 +- src/query.ts | 27 ++++++++++----------------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/.npmrc b/.npmrc index a4d9caf..7446745 100644 --- a/.npmrc +++ b/.npmrc @@ -1,3 +1,2 @@ //npm.xiongxiao.me/:_authToken=${ME_NPM_TOKEN} -@abearxiong:registry=https://npm.pkg.github.com //registry.npmjs.org/:_authToken=${NPM_TOKEN} \ No newline at end of file diff --git a/package.json b/package.json index 12dcf6e..7a5d694 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/query", - "version": "0.0.31", + "version": "0.0.32", "main": "dist/query-browser.js", "private": false, "type": "module", diff --git a/src/query.ts b/src/query.ts index fda90bc..e033c93 100644 --- a/src/query.ts +++ b/src/query.ts @@ -23,23 +23,11 @@ export type Data = { payload?: Record; [key: string]: any; }; -export type Result = { +export type Result = { code: number; data?: S; message?: string; - success: boolean; - /** - * 是否不返回 message - */ - noMsg?: boolean; - /** - * 显示错误, 当 handle的信息被处理的时候,如果不是success,同时自己设置了noMsg,那么就不显示错误信息了,因为被处理。 - * - * 日常: fetch().then(res=>if(res.sucess){message.error('error')})的时候,比如401被处理过了,就不再提示401错误了。 - * - */ - showError: (fn?: () => void) => void; -}; +} & U; // 额外功能 export type DataOpts = Partial & { beforeRequest?: Fn; @@ -55,7 +43,7 @@ export type DataOpts = Partial & { * showError 是 如果 success 为 false 且 noMsg 为 false, 则调用 showError * @param res 响应 */ -export const setBaseResponse = (res: Partial) => { +export const setBaseResponse = (res: Partial void) => void; noMsg?: boolean }>) => { res.success = res.code === 200; /** * 显示错误 @@ -199,7 +187,6 @@ export class Query { } return _adapter(req).then(async (res) => { try { - setBaseResponse(res); if (_afterResponse) { return await _afterResponse(res, { req, @@ -250,7 +237,13 @@ export class Query { ...(_options?.headers || {}), }, }); - return setBaseResponse(res); + if (res && !res.code) { + return { + code: 200, + data: res, + } + } + return res; } }