cloud-web-corejs 1.0.296 → 1.0.298
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/package.json +1 -1
- package/src/components/errorMsg/index.vue +67 -10
- package/src/components/errorMsg/mixins.js +53 -0
- package/src/components/onlineTalk/mixins.js +10 -7
- package/src/components/xform/form-designer/form-widget/field-widget/fieldMixin.js +10 -6
- package/src/components/xform/form-designer/form-widget/field-widget/form-item-wrapper.vue +13 -3
- package/src/components/xform/form-render/container-item/data-table-mixin.js +6 -2
- package/src/components/xform/form-render/indexMixin.js +3 -0
- package/src/components/xform/utils/util.js +34 -0
- package/src/utils/request.js +112 -14
- package/src/views/user/home/default.vue +1120 -1117
- package/src/views/user/home/default2.vue +3 -3
package/package.json
CHANGED
|
@@ -6,20 +6,25 @@
|
|
|
6
6
|
v-if="showWrap"
|
|
7
7
|
:close-on-click-modal="false"
|
|
8
8
|
width="501px"
|
|
9
|
-
custom-class="dialog-style tips-dialog error"
|
|
9
|
+
:custom-class="structuredDetail ? `dialog-style tips-dialog error error-message-dialog${showTextFlag ? ' is-detail' : ''}` : 'dialog-style tips-dialog error'"
|
|
10
10
|
:append-to-body="true"
|
|
11
11
|
:modal="false"
|
|
12
12
|
@close="closeDialog"
|
|
13
13
|
v-el-drag-dialog
|
|
14
14
|
>
|
|
15
15
|
<div class="cont">
|
|
16
|
-
<p
|
|
17
|
-
<p v-if="rmid">Error({{ rmid }}):</p>
|
|
16
|
+
<p>{{ errorTitle }}</p>
|
|
18
17
|
<template v-if="!showTextFlag">
|
|
19
18
|
<p v-html="text1"></p>
|
|
20
19
|
</template>
|
|
21
|
-
<
|
|
22
|
-
|
|
20
|
+
<div v-if="showTextFlag && structuredDetail" class="error-detail-list">
|
|
21
|
+
<div v-for="(item, index) in detailItems" :key="index" class="error-detail-row" :class="{ 'is-summary': item.isSummary, 'is-section': item.isSection, 'is-cause': item.isCause }">
|
|
22
|
+
<span v-if="item.label" class="error-detail-label">{{ item.label }}</span>
|
|
23
|
+
<span v-if="item.value" class="error-detail-value">{{ item.value }}</span>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
<p v-else-if="showTextFlag" class="error-detail-plain" v-html="text2"></p>
|
|
27
|
+
<a class="error-detail-toggle" href="javascript:void(0);" @click="showTextFlag = !showTextFlag">{{
|
|
23
28
|
!showTextFlag
|
|
24
29
|
? $t2("详情", "components.errorMsg.detail")
|
|
25
30
|
: $t2("收起", "components.errorMsg.collapse")
|
|
@@ -44,12 +49,17 @@
|
|
|
44
49
|
<i class="icon"></i>
|
|
45
50
|
<div class="cont">
|
|
46
51
|
<p class="name">{{ title }}</p>
|
|
47
|
-
<p class="txt"
|
|
48
|
-
<p class="txt" v-if="rmid">Error({{ rmid }}):</p>
|
|
52
|
+
<p class="txt">{{ errorTitle }}</p>
|
|
49
53
|
<template v-if="!showTextFlag">
|
|
50
54
|
<p class="txt">{{ text1 }}</p>
|
|
51
55
|
</template>
|
|
52
|
-
<
|
|
56
|
+
<div v-if="showTextFlag && structuredDetail" class="error-detail-list">
|
|
57
|
+
<div v-for="(item, index) in detailItems" :key="index" class="error-detail-row" :class="{ 'is-summary': item.isSummary, 'is-section': item.isSection, 'is-cause': item.isCause }">
|
|
58
|
+
<span v-if="item.label" class="error-detail-label">{{ item.label }}</span>
|
|
59
|
+
<span v-if="item.value" class="error-detail-value">{{ item.value }}</span>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
<p class="txt" v-else-if="showTextFlag" v-html="text2"></p>
|
|
53
63
|
<a href="javascript:void(0);" @click="showTextFlag = !showTextFlag">{{
|
|
54
64
|
!showTextFlag
|
|
55
65
|
? $t2("详情", "components.errorMsg.detail")
|
|
@@ -70,9 +80,56 @@
|
|
|
70
80
|
import { mixins } from "./mixins";
|
|
71
81
|
|
|
72
82
|
export default {
|
|
73
|
-
|
|
83
|
+
name: "ErrorMessage",
|
|
74
84
|
mixins: [mixins],
|
|
75
85
|
};
|
|
76
86
|
</script>
|
|
77
87
|
|
|
78
|
-
<style
|
|
88
|
+
<style lang="scss">
|
|
89
|
+
.error-message-dialog {
|
|
90
|
+
.el-dialog__body .cont {
|
|
91
|
+
padding: 18px 20px 16px;
|
|
92
|
+
max-height: min(520px, calc(100vh - 190px));
|
|
93
|
+
}
|
|
94
|
+
&.is-detail .el-dialog__body:after { display: none; }
|
|
95
|
+
}
|
|
96
|
+
.error-detail-list {
|
|
97
|
+
overflow: hidden; border: 1px solid #dfe6f1; border-radius: 6px;
|
|
98
|
+
background: rgba(255, 255, 255, 0.86);
|
|
99
|
+
}
|
|
100
|
+
.error-detail-row {
|
|
101
|
+
display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 12px;
|
|
102
|
+
padding: 7px 12px; border-bottom: 1px solid #edf0f5;
|
|
103
|
+
line-height: 1.55; word-break: break-word;
|
|
104
|
+
&:last-child { border-bottom: 0; }
|
|
105
|
+
&.is-summary, &.is-section { display: block; }
|
|
106
|
+
&.is-summary {
|
|
107
|
+
padding: 10px 12px; background: #edf4ff; color: #315f91; font-weight: 600;
|
|
108
|
+
}
|
|
109
|
+
&.is-section {
|
|
110
|
+
padding: 9px 12px 5px; border-bottom: 0; color: #303133; font-weight: 600;
|
|
111
|
+
}
|
|
112
|
+
&.is-cause {
|
|
113
|
+
position: relative; display: block; padding: 4px 12px 4px 30px; border-bottom: 0;
|
|
114
|
+
&:before {
|
|
115
|
+
content: ""; position: absolute; top: 13px; left: 17px;
|
|
116
|
+
width: 4px; height: 4px; border-radius: 50%; background: #8ca5c2;
|
|
117
|
+
}
|
|
118
|
+
.error-detail-label { margin-right: 4px; }
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
.error-detail-label { color: #606266; font-weight: 600; }
|
|
122
|
+
.error-detail-value { min-width: 0; color: #606266; }
|
|
123
|
+
.error-detail-toggle { display: inline-block; margin-top: 12px; }
|
|
124
|
+
.error-detail-plain { line-height: 1.65; word-break: break-word; }
|
|
125
|
+
.pop-tipsBox.error .error-detail-list {
|
|
126
|
+
max-height: 42vh; overflow: auto; text-align: left;
|
|
127
|
+
}
|
|
128
|
+
@media (max-width: 640px) {
|
|
129
|
+
.error-detail-row {
|
|
130
|
+
display: block;
|
|
131
|
+
.error-detail-label { display: block; margin-bottom: 2px; }
|
|
132
|
+
&.is-cause .error-detail-label { display: inline; }
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
</style>
|
|
@@ -14,6 +14,9 @@ tmixins = {
|
|
|
14
14
|
},
|
|
15
15
|
objx: Object,
|
|
16
16
|
_errorMsg: null,
|
|
17
|
+
errorLabel: {
|
|
18
|
+
default: "",
|
|
19
|
+
},
|
|
17
20
|
},
|
|
18
21
|
created() {
|
|
19
22
|
if (this.$baseEventBus.isMobile) {
|
|
@@ -26,11 +29,25 @@ tmixins = {
|
|
|
26
29
|
title: this.$t2("提示", "components.errorMsg.title"),
|
|
27
30
|
text1: "",
|
|
28
31
|
text2: "",
|
|
32
|
+
detailItems: [],
|
|
33
|
+
structuredDetail: false,
|
|
29
34
|
showWrap: false,
|
|
30
35
|
showTextFlag: false,
|
|
36
|
+
displayErrorLabel: "",
|
|
31
37
|
zIndex: null,
|
|
32
38
|
};
|
|
33
39
|
},
|
|
40
|
+
computed: {
|
|
41
|
+
errorTitle() {
|
|
42
|
+
if (this.rmid) return `Error(${this.rmid}):`;
|
|
43
|
+
if (!this.displayErrorLabel) return "Error:";
|
|
44
|
+
if (this.isNetworkErrorLabel) return `${this.displayErrorLabel}:`;
|
|
45
|
+
return `Error(${this.displayErrorLabel}):`;
|
|
46
|
+
},
|
|
47
|
+
isNetworkErrorLabel() {
|
|
48
|
+
return /^network error$/i.test(String(this.displayErrorLabel).trim());
|
|
49
|
+
},
|
|
50
|
+
},
|
|
34
51
|
beforeDestroy() {
|
|
35
52
|
this.removeEnterEvent();
|
|
36
53
|
},
|
|
@@ -56,6 +73,31 @@ tmixins = {
|
|
|
56
73
|
if (!text) return text;
|
|
57
74
|
return text.replace(/(\r\n|\n|\r)/gm, "<br />");
|
|
58
75
|
},
|
|
76
|
+
getHttpStatusCode(detailItems) {
|
|
77
|
+
const item = (detailItems || []).find((row) => row.label === "状态码");
|
|
78
|
+
const value = item && String(item.value).trim();
|
|
79
|
+
return /^\d{3}$/.test(value) ? value : "";
|
|
80
|
+
},
|
|
81
|
+
getDetailItems(text) {
|
|
82
|
+
let inCauseSection = false;
|
|
83
|
+
return String(text || "")
|
|
84
|
+
.split(/\r\n|\n|\r/)
|
|
85
|
+
.filter((line) => line.trim())
|
|
86
|
+
.map((line, index) => {
|
|
87
|
+
const separatorIndex = line.search(/[::]/);
|
|
88
|
+
const label = separatorIndex >= 0 ? line.slice(0, separatorIndex) : "";
|
|
89
|
+
const value = separatorIndex >= 0 ? line.slice(separatorIndex + 1).trim() : line;
|
|
90
|
+
const isSection = label === "可能原因";
|
|
91
|
+
if (isSection) inCauseSection = true;
|
|
92
|
+
return {
|
|
93
|
+
label,
|
|
94
|
+
value,
|
|
95
|
+
isSection,
|
|
96
|
+
isSummary: index === 0 && separatorIndex < 0,
|
|
97
|
+
isCause: inCauseSection && !isSection,
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
},
|
|
59
101
|
showMsgBox: function () {
|
|
60
102
|
this.removeEnterEvent();
|
|
61
103
|
this.addEnterEvent();
|
|
@@ -79,10 +121,21 @@ tmixins = {
|
|
|
79
121
|
);
|
|
80
122
|
if (this._errorMsg) {
|
|
81
123
|
this.text2 = this.getShowText(this._errorMsg);
|
|
124
|
+
this.structuredDetail = /(^|\n)状态码[::]/.test(this._errorMsg);
|
|
125
|
+
this.detailItems = this.structuredDetail
|
|
126
|
+
? this.getDetailItems(this._errorMsg)
|
|
127
|
+
: [];
|
|
82
128
|
} else {
|
|
83
129
|
this.text2 = this.getShowText(content);
|
|
130
|
+
this.structuredDetail = false;
|
|
131
|
+
this.detailItems = [];
|
|
84
132
|
}
|
|
133
|
+
} else {
|
|
134
|
+
this.detailItems = [];
|
|
135
|
+
this.structuredDetail = false;
|
|
85
136
|
}
|
|
137
|
+
this.displayErrorLabel =
|
|
138
|
+
this.errorLabel || this.getHttpStatusCode(this.detailItems) || "";
|
|
86
139
|
this.showTextFlag = false;
|
|
87
140
|
this.showWrap = true;
|
|
88
141
|
this.promise = new Promise((resolve, reject) => {
|
|
@@ -272,7 +272,7 @@ tmixins = {
|
|
|
272
272
|
}
|
|
273
273
|
});
|
|
274
274
|
},
|
|
275
|
-
getUserPage(flag) {
|
|
275
|
+
getUserPage(flag, silent) {
|
|
276
276
|
if (!this.dialogTableVisible) return
|
|
277
277
|
if (!this.inited) {
|
|
278
278
|
flag = null;
|
|
@@ -284,6 +284,7 @@ tmixins = {
|
|
|
284
284
|
method: `post`,
|
|
285
285
|
data: {operateTime: time},
|
|
286
286
|
modal: false,
|
|
287
|
+
...(silent ? { ignoreNetworkError: true } : {}),
|
|
287
288
|
success: res => {
|
|
288
289
|
let records = res.objx || [];
|
|
289
290
|
records.forEach(record => {
|
|
@@ -368,7 +369,7 @@ tmixins = {
|
|
|
368
369
|
}
|
|
369
370
|
return lastTalkRecordId;
|
|
370
371
|
},
|
|
371
|
-
getList(direction, callback) {
|
|
372
|
+
getList(direction, callback, silent) {
|
|
372
373
|
if (!this.dialogTableVisible) return
|
|
373
374
|
if (!this.talkUserId) return
|
|
374
375
|
let talkUser = this.talkUser;
|
|
@@ -387,6 +388,7 @@ tmixins = {
|
|
|
387
388
|
direction: direction
|
|
388
389
|
},
|
|
389
390
|
modal: false,
|
|
391
|
+
...(silent ? { ignoreNetworkError: true } : {}),
|
|
390
392
|
success: res => {
|
|
391
393
|
let rows = res.objx || [];
|
|
392
394
|
if (rows.length) {
|
|
@@ -456,15 +458,15 @@ tmixins = {
|
|
|
456
458
|
createTimerHandle() {
|
|
457
459
|
this.clearTimerHandle();
|
|
458
460
|
this.handleExitsRead();
|
|
459
|
-
this.talkHandle();
|
|
461
|
+
this.talkHandle(true);
|
|
460
462
|
this.timer = setInterval(() => {
|
|
461
463
|
this.handleExitsRead();
|
|
462
|
-
this.talkHandle();
|
|
464
|
+
this.talkHandle(true);
|
|
463
465
|
}, 10000)
|
|
464
466
|
},
|
|
465
|
-
talkHandle() {
|
|
466
|
-
this.getUserPage(1);
|
|
467
|
-
this.getList(0);
|
|
467
|
+
talkHandle(silent) {
|
|
468
|
+
this.getUserPage(1, silent);
|
|
469
|
+
this.getList(0, null, silent);
|
|
468
470
|
},
|
|
469
471
|
clearTimerHandle() {
|
|
470
472
|
if (this.timer) {
|
|
@@ -488,6 +490,7 @@ tmixins = {
|
|
|
488
490
|
method: `post`,
|
|
489
491
|
data: {},
|
|
490
492
|
modal: false,
|
|
493
|
+
ignoreNetworkError: true,
|
|
491
494
|
success: res => {
|
|
492
495
|
this.isExitsRead = res.objx === 1;
|
|
493
496
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
isArrayValueWidgetType,
|
|
12
12
|
isAttachmentWidgetType,
|
|
13
13
|
isEmptyArrayFieldValue,
|
|
14
|
+
resolveElementFormItemProp,
|
|
14
15
|
} from "../../../../../components/xform/utils/util";
|
|
15
16
|
import FormValidators, {
|
|
16
17
|
getRegExp,
|
|
@@ -346,19 +347,22 @@ modules = {
|
|
|
346
347
|
);
|
|
347
348
|
},
|
|
348
349
|
getPropName: function () {
|
|
350
|
+
let propName;
|
|
349
351
|
if (this.formItemProp) {
|
|
350
|
-
|
|
352
|
+
propName = this.formItemProp;
|
|
351
353
|
} else {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
+
propName =
|
|
355
|
+
this.subFormItemFlag && !this.designState
|
|
356
|
+
? this.subFormName +
|
|
354
357
|
"." +
|
|
355
358
|
this.subFormRowIndex +
|
|
356
359
|
"." +
|
|
357
360
|
this.fieldKeyName
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
+
: this.getObjectFieldFlag() && !this.designState
|
|
362
|
+
? this.getObjectName() + "." + this.fieldKeyName
|
|
363
|
+
: this.fieldKeyName;
|
|
361
364
|
}
|
|
365
|
+
return resolveElementFormItemProp(this.formModel, propName);
|
|
362
366
|
},
|
|
363
367
|
initFieldModel: function (flag) {
|
|
364
368
|
let e = this;
|
|
@@ -256,6 +256,7 @@ import i18n from "../../../../../components/xform/utils/i18n";
|
|
|
256
256
|
import {
|
|
257
257
|
getSubFormNameByFieldId,
|
|
258
258
|
isVabsearchMultiWidget,
|
|
259
|
+
resolveElementFormItemProp,
|
|
259
260
|
} from "../../../../../components/xform/utils/util";
|
|
260
261
|
import compareView from "../../../../../components/xform/form-render/compareView.vue";
|
|
261
262
|
import {
|
|
@@ -307,6 +308,7 @@ export default {
|
|
|
307
308
|
},
|
|
308
309
|
inject: {
|
|
309
310
|
getFormConfig: { default: () => () => ({}) },
|
|
311
|
+
globalModel: { default: () => ({ formModel: {} }) },
|
|
310
312
|
getSubFormFieldFlag: { default: () => () => false },
|
|
311
313
|
getSubFormName: { default: () => () => "" },
|
|
312
314
|
tableParam: { default: null },
|
|
@@ -559,6 +561,12 @@ export default {
|
|
|
559
561
|
getRules() {
|
|
560
562
|
return this.rules;
|
|
561
563
|
},
|
|
564
|
+
getFormModelForProp() {
|
|
565
|
+
return (this.globalModel && this.globalModel.formModel) || null;
|
|
566
|
+
},
|
|
567
|
+
resolveFormItemProp(propName) {
|
|
568
|
+
return resolveElementFormItemProp(this.getFormModelForProp(), propName);
|
|
569
|
+
},
|
|
562
570
|
getPropName() {
|
|
563
571
|
if (this.formItemProp === "false") {
|
|
564
572
|
return null;
|
|
@@ -568,12 +576,14 @@ export default {
|
|
|
568
576
|
// }
|
|
569
577
|
if (this.tableParam && !this.tableParam.$table?.$parent?.$parent) {
|
|
570
578
|
if (this.formItemProp) {
|
|
571
|
-
return this.formItemProp;
|
|
579
|
+
return this.resolveFormItemProp(this.formItemProp);
|
|
572
580
|
}
|
|
573
581
|
return null;
|
|
574
582
|
}
|
|
575
583
|
if (this.tableParam && !!this.tableParam.$table?.$parent?.$parent) {
|
|
576
|
-
return this.
|
|
584
|
+
return this.resolveFormItemProp(
|
|
585
|
+
this.getColumnProp(this.field, this.tableParam)
|
|
586
|
+
);
|
|
577
587
|
}
|
|
578
588
|
let o = this.field.options.name;
|
|
579
589
|
let propName =
|
|
@@ -586,7 +596,7 @@ export default {
|
|
|
586
596
|
? this.getObjectName() + "." + o
|
|
587
597
|
: o);
|
|
588
598
|
|
|
589
|
-
return propName;
|
|
599
|
+
return this.resolveFormItemProp(propName);
|
|
590
600
|
},
|
|
591
601
|
getFieldKeyName(widget) {
|
|
592
602
|
let o = widget.options.name;
|
|
@@ -3759,7 +3759,11 @@ modules = {
|
|
|
3759
3759
|
let nullValue = newData.hasOwnProperty(field)
|
|
3760
3760
|
? null
|
|
3761
3761
|
: this.getColumnNullValue(widget, defaultValueEnabled);
|
|
3762
|
-
|
|
3762
|
+
// 带点 keyName 是 lookup 嵌套路径。写成字面量键后,XEUtils.get 会命中
|
|
3763
|
+
// 这个 null,不再走进 msdyn_substatus.Name 这类对象取值。
|
|
3764
|
+
if (typeof field !== "string" || field.indexOf(".") === -1) {
|
|
3765
|
+
newData[field] = nullValue;
|
|
3766
|
+
}
|
|
3763
3767
|
if (this.isSingerlSearch(widget)) {
|
|
3764
3768
|
let vabSearchName = widget.options.vabSearchName;
|
|
3765
3769
|
if (vabSearchName) newData[vabSearchName] = null;
|
|
@@ -3796,7 +3800,7 @@ modules = {
|
|
|
3796
3800
|
} else {
|
|
3797
3801
|
if (widget) {
|
|
3798
3802
|
this.handleWidgetNullValue(widget, newData, defaultValueEnabled);
|
|
3799
|
-
} else {
|
|
3803
|
+
} else if (String(item.prop).indexOf(".") === -1) {
|
|
3800
3804
|
newData[item.prop] = null;
|
|
3801
3805
|
}
|
|
3802
3806
|
}
|
|
@@ -1827,6 +1827,9 @@ modules = {
|
|
|
1827
1827
|
let e = this;
|
|
1828
1828
|
this.$off("fieldValidation"),
|
|
1829
1829
|
this.$on("fieldValidation", function (t) {
|
|
1830
|
+
// 查询区带点 keyName 不会注册到 el-form-item,getPropName 为 null。
|
|
1831
|
+
// Element validateField(null) 会 warn「please pass correct props!」
|
|
1832
|
+
if (!t || !e.$refs.renderForm) return;
|
|
1830
1833
|
e.$refs.renderForm.validateField(t);
|
|
1831
1834
|
});
|
|
1832
1835
|
},
|
|
@@ -121,6 +121,40 @@ export function isEmptyStr(str) {
|
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Element el-form-item 的 prop 按 '.' / '[]' 拆成嵌套路径,中间对象不存在会抛
|
|
126
|
+
* "please transfer a valid prop path to form item"。
|
|
127
|
+
* 本系统大量 keyName 是 Dynamics 风格字面量键(如 msdyn_reportedbycontact.fullname),
|
|
128
|
+
* 存在 model["a.b"] 上而不是 model.a.b,不能交给 el-form-item。
|
|
129
|
+
*/
|
|
130
|
+
export function isElementFormPropReachable(model, prop) {
|
|
131
|
+
if (prop == null || prop === "" || prop === false || prop === "false") {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
const path = String(prop);
|
|
135
|
+
if (path.indexOf(".") === -1 && path.indexOf("[") === -1) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
if (model == null || typeof model !== "object") {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
let tempObj = model;
|
|
142
|
+
const normalized = path.replace(/\[(\w+)\]/g, ".$1").replace(/^\./, "");
|
|
143
|
+
const keyArr = normalized.split(".");
|
|
144
|
+
for (let i = 0; i < keyArr.length - 1; i++) {
|
|
145
|
+
const key = keyArr[i];
|
|
146
|
+
if (tempObj == null || typeof tempObj !== "object" || !(key in tempObj)) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
tempObj = tempObj[key];
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function resolveElementFormItemProp(model, prop) {
|
|
155
|
+
return isElementFormPropReachable(model, prop) ? prop : null;
|
|
156
|
+
}
|
|
157
|
+
|
|
124
158
|
export const generateId = function () {
|
|
125
159
|
return Math.floor(
|
|
126
160
|
Math.random() * 100000 + Math.random() * 20000 + Math.random() * 5000
|
package/src/utils/request.js
CHANGED
|
@@ -8,8 +8,8 @@ import ErroreBox from "../components/errorMsg/index.js";
|
|
|
8
8
|
import PopupManager from "element-ui/src/utils/popup/popup-manager.js";
|
|
9
9
|
import settingConfig from "@/settings.js";
|
|
10
10
|
import { encode } from "js-base64";
|
|
11
|
-
import { encrypt } from "@base/utils/aes";
|
|
12
|
-
import { handleRequestNetworkError } from "@base/utils/runtimeRecovery";
|
|
11
|
+
import { encrypt } from "@base/utils/aes";
|
|
12
|
+
import { handleRequestNetworkError } from "@base/utils/runtimeRecovery";
|
|
13
13
|
|
|
14
14
|
let configUtil = {
|
|
15
15
|
baseUrl: process.env.VUE_APP_BASE_API,
|
|
@@ -125,6 +125,95 @@ function removeModel(config) {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
function getSafeRequestUrl(config) {
|
|
129
|
+
if (!config || !config.url) return t1("未知");
|
|
130
|
+
const rawUrl = String(config.url).split("?")[0].split("#")[0];
|
|
131
|
+
const baseUrl = config.baseURL || "";
|
|
132
|
+
if (/^https?:\/\//i.test(rawUrl)) return rawUrl;
|
|
133
|
+
return `${baseUrl || ""}${rawUrl}` || t1("未知");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function t1(path, values) {
|
|
137
|
+
const translate = Vue.prototype.$t1;
|
|
138
|
+
return typeof translate === "function" ? translate(path, values) : path;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function isAxiosNetworkError(error) {
|
|
142
|
+
if (!error || error.response) return false;
|
|
143
|
+
const message = (error.message || "").toString();
|
|
144
|
+
if (error.code === "ECONNABORTED" || /timeout/i.test(message)) return false;
|
|
145
|
+
return error.code === "ERR_NETWORK" || /network error/i.test(message);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function shouldSwallowNetworkError(config, error) {
|
|
149
|
+
return !!(
|
|
150
|
+
config &&
|
|
151
|
+
config.ignoreNetworkError === true &&
|
|
152
|
+
isAxiosNetworkError(error)
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getRequestErrorMessage(error) {
|
|
157
|
+
const config = (error && error.config) || {};
|
|
158
|
+
const response = error && error.response;
|
|
159
|
+
const status = response && response.status;
|
|
160
|
+
const method = String(config.method || "GET").toUpperCase();
|
|
161
|
+
const requestUrl = getSafeRequestUrl(config);
|
|
162
|
+
const originalMessage = (error && error.message) || "未知错误";
|
|
163
|
+
let summary = t1("请求失败,请稍后重试。");
|
|
164
|
+
|
|
165
|
+
if (error && (error.code === "ECONNABORTED" || /timeout/i.test(originalMessage))) {
|
|
166
|
+
summary = t1("请求超时,请检查网络或稍后重试。");
|
|
167
|
+
} else if (!response) {
|
|
168
|
+
summary = t1("无法连接服务器,请检查网络、VPN/代理及服务状态后重试。");
|
|
169
|
+
} else if ([501, 502, 503, 504].includes(status)) {
|
|
170
|
+
summary = t1("网关或后端服务异常,请稍后重试或联系管理员。");
|
|
171
|
+
} else if (status >= 500) {
|
|
172
|
+
summary = t1("服务器暂时不可用,请稍后重试或联系管理员。");
|
|
173
|
+
} else if (status === 404) {
|
|
174
|
+
summary = t1("请求的服务地址不存在,请联系管理员检查接口配置。");
|
|
175
|
+
} else if (status === 403) {
|
|
176
|
+
summary = t1("服务器拒绝了本次请求,请检查访问权限。");
|
|
177
|
+
} else if (status === 401) {
|
|
178
|
+
summary = t1("登录状态已失效或无效,请重新登录。");
|
|
179
|
+
} else if (status >= 400) {
|
|
180
|
+
summary = t1("服务器未能处理本次请求,请检查输入后重试。");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const details = [
|
|
184
|
+
summary,
|
|
185
|
+
t1("请求:{method} {url}", { method, url: requestUrl }),
|
|
186
|
+
t1("状态码:{status}", {
|
|
187
|
+
status: status || t1("未收到服务器响应(浏览器未提供 HTTP 状态码)"),
|
|
188
|
+
}),
|
|
189
|
+
];
|
|
190
|
+
if (error && error.code) {
|
|
191
|
+
details.push(t1("错误码:{code}", { code: error.code }));
|
|
192
|
+
}
|
|
193
|
+
details.push(
|
|
194
|
+
t1("原始错误:{message}", { message: originalMessage }),
|
|
195
|
+
t1("发生时间:{time}", { time: new Date().toLocaleString() })
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
if (!response) {
|
|
199
|
+
details.push(t1("可能原因:"));
|
|
200
|
+
details.push(t1("ERR_CONNECTION_RESET:连接被服务端、网关或安全设备重置;"));
|
|
201
|
+
details.push(t1("CORS:浏览器跨域配置异常;"));
|
|
202
|
+
details.push(t1("ERR_CERT_*:HTTPS 证书异常;"));
|
|
203
|
+
details.push(t1("请求长期 Pending:接口阻塞或连接未释放。"));
|
|
204
|
+
details.push(t1("实际 HTTP 状态码请在浏览器 Network 面板或网关日志中确认。"));
|
|
205
|
+
} else if ([501, 502, 503, 504].includes(status)) {
|
|
206
|
+
details.push(t1("501/502/503/504:网关或后端服务异常。"));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
summary,
|
|
211
|
+
details: details.join("\n"),
|
|
212
|
+
// 有 HTTP 状态码时直接挂到弹窗标题 Error(502),不用点开「详情」
|
|
213
|
+
errorLabel: status ? String(status) : !response ? originalMessage : "",
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
128
217
|
async function handleNickName(option) {
|
|
129
218
|
let { vueTarget, res, callback, config } = option;
|
|
130
219
|
if (res.type !== "success" || !res.objx) {
|
|
@@ -398,14 +487,17 @@ service.interceptors.response.use(
|
|
|
398
487
|
// 那个 else 分支无条件弹 ErroreBox —— 而 ErroreBox 是弹窗不是 toast,取消 N 个
|
|
399
488
|
// 在途请求就会连弹 N 个错误框。config.errorMsg 那条逃生口在 if (config) 里面,
|
|
400
489
|
// Cancel 走不到,所以只能在这里拦。调用方按需自行 catch。
|
|
401
|
-
if (axios.isCancel(error)) {
|
|
402
|
-
return Promise.reject(error);
|
|
403
|
-
}
|
|
404
|
-
let config = error.config;
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
490
|
+
if (axios.isCancel(error)) {
|
|
491
|
+
return Promise.reject(error);
|
|
492
|
+
}
|
|
493
|
+
let config = error.config;
|
|
494
|
+
// 仅 Network Error 可被 ignoreNetworkError 吞掉(首页/在线聊天定时轮询)。
|
|
495
|
+
// 超时、5xx、业务失败等其它异常照常弹窗并 reject。
|
|
496
|
+
const swallowNetworkError = shouldSwallowNetworkError(config, error);
|
|
497
|
+
if (handleRequestNetworkError()) {
|
|
498
|
+
if (config && config.modalStrictly !== true) removeModel(config);
|
|
499
|
+
return swallowNetworkError ? Promise.resolve() : Promise.reject(error);
|
|
500
|
+
}
|
|
409
501
|
if (
|
|
410
502
|
error.response &&
|
|
411
503
|
error.response.data &&
|
|
@@ -419,20 +511,26 @@ service.interceptors.response.use(
|
|
|
419
511
|
if (config.modalStrictly !== true) {
|
|
420
512
|
removeModel(config);
|
|
421
513
|
}
|
|
422
|
-
if (config.errorMsg !== false) {
|
|
514
|
+
if (config.errorMsg !== false && !swallowNetworkError) {
|
|
515
|
+
const requestError = getRequestErrorMessage(error);
|
|
423
516
|
ErroreBox.msg({
|
|
424
|
-
content:
|
|
517
|
+
content: requestError.summary,
|
|
518
|
+
_errorMsg: requestError.details,
|
|
519
|
+
errorLabel: requestError.errorLabel,
|
|
425
520
|
type: "error",
|
|
426
521
|
});
|
|
427
522
|
}
|
|
428
523
|
} else {
|
|
524
|
+
const requestError = getRequestErrorMessage(error);
|
|
429
525
|
ErroreBox.msg({
|
|
430
|
-
content:
|
|
526
|
+
content: requestError.summary,
|
|
527
|
+
_errorMsg: requestError.details,
|
|
528
|
+
errorLabel: requestError.errorLabel,
|
|
431
529
|
type: "error",
|
|
432
530
|
});
|
|
433
531
|
}
|
|
434
532
|
}
|
|
435
|
-
return Promise.reject(error);
|
|
533
|
+
return swallowNetworkError ? Promise.resolve() : Promise.reject(error);
|
|
436
534
|
}
|
|
437
535
|
);
|
|
438
536
|
|