@zero-library/common 2.1.2 → 2.1.4
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 +66 -104
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +19 -30
- package/dist/index.d.ts +19 -30
- package/dist/index.esm.js +67 -100
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -993,112 +993,78 @@ var MISSING_PARAMETER = 400;
|
|
|
993
993
|
var UNAUTHORIZED = 401;
|
|
994
994
|
var FORBIDDEN = 403;
|
|
995
995
|
var NOT_FOUND = 404;
|
|
996
|
-
var ILLEGAL_PARAMETER = 901;
|
|
997
996
|
var PERMISSION_DENIED = 13001;
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
function(config) {
|
|
1014
|
-
config.headers[TOKEN_KEY] = getToken();
|
|
1015
|
-
if (config.url && !config.url.startsWith("/api/")) {
|
|
1016
|
-
config.baseURL = "/api";
|
|
997
|
+
function createRequest(baseURL = "/api") {
|
|
998
|
+
const redirectUrl = () => {
|
|
999
|
+
emit("jumpLink", { url: `/uc${getSignPath()}` });
|
|
1000
|
+
};
|
|
1001
|
+
const instance = axios__default.default.create({
|
|
1002
|
+
baseURL,
|
|
1003
|
+
timeout: 6e4
|
|
1004
|
+
});
|
|
1005
|
+
instance.interceptors.request.use(
|
|
1006
|
+
function(config) {
|
|
1007
|
+
config.headers[TOKEN_KEY] = getToken();
|
|
1008
|
+
return config;
|
|
1009
|
+
},
|
|
1010
|
+
function(error) {
|
|
1011
|
+
return Promise.reject(error);
|
|
1017
1012
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
)
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1013
|
+
);
|
|
1014
|
+
instance.interceptors.response.use(
|
|
1015
|
+
function(response) {
|
|
1016
|
+
if (isBlob(response.data)) return response;
|
|
1017
|
+
if (response.data?.code !== OK) {
|
|
1018
|
+
const isPermission = response.data?.code === PERMISSION_DENIED;
|
|
1019
|
+
if (response.config?.showError !== false) {
|
|
1020
|
+
showMessage({
|
|
1021
|
+
title: isPermission ? "" : void 0,
|
|
1022
|
+
content: response.data.message,
|
|
1023
|
+
duration: isPermission ? 0 : 3
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
return Promise.reject(response.data);
|
|
1027
|
+
}
|
|
1028
1028
|
return response;
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
const
|
|
1032
|
-
if (response
|
|
1033
|
-
showMessage({
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1029
|
+
},
|
|
1030
|
+
function(err) {
|
|
1031
|
+
const showError = err?.config?.showError !== false;
|
|
1032
|
+
if (!err.response) {
|
|
1033
|
+
if (showError) showMessage({ content: "\u7F51\u7EDC\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC", type: "error" });
|
|
1034
|
+
} else {
|
|
1035
|
+
switch (err.response?.status) {
|
|
1036
|
+
case UNAUTHORIZED:
|
|
1037
|
+
if (showError) showMessage({ content: err.response?.data.message, type: "error" });
|
|
1038
|
+
redirectUrl();
|
|
1039
|
+
break;
|
|
1040
|
+
default:
|
|
1041
|
+
if (showError) showMessage({ content: err.response?.data.message || "\u8BF7\u6C42\u9519\u8BEF\uFF01", type: "error" });
|
|
1042
|
+
}
|
|
1038
1043
|
}
|
|
1039
|
-
return Promise.reject(
|
|
1044
|
+
return Promise.reject(err);
|
|
1040
1045
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
if (showError) showMessage({ content: err.response?.data.message, type: "error" });
|
|
1059
|
-
break;
|
|
1060
|
-
default:
|
|
1061
|
-
if (showError) showMessage({ content: "\u8BF7\u6C42\u6570\u636E\u53D1\u751F\u9519\u8BEF\uFF01", type: "info" });
|
|
1062
|
-
}
|
|
1046
|
+
);
|
|
1047
|
+
return {
|
|
1048
|
+
get: async (url, params, options) => {
|
|
1049
|
+
const res = await instance({ method: "get", url, params, ...options });
|
|
1050
|
+
return res.data;
|
|
1051
|
+
},
|
|
1052
|
+
post: async (url, data, options) => {
|
|
1053
|
+
const res = await instance({ method: "post", url, data, ...options });
|
|
1054
|
+
return res.data;
|
|
1055
|
+
},
|
|
1056
|
+
put: async (url, data, options) => {
|
|
1057
|
+
const res = await instance({ method: "put", url, data, ...options });
|
|
1058
|
+
return res.data;
|
|
1059
|
+
},
|
|
1060
|
+
delete: async (url, data, options) => {
|
|
1061
|
+
const res = await instance({ method: "delete", url, data, ...options });
|
|
1062
|
+
return res.data;
|
|
1063
1063
|
}
|
|
1064
|
-
return Promise.reject(err);
|
|
1065
|
-
}
|
|
1066
|
-
);
|
|
1067
|
-
var get = async (url, params, options) => {
|
|
1068
|
-
const res = await axios__default.default({ method: "get", url, params, ...options });
|
|
1069
|
-
return res.data;
|
|
1070
|
-
};
|
|
1071
|
-
var post = async (url, data, options) => {
|
|
1072
|
-
const res = await axios__default.default({
|
|
1073
|
-
method: "post",
|
|
1074
|
-
url,
|
|
1075
|
-
data,
|
|
1076
|
-
...parseOptions(options)
|
|
1077
|
-
});
|
|
1078
|
-
return res.data;
|
|
1079
|
-
};
|
|
1080
|
-
var put = async (url, data, options) => {
|
|
1081
|
-
const res = await axios__default.default({ method: "put", url, data, ...parseOptions(options) });
|
|
1082
|
-
return res.data;
|
|
1083
|
-
};
|
|
1084
|
-
var del = async (url, data, options) => {
|
|
1085
|
-
const reqConfig = {
|
|
1086
|
-
method: "delete",
|
|
1087
|
-
url,
|
|
1088
|
-
...parseOptions(options)
|
|
1089
1064
|
};
|
|
1090
|
-
|
|
1091
|
-
const res = await axios__default.default({ ...reqConfig, ...params });
|
|
1092
|
-
return res.data;
|
|
1093
|
-
};
|
|
1094
|
-
var request_default = {
|
|
1095
|
-
get,
|
|
1096
|
-
post,
|
|
1097
|
-
put,
|
|
1098
|
-
delete: del
|
|
1099
|
-
};
|
|
1065
|
+
}
|
|
1100
1066
|
|
|
1101
|
-
// src/hooks/useWebSocket.ts
|
|
1067
|
+
// src/hooks/webSocket/useWebSocket.ts
|
|
1102
1068
|
var useWebSocket = ({
|
|
1103
1069
|
url,
|
|
1104
1070
|
onMessage,
|
|
@@ -1207,6 +1173,7 @@ var useWebSocket = ({
|
|
|
1207
1173
|
}
|
|
1208
1174
|
};
|
|
1209
1175
|
React16.useEffect(() => {
|
|
1176
|
+
if (!url) return;
|
|
1210
1177
|
isDestroy.current = false;
|
|
1211
1178
|
createAndListenWebSocket();
|
|
1212
1179
|
window.addEventListener("visibilitychange", handleVisibilityChange);
|
|
@@ -5263,15 +5230,12 @@ exports.DateFormatType = DateFormatType;
|
|
|
5263
5230
|
exports.DateFormatType2 = DateFormatType2;
|
|
5264
5231
|
exports.ERROR = ERROR;
|
|
5265
5232
|
exports.FORBIDDEN = FORBIDDEN;
|
|
5266
|
-
exports.FacePastCode = FacePastCode;
|
|
5267
5233
|
exports.FileIcon = FileIcon_default;
|
|
5268
5234
|
exports.FilePreview = FilePreview_default;
|
|
5269
5235
|
exports.FilePreviewDrawer = FilePreviewDrawer_default;
|
|
5270
|
-
exports.ILLEGAL_PARAMETER = ILLEGAL_PARAMETER;
|
|
5271
5236
|
exports.Iframe = Iframe_default;
|
|
5272
5237
|
exports.LazyComponent = LazyComponent_default;
|
|
5273
5238
|
exports.LgPrimaryColor = LgPrimaryColor;
|
|
5274
|
-
exports.LoginPastCode = LoginPastCode;
|
|
5275
5239
|
exports.MISSING_PARAMETER = MISSING_PARAMETER;
|
|
5276
5240
|
exports.MarkdownEditor = MarkdownEditor_default;
|
|
5277
5241
|
exports.MarkdownPreview = MarkdownPreview_default;
|
|
@@ -5294,6 +5258,7 @@ exports.clearCurrentUser = clearCurrentUser;
|
|
|
5294
5258
|
exports.clearToken = clearToken;
|
|
5295
5259
|
exports.compareNum = compareNum;
|
|
5296
5260
|
exports.copyText = copyText;
|
|
5261
|
+
exports.createRequest = createRequest;
|
|
5297
5262
|
exports.decimalPlaces = decimalPlaces;
|
|
5298
5263
|
exports.deepCopy = deepCopy;
|
|
5299
5264
|
exports.deepEqual = deepEqual;
|
|
@@ -5302,7 +5267,6 @@ exports.dividedBy = dividedBy;
|
|
|
5302
5267
|
exports.downloadFile = downloadFile;
|
|
5303
5268
|
exports.emit = emit;
|
|
5304
5269
|
exports.emitToChild = emitToChild;
|
|
5305
|
-
exports.formType = formType;
|
|
5306
5270
|
exports.formatDate = formatDate;
|
|
5307
5271
|
exports.formatNumberWithCommas = formatNumberWithCommas;
|
|
5308
5272
|
exports.genNonDuplicateID = genNonDuplicateID;
|
|
@@ -5347,14 +5311,12 @@ exports.isServer = isServer;
|
|
|
5347
5311
|
exports.isString = isString;
|
|
5348
5312
|
exports.isUnDef = isUnDef;
|
|
5349
5313
|
exports.isWindow = isWindow;
|
|
5350
|
-
exports.jsonType = jsonType;
|
|
5351
5314
|
exports.minus = minus;
|
|
5352
5315
|
exports.nsSetInterval = nsSetInterval;
|
|
5353
5316
|
exports.objToOptions = objToOptions;
|
|
5354
5317
|
exports.plus = plus;
|
|
5355
5318
|
exports.precision = precision;
|
|
5356
5319
|
exports.propsMerge = propsMerge;
|
|
5357
|
-
exports.request = request_default;
|
|
5358
5320
|
exports.setCurrentUser = setCurrentUser;
|
|
5359
5321
|
exports.setToken = setToken;
|
|
5360
5322
|
exports.shouldRender = shouldRender;
|