@ks-web/use 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js
CHANGED
|
@@ -4949,6 +4949,30 @@ var KUASHENG_TOKEN_KEY = "ks_token";
|
|
|
4949
4949
|
// src/useHttp/http/http.ts
|
|
4950
4950
|
var import_qs = __toESM(require_lib());
|
|
4951
4951
|
|
|
4952
|
+
// src/useHttp/interceptors/response.ts
|
|
4953
|
+
var import_ks = require("@ks-web/ks");
|
|
4954
|
+
var import_style = require("@ks-web/ks/es/toast/style");
|
|
4955
|
+
var getErrorsTips = {
|
|
4956
|
+
"Network Error": "网络错误,请检查网络",
|
|
4957
|
+
[`timeout of 20000ms exceeded`]: "请求超时,服务器未响应",
|
|
4958
|
+
"Request failed with status code 500": "请求服务器错误",
|
|
4959
|
+
"Internal Server Error": "请求服务器错误",
|
|
4960
|
+
"Request failed with status code 502": "请求服务器错误",
|
|
4961
|
+
api: "接口错误"
|
|
4962
|
+
};
|
|
4963
|
+
function ksResponseInterceptor(res) {
|
|
4964
|
+
if (res.data && String(res.data.code) === "0") {
|
|
4965
|
+
return res.data.data;
|
|
4966
|
+
}
|
|
4967
|
+
const { tips } = res.config.userConfig || {};
|
|
4968
|
+
let { msg = res.message || res.msg } = res.data || {};
|
|
4969
|
+
const errorTips = getErrorsTips[msg];
|
|
4970
|
+
if (tips !== false && msg) {
|
|
4971
|
+
(0, import_ks.showToast)(errorTips || msg);
|
|
4972
|
+
}
|
|
4973
|
+
return Promise.reject(res);
|
|
4974
|
+
}
|
|
4975
|
+
|
|
4952
4976
|
// src/useType/index.ts
|
|
4953
4977
|
var toString3 = Object.prototype.toString;
|
|
4954
4978
|
var { is } = function _internal() {
|
|
@@ -5110,6 +5134,7 @@ function getRequest(httpInstance, url, method2, param, config) {
|
|
|
5110
5134
|
httpInstance.http(options).then((res) => {
|
|
5111
5135
|
resolve(origin ? res : res.data.data);
|
|
5112
5136
|
}).catch((e) => {
|
|
5137
|
+
ksResponseInterceptor(e);
|
|
5113
5138
|
reject(e);
|
|
5114
5139
|
}).finally(
|
|
5115
5140
|
() => loading && typeof (loadingOptions == null ? void 0 : loadingOptions.hide) === "function" && (loadingOptions == null ? void 0 : loadingOptions.hide())
|
|
@@ -5164,6 +5189,7 @@ function handleOptions(httpInstance, url, method2, param, config) {
|
|
|
5164
5189
|
const headers = {};
|
|
5165
5190
|
Object.assign(headers, config.headers || {}, casHeaders);
|
|
5166
5191
|
return __spreadValues(__spreadValues({
|
|
5192
|
+
userConfig: __spreadValues({}, config),
|
|
5167
5193
|
url: getRequestUrl(
|
|
5168
5194
|
url,
|
|
5169
5195
|
config.baseURL ? config.baseURL : httpInstance.baseURL
|
|
@@ -5263,7 +5289,10 @@ var http_default = function() {
|
|
|
5263
5289
|
|
|
5264
5290
|
// src/useHttp/openApi.ts
|
|
5265
5291
|
var http = http_default({
|
|
5266
|
-
baseURL: "/router/rest"
|
|
5292
|
+
baseURL: "/router/rest",
|
|
5293
|
+
interceptors: {
|
|
5294
|
+
response: [ksResponseInterceptor]
|
|
5295
|
+
}
|
|
5267
5296
|
});
|
|
5268
5297
|
function createRequest(type) {
|
|
5269
5298
|
return function(url, appKey, data, config) {
|
package/dist/index.esm.mjs
CHANGED
|
@@ -4931,6 +4931,30 @@ var KUASHENG_TOKEN_KEY = "ks_token";
|
|
|
4931
4931
|
// src/useHttp/http/http.ts
|
|
4932
4932
|
var import_qs = __toESM(require_lib());
|
|
4933
4933
|
|
|
4934
|
+
// src/useHttp/interceptors/response.ts
|
|
4935
|
+
import { showToast } from "@ks-web/ks";
|
|
4936
|
+
import "@ks-web/ks/es/toast/style";
|
|
4937
|
+
var getErrorsTips = {
|
|
4938
|
+
"Network Error": "网络错误,请检查网络",
|
|
4939
|
+
[`timeout of 20000ms exceeded`]: "请求超时,服务器未响应",
|
|
4940
|
+
"Request failed with status code 500": "请求服务器错误",
|
|
4941
|
+
"Internal Server Error": "请求服务器错误",
|
|
4942
|
+
"Request failed with status code 502": "请求服务器错误",
|
|
4943
|
+
api: "接口错误"
|
|
4944
|
+
};
|
|
4945
|
+
function ksResponseInterceptor(res) {
|
|
4946
|
+
if (res.data && String(res.data.code) === "0") {
|
|
4947
|
+
return res.data.data;
|
|
4948
|
+
}
|
|
4949
|
+
const { tips } = res.config.userConfig || {};
|
|
4950
|
+
let { msg = res.message || res.msg } = res.data || {};
|
|
4951
|
+
const errorTips = getErrorsTips[msg];
|
|
4952
|
+
if (tips !== false && msg) {
|
|
4953
|
+
showToast(errorTips || msg);
|
|
4954
|
+
}
|
|
4955
|
+
return Promise.reject(res);
|
|
4956
|
+
}
|
|
4957
|
+
|
|
4934
4958
|
// src/useType/index.ts
|
|
4935
4959
|
var toString3 = Object.prototype.toString;
|
|
4936
4960
|
var { is } = function _internal() {
|
|
@@ -5092,6 +5116,7 @@ function getRequest(httpInstance, url, method2, param, config) {
|
|
|
5092
5116
|
httpInstance.http(options).then((res) => {
|
|
5093
5117
|
resolve(origin ? res : res.data.data);
|
|
5094
5118
|
}).catch((e) => {
|
|
5119
|
+
ksResponseInterceptor(e);
|
|
5095
5120
|
reject(e);
|
|
5096
5121
|
}).finally(
|
|
5097
5122
|
() => loading && typeof (loadingOptions == null ? void 0 : loadingOptions.hide) === "function" && (loadingOptions == null ? void 0 : loadingOptions.hide())
|
|
@@ -5146,6 +5171,7 @@ function handleOptions(httpInstance, url, method2, param, config) {
|
|
|
5146
5171
|
const headers = {};
|
|
5147
5172
|
Object.assign(headers, config.headers || {}, casHeaders);
|
|
5148
5173
|
return __spreadValues(__spreadValues({
|
|
5174
|
+
userConfig: __spreadValues({}, config),
|
|
5149
5175
|
url: getRequestUrl(
|
|
5150
5176
|
url,
|
|
5151
5177
|
config.baseURL ? config.baseURL : httpInstance.baseURL
|
|
@@ -5245,7 +5271,10 @@ var http_default = function() {
|
|
|
5245
5271
|
|
|
5246
5272
|
// src/useHttp/openApi.ts
|
|
5247
5273
|
var http = http_default({
|
|
5248
|
-
baseURL: "/router/rest"
|
|
5274
|
+
baseURL: "/router/rest",
|
|
5275
|
+
interceptors: {
|
|
5276
|
+
response: [ksResponseInterceptor]
|
|
5277
|
+
}
|
|
5249
5278
|
});
|
|
5250
5279
|
function createRequest(type) {
|
|
5251
5280
|
return function(url, appKey, data, config) {
|
|
@@ -50,6 +50,32 @@ export declare function handleOptions(httpInstance: HttpClient, url: string, met
|
|
|
50
50
|
FormData?: (new (...args: any[]) => object) | undefined;
|
|
51
51
|
} | undefined;
|
|
52
52
|
formSerializer?: import("axios").FormSerializerOptions | undefined;
|
|
53
|
+
userConfig: {
|
|
54
|
+
baseURL?: string | undefined;
|
|
55
|
+
headers?: Record<string, any> | undefined;
|
|
56
|
+
cancelToken?: CancelToken | import("axios").CancelTokenSource | undefined;
|
|
57
|
+
ksAdapter?: boolean | undefined;
|
|
58
|
+
failToast?: boolean | undefined;
|
|
59
|
+
loading?: boolean | undefined;
|
|
60
|
+
tips?: boolean | undefined;
|
|
61
|
+
customHeaders?: boolean | undefined;
|
|
62
|
+
onUploadProgress?: ((progressEvent: any) => void) | undefined;
|
|
63
|
+
onDownloadProgress?: ((progressEvent: any) => void) | undefined;
|
|
64
|
+
options?: Record<string, any> | undefined;
|
|
65
|
+
origin?: boolean | undefined;
|
|
66
|
+
appKey?: string | number | undefined;
|
|
67
|
+
timeout?: number | undefined;
|
|
68
|
+
adapter?: import("axios").AxiosAdapter | undefined;
|
|
69
|
+
transformRequest?: AxiosRequestTransformer | undefined;
|
|
70
|
+
transformResponse?: AxiosResponseTransformer | undefined;
|
|
71
|
+
validateStatus?: ((status: number) => boolean) | undefined;
|
|
72
|
+
interceptors?: HttpInterceptorMap | undefined;
|
|
73
|
+
loadingOptions?: {
|
|
74
|
+
show?: (() => void) | undefined;
|
|
75
|
+
hide?: (() => void) | undefined;
|
|
76
|
+
} | undefined;
|
|
77
|
+
casToken?: boolean | undefined;
|
|
78
|
+
};
|
|
53
79
|
};
|
|
54
80
|
type InterceptorList = Array<{
|
|
55
81
|
type: 'request' | 'response' | 'rejectRequest' | 'rejectResponse';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ks-web/use",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Vant Composition API",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.mjs",
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"release-it": "^16.1.3",
|
|
48
48
|
"rimraf": "^5.0.0",
|
|
49
49
|
"typescript": "^5.0.4",
|
|
50
|
-
"vue": "^3.3.4"
|
|
50
|
+
"vue": "^3.3.4",
|
|
51
|
+
"@ks-web/ks": "0.0.8-beta.2"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
54
|
"vue": "^3.0.0"
|