@qlibs/utils 1.10.0 → 1.11.0
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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBasePath = getBasePath;
|
|
4
|
+
exports.goBack = goBack;
|
|
5
|
+
function getBasePath() {
|
|
6
|
+
const pathname = window.location.pathname;
|
|
7
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
8
|
+
if (segments.length <= 1)
|
|
9
|
+
return '/' + (segments[0] || '');
|
|
10
|
+
const baseSegments = segments.slice(0, -1);
|
|
11
|
+
return '/' + baseSegments.join('/');
|
|
12
|
+
}
|
|
13
|
+
function goBack(navigateFunction) {
|
|
14
|
+
if (window.history.length > 0) {
|
|
15
|
+
navigateFunction(-1);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const backPath = getBasePath();
|
|
19
|
+
navigateFunction(backPath);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -5,6 +5,7 @@ exports.getErrorCode = getErrorCode;
|
|
|
5
5
|
exports.getErrors = getErrors;
|
|
6
6
|
exports.getStandardError = getStandardError;
|
|
7
7
|
exports.handleFormValidation = handleFormValidation;
|
|
8
|
+
exports.showErrorMessage = showErrorMessage;
|
|
8
9
|
function getErrorMessage(err, config) {
|
|
9
10
|
let errMessage = 'Failed. Please try again.';
|
|
10
11
|
console.info('err', err);
|
|
@@ -116,20 +117,8 @@ function getStandardError(err, config) {
|
|
|
116
117
|
if (config === null || config === void 0 ? void 0 : config.triggerFormValidation) {
|
|
117
118
|
handleFormValidation(errors || [], config.formRef);
|
|
118
119
|
}
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
config.toastFunction.error({
|
|
122
|
-
title: 'Failed',
|
|
123
|
-
content: message,
|
|
124
|
-
closable: true,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
else if (config.toastFunction.error) {
|
|
128
|
-
config.toastFunction.error(message);
|
|
129
|
-
}
|
|
130
|
-
else if (typeof config.toastFunction === 'function') {
|
|
131
|
-
config.toastFunction(message);
|
|
132
|
-
}
|
|
120
|
+
if (config === null || config === void 0 ? void 0 : config.showToast) {
|
|
121
|
+
showErrorMessage(config.toastFunction, message);
|
|
133
122
|
}
|
|
134
123
|
return {
|
|
135
124
|
code,
|
|
@@ -163,3 +152,20 @@ function handleFormValidation(errors, formRef) {
|
|
|
163
152
|
formRef.setFields(fields);
|
|
164
153
|
}
|
|
165
154
|
}
|
|
155
|
+
function showErrorMessage(toastFunction, message) {
|
|
156
|
+
if (toastFunction) {
|
|
157
|
+
if (toastFunction.confirm) {
|
|
158
|
+
toastFunction.error({
|
|
159
|
+
title: 'Failed',
|
|
160
|
+
content: message,
|
|
161
|
+
closable: true,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
else if (toastFunction.error) {
|
|
165
|
+
toastFunction.error(message);
|
|
166
|
+
}
|
|
167
|
+
else if (typeof toastFunction === 'function') {
|
|
168
|
+
toastFunction(message);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.onFinishFailed = void 0;
|
|
4
|
+
const errorHandler_1 = require("./errorHandler");
|
|
4
5
|
const onFinishFailed = (antdErrorInfo, config) => {
|
|
5
6
|
console.error('antdErrorInfo', antdErrorInfo);
|
|
6
7
|
const { errorFields } = antdErrorInfo;
|
|
7
8
|
if (errorFields && errorFields.length > 0) {
|
|
8
9
|
const firstError = errorFields[0];
|
|
9
10
|
if (firstError.errors && firstError.errors.length > 0) {
|
|
10
|
-
|
|
11
|
+
const message = firstError.errors.join(' ');
|
|
12
|
+
(0, errorHandler_1.showErrorMessage)(config.toastFunction, message);
|
|
11
13
|
}
|
|
12
14
|
setTimeout(() => {
|
|
13
15
|
config.form.scrollToField(firstError.name, {
|
|
@@ -17,7 +19,7 @@ const onFinishFailed = (antdErrorInfo, config) => {
|
|
|
17
19
|
}, 100);
|
|
18
20
|
}
|
|
19
21
|
else {
|
|
20
|
-
config.toastFunction
|
|
22
|
+
(0, errorHandler_1.showErrorMessage)(config.toastFunction, 'Something wrong. Please check your inputs.');
|
|
21
23
|
}
|
|
22
24
|
};
|
|
23
25
|
exports.onFinishFailed = onFinishFailed;
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./auth"), exports);
|
|
18
18
|
__exportStar(require("./axios"), exports);
|
|
19
|
+
__exportStar(require("./basePath"), exports);
|
|
19
20
|
__exportStar(require("./datetime"), exports);
|
|
20
21
|
__exportStar(require("./errorHandler"), exports);
|
|
21
22
|
__exportStar(require("./formRules"), exports);
|