@ks-web/use 0.0.6 → 0.0.8
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,33 @@ 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;
|
|
4966
|
+
}
|
|
4967
|
+
try {
|
|
4968
|
+
const { tips } = res.config.userConfig || {};
|
|
4969
|
+
let { msg = res.message || res.msg } = res.data || {};
|
|
4970
|
+
const errorTips = getErrorsTips[msg];
|
|
4971
|
+
if (tips !== false && msg) {
|
|
4972
|
+
(0, import_ks.showToast)(errorTips || msg);
|
|
4973
|
+
}
|
|
4974
|
+
} catch (e) {
|
|
4975
|
+
}
|
|
4976
|
+
return Promise.reject(res);
|
|
4977
|
+
}
|
|
4978
|
+
|
|
4952
4979
|
// src/useType/index.ts
|
|
4953
4980
|
var toString3 = Object.prototype.toString;
|
|
4954
4981
|
var { is } = function _internal() {
|
|
@@ -5002,7 +5029,9 @@ function createCasHeaders(opt) {
|
|
|
5002
5029
|
sign: _getSign(),
|
|
5003
5030
|
format: "JSON",
|
|
5004
5031
|
timestamp: now,
|
|
5005
|
-
"x-webtrace-id": _getXWebTraceId(user.id, menu.id, now)
|
|
5032
|
+
"x-webtrace-id": _getXWebTraceId(user.id, menu.id, now),
|
|
5033
|
+
webTraceId: `${user.id}-${now}-${_random(4)}-${menu.id || "xxxx"}`,
|
|
5034
|
+
"X-menu-id": menu.id
|
|
5006
5035
|
};
|
|
5007
5036
|
return _headers;
|
|
5008
5037
|
}
|
|
@@ -5110,6 +5139,7 @@ function getRequest(httpInstance, url, method2, param, config) {
|
|
|
5110
5139
|
httpInstance.http(options).then((res) => {
|
|
5111
5140
|
resolve(origin ? res : res.data.data);
|
|
5112
5141
|
}).catch((e) => {
|
|
5142
|
+
ksResponseInterceptor(e);
|
|
5113
5143
|
reject(e);
|
|
5114
5144
|
}).finally(
|
|
5115
5145
|
() => loading && typeof (loadingOptions == null ? void 0 : loadingOptions.hide) === "function" && (loadingOptions == null ? void 0 : loadingOptions.hide())
|
|
@@ -5164,6 +5194,7 @@ function handleOptions(httpInstance, url, method2, param, config) {
|
|
|
5164
5194
|
const headers = {};
|
|
5165
5195
|
Object.assign(headers, config.headers || {}, casHeaders);
|
|
5166
5196
|
return __spreadValues(__spreadValues({
|
|
5197
|
+
userConfig: __spreadValues({}, config),
|
|
5167
5198
|
url: getRequestUrl(
|
|
5168
5199
|
url,
|
|
5169
5200
|
config.baseURL ? config.baseURL : httpInstance.baseURL
|
|
@@ -5263,7 +5294,10 @@ var http_default = function() {
|
|
|
5263
5294
|
|
|
5264
5295
|
// src/useHttp/openApi.ts
|
|
5265
5296
|
var http = http_default({
|
|
5266
|
-
baseURL: "/router/rest"
|
|
5297
|
+
baseURL: "/router/rest",
|
|
5298
|
+
interceptors: {
|
|
5299
|
+
response: [ksResponseInterceptor]
|
|
5300
|
+
}
|
|
5267
5301
|
});
|
|
5268
5302
|
function createRequest(type) {
|
|
5269
5303
|
return function(url, appKey, data, config) {
|
package/dist/index.esm.mjs
CHANGED
|
@@ -4931,6 +4931,33 @@ 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;
|
|
4948
|
+
}
|
|
4949
|
+
try {
|
|
4950
|
+
const { tips } = res.config.userConfig || {};
|
|
4951
|
+
let { msg = res.message || res.msg } = res.data || {};
|
|
4952
|
+
const errorTips = getErrorsTips[msg];
|
|
4953
|
+
if (tips !== false && msg) {
|
|
4954
|
+
showToast(errorTips || msg);
|
|
4955
|
+
}
|
|
4956
|
+
} catch (e) {
|
|
4957
|
+
}
|
|
4958
|
+
return Promise.reject(res);
|
|
4959
|
+
}
|
|
4960
|
+
|
|
4934
4961
|
// src/useType/index.ts
|
|
4935
4962
|
var toString3 = Object.prototype.toString;
|
|
4936
4963
|
var { is } = function _internal() {
|
|
@@ -4984,7 +5011,9 @@ function createCasHeaders(opt) {
|
|
|
4984
5011
|
sign: _getSign(),
|
|
4985
5012
|
format: "JSON",
|
|
4986
5013
|
timestamp: now,
|
|
4987
|
-
"x-webtrace-id": _getXWebTraceId(user.id, menu.id, now)
|
|
5014
|
+
"x-webtrace-id": _getXWebTraceId(user.id, menu.id, now),
|
|
5015
|
+
webTraceId: `${user.id}-${now}-${_random(4)}-${menu.id || "xxxx"}`,
|
|
5016
|
+
"X-menu-id": menu.id
|
|
4988
5017
|
};
|
|
4989
5018
|
return _headers;
|
|
4990
5019
|
}
|
|
@@ -5092,6 +5121,7 @@ function getRequest(httpInstance, url, method2, param, config) {
|
|
|
5092
5121
|
httpInstance.http(options).then((res) => {
|
|
5093
5122
|
resolve(origin ? res : res.data.data);
|
|
5094
5123
|
}).catch((e) => {
|
|
5124
|
+
ksResponseInterceptor(e);
|
|
5095
5125
|
reject(e);
|
|
5096
5126
|
}).finally(
|
|
5097
5127
|
() => loading && typeof (loadingOptions == null ? void 0 : loadingOptions.hide) === "function" && (loadingOptions == null ? void 0 : loadingOptions.hide())
|
|
@@ -5146,6 +5176,7 @@ function handleOptions(httpInstance, url, method2, param, config) {
|
|
|
5146
5176
|
const headers = {};
|
|
5147
5177
|
Object.assign(headers, config.headers || {}, casHeaders);
|
|
5148
5178
|
return __spreadValues(__spreadValues({
|
|
5179
|
+
userConfig: __spreadValues({}, config),
|
|
5149
5180
|
url: getRequestUrl(
|
|
5150
5181
|
url,
|
|
5151
5182
|
config.baseURL ? config.baseURL : httpInstance.baseURL
|
|
@@ -5245,7 +5276,10 @@ var http_default = function() {
|
|
|
5245
5276
|
|
|
5246
5277
|
// src/useHttp/openApi.ts
|
|
5247
5278
|
var http = http_default({
|
|
5248
|
-
baseURL: "/router/rest"
|
|
5279
|
+
baseURL: "/router/rest",
|
|
5280
|
+
interceptors: {
|
|
5281
|
+
response: [ksResponseInterceptor]
|
|
5282
|
+
}
|
|
5249
5283
|
});
|
|
5250
5284
|
function createRequest(type) {
|
|
5251
5285
|
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';
|
|
@@ -13,6 +13,8 @@ export declare function createCasHeaders(opt: CasHeadersTransformOptions): {
|
|
|
13
13
|
format: string;
|
|
14
14
|
timestamp: number;
|
|
15
15
|
'x-webtrace-id': string;
|
|
16
|
+
webTraceId: string;
|
|
17
|
+
'X-menu-id': string;
|
|
16
18
|
};
|
|
17
19
|
export declare function casInterceptorResponse(response: AxiosResponse): AxiosResponse<any, any>;
|
|
18
20
|
export declare function createKuaShengAdapter(config: InternalAxiosRequestConfig): AxiosPromise;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ks-web/use",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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"
|