vue-devui 1.0.0-alpha.6 → 1.0.0-beta.12
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/README.md +32 -35
- package/accordion/index.d.ts +7 -0
- package/accordion/index.es.js +508 -1
- package/accordion/index.umd.js +1 -1
- package/accordion/style.css +1 -1
- package/alert/index.d.ts +7 -0
- package/alert/index.es.js +178 -1
- package/alert/index.umd.js +1 -1
- package/alert/style.css +1 -1
- package/anchor/index.d.ts +7 -0
- package/anchor/index.es.js +263 -1
- package/anchor/index.umd.js +1 -1
- package/avatar/index.d.ts +7 -0
- package/avatar/index.es.js +301 -1
- package/avatar/index.umd.js +1 -1
- package/back-top/index.d.ts +7 -0
- package/back-top/index.es.js +128 -0
- package/back-top/index.umd.js +1 -0
- package/back-top/package.json +7 -0
- package/back-top/style.css +1 -0
- package/badge/index.d.ts +7 -0
- package/badge/index.es.js +95 -1
- package/badge/index.umd.js +1 -1
- package/breadcrumb/index.d.ts +7 -0
- package/breadcrumb/index.es.js +127 -1
- package/breadcrumb/index.umd.js +1 -1
- package/button/index.d.ts +7 -0
- package/button/index.es.js +392 -1
- package/button/index.umd.js +1 -1
- package/button/style.css +1 -1
- package/card/index.d.ts +7 -0
- package/card/index.es.js +61 -1
- package/card/index.umd.js +1 -1
- package/carousel/index.d.ts +7 -0
- package/carousel/index.es.js +329 -1
- package/carousel/index.umd.js +1 -1
- package/cascader/index.d.ts +7 -0
- package/cascader/index.es.js +1343 -1
- package/cascader/index.umd.js +1 -1
- package/cascader/style.css +1 -1
- package/checkbox/index.d.ts +7 -0
- package/checkbox/index.es.js +377 -1
- package/checkbox/index.umd.js +1 -1
- package/comment/index.d.ts +7 -0
- package/comment/index.es.js +85 -0
- package/comment/index.umd.js +1 -0
- package/comment/package.json +7 -0
- package/comment/style.css +1 -0
- package/countdown/index.d.ts +7 -0
- package/countdown/index.es.js +176 -0
- package/countdown/index.umd.js +1 -0
- package/countdown/package.json +7 -0
- package/countdown/style.css +1 -0
- package/date-picker/index.d.ts +7 -0
- package/date-picker/index.es.js +1172 -1
- package/date-picker/index.umd.js +1 -1
- package/date-picker/style.css +1 -1
- package/dragdrop/index.d.ts +7 -0
- package/dragdrop/index.es.js +32 -0
- package/dragdrop/index.umd.js +1 -0
- package/dragdrop/package.json +7 -0
- package/drawer/index.d.ts +7 -0
- package/drawer/index.es.js +287 -0
- package/drawer/index.umd.js +1 -0
- package/drawer/package.json +7 -0
- package/drawer/style.css +1 -0
- package/dropdown/index.d.ts +7 -0
- package/dropdown/index.es.js +535 -0
- package/dropdown/index.umd.js +1 -0
- package/dropdown/package.json +7 -0
- package/dropdown/style.css +1 -0
- package/editable-select/index.d.ts +7 -0
- package/editable-select/index.es.js +5857 -1
- package/editable-select/index.umd.js +27 -1
- package/editable-select/style.css +1 -1
- package/form/index.d.ts +7 -0
- package/form/index.es.js +2244 -0
- package/form/index.umd.js +1 -0
- package/form/package.json +7 -0
- package/form/style.css +1 -0
- package/fullscreen/index.d.ts +7 -0
- package/fullscreen/index.es.js +163 -1
- package/fullscreen/index.umd.js +1 -1
- package/gantt/index.d.ts +7 -0
- package/gantt/index.es.js +535 -0
- package/gantt/index.umd.js +1 -0
- package/gantt/package.json +7 -0
- package/gantt/style.css +1 -0
- package/grid/index.d.ts +7 -0
- package/grid/index.es.js +269 -0
- package/grid/index.umd.js +1 -0
- package/grid/package.json +7 -0
- package/grid/style.css +1 -0
- package/icon/index.d.ts +7 -0
- package/icon/index.es.js +75 -1
- package/icon/index.umd.js +1 -1
- package/image-preview/index.d.ts +7 -0
- package/image-preview/index.es.js +498 -1
- package/image-preview/index.umd.js +1 -1
- package/image-preview/style.css +1 -1
- package/index.d.ts +7 -0
- package/input/index.d.ts +7 -0
- package/input/index.es.js +190 -1
- package/input/index.umd.js +1 -1
- package/input-icon/index.d.ts +7 -0
- package/input-icon/index.es.js +332 -0
- package/input-icon/index.umd.js +1 -0
- package/input-icon/package.json +7 -0
- package/input-icon/style.css +1 -0
- package/input-number/index.d.ts +7 -0
- package/input-number/index.es.js +240 -1
- package/input-number/index.umd.js +1 -1
- package/layout/index.d.ts +7 -0
- package/layout/index.es.js +100 -0
- package/layout/index.umd.js +1 -0
- package/layout/package.json +7 -0
- package/layout/style.css +1 -0
- package/loading/index.d.ts +7 -0
- package/loading/index.es.js +256 -1
- package/loading/index.umd.js +1 -1
- package/modal/index.d.ts +7 -0
- package/modal/index.es.js +1225 -1
- package/modal/index.umd.js +1 -1
- package/modal/style.css +1 -1
- package/nav-sprite/index.d.ts +7 -0
- package/nav-sprite/index.es.js +742 -0
- package/nav-sprite/index.umd.js +1 -0
- package/nav-sprite/package.json +7 -0
- package/nuxt/components/Accordion.js +3 -0
- package/nuxt/components/Alert.js +3 -0
- package/nuxt/components/Anchor.js +3 -0
- package/nuxt/components/Aside.js +3 -0
- package/nuxt/components/Avatar.js +3 -0
- package/nuxt/components/BackTop.js +3 -0
- package/nuxt/components/Badge.js +3 -0
- package/nuxt/components/Breadcrumb.js +3 -0
- package/nuxt/components/Button.js +3 -0
- package/nuxt/components/Card.js +3 -0
- package/nuxt/components/Carousel.js +3 -0
- package/nuxt/components/Cascader.js +3 -0
- package/nuxt/components/Checkbox.js +3 -0
- package/nuxt/components/Col.js +3 -0
- package/nuxt/components/Column.js +3 -0
- package/nuxt/components/Comment.js +3 -0
- package/nuxt/components/Content.js +3 -0
- package/nuxt/components/Countdown.js +3 -0
- package/nuxt/components/DatePicker.js +3 -0
- package/nuxt/components/Drawer.js +3 -0
- package/nuxt/components/Dropdown.js +3 -0
- package/nuxt/components/EditableSelect.js +3 -0
- package/nuxt/components/FixedOverlay.js +3 -0
- package/nuxt/components/FlexibleOverlay.js +3 -0
- package/nuxt/components/Footer.js +3 -0
- package/nuxt/components/Form.js +3 -0
- package/nuxt/components/FormControl.js +3 -0
- package/nuxt/components/FormItem.js +3 -0
- package/nuxt/components/FormLabel.js +3 -0
- package/nuxt/components/FormOperation.js +3 -0
- package/nuxt/components/Fullscreen.js +3 -0
- package/nuxt/components/Gantt.js +3 -0
- package/nuxt/components/Header.js +3 -0
- package/nuxt/components/Icon.js +2 -0
- package/nuxt/components/ImagePreviewService.js +3 -0
- package/nuxt/components/Input.js +3 -0
- package/nuxt/components/InputIcon.js +3 -0
- package/nuxt/components/InputNumber.js +3 -0
- package/nuxt/components/Layout.js +3 -0
- package/nuxt/components/Loading.js +3 -0
- package/nuxt/components/LoadingService.js +3 -0
- package/nuxt/components/Modal.js +3 -0
- package/nuxt/components/NavSprite.js +2 -0
- package/nuxt/components/Pagination.js +3 -0
- package/nuxt/components/Panel.js +3 -0
- package/nuxt/components/Popover.js +3 -0
- package/nuxt/components/Progress.js +3 -0
- package/nuxt/components/QuadrantDiagram.js +3 -0
- package/nuxt/components/Radio.js +3 -0
- package/nuxt/components/RadioGroup.js +3 -0
- package/nuxt/components/Rate.js +3 -0
- package/nuxt/components/ReadTip.js +3 -0
- package/nuxt/components/Result.js +3 -0
- package/nuxt/components/Row.js +3 -0
- package/nuxt/components/Search.js +3 -0
- package/nuxt/components/Select.js +3 -0
- package/nuxt/components/Skeleton.js +3 -0
- package/nuxt/components/SkeletonItem.js +3 -0
- package/nuxt/components/Slider.js +3 -0
- package/nuxt/components/Splitter.js +3 -0
- package/nuxt/components/Statistic.js +3 -0
- package/nuxt/components/Status.js +3 -0
- package/nuxt/components/StepsGuide.js +3 -0
- package/nuxt/components/StickSlider.js +3 -0
- package/nuxt/components/Sticky.js +2 -0
- package/nuxt/components/Switch.js +3 -0
- package/nuxt/components/Table.js +3 -0
- package/nuxt/components/Tabs.js +3 -0
- package/nuxt/components/Tag.js +3 -0
- package/nuxt/components/TagInput.js +3 -0
- package/nuxt/components/Textarea.js +3 -0
- package/nuxt/components/TimeAxis.js +3 -0
- package/nuxt/components/TimeAxisItem.js +3 -0
- package/nuxt/components/TimePicker.js +3 -0
- package/nuxt/components/Toast.js +3 -0
- package/nuxt/components/ToastService.js +3 -0
- package/nuxt/components/Tooltip.js +3 -0
- package/nuxt/components/Transfer.js +3 -0
- package/nuxt/components/Tree.js +3 -0
- package/nuxt/components/TreeSelect.js +3 -0
- package/nuxt/components/Upload.js +3 -0
- package/nuxt/components/buttonProps.js +3 -0
- package/nuxt/index.js +13 -0
- package/overlay/index.d.ts +7 -0
- package/overlay/index.es.js +368 -1
- package/overlay/index.umd.js +1 -1
- package/overlay/style.css +1 -1
- package/package.json +6 -47
- package/pagination/index.d.ts +7 -0
- package/pagination/index.es.js +642 -1
- package/pagination/index.umd.js +1 -1
- package/panel/index.d.ts +7 -0
- package/panel/index.es.js +205 -1
- package/panel/index.umd.js +1 -1
- package/panel/style.css +1 -1
- package/popover/index.d.ts +7 -0
- package/popover/index.es.js +236 -1
- package/popover/index.umd.js +1 -1
- package/progress/index.d.ts +7 -0
- package/progress/index.es.js +153 -1
- package/progress/index.umd.js +3 -1
- package/quadrant-diagram/index.d.ts +7 -0
- package/quadrant-diagram/index.es.js +489 -1
- package/quadrant-diagram/index.umd.js +1 -1
- package/radio/index.d.ts +7 -0
- package/radio/index.es.js +225 -1
- package/radio/index.umd.js +1 -1
- package/rate/index.d.ts +7 -0
- package/rate/index.es.js +220 -1
- package/rate/index.umd.js +1 -1
- package/read-tip/index.d.ts +7 -0
- package/read-tip/index.es.js +258 -0
- package/read-tip/index.umd.js +1 -0
- package/read-tip/package.json +7 -0
- package/read-tip/style.css +1 -0
- package/result/index.d.ts +7 -0
- package/result/index.es.js +119 -0
- package/result/index.umd.js +1 -0
- package/result/package.json +7 -0
- package/result/style.css +1 -0
- package/ripple/index.d.ts +7 -0
- package/ripple/index.es.js +181 -1
- package/ripple/index.umd.js +1 -1
- package/search/index.d.ts +7 -0
- package/search/index.es.js +543 -1
- package/search/index.umd.js +1 -1
- package/select/index.d.ts +7 -0
- package/select/index.es.js +706 -1
- package/select/index.umd.js +1 -1
- package/skeleton/index.d.ts +7 -0
- package/skeleton/index.es.js +297 -1
- package/skeleton/index.umd.js +1 -1
- package/skeleton/style.css +1 -1
- package/slider/index.d.ts +7 -0
- package/slider/index.es.js +199 -1
- package/slider/index.umd.js +1 -1
- package/slider/style.css +1 -1
- package/splitter/index.d.ts +7 -0
- package/splitter/index.es.js +636 -1
- package/splitter/index.umd.js +1 -1
- package/statistic/index.d.ts +7 -0
- package/statistic/index.es.js +280 -0
- package/statistic/index.umd.js +1 -0
- package/statistic/package.json +7 -0
- package/statistic/style.css +1 -0
- package/status/index.d.ts +7 -0
- package/status/index.es.js +42 -1
- package/status/index.umd.js +1 -1
- package/steps-guide/index.d.ts +7 -0
- package/steps-guide/index.es.js +239 -1
- package/steps-guide/index.umd.js +1 -1
- package/steps-guide/style.css +1 -1
- package/sticky/index.d.ts +7 -0
- package/sticky/index.es.js +197 -1
- package/sticky/index.umd.js +1 -1
- package/style.css +1 -1
- package/switch/index.d.ts +7 -0
- package/switch/index.es.js +100 -1
- package/switch/index.umd.js +1 -1
- package/switch/style.css +1 -1
- package/table/index.d.ts +7 -0
- package/table/index.es.js +1836 -1
- package/table/index.umd.js +1 -1
- package/table/style.css +1 -1
- package/tabs/index.d.ts +7 -0
- package/tabs/index.es.js +195 -1
- package/tabs/index.umd.js +1 -1
- package/tabs/style.css +1 -1
- package/tag/index.d.ts +7 -0
- package/tag/index.es.js +131 -0
- package/tag/index.umd.js +1 -0
- package/tag/package.json +7 -0
- package/tag/style.css +1 -0
- package/tag-input/index.d.ts +7 -0
- package/tag-input/index.es.js +329 -1
- package/tag-input/index.umd.js +1 -1
- package/textarea/index.d.ts +7 -0
- package/textarea/index.es.js +132 -0
- package/textarea/index.umd.js +1 -0
- package/textarea/package.json +7 -0
- package/textarea/style.css +1 -0
- package/time-axis/index.d.ts +7 -0
- package/time-axis/index.es.js +299 -0
- package/time-axis/index.umd.js +1 -0
- package/time-axis/package.json +7 -0
- package/time-axis/style.css +1 -0
- package/time-picker/index.d.ts +7 -0
- package/time-picker/index.es.js +1260 -1
- package/time-picker/index.umd.js +1 -1
- package/time-picker/style.css +1 -1
- package/toast/index.d.ts +7 -0
- package/toast/index.es.js +2060 -1
- package/toast/index.umd.js +1 -1
- package/toast/style.css +1 -1
- package/tooltip/index.d.ts +7 -0
- package/tooltip/index.es.js +171 -1
- package/tooltip/index.umd.js +1 -1
- package/transfer/index.d.ts +7 -0
- package/transfer/index.es.js +1725 -1
- package/transfer/index.umd.js +1 -1
- package/transfer/style.css +1 -1
- package/tree/index.d.ts +7 -0
- package/tree/index.es.js +907 -1
- package/tree/index.umd.js +1 -1
- package/tree/style.css +1 -1
- package/tree-select/index.d.ts +7 -0
- package/tree-select/index.es.js +528 -0
- package/tree-select/index.umd.js +1 -0
- package/tree-select/package.json +7 -0
- package/tree-select/style.css +1 -0
- package/upload/index.d.ts +7 -0
- package/upload/index.es.js +2834 -1
- package/upload/index.umd.js +1 -1
- package/upload/style.css +1 -1
- package/vue-devui.es.js +27777 -1
- package/vue-devui.umd.js +29 -1
package/form/index.es.js
ADDED
|
@@ -0,0 +1,2244 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
import { defineComponent, provide, createVNode, ref, toRefs, reactive, watch, withDirectives, resolveDirective, resolveComponent, inject, computed, onMounted, onBeforeUnmount, Teleport } from "vue";
|
|
18
|
+
function mitt(n) {
|
|
19
|
+
return { all: n = n || new Map(), on: function(t, e) {
|
|
20
|
+
var i = n.get(t);
|
|
21
|
+
i ? i.push(e) : n.set(t, [e]);
|
|
22
|
+
}, off: function(t, e) {
|
|
23
|
+
var i = n.get(t);
|
|
24
|
+
i && (e ? i.splice(i.indexOf(e) >>> 0, 1) : n.set(t, []));
|
|
25
|
+
}, emit: function(t, e) {
|
|
26
|
+
var i = n.get(t);
|
|
27
|
+
i && i.slice().map(function(n2) {
|
|
28
|
+
n2(e);
|
|
29
|
+
}), (i = n.get("*")) && i.slice().map(function(n2) {
|
|
30
|
+
n2(t, e);
|
|
31
|
+
});
|
|
32
|
+
} };
|
|
33
|
+
}
|
|
34
|
+
const formProps = {
|
|
35
|
+
formData: {
|
|
36
|
+
type: Object,
|
|
37
|
+
default: {}
|
|
38
|
+
},
|
|
39
|
+
layout: {
|
|
40
|
+
type: String,
|
|
41
|
+
default: "horizontal"
|
|
42
|
+
},
|
|
43
|
+
labelSize: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: ""
|
|
46
|
+
},
|
|
47
|
+
labelAlign: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: "start"
|
|
50
|
+
},
|
|
51
|
+
rules: {
|
|
52
|
+
type: Object,
|
|
53
|
+
default: {}
|
|
54
|
+
},
|
|
55
|
+
columnsClass: {
|
|
56
|
+
type: String,
|
|
57
|
+
default: ""
|
|
58
|
+
},
|
|
59
|
+
name: {
|
|
60
|
+
type: String,
|
|
61
|
+
default: ""
|
|
62
|
+
},
|
|
63
|
+
messageShowType: {
|
|
64
|
+
type: String,
|
|
65
|
+
default: "popover"
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const formItemProps = {
|
|
69
|
+
dHasFeedback: {
|
|
70
|
+
type: Boolean,
|
|
71
|
+
default: false
|
|
72
|
+
},
|
|
73
|
+
prop: {
|
|
74
|
+
type: String,
|
|
75
|
+
default: ""
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const formLabelProps = {
|
|
79
|
+
required: {
|
|
80
|
+
type: Boolean,
|
|
81
|
+
default: false
|
|
82
|
+
},
|
|
83
|
+
hasHelp: {
|
|
84
|
+
type: Boolean,
|
|
85
|
+
default: false
|
|
86
|
+
},
|
|
87
|
+
helpTips: {
|
|
88
|
+
type: String,
|
|
89
|
+
default: ""
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const formControlProps = {
|
|
93
|
+
feedbackStatus: {
|
|
94
|
+
type: String,
|
|
95
|
+
default: ""
|
|
96
|
+
},
|
|
97
|
+
extraInfo: {
|
|
98
|
+
type: String,
|
|
99
|
+
default: ""
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const dFormEvents = {
|
|
103
|
+
addField: "d.form.addField",
|
|
104
|
+
removeField: "d.form.removeField"
|
|
105
|
+
};
|
|
106
|
+
const formInjectionKey = Symbol("dForm");
|
|
107
|
+
const formItemInjectionKey = Symbol("dFormItem");
|
|
108
|
+
const dFormItemEvents = {
|
|
109
|
+
blur: "d.form.blur",
|
|
110
|
+
change: "d.form.change",
|
|
111
|
+
input: "d.form.input"
|
|
112
|
+
};
|
|
113
|
+
var eventBus = mitt();
|
|
114
|
+
const EventBus = eventBus;
|
|
115
|
+
function isObject$1(obj) {
|
|
116
|
+
return Object.prototype.toString.call(obj).slice(8, -1) === "Object";
|
|
117
|
+
}
|
|
118
|
+
function hasKey(obj, key) {
|
|
119
|
+
if (!isObject$1(obj))
|
|
120
|
+
return false;
|
|
121
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
122
|
+
}
|
|
123
|
+
function getElOffset(curEl) {
|
|
124
|
+
let totalLeft = 0;
|
|
125
|
+
let totalTop = 0;
|
|
126
|
+
let par = curEl.offsetParent;
|
|
127
|
+
totalLeft += curEl.offsetLeft;
|
|
128
|
+
totalTop += curEl.offsetTop;
|
|
129
|
+
while (par) {
|
|
130
|
+
if (navigator.userAgent.indexOf("MSIE 8.0") === -1) {
|
|
131
|
+
totalTop += par.clientTop;
|
|
132
|
+
totalLeft += par.clientLeft;
|
|
133
|
+
}
|
|
134
|
+
totalTop += par.offsetTop;
|
|
135
|
+
totalLeft += par.offsetLeft;
|
|
136
|
+
par = par.offsetParent;
|
|
137
|
+
}
|
|
138
|
+
return { left: totalLeft, top: totalTop };
|
|
139
|
+
}
|
|
140
|
+
var form = "";
|
|
141
|
+
var Form = defineComponent({
|
|
142
|
+
name: "DForm",
|
|
143
|
+
props: formProps,
|
|
144
|
+
emits: ["submit"],
|
|
145
|
+
setup(props, ctx2) {
|
|
146
|
+
const formMitt = mitt();
|
|
147
|
+
const fields = [];
|
|
148
|
+
const resetFormFields = () => {
|
|
149
|
+
fields.forEach((field) => {
|
|
150
|
+
field.resetField();
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
formMitt.on(dFormEvents.addField, (field) => {
|
|
154
|
+
if (field) {
|
|
155
|
+
fields.push(field);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
formMitt.on(dFormEvents.removeField, (field) => {
|
|
159
|
+
if (field.prop) {
|
|
160
|
+
fields.splice(fields.indexOf(field), 1);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
provide(formInjectionKey, {
|
|
164
|
+
formData: props.formData,
|
|
165
|
+
formMitt,
|
|
166
|
+
labelData: {
|
|
167
|
+
layout: props.layout,
|
|
168
|
+
labelSize: props.labelSize,
|
|
169
|
+
labelAlign: props.labelAlign
|
|
170
|
+
},
|
|
171
|
+
rules: props.rules,
|
|
172
|
+
columnsClass: props.columnsClass,
|
|
173
|
+
messageShowType: "popover"
|
|
174
|
+
});
|
|
175
|
+
const onSubmit = (e) => {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
ctx2.emit("submit", e);
|
|
178
|
+
EventBus.emit(`formSubmit:${props.name}`);
|
|
179
|
+
};
|
|
180
|
+
return {
|
|
181
|
+
fields,
|
|
182
|
+
formMitt,
|
|
183
|
+
onSubmit,
|
|
184
|
+
resetFormFields
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
render() {
|
|
188
|
+
var _a, _b;
|
|
189
|
+
const {
|
|
190
|
+
onSubmit
|
|
191
|
+
} = this;
|
|
192
|
+
return createVNode("form", {
|
|
193
|
+
"onSubmit": onSubmit,
|
|
194
|
+
"class": "d-form"
|
|
195
|
+
}, [(_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a)]);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
var Icon = defineComponent({
|
|
199
|
+
name: "DIcon",
|
|
200
|
+
props: {
|
|
201
|
+
name: {
|
|
202
|
+
type: String,
|
|
203
|
+
required: true
|
|
204
|
+
},
|
|
205
|
+
size: {
|
|
206
|
+
type: String,
|
|
207
|
+
default: "inherit"
|
|
208
|
+
},
|
|
209
|
+
color: {
|
|
210
|
+
type: String,
|
|
211
|
+
default: "inherit"
|
|
212
|
+
},
|
|
213
|
+
classPrefix: {
|
|
214
|
+
type: String,
|
|
215
|
+
default: "icon"
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
setup(props) {
|
|
219
|
+
return __spreadValues({}, props);
|
|
220
|
+
},
|
|
221
|
+
render() {
|
|
222
|
+
const {
|
|
223
|
+
name,
|
|
224
|
+
size,
|
|
225
|
+
color,
|
|
226
|
+
classPrefix
|
|
227
|
+
} = this;
|
|
228
|
+
return /^((https?):)?\/\//.test(name) ? createVNode("img", {
|
|
229
|
+
"src": name,
|
|
230
|
+
"alt": name.split("/")[name.split("/").length - 1],
|
|
231
|
+
"style": {
|
|
232
|
+
width: size,
|
|
233
|
+
verticalAlign: "text-bottom"
|
|
234
|
+
}
|
|
235
|
+
}, null) : createVNode("i", {
|
|
236
|
+
"class": `${classPrefix} ${classPrefix}-${name}`,
|
|
237
|
+
"style": {
|
|
238
|
+
fontSize: size,
|
|
239
|
+
color
|
|
240
|
+
}
|
|
241
|
+
}, null);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
var debounce$1 = (callBack, wait) => {
|
|
245
|
+
let time = null;
|
|
246
|
+
return () => {
|
|
247
|
+
time && clearTimeout(time);
|
|
248
|
+
time = setTimeout(() => {
|
|
249
|
+
callBack == null ? void 0 : callBack();
|
|
250
|
+
}, wait);
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
const inBrowser = typeof window !== "undefined";
|
|
254
|
+
function on(element, eventName, handler) {
|
|
255
|
+
if (document.addEventListener) {
|
|
256
|
+
if (element && eventName && handler) {
|
|
257
|
+
element.addEventListener(eventName, handler, false);
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
if (element && eventName && handler) {
|
|
261
|
+
element.attachEvent("on" + eventName, handler);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const ctx = Symbol("@@clickoutside");
|
|
266
|
+
const nodeList = new Map();
|
|
267
|
+
let startClick;
|
|
268
|
+
let nid = 0;
|
|
269
|
+
let isFirst = true;
|
|
270
|
+
function createDocumentHandler(el, binding, vnode) {
|
|
271
|
+
if (inBrowser && isFirst) {
|
|
272
|
+
isFirst = false;
|
|
273
|
+
on(document, "mousedown", (e) => {
|
|
274
|
+
startClick = e;
|
|
275
|
+
});
|
|
276
|
+
on(document, "mouseup", (e) => {
|
|
277
|
+
for (const [id, node] of nodeList) {
|
|
278
|
+
node[ctx].documentHandler(e, startClick);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
return function(mouseup, mousedown) {
|
|
283
|
+
if (!vnode || !binding.instance || !mouseup.target || !mousedown.target || el.contains(mouseup.target) || el.contains(mousedown.target) || el === mouseup.target) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
el[ctx].bindingFn && el[ctx].bindingFn();
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
const clickoutsideDirective = {
|
|
290
|
+
beforeMount: function(el, binding, vnode) {
|
|
291
|
+
nid++;
|
|
292
|
+
nodeList.set(nid, el);
|
|
293
|
+
el[ctx] = {
|
|
294
|
+
nid,
|
|
295
|
+
documentHandler: createDocumentHandler(el, binding, vnode),
|
|
296
|
+
bindingFn: binding.value
|
|
297
|
+
};
|
|
298
|
+
},
|
|
299
|
+
updated: function(el, binding, vnode) {
|
|
300
|
+
el[ctx].documentHandler = createDocumentHandler(el, binding, vnode);
|
|
301
|
+
el[ctx].bindingFn = binding.value;
|
|
302
|
+
},
|
|
303
|
+
unmounted: function(el) {
|
|
304
|
+
nodeList.delete(el[ctx].nid);
|
|
305
|
+
delete el[ctx];
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
var popover = "";
|
|
309
|
+
const popTypeClass = {
|
|
310
|
+
success: {
|
|
311
|
+
name: "right-o",
|
|
312
|
+
color: "rgb(61, 204, 166)"
|
|
313
|
+
},
|
|
314
|
+
error: {
|
|
315
|
+
name: "error-o",
|
|
316
|
+
color: "rgb(249, 95, 91)"
|
|
317
|
+
},
|
|
318
|
+
info: {
|
|
319
|
+
name: "info-o",
|
|
320
|
+
color: "rgb(81, 112, 255)"
|
|
321
|
+
},
|
|
322
|
+
warning: {
|
|
323
|
+
name: "warning-o",
|
|
324
|
+
color: "rgb(254, 204, 85)"
|
|
325
|
+
},
|
|
326
|
+
default: {}
|
|
327
|
+
};
|
|
328
|
+
var Popover = defineComponent({
|
|
329
|
+
name: "DPopover",
|
|
330
|
+
directives: {
|
|
331
|
+
clickoutside: clickoutsideDirective
|
|
332
|
+
},
|
|
333
|
+
props: {
|
|
334
|
+
visible: {
|
|
335
|
+
type: Boolean,
|
|
336
|
+
default: false
|
|
337
|
+
},
|
|
338
|
+
position: {
|
|
339
|
+
type: String,
|
|
340
|
+
default: "bottom"
|
|
341
|
+
},
|
|
342
|
+
content: {
|
|
343
|
+
type: String,
|
|
344
|
+
default: "default"
|
|
345
|
+
},
|
|
346
|
+
trigger: {
|
|
347
|
+
type: String,
|
|
348
|
+
default: "click"
|
|
349
|
+
},
|
|
350
|
+
zIndex: {
|
|
351
|
+
type: Number,
|
|
352
|
+
default: 1060
|
|
353
|
+
},
|
|
354
|
+
popType: {
|
|
355
|
+
type: String,
|
|
356
|
+
default: "default"
|
|
357
|
+
},
|
|
358
|
+
showAnimation: {
|
|
359
|
+
type: Boolean,
|
|
360
|
+
default: true
|
|
361
|
+
},
|
|
362
|
+
mouseEnterDelay: {
|
|
363
|
+
type: Number,
|
|
364
|
+
default: 150
|
|
365
|
+
},
|
|
366
|
+
mouseLeaveDelay: {
|
|
367
|
+
type: Number,
|
|
368
|
+
default: 100
|
|
369
|
+
},
|
|
370
|
+
popMaxWidth: {
|
|
371
|
+
type: Number,
|
|
372
|
+
default: void 0
|
|
373
|
+
},
|
|
374
|
+
popoverStyle: {
|
|
375
|
+
type: Object,
|
|
376
|
+
default: () => ({})
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
setup(props, ctx2) {
|
|
380
|
+
const {
|
|
381
|
+
slots
|
|
382
|
+
} = ctx2;
|
|
383
|
+
const visible = ref(props.visible);
|
|
384
|
+
const {
|
|
385
|
+
position,
|
|
386
|
+
content,
|
|
387
|
+
zIndex,
|
|
388
|
+
trigger,
|
|
389
|
+
popType,
|
|
390
|
+
popoverStyle,
|
|
391
|
+
mouseEnterDelay,
|
|
392
|
+
mouseLeaveDelay,
|
|
393
|
+
showAnimation,
|
|
394
|
+
popMaxWidth
|
|
395
|
+
} = toRefs(props);
|
|
396
|
+
const style2 = __spreadValues({
|
|
397
|
+
zIndex: zIndex.value
|
|
398
|
+
}, popoverStyle.value);
|
|
399
|
+
const isClick = trigger.value === "click";
|
|
400
|
+
const iconType = reactive(popTypeClass[popType.value]);
|
|
401
|
+
const event = function() {
|
|
402
|
+
if (visible.value) {
|
|
403
|
+
visible.value = false;
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
visible.value = true;
|
|
407
|
+
};
|
|
408
|
+
const onClick = isClick ? event : null;
|
|
409
|
+
const enter = debounce$1(() => {
|
|
410
|
+
visible.value = true;
|
|
411
|
+
}, mouseEnterDelay.value);
|
|
412
|
+
const leave = debounce$1(() => {
|
|
413
|
+
visible.value = false;
|
|
414
|
+
}, mouseLeaveDelay.value);
|
|
415
|
+
const onMouseenter = isClick ? null : enter;
|
|
416
|
+
const onMouseleave = isClick ? null : leave;
|
|
417
|
+
const hiddenContext = () => {
|
|
418
|
+
visible.value = false;
|
|
419
|
+
};
|
|
420
|
+
popMaxWidth.value && (style2.maxWidth = `${popMaxWidth.value}px`);
|
|
421
|
+
watch(() => props.visible, (newVal) => {
|
|
422
|
+
visible.value = newVal;
|
|
423
|
+
});
|
|
424
|
+
return () => {
|
|
425
|
+
var _a, _b;
|
|
426
|
+
return createVNode("div", {
|
|
427
|
+
"class": ["devui-popover", position.value, {
|
|
428
|
+
"devui-popover-animation": showAnimation.value,
|
|
429
|
+
"devui-popover-isVisible": visible.value
|
|
430
|
+
}]
|
|
431
|
+
}, [withDirectives(createVNode("div", {
|
|
432
|
+
"class": "devui-popover-reference",
|
|
433
|
+
"onMouseenter": onMouseenter,
|
|
434
|
+
"onMouseleave": onMouseleave,
|
|
435
|
+
"onClick": onClick
|
|
436
|
+
}, [(_a = slots.reference) == null ? void 0 : _a.call(slots)]), [[resolveDirective("clickoutside"), hiddenContext]]), createVNode("div", {
|
|
437
|
+
"class": ["devui-popover-content", iconType.name ? "is-icon" : ""],
|
|
438
|
+
"style": style2
|
|
439
|
+
}, [iconType.name && createVNode(resolveComponent("d-icon"), {
|
|
440
|
+
"name": iconType.name,
|
|
441
|
+
"color": iconType.color,
|
|
442
|
+
"class": "devui-popover-icon",
|
|
443
|
+
"size": "16px"
|
|
444
|
+
}, null), ((_b = slots.content) == null ? void 0 : _b.call(slots)) || createVNode("span", null, [content.value]), createVNode("span", {
|
|
445
|
+
"class": "after",
|
|
446
|
+
"style": style2
|
|
447
|
+
}, null)])]);
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
var formLabel = "";
|
|
452
|
+
var FormLabel = defineComponent({
|
|
453
|
+
name: "DFormLabel",
|
|
454
|
+
props: formLabelProps,
|
|
455
|
+
setup(props, ctx2) {
|
|
456
|
+
const dForm = reactive(inject(formInjectionKey, {}));
|
|
457
|
+
const labelData = reactive(dForm.labelData);
|
|
458
|
+
const isHorizontal = computed(() => labelData.layout === "horizontal").value;
|
|
459
|
+
const isLg = computed(() => labelData.labelSize === "lg").value;
|
|
460
|
+
const isSm = computed(() => labelData.labelSize === "sm").value;
|
|
461
|
+
const isCenter = computed(() => labelData.labelAlign === "center").value;
|
|
462
|
+
const isEnd = computed(() => labelData.labelAlign === "end").value;
|
|
463
|
+
const wrapperCls = `form-label${isHorizontal ? isSm ? " form-label_sm" : isLg ? " form-label_lg" : " form-label_sd" : ""}${isCenter ? " form-label_center" : isEnd ? " form-label_end" : ""}`;
|
|
464
|
+
const className = `${props.required ? " devui-required" : ""}`;
|
|
465
|
+
const style2 = {
|
|
466
|
+
display: isHorizontal ? "inline" : "inline-block"
|
|
467
|
+
};
|
|
468
|
+
return () => {
|
|
469
|
+
var _a, _b;
|
|
470
|
+
return createVNode("span", {
|
|
471
|
+
"class": wrapperCls,
|
|
472
|
+
"style": style2
|
|
473
|
+
}, [createVNode("span", {
|
|
474
|
+
"class": className
|
|
475
|
+
}, [(_b = (_a = ctx2.slots).default) == null ? void 0 : _b.call(_a), props.hasHelp && props.helpTips && createVNode(Popover, {
|
|
476
|
+
"content": props.helpTips,
|
|
477
|
+
"showAnimation": false,
|
|
478
|
+
"position": "top",
|
|
479
|
+
"trigger": "hover"
|
|
480
|
+
}, {
|
|
481
|
+
reference: () => createVNode("span", {
|
|
482
|
+
"class": "form-label-help"
|
|
483
|
+
}, [createVNode(Icon, {
|
|
484
|
+
"name": "helping",
|
|
485
|
+
"color": "#252b3a"
|
|
486
|
+
}, null)])
|
|
487
|
+
})])]);
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
function _extends() {
|
|
492
|
+
_extends = Object.assign || function(target) {
|
|
493
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
494
|
+
var source = arguments[i];
|
|
495
|
+
for (var key in source) {
|
|
496
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
497
|
+
target[key] = source[key];
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return target;
|
|
502
|
+
};
|
|
503
|
+
return _extends.apply(this, arguments);
|
|
504
|
+
}
|
|
505
|
+
function _inheritsLoose(subClass, superClass) {
|
|
506
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
507
|
+
subClass.prototype.constructor = subClass;
|
|
508
|
+
_setPrototypeOf(subClass, superClass);
|
|
509
|
+
}
|
|
510
|
+
function _getPrototypeOf(o) {
|
|
511
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf2(o2) {
|
|
512
|
+
return o2.__proto__ || Object.getPrototypeOf(o2);
|
|
513
|
+
};
|
|
514
|
+
return _getPrototypeOf(o);
|
|
515
|
+
}
|
|
516
|
+
function _setPrototypeOf(o, p) {
|
|
517
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf2(o2, p2) {
|
|
518
|
+
o2.__proto__ = p2;
|
|
519
|
+
return o2;
|
|
520
|
+
};
|
|
521
|
+
return _setPrototypeOf(o, p);
|
|
522
|
+
}
|
|
523
|
+
function _isNativeReflectConstruct() {
|
|
524
|
+
if (typeof Reflect === "undefined" || !Reflect.construct)
|
|
525
|
+
return false;
|
|
526
|
+
if (Reflect.construct.sham)
|
|
527
|
+
return false;
|
|
528
|
+
if (typeof Proxy === "function")
|
|
529
|
+
return true;
|
|
530
|
+
try {
|
|
531
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
|
|
532
|
+
}));
|
|
533
|
+
return true;
|
|
534
|
+
} catch (e) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
function _construct(Parent, args, Class) {
|
|
539
|
+
if (_isNativeReflectConstruct()) {
|
|
540
|
+
_construct = Reflect.construct;
|
|
541
|
+
} else {
|
|
542
|
+
_construct = function _construct2(Parent2, args2, Class2) {
|
|
543
|
+
var a = [null];
|
|
544
|
+
a.push.apply(a, args2);
|
|
545
|
+
var Constructor = Function.bind.apply(Parent2, a);
|
|
546
|
+
var instance = new Constructor();
|
|
547
|
+
if (Class2)
|
|
548
|
+
_setPrototypeOf(instance, Class2.prototype);
|
|
549
|
+
return instance;
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
return _construct.apply(null, arguments);
|
|
553
|
+
}
|
|
554
|
+
function _isNativeFunction(fn) {
|
|
555
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
556
|
+
}
|
|
557
|
+
function _wrapNativeSuper(Class) {
|
|
558
|
+
var _cache = typeof Map === "function" ? new Map() : void 0;
|
|
559
|
+
_wrapNativeSuper = function _wrapNativeSuper2(Class2) {
|
|
560
|
+
if (Class2 === null || !_isNativeFunction(Class2))
|
|
561
|
+
return Class2;
|
|
562
|
+
if (typeof Class2 !== "function") {
|
|
563
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
564
|
+
}
|
|
565
|
+
if (typeof _cache !== "undefined") {
|
|
566
|
+
if (_cache.has(Class2))
|
|
567
|
+
return _cache.get(Class2);
|
|
568
|
+
_cache.set(Class2, Wrapper);
|
|
569
|
+
}
|
|
570
|
+
function Wrapper() {
|
|
571
|
+
return _construct(Class2, arguments, _getPrototypeOf(this).constructor);
|
|
572
|
+
}
|
|
573
|
+
Wrapper.prototype = Object.create(Class2.prototype, {
|
|
574
|
+
constructor: {
|
|
575
|
+
value: Wrapper,
|
|
576
|
+
enumerable: false,
|
|
577
|
+
writable: true,
|
|
578
|
+
configurable: true
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
return _setPrototypeOf(Wrapper, Class2);
|
|
582
|
+
};
|
|
583
|
+
return _wrapNativeSuper(Class);
|
|
584
|
+
}
|
|
585
|
+
var formatRegExp = /%[sdj%]/g;
|
|
586
|
+
var warning = function warning2() {
|
|
587
|
+
};
|
|
588
|
+
if (typeof process !== "undefined" && process.env && false) {
|
|
589
|
+
warning = function warning3(type4, errors) {
|
|
590
|
+
if (typeof console !== "undefined" && console.warn && typeof ASYNC_VALIDATOR_NO_WARNING === "undefined") {
|
|
591
|
+
if (errors.every(function(e) {
|
|
592
|
+
return typeof e === "string";
|
|
593
|
+
})) {
|
|
594
|
+
console.warn(type4, errors);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
function convertFieldsError(errors) {
|
|
600
|
+
if (!errors || !errors.length)
|
|
601
|
+
return null;
|
|
602
|
+
var fields = {};
|
|
603
|
+
errors.forEach(function(error) {
|
|
604
|
+
var field = error.field;
|
|
605
|
+
fields[field] = fields[field] || [];
|
|
606
|
+
fields[field].push(error);
|
|
607
|
+
});
|
|
608
|
+
return fields;
|
|
609
|
+
}
|
|
610
|
+
function format(template) {
|
|
611
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
612
|
+
args[_key - 1] = arguments[_key];
|
|
613
|
+
}
|
|
614
|
+
var i = 0;
|
|
615
|
+
var len = args.length;
|
|
616
|
+
if (typeof template === "function") {
|
|
617
|
+
return template.apply(null, args);
|
|
618
|
+
}
|
|
619
|
+
if (typeof template === "string") {
|
|
620
|
+
var str = template.replace(formatRegExp, function(x) {
|
|
621
|
+
if (x === "%%") {
|
|
622
|
+
return "%";
|
|
623
|
+
}
|
|
624
|
+
if (i >= len) {
|
|
625
|
+
return x;
|
|
626
|
+
}
|
|
627
|
+
switch (x) {
|
|
628
|
+
case "%s":
|
|
629
|
+
return String(args[i++]);
|
|
630
|
+
case "%d":
|
|
631
|
+
return Number(args[i++]);
|
|
632
|
+
case "%j":
|
|
633
|
+
try {
|
|
634
|
+
return JSON.stringify(args[i++]);
|
|
635
|
+
} catch (_) {
|
|
636
|
+
return "[Circular]";
|
|
637
|
+
}
|
|
638
|
+
break;
|
|
639
|
+
default:
|
|
640
|
+
return x;
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
return str;
|
|
644
|
+
}
|
|
645
|
+
return template;
|
|
646
|
+
}
|
|
647
|
+
function isNativeStringType(type4) {
|
|
648
|
+
return type4 === "string" || type4 === "url" || type4 === "hex" || type4 === "email" || type4 === "date" || type4 === "pattern";
|
|
649
|
+
}
|
|
650
|
+
function isEmptyValue(value, type4) {
|
|
651
|
+
if (value === void 0 || value === null) {
|
|
652
|
+
return true;
|
|
653
|
+
}
|
|
654
|
+
if (type4 === "array" && Array.isArray(value) && !value.length) {
|
|
655
|
+
return true;
|
|
656
|
+
}
|
|
657
|
+
if (isNativeStringType(type4) && typeof value === "string" && !value) {
|
|
658
|
+
return true;
|
|
659
|
+
}
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
function asyncParallelArray(arr, func, callback) {
|
|
663
|
+
var results = [];
|
|
664
|
+
var total = 0;
|
|
665
|
+
var arrLength = arr.length;
|
|
666
|
+
function count(errors) {
|
|
667
|
+
results.push.apply(results, errors || []);
|
|
668
|
+
total++;
|
|
669
|
+
if (total === arrLength) {
|
|
670
|
+
callback(results);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
arr.forEach(function(a) {
|
|
674
|
+
func(a, count);
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
function asyncSerialArray(arr, func, callback) {
|
|
678
|
+
var index2 = 0;
|
|
679
|
+
var arrLength = arr.length;
|
|
680
|
+
function next(errors) {
|
|
681
|
+
if (errors && errors.length) {
|
|
682
|
+
callback(errors);
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
var original = index2;
|
|
686
|
+
index2 = index2 + 1;
|
|
687
|
+
if (original < arrLength) {
|
|
688
|
+
func(arr[original], next);
|
|
689
|
+
} else {
|
|
690
|
+
callback([]);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
next([]);
|
|
694
|
+
}
|
|
695
|
+
function flattenObjArr(objArr) {
|
|
696
|
+
var ret = [];
|
|
697
|
+
Object.keys(objArr).forEach(function(k) {
|
|
698
|
+
ret.push.apply(ret, objArr[k] || []);
|
|
699
|
+
});
|
|
700
|
+
return ret;
|
|
701
|
+
}
|
|
702
|
+
var AsyncValidationError = /* @__PURE__ */ function(_Error) {
|
|
703
|
+
_inheritsLoose(AsyncValidationError2, _Error);
|
|
704
|
+
function AsyncValidationError2(errors, fields) {
|
|
705
|
+
var _this;
|
|
706
|
+
_this = _Error.call(this, "Async Validation Error") || this;
|
|
707
|
+
_this.errors = errors;
|
|
708
|
+
_this.fields = fields;
|
|
709
|
+
return _this;
|
|
710
|
+
}
|
|
711
|
+
return AsyncValidationError2;
|
|
712
|
+
}(/* @__PURE__ */ _wrapNativeSuper(Error));
|
|
713
|
+
function asyncMap(objArr, option, func, callback, source) {
|
|
714
|
+
if (option.first) {
|
|
715
|
+
var _pending = new Promise(function(resolve, reject) {
|
|
716
|
+
var next = function next2(errors) {
|
|
717
|
+
callback(errors);
|
|
718
|
+
return errors.length ? reject(new AsyncValidationError(errors, convertFieldsError(errors))) : resolve(source);
|
|
719
|
+
};
|
|
720
|
+
var flattenArr = flattenObjArr(objArr);
|
|
721
|
+
asyncSerialArray(flattenArr, func, next);
|
|
722
|
+
});
|
|
723
|
+
_pending["catch"](function(e) {
|
|
724
|
+
return e;
|
|
725
|
+
});
|
|
726
|
+
return _pending;
|
|
727
|
+
}
|
|
728
|
+
var firstFields = option.firstFields === true ? Object.keys(objArr) : option.firstFields || [];
|
|
729
|
+
var objArrKeys = Object.keys(objArr);
|
|
730
|
+
var objArrLength = objArrKeys.length;
|
|
731
|
+
var total = 0;
|
|
732
|
+
var results = [];
|
|
733
|
+
var pending = new Promise(function(resolve, reject) {
|
|
734
|
+
var next = function next2(errors) {
|
|
735
|
+
results.push.apply(results, errors);
|
|
736
|
+
total++;
|
|
737
|
+
if (total === objArrLength) {
|
|
738
|
+
callback(results);
|
|
739
|
+
return results.length ? reject(new AsyncValidationError(results, convertFieldsError(results))) : resolve(source);
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
if (!objArrKeys.length) {
|
|
743
|
+
callback(results);
|
|
744
|
+
resolve(source);
|
|
745
|
+
}
|
|
746
|
+
objArrKeys.forEach(function(key) {
|
|
747
|
+
var arr = objArr[key];
|
|
748
|
+
if (firstFields.indexOf(key) !== -1) {
|
|
749
|
+
asyncSerialArray(arr, func, next);
|
|
750
|
+
} else {
|
|
751
|
+
asyncParallelArray(arr, func, next);
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
});
|
|
755
|
+
pending["catch"](function(e) {
|
|
756
|
+
return e;
|
|
757
|
+
});
|
|
758
|
+
return pending;
|
|
759
|
+
}
|
|
760
|
+
function isErrorObj(obj) {
|
|
761
|
+
return !!(obj && obj.message !== void 0);
|
|
762
|
+
}
|
|
763
|
+
function getValue(value, path) {
|
|
764
|
+
var v = value;
|
|
765
|
+
for (var i = 0; i < path.length; i++) {
|
|
766
|
+
if (v == void 0) {
|
|
767
|
+
return v;
|
|
768
|
+
}
|
|
769
|
+
v = v[path[i]];
|
|
770
|
+
}
|
|
771
|
+
return v;
|
|
772
|
+
}
|
|
773
|
+
function complementError(rule, source) {
|
|
774
|
+
return function(oe) {
|
|
775
|
+
var fieldValue;
|
|
776
|
+
if (rule.fullFields) {
|
|
777
|
+
fieldValue = getValue(source, rule.fullFields);
|
|
778
|
+
} else {
|
|
779
|
+
fieldValue = source[oe.field || rule.fullField];
|
|
780
|
+
}
|
|
781
|
+
if (isErrorObj(oe)) {
|
|
782
|
+
oe.field = oe.field || rule.fullField;
|
|
783
|
+
oe.fieldValue = fieldValue;
|
|
784
|
+
return oe;
|
|
785
|
+
}
|
|
786
|
+
return {
|
|
787
|
+
message: typeof oe === "function" ? oe() : oe,
|
|
788
|
+
fieldValue,
|
|
789
|
+
field: oe.field || rule.fullField
|
|
790
|
+
};
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
function deepMerge(target, source) {
|
|
794
|
+
if (source) {
|
|
795
|
+
for (var s in source) {
|
|
796
|
+
if (source.hasOwnProperty(s)) {
|
|
797
|
+
var value = source[s];
|
|
798
|
+
if (typeof value === "object" && typeof target[s] === "object") {
|
|
799
|
+
target[s] = _extends({}, target[s], value);
|
|
800
|
+
} else {
|
|
801
|
+
target[s] = value;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return target;
|
|
807
|
+
}
|
|
808
|
+
var required$1 = function required(rule, value, source, errors, options, type4) {
|
|
809
|
+
if (rule.required && (!source.hasOwnProperty(rule.field) || isEmptyValue(value, type4 || rule.type))) {
|
|
810
|
+
errors.push(format(options.messages.required, rule.fullField));
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
var whitespace = function whitespace2(rule, value, source, errors, options) {
|
|
814
|
+
if (/^\s+$/.test(value) || value === "") {
|
|
815
|
+
errors.push(format(options.messages.whitespace, rule.fullField));
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
var pattern$2 = {
|
|
819
|
+
email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,
|
|
820
|
+
url: new RegExp("^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$", "i"),
|
|
821
|
+
hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i
|
|
822
|
+
};
|
|
823
|
+
var types = {
|
|
824
|
+
integer: function integer(value) {
|
|
825
|
+
return types.number(value) && parseInt(value, 10) === value;
|
|
826
|
+
},
|
|
827
|
+
"float": function float(value) {
|
|
828
|
+
return types.number(value) && !types.integer(value);
|
|
829
|
+
},
|
|
830
|
+
array: function array(value) {
|
|
831
|
+
return Array.isArray(value);
|
|
832
|
+
},
|
|
833
|
+
regexp: function regexp(value) {
|
|
834
|
+
if (value instanceof RegExp) {
|
|
835
|
+
return true;
|
|
836
|
+
}
|
|
837
|
+
try {
|
|
838
|
+
return !!new RegExp(value);
|
|
839
|
+
} catch (e) {
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
},
|
|
843
|
+
date: function date(value) {
|
|
844
|
+
return typeof value.getTime === "function" && typeof value.getMonth === "function" && typeof value.getYear === "function" && !isNaN(value.getTime());
|
|
845
|
+
},
|
|
846
|
+
number: function number(value) {
|
|
847
|
+
if (isNaN(value)) {
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
return typeof value === "number";
|
|
851
|
+
},
|
|
852
|
+
object: function object(value) {
|
|
853
|
+
return typeof value === "object" && !types.array(value);
|
|
854
|
+
},
|
|
855
|
+
method: function method(value) {
|
|
856
|
+
return typeof value === "function";
|
|
857
|
+
},
|
|
858
|
+
email: function email(value) {
|
|
859
|
+
return typeof value === "string" && value.length <= 320 && !!value.match(pattern$2.email);
|
|
860
|
+
},
|
|
861
|
+
url: function url(value) {
|
|
862
|
+
return typeof value === "string" && value.length <= 2048 && !!value.match(pattern$2.url);
|
|
863
|
+
},
|
|
864
|
+
hex: function hex(value) {
|
|
865
|
+
return typeof value === "string" && !!value.match(pattern$2.hex);
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
var type$1 = function type(rule, value, source, errors, options) {
|
|
869
|
+
if (rule.required && value === void 0) {
|
|
870
|
+
required$1(rule, value, source, errors, options);
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
var custom = ["integer", "float", "array", "regexp", "object", "method", "email", "number", "date", "url", "hex"];
|
|
874
|
+
var ruleType = rule.type;
|
|
875
|
+
if (custom.indexOf(ruleType) > -1) {
|
|
876
|
+
if (!types[ruleType](value)) {
|
|
877
|
+
errors.push(format(options.messages.types[ruleType], rule.fullField, rule.type));
|
|
878
|
+
}
|
|
879
|
+
} else if (ruleType && typeof value !== rule.type) {
|
|
880
|
+
errors.push(format(options.messages.types[ruleType], rule.fullField, rule.type));
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
var range = function range2(rule, value, source, errors, options) {
|
|
884
|
+
var len = typeof rule.len === "number";
|
|
885
|
+
var min = typeof rule.min === "number";
|
|
886
|
+
var max = typeof rule.max === "number";
|
|
887
|
+
var spRegexp = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
888
|
+
var val = value;
|
|
889
|
+
var key = null;
|
|
890
|
+
var num = typeof value === "number";
|
|
891
|
+
var str = typeof value === "string";
|
|
892
|
+
var arr = Array.isArray(value);
|
|
893
|
+
if (num) {
|
|
894
|
+
key = "number";
|
|
895
|
+
} else if (str) {
|
|
896
|
+
key = "string";
|
|
897
|
+
} else if (arr) {
|
|
898
|
+
key = "array";
|
|
899
|
+
}
|
|
900
|
+
if (!key) {
|
|
901
|
+
return false;
|
|
902
|
+
}
|
|
903
|
+
if (arr) {
|
|
904
|
+
val = value.length;
|
|
905
|
+
}
|
|
906
|
+
if (str) {
|
|
907
|
+
val = value.replace(spRegexp, "_").length;
|
|
908
|
+
}
|
|
909
|
+
if (len) {
|
|
910
|
+
if (val !== rule.len) {
|
|
911
|
+
errors.push(format(options.messages[key].len, rule.fullField, rule.len));
|
|
912
|
+
}
|
|
913
|
+
} else if (min && !max && val < rule.min) {
|
|
914
|
+
errors.push(format(options.messages[key].min, rule.fullField, rule.min));
|
|
915
|
+
} else if (max && !min && val > rule.max) {
|
|
916
|
+
errors.push(format(options.messages[key].max, rule.fullField, rule.max));
|
|
917
|
+
} else if (min && max && (val < rule.min || val > rule.max)) {
|
|
918
|
+
errors.push(format(options.messages[key].range, rule.fullField, rule.min, rule.max));
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
var ENUM$1 = "enum";
|
|
922
|
+
var enumerable$1 = function enumerable(rule, value, source, errors, options) {
|
|
923
|
+
rule[ENUM$1] = Array.isArray(rule[ENUM$1]) ? rule[ENUM$1] : [];
|
|
924
|
+
if (rule[ENUM$1].indexOf(value) === -1) {
|
|
925
|
+
errors.push(format(options.messages[ENUM$1], rule.fullField, rule[ENUM$1].join(", ")));
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
var pattern$1 = function pattern(rule, value, source, errors, options) {
|
|
929
|
+
if (rule.pattern) {
|
|
930
|
+
if (rule.pattern instanceof RegExp) {
|
|
931
|
+
rule.pattern.lastIndex = 0;
|
|
932
|
+
if (!rule.pattern.test(value)) {
|
|
933
|
+
errors.push(format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
|
934
|
+
}
|
|
935
|
+
} else if (typeof rule.pattern === "string") {
|
|
936
|
+
var _pattern = new RegExp(rule.pattern);
|
|
937
|
+
if (!_pattern.test(value)) {
|
|
938
|
+
errors.push(format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
var rules = {
|
|
944
|
+
required: required$1,
|
|
945
|
+
whitespace,
|
|
946
|
+
type: type$1,
|
|
947
|
+
range,
|
|
948
|
+
"enum": enumerable$1,
|
|
949
|
+
pattern: pattern$1
|
|
950
|
+
};
|
|
951
|
+
var string = function string2(rule, value, callback, source, options) {
|
|
952
|
+
var errors = [];
|
|
953
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
954
|
+
if (validate) {
|
|
955
|
+
if (isEmptyValue(value, "string") && !rule.required) {
|
|
956
|
+
return callback();
|
|
957
|
+
}
|
|
958
|
+
rules.required(rule, value, source, errors, options, "string");
|
|
959
|
+
if (!isEmptyValue(value, "string")) {
|
|
960
|
+
rules.type(rule, value, source, errors, options);
|
|
961
|
+
rules.range(rule, value, source, errors, options);
|
|
962
|
+
rules.pattern(rule, value, source, errors, options);
|
|
963
|
+
if (rule.whitespace === true) {
|
|
964
|
+
rules.whitespace(rule, value, source, errors, options);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
callback(errors);
|
|
969
|
+
};
|
|
970
|
+
var method2 = function method3(rule, value, callback, source, options) {
|
|
971
|
+
var errors = [];
|
|
972
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
973
|
+
if (validate) {
|
|
974
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
975
|
+
return callback();
|
|
976
|
+
}
|
|
977
|
+
rules.required(rule, value, source, errors, options);
|
|
978
|
+
if (value !== void 0) {
|
|
979
|
+
rules.type(rule, value, source, errors, options);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
callback(errors);
|
|
983
|
+
};
|
|
984
|
+
var number2 = function number3(rule, value, callback, source, options) {
|
|
985
|
+
var errors = [];
|
|
986
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
987
|
+
if (validate) {
|
|
988
|
+
if (value === "") {
|
|
989
|
+
value = void 0;
|
|
990
|
+
}
|
|
991
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
992
|
+
return callback();
|
|
993
|
+
}
|
|
994
|
+
rules.required(rule, value, source, errors, options);
|
|
995
|
+
if (value !== void 0) {
|
|
996
|
+
rules.type(rule, value, source, errors, options);
|
|
997
|
+
rules.range(rule, value, source, errors, options);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
callback(errors);
|
|
1001
|
+
};
|
|
1002
|
+
var _boolean = function _boolean2(rule, value, callback, source, options) {
|
|
1003
|
+
var errors = [];
|
|
1004
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1005
|
+
if (validate) {
|
|
1006
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1007
|
+
return callback();
|
|
1008
|
+
}
|
|
1009
|
+
rules.required(rule, value, source, errors, options);
|
|
1010
|
+
if (value !== void 0) {
|
|
1011
|
+
rules.type(rule, value, source, errors, options);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
callback(errors);
|
|
1015
|
+
};
|
|
1016
|
+
var regexp2 = function regexp3(rule, value, callback, source, options) {
|
|
1017
|
+
var errors = [];
|
|
1018
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1019
|
+
if (validate) {
|
|
1020
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1021
|
+
return callback();
|
|
1022
|
+
}
|
|
1023
|
+
rules.required(rule, value, source, errors, options);
|
|
1024
|
+
if (!isEmptyValue(value)) {
|
|
1025
|
+
rules.type(rule, value, source, errors, options);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
callback(errors);
|
|
1029
|
+
};
|
|
1030
|
+
var integer2 = function integer3(rule, value, callback, source, options) {
|
|
1031
|
+
var errors = [];
|
|
1032
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1033
|
+
if (validate) {
|
|
1034
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1035
|
+
return callback();
|
|
1036
|
+
}
|
|
1037
|
+
rules.required(rule, value, source, errors, options);
|
|
1038
|
+
if (value !== void 0) {
|
|
1039
|
+
rules.type(rule, value, source, errors, options);
|
|
1040
|
+
rules.range(rule, value, source, errors, options);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
callback(errors);
|
|
1044
|
+
};
|
|
1045
|
+
var floatFn = function floatFn2(rule, value, callback, source, options) {
|
|
1046
|
+
var errors = [];
|
|
1047
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1048
|
+
if (validate) {
|
|
1049
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1050
|
+
return callback();
|
|
1051
|
+
}
|
|
1052
|
+
rules.required(rule, value, source, errors, options);
|
|
1053
|
+
if (value !== void 0) {
|
|
1054
|
+
rules.type(rule, value, source, errors, options);
|
|
1055
|
+
rules.range(rule, value, source, errors, options);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
callback(errors);
|
|
1059
|
+
};
|
|
1060
|
+
var array2 = function array3(rule, value, callback, source, options) {
|
|
1061
|
+
var errors = [];
|
|
1062
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1063
|
+
if (validate) {
|
|
1064
|
+
if ((value === void 0 || value === null) && !rule.required) {
|
|
1065
|
+
return callback();
|
|
1066
|
+
}
|
|
1067
|
+
rules.required(rule, value, source, errors, options, "array");
|
|
1068
|
+
if (value !== void 0 && value !== null) {
|
|
1069
|
+
rules.type(rule, value, source, errors, options);
|
|
1070
|
+
rules.range(rule, value, source, errors, options);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
callback(errors);
|
|
1074
|
+
};
|
|
1075
|
+
var object2 = function object3(rule, value, callback, source, options) {
|
|
1076
|
+
var errors = [];
|
|
1077
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1078
|
+
if (validate) {
|
|
1079
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1080
|
+
return callback();
|
|
1081
|
+
}
|
|
1082
|
+
rules.required(rule, value, source, errors, options);
|
|
1083
|
+
if (value !== void 0) {
|
|
1084
|
+
rules.type(rule, value, source, errors, options);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
callback(errors);
|
|
1088
|
+
};
|
|
1089
|
+
var ENUM = "enum";
|
|
1090
|
+
var enumerable2 = function enumerable3(rule, value, callback, source, options) {
|
|
1091
|
+
var errors = [];
|
|
1092
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1093
|
+
if (validate) {
|
|
1094
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1095
|
+
return callback();
|
|
1096
|
+
}
|
|
1097
|
+
rules.required(rule, value, source, errors, options);
|
|
1098
|
+
if (value !== void 0) {
|
|
1099
|
+
rules[ENUM](rule, value, source, errors, options);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
callback(errors);
|
|
1103
|
+
};
|
|
1104
|
+
var pattern2 = function pattern3(rule, value, callback, source, options) {
|
|
1105
|
+
var errors = [];
|
|
1106
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1107
|
+
if (validate) {
|
|
1108
|
+
if (isEmptyValue(value, "string") && !rule.required) {
|
|
1109
|
+
return callback();
|
|
1110
|
+
}
|
|
1111
|
+
rules.required(rule, value, source, errors, options);
|
|
1112
|
+
if (!isEmptyValue(value, "string")) {
|
|
1113
|
+
rules.pattern(rule, value, source, errors, options);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
callback(errors);
|
|
1117
|
+
};
|
|
1118
|
+
var date2 = function date3(rule, value, callback, source, options) {
|
|
1119
|
+
var errors = [];
|
|
1120
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1121
|
+
if (validate) {
|
|
1122
|
+
if (isEmptyValue(value, "date") && !rule.required) {
|
|
1123
|
+
return callback();
|
|
1124
|
+
}
|
|
1125
|
+
rules.required(rule, value, source, errors, options);
|
|
1126
|
+
if (!isEmptyValue(value, "date")) {
|
|
1127
|
+
var dateObject;
|
|
1128
|
+
if (value instanceof Date) {
|
|
1129
|
+
dateObject = value;
|
|
1130
|
+
} else {
|
|
1131
|
+
dateObject = new Date(value);
|
|
1132
|
+
}
|
|
1133
|
+
rules.type(rule, dateObject, source, errors, options);
|
|
1134
|
+
if (dateObject) {
|
|
1135
|
+
rules.range(rule, dateObject.getTime(), source, errors, options);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
callback(errors);
|
|
1140
|
+
};
|
|
1141
|
+
var required2 = function required3(rule, value, callback, source, options) {
|
|
1142
|
+
var errors = [];
|
|
1143
|
+
var type4 = Array.isArray(value) ? "array" : typeof value;
|
|
1144
|
+
rules.required(rule, value, source, errors, options, type4);
|
|
1145
|
+
callback(errors);
|
|
1146
|
+
};
|
|
1147
|
+
var type2 = function type3(rule, value, callback, source, options) {
|
|
1148
|
+
var ruleType = rule.type;
|
|
1149
|
+
var errors = [];
|
|
1150
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1151
|
+
if (validate) {
|
|
1152
|
+
if (isEmptyValue(value, ruleType) && !rule.required) {
|
|
1153
|
+
return callback();
|
|
1154
|
+
}
|
|
1155
|
+
rules.required(rule, value, source, errors, options, ruleType);
|
|
1156
|
+
if (!isEmptyValue(value, ruleType)) {
|
|
1157
|
+
rules.type(rule, value, source, errors, options);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
callback(errors);
|
|
1161
|
+
};
|
|
1162
|
+
var any = function any2(rule, value, callback, source, options) {
|
|
1163
|
+
var errors = [];
|
|
1164
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1165
|
+
if (validate) {
|
|
1166
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1167
|
+
return callback();
|
|
1168
|
+
}
|
|
1169
|
+
rules.required(rule, value, source, errors, options);
|
|
1170
|
+
}
|
|
1171
|
+
callback(errors);
|
|
1172
|
+
};
|
|
1173
|
+
var validators = {
|
|
1174
|
+
string,
|
|
1175
|
+
method: method2,
|
|
1176
|
+
number: number2,
|
|
1177
|
+
"boolean": _boolean,
|
|
1178
|
+
regexp: regexp2,
|
|
1179
|
+
integer: integer2,
|
|
1180
|
+
"float": floatFn,
|
|
1181
|
+
array: array2,
|
|
1182
|
+
object: object2,
|
|
1183
|
+
"enum": enumerable2,
|
|
1184
|
+
pattern: pattern2,
|
|
1185
|
+
date: date2,
|
|
1186
|
+
url: type2,
|
|
1187
|
+
hex: type2,
|
|
1188
|
+
email: type2,
|
|
1189
|
+
required: required2,
|
|
1190
|
+
any
|
|
1191
|
+
};
|
|
1192
|
+
function newMessages() {
|
|
1193
|
+
return {
|
|
1194
|
+
"default": "Validation error on field %s",
|
|
1195
|
+
required: "%s is required",
|
|
1196
|
+
"enum": "%s must be one of %s",
|
|
1197
|
+
whitespace: "%s cannot be empty",
|
|
1198
|
+
date: {
|
|
1199
|
+
format: "%s date %s is invalid for format %s",
|
|
1200
|
+
parse: "%s date could not be parsed, %s is invalid ",
|
|
1201
|
+
invalid: "%s date %s is invalid"
|
|
1202
|
+
},
|
|
1203
|
+
types: {
|
|
1204
|
+
string: "%s is not a %s",
|
|
1205
|
+
method: "%s is not a %s (function)",
|
|
1206
|
+
array: "%s is not an %s",
|
|
1207
|
+
object: "%s is not an %s",
|
|
1208
|
+
number: "%s is not a %s",
|
|
1209
|
+
date: "%s is not a %s",
|
|
1210
|
+
"boolean": "%s is not a %s",
|
|
1211
|
+
integer: "%s is not an %s",
|
|
1212
|
+
"float": "%s is not a %s",
|
|
1213
|
+
regexp: "%s is not a valid %s",
|
|
1214
|
+
email: "%s is not a valid %s",
|
|
1215
|
+
url: "%s is not a valid %s",
|
|
1216
|
+
hex: "%s is not a valid %s"
|
|
1217
|
+
},
|
|
1218
|
+
string: {
|
|
1219
|
+
len: "%s must be exactly %s characters",
|
|
1220
|
+
min: "%s must be at least %s characters",
|
|
1221
|
+
max: "%s cannot be longer than %s characters",
|
|
1222
|
+
range: "%s must be between %s and %s characters"
|
|
1223
|
+
},
|
|
1224
|
+
number: {
|
|
1225
|
+
len: "%s must equal %s",
|
|
1226
|
+
min: "%s cannot be less than %s",
|
|
1227
|
+
max: "%s cannot be greater than %s",
|
|
1228
|
+
range: "%s must be between %s and %s"
|
|
1229
|
+
},
|
|
1230
|
+
array: {
|
|
1231
|
+
len: "%s must be exactly %s in length",
|
|
1232
|
+
min: "%s cannot be less than %s in length",
|
|
1233
|
+
max: "%s cannot be greater than %s in length",
|
|
1234
|
+
range: "%s must be between %s and %s in length"
|
|
1235
|
+
},
|
|
1236
|
+
pattern: {
|
|
1237
|
+
mismatch: "%s value %s does not match pattern %s"
|
|
1238
|
+
},
|
|
1239
|
+
clone: function clone() {
|
|
1240
|
+
var cloned = JSON.parse(JSON.stringify(this));
|
|
1241
|
+
cloned.clone = this.clone;
|
|
1242
|
+
return cloned;
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
var messages = newMessages();
|
|
1247
|
+
var Schema = /* @__PURE__ */ function() {
|
|
1248
|
+
function Schema2(descriptor) {
|
|
1249
|
+
this.rules = null;
|
|
1250
|
+
this._messages = messages;
|
|
1251
|
+
this.define(descriptor);
|
|
1252
|
+
}
|
|
1253
|
+
var _proto = Schema2.prototype;
|
|
1254
|
+
_proto.define = function define(rules2) {
|
|
1255
|
+
var _this = this;
|
|
1256
|
+
if (!rules2) {
|
|
1257
|
+
throw new Error("Cannot configure a schema with no rules");
|
|
1258
|
+
}
|
|
1259
|
+
if (typeof rules2 !== "object" || Array.isArray(rules2)) {
|
|
1260
|
+
throw new Error("Rules must be an object");
|
|
1261
|
+
}
|
|
1262
|
+
this.rules = {};
|
|
1263
|
+
Object.keys(rules2).forEach(function(name) {
|
|
1264
|
+
var item = rules2[name];
|
|
1265
|
+
_this.rules[name] = Array.isArray(item) ? item : [item];
|
|
1266
|
+
});
|
|
1267
|
+
};
|
|
1268
|
+
_proto.messages = function messages2(_messages) {
|
|
1269
|
+
if (_messages) {
|
|
1270
|
+
this._messages = deepMerge(newMessages(), _messages);
|
|
1271
|
+
}
|
|
1272
|
+
return this._messages;
|
|
1273
|
+
};
|
|
1274
|
+
_proto.validate = function validate(source_, o, oc) {
|
|
1275
|
+
var _this2 = this;
|
|
1276
|
+
if (o === void 0) {
|
|
1277
|
+
o = {};
|
|
1278
|
+
}
|
|
1279
|
+
if (oc === void 0) {
|
|
1280
|
+
oc = function oc2() {
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
var source = source_;
|
|
1284
|
+
var options = o;
|
|
1285
|
+
var callback = oc;
|
|
1286
|
+
if (typeof options === "function") {
|
|
1287
|
+
callback = options;
|
|
1288
|
+
options = {};
|
|
1289
|
+
}
|
|
1290
|
+
if (!this.rules || Object.keys(this.rules).length === 0) {
|
|
1291
|
+
if (callback) {
|
|
1292
|
+
callback(null, source);
|
|
1293
|
+
}
|
|
1294
|
+
return Promise.resolve(source);
|
|
1295
|
+
}
|
|
1296
|
+
function complete(results) {
|
|
1297
|
+
var errors = [];
|
|
1298
|
+
var fields = {};
|
|
1299
|
+
function add(e) {
|
|
1300
|
+
if (Array.isArray(e)) {
|
|
1301
|
+
var _errors;
|
|
1302
|
+
errors = (_errors = errors).concat.apply(_errors, e);
|
|
1303
|
+
} else {
|
|
1304
|
+
errors.push(e);
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
for (var i = 0; i < results.length; i++) {
|
|
1308
|
+
add(results[i]);
|
|
1309
|
+
}
|
|
1310
|
+
if (!errors.length) {
|
|
1311
|
+
callback(null, source);
|
|
1312
|
+
} else {
|
|
1313
|
+
fields = convertFieldsError(errors);
|
|
1314
|
+
callback(errors, fields);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
if (options.messages) {
|
|
1318
|
+
var messages$1 = this.messages();
|
|
1319
|
+
if (messages$1 === messages) {
|
|
1320
|
+
messages$1 = newMessages();
|
|
1321
|
+
}
|
|
1322
|
+
deepMerge(messages$1, options.messages);
|
|
1323
|
+
options.messages = messages$1;
|
|
1324
|
+
} else {
|
|
1325
|
+
options.messages = this.messages();
|
|
1326
|
+
}
|
|
1327
|
+
var series = {};
|
|
1328
|
+
var keys = options.keys || Object.keys(this.rules);
|
|
1329
|
+
keys.forEach(function(z) {
|
|
1330
|
+
var arr = _this2.rules[z];
|
|
1331
|
+
var value = source[z];
|
|
1332
|
+
arr.forEach(function(r) {
|
|
1333
|
+
var rule = r;
|
|
1334
|
+
if (typeof rule.transform === "function") {
|
|
1335
|
+
if (source === source_) {
|
|
1336
|
+
source = _extends({}, source);
|
|
1337
|
+
}
|
|
1338
|
+
value = source[z] = rule.transform(value);
|
|
1339
|
+
}
|
|
1340
|
+
if (typeof rule === "function") {
|
|
1341
|
+
rule = {
|
|
1342
|
+
validator: rule
|
|
1343
|
+
};
|
|
1344
|
+
} else {
|
|
1345
|
+
rule = _extends({}, rule);
|
|
1346
|
+
}
|
|
1347
|
+
rule.validator = _this2.getValidationMethod(rule);
|
|
1348
|
+
if (!rule.validator) {
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
rule.field = z;
|
|
1352
|
+
rule.fullField = rule.fullField || z;
|
|
1353
|
+
rule.type = _this2.getType(rule);
|
|
1354
|
+
series[z] = series[z] || [];
|
|
1355
|
+
series[z].push({
|
|
1356
|
+
rule,
|
|
1357
|
+
value,
|
|
1358
|
+
source,
|
|
1359
|
+
field: z
|
|
1360
|
+
});
|
|
1361
|
+
});
|
|
1362
|
+
});
|
|
1363
|
+
var errorFields = {};
|
|
1364
|
+
return asyncMap(series, options, function(data, doIt) {
|
|
1365
|
+
var rule = data.rule;
|
|
1366
|
+
var deep = (rule.type === "object" || rule.type === "array") && (typeof rule.fields === "object" || typeof rule.defaultField === "object");
|
|
1367
|
+
deep = deep && (rule.required || !rule.required && data.value);
|
|
1368
|
+
rule.field = data.field;
|
|
1369
|
+
function addFullField(key, schema) {
|
|
1370
|
+
return _extends({}, schema, {
|
|
1371
|
+
fullField: rule.fullField + "." + key,
|
|
1372
|
+
fullFields: rule.fullFields ? [].concat(rule.fullFields, [key]) : [key]
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
function cb(e) {
|
|
1376
|
+
if (e === void 0) {
|
|
1377
|
+
e = [];
|
|
1378
|
+
}
|
|
1379
|
+
var errorList = Array.isArray(e) ? e : [e];
|
|
1380
|
+
if (!options.suppressWarning && errorList.length) {
|
|
1381
|
+
Schema2.warning("async-validator:", errorList);
|
|
1382
|
+
}
|
|
1383
|
+
if (errorList.length && rule.message !== void 0) {
|
|
1384
|
+
errorList = [].concat(rule.message);
|
|
1385
|
+
}
|
|
1386
|
+
var filledErrors = errorList.map(complementError(rule, source));
|
|
1387
|
+
if (options.first && filledErrors.length) {
|
|
1388
|
+
errorFields[rule.field] = 1;
|
|
1389
|
+
return doIt(filledErrors);
|
|
1390
|
+
}
|
|
1391
|
+
if (!deep) {
|
|
1392
|
+
doIt(filledErrors);
|
|
1393
|
+
} else {
|
|
1394
|
+
if (rule.required && !data.value) {
|
|
1395
|
+
if (rule.message !== void 0) {
|
|
1396
|
+
filledErrors = [].concat(rule.message).map(complementError(rule, source));
|
|
1397
|
+
} else if (options.error) {
|
|
1398
|
+
filledErrors = [options.error(rule, format(options.messages.required, rule.field))];
|
|
1399
|
+
}
|
|
1400
|
+
return doIt(filledErrors);
|
|
1401
|
+
}
|
|
1402
|
+
var fieldsSchema = {};
|
|
1403
|
+
if (rule.defaultField) {
|
|
1404
|
+
Object.keys(data.value).map(function(key) {
|
|
1405
|
+
fieldsSchema[key] = rule.defaultField;
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
fieldsSchema = _extends({}, fieldsSchema, data.rule.fields);
|
|
1409
|
+
var paredFieldsSchema = {};
|
|
1410
|
+
Object.keys(fieldsSchema).forEach(function(field) {
|
|
1411
|
+
var fieldSchema = fieldsSchema[field];
|
|
1412
|
+
var fieldSchemaList = Array.isArray(fieldSchema) ? fieldSchema : [fieldSchema];
|
|
1413
|
+
paredFieldsSchema[field] = fieldSchemaList.map(addFullField.bind(null, field));
|
|
1414
|
+
});
|
|
1415
|
+
var schema = new Schema2(paredFieldsSchema);
|
|
1416
|
+
schema.messages(options.messages);
|
|
1417
|
+
if (data.rule.options) {
|
|
1418
|
+
data.rule.options.messages = options.messages;
|
|
1419
|
+
data.rule.options.error = options.error;
|
|
1420
|
+
}
|
|
1421
|
+
schema.validate(data.value, data.rule.options || options, function(errs) {
|
|
1422
|
+
var finalErrors = [];
|
|
1423
|
+
if (filledErrors && filledErrors.length) {
|
|
1424
|
+
finalErrors.push.apply(finalErrors, filledErrors);
|
|
1425
|
+
}
|
|
1426
|
+
if (errs && errs.length) {
|
|
1427
|
+
finalErrors.push.apply(finalErrors, errs);
|
|
1428
|
+
}
|
|
1429
|
+
doIt(finalErrors.length ? finalErrors : null);
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
var res;
|
|
1434
|
+
if (rule.asyncValidator) {
|
|
1435
|
+
res = rule.asyncValidator(rule, data.value, cb, data.source, options);
|
|
1436
|
+
} else if (rule.validator) {
|
|
1437
|
+
res = rule.validator(rule, data.value, cb, data.source, options);
|
|
1438
|
+
if (res === true) {
|
|
1439
|
+
cb();
|
|
1440
|
+
} else if (res === false) {
|
|
1441
|
+
cb(typeof rule.message === "function" ? rule.message(rule.fullField || rule.field) : rule.message || (rule.fullField || rule.field) + " fails");
|
|
1442
|
+
} else if (res instanceof Array) {
|
|
1443
|
+
cb(res);
|
|
1444
|
+
} else if (res instanceof Error) {
|
|
1445
|
+
cb(res.message);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
if (res && res.then) {
|
|
1449
|
+
res.then(function() {
|
|
1450
|
+
return cb();
|
|
1451
|
+
}, function(e) {
|
|
1452
|
+
return cb(e);
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
}, function(results) {
|
|
1456
|
+
complete(results);
|
|
1457
|
+
}, source);
|
|
1458
|
+
};
|
|
1459
|
+
_proto.getType = function getType(rule) {
|
|
1460
|
+
if (rule.type === void 0 && rule.pattern instanceof RegExp) {
|
|
1461
|
+
rule.type = "pattern";
|
|
1462
|
+
}
|
|
1463
|
+
if (typeof rule.validator !== "function" && rule.type && !validators.hasOwnProperty(rule.type)) {
|
|
1464
|
+
throw new Error(format("Unknown rule type %s", rule.type));
|
|
1465
|
+
}
|
|
1466
|
+
return rule.type || "string";
|
|
1467
|
+
};
|
|
1468
|
+
_proto.getValidationMethod = function getValidationMethod(rule) {
|
|
1469
|
+
if (typeof rule.validator === "function") {
|
|
1470
|
+
return rule.validator;
|
|
1471
|
+
}
|
|
1472
|
+
var keys = Object.keys(rule);
|
|
1473
|
+
var messageIndex = keys.indexOf("message");
|
|
1474
|
+
if (messageIndex !== -1) {
|
|
1475
|
+
keys.splice(messageIndex, 1);
|
|
1476
|
+
}
|
|
1477
|
+
if (keys.length === 1 && keys[0] === "required") {
|
|
1478
|
+
return validators.required;
|
|
1479
|
+
}
|
|
1480
|
+
return validators[this.getType(rule)] || void 0;
|
|
1481
|
+
};
|
|
1482
|
+
return Schema2;
|
|
1483
|
+
}();
|
|
1484
|
+
Schema.register = function register(type4, validator) {
|
|
1485
|
+
if (typeof validator !== "function") {
|
|
1486
|
+
throw new Error("Cannot register a validator by type, validator is not a function");
|
|
1487
|
+
}
|
|
1488
|
+
validators[type4] = validator;
|
|
1489
|
+
};
|
|
1490
|
+
Schema.warning = warning;
|
|
1491
|
+
Schema.messages = messages;
|
|
1492
|
+
Schema.validators = validators;
|
|
1493
|
+
var formItem = "";
|
|
1494
|
+
var FormItem = defineComponent({
|
|
1495
|
+
name: "DFormItem",
|
|
1496
|
+
props: formItemProps,
|
|
1497
|
+
setup(props, ctx2) {
|
|
1498
|
+
const formItemMitt = mitt();
|
|
1499
|
+
const dForm = reactive(inject(formInjectionKey, {}));
|
|
1500
|
+
const formData = reactive(dForm.formData);
|
|
1501
|
+
const columnsClass = ref(dForm.columnsClass);
|
|
1502
|
+
const initFormItemData = formData[props.prop];
|
|
1503
|
+
const labelData = reactive(dForm.labelData);
|
|
1504
|
+
const rules2 = reactive(dForm.rules);
|
|
1505
|
+
const resetField = () => {
|
|
1506
|
+
formData[props.prop] = initFormItemData;
|
|
1507
|
+
};
|
|
1508
|
+
const formItem2 = reactive({
|
|
1509
|
+
dHasFeedback: props.dHasFeedback,
|
|
1510
|
+
prop: props.prop,
|
|
1511
|
+
formItemMitt,
|
|
1512
|
+
resetField
|
|
1513
|
+
});
|
|
1514
|
+
provide(formItemInjectionKey, formItem2);
|
|
1515
|
+
const isHorizontal = labelData.layout === "horizontal";
|
|
1516
|
+
const isVertical = labelData.layout === "vertical";
|
|
1517
|
+
const isColumns = labelData.layout === "columns";
|
|
1518
|
+
const showMessage = ref(false);
|
|
1519
|
+
const tipMessage = ref("");
|
|
1520
|
+
const validate = (trigger) => {
|
|
1521
|
+
const ruleKey = props.prop;
|
|
1522
|
+
const ruleItem = rules2[ruleKey];
|
|
1523
|
+
const descriptor = {};
|
|
1524
|
+
descriptor[ruleKey] = ruleItem;
|
|
1525
|
+
const validator = new Schema(descriptor);
|
|
1526
|
+
validator.validate({
|
|
1527
|
+
[ruleKey]: formData[ruleKey]
|
|
1528
|
+
}).then(() => {
|
|
1529
|
+
showMessage.value = false;
|
|
1530
|
+
tipMessage.value = "";
|
|
1531
|
+
}).catch(({
|
|
1532
|
+
errors
|
|
1533
|
+
}) => {
|
|
1534
|
+
showMessage.value = true;
|
|
1535
|
+
tipMessage.value = errors[0].message;
|
|
1536
|
+
});
|
|
1537
|
+
};
|
|
1538
|
+
const validateEvents = [];
|
|
1539
|
+
const addValidateEvents = () => {
|
|
1540
|
+
if (rules2 && rules2[props.prop]) {
|
|
1541
|
+
const ruleItem = rules2[props.prop];
|
|
1542
|
+
let eventName = ruleItem["trigger"];
|
|
1543
|
+
if (Array.isArray(ruleItem)) {
|
|
1544
|
+
ruleItem.forEach((item) => {
|
|
1545
|
+
eventName = item["trigger"];
|
|
1546
|
+
const cb = () => validate();
|
|
1547
|
+
validateEvents.push({
|
|
1548
|
+
eventName: cb
|
|
1549
|
+
});
|
|
1550
|
+
formItem2.formItemMitt.on(dFormItemEvents[eventName], cb);
|
|
1551
|
+
});
|
|
1552
|
+
} else {
|
|
1553
|
+
const cb = () => validate();
|
|
1554
|
+
validateEvents.push({
|
|
1555
|
+
eventName: cb
|
|
1556
|
+
});
|
|
1557
|
+
ruleItem && formItem2.formItemMitt.on(dFormItemEvents[eventName], cb);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
const removeValidateEvents = () => {
|
|
1562
|
+
if (rules2 && rules2[props.prop] && validateEvents.length > 0) {
|
|
1563
|
+
validateEvents.forEach((item) => {
|
|
1564
|
+
formItem2.formItemMitt.off(item.eventName, item.cb);
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
onMounted(() => {
|
|
1569
|
+
dForm.formMitt.emit(dFormEvents.addField, formItem2);
|
|
1570
|
+
addValidateEvents();
|
|
1571
|
+
});
|
|
1572
|
+
onBeforeUnmount(() => {
|
|
1573
|
+
dForm.formMitt.emit(dFormEvents.removeField, formItem2);
|
|
1574
|
+
removeValidateEvents();
|
|
1575
|
+
});
|
|
1576
|
+
return () => {
|
|
1577
|
+
var _a, _b;
|
|
1578
|
+
return createVNode("div", {
|
|
1579
|
+
"class": `form-item${isHorizontal ? "" : isVertical ? " form-item-vertical" : " form-item-columns"}${isColumns ? " column-item " + columnsClass.value : ""}`
|
|
1580
|
+
}, [(_b = (_a = ctx2.slots).default) == null ? void 0 : _b.call(_a), createVNode("div", {
|
|
1581
|
+
"class": `d-validate-tip${isHorizontal ? " d-validate-tip-horizontal" : ""}`
|
|
1582
|
+
}, [showMessage.value && tipMessage.value])]);
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1585
|
+
});
|
|
1586
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
1587
|
+
var freeGlobal$1 = freeGlobal;
|
|
1588
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
1589
|
+
var root = freeGlobal$1 || freeSelf || Function("return this")();
|
|
1590
|
+
var root$1 = root;
|
|
1591
|
+
var Symbol$1 = root$1.Symbol;
|
|
1592
|
+
var Symbol$2 = Symbol$1;
|
|
1593
|
+
var objectProto$1 = Object.prototype;
|
|
1594
|
+
var hasOwnProperty = objectProto$1.hasOwnProperty;
|
|
1595
|
+
var nativeObjectToString$1 = objectProto$1.toString;
|
|
1596
|
+
var symToStringTag$1 = Symbol$2 ? Symbol$2.toStringTag : void 0;
|
|
1597
|
+
function getRawTag(value) {
|
|
1598
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag$1), tag = value[symToStringTag$1];
|
|
1599
|
+
try {
|
|
1600
|
+
value[symToStringTag$1] = void 0;
|
|
1601
|
+
var unmasked = true;
|
|
1602
|
+
} catch (e) {
|
|
1603
|
+
}
|
|
1604
|
+
var result = nativeObjectToString$1.call(value);
|
|
1605
|
+
if (unmasked) {
|
|
1606
|
+
if (isOwn) {
|
|
1607
|
+
value[symToStringTag$1] = tag;
|
|
1608
|
+
} else {
|
|
1609
|
+
delete value[symToStringTag$1];
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
return result;
|
|
1613
|
+
}
|
|
1614
|
+
var objectProto = Object.prototype;
|
|
1615
|
+
var nativeObjectToString = objectProto.toString;
|
|
1616
|
+
function objectToString(value) {
|
|
1617
|
+
return nativeObjectToString.call(value);
|
|
1618
|
+
}
|
|
1619
|
+
var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
|
|
1620
|
+
var symToStringTag = Symbol$2 ? Symbol$2.toStringTag : void 0;
|
|
1621
|
+
function baseGetTag(value) {
|
|
1622
|
+
if (value == null) {
|
|
1623
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
1624
|
+
}
|
|
1625
|
+
return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
|
|
1626
|
+
}
|
|
1627
|
+
function isObjectLike(value) {
|
|
1628
|
+
return value != null && typeof value == "object";
|
|
1629
|
+
}
|
|
1630
|
+
var symbolTag = "[object Symbol]";
|
|
1631
|
+
function isSymbol(value) {
|
|
1632
|
+
return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
|
|
1633
|
+
}
|
|
1634
|
+
function arrayMap(array4, iteratee) {
|
|
1635
|
+
var index2 = -1, length = array4 == null ? 0 : array4.length, result = Array(length);
|
|
1636
|
+
while (++index2 < length) {
|
|
1637
|
+
result[index2] = iteratee(array4[index2], index2, array4);
|
|
1638
|
+
}
|
|
1639
|
+
return result;
|
|
1640
|
+
}
|
|
1641
|
+
var isArray = Array.isArray;
|
|
1642
|
+
var isArray$1 = isArray;
|
|
1643
|
+
var INFINITY = 1 / 0;
|
|
1644
|
+
var symbolProto = Symbol$2 ? Symbol$2.prototype : void 0, symbolToString = symbolProto ? symbolProto.toString : void 0;
|
|
1645
|
+
function baseToString(value) {
|
|
1646
|
+
if (typeof value == "string") {
|
|
1647
|
+
return value;
|
|
1648
|
+
}
|
|
1649
|
+
if (isArray$1(value)) {
|
|
1650
|
+
return arrayMap(value, baseToString) + "";
|
|
1651
|
+
}
|
|
1652
|
+
if (isSymbol(value)) {
|
|
1653
|
+
return symbolToString ? symbolToString.call(value) : "";
|
|
1654
|
+
}
|
|
1655
|
+
var result = value + "";
|
|
1656
|
+
return result == "0" && 1 / value == -INFINITY ? "-0" : result;
|
|
1657
|
+
}
|
|
1658
|
+
var reWhitespace = /\s/;
|
|
1659
|
+
function trimmedEndIndex(string3) {
|
|
1660
|
+
var index2 = string3.length;
|
|
1661
|
+
while (index2-- && reWhitespace.test(string3.charAt(index2))) {
|
|
1662
|
+
}
|
|
1663
|
+
return index2;
|
|
1664
|
+
}
|
|
1665
|
+
var reTrimStart = /^\s+/;
|
|
1666
|
+
function baseTrim(string3) {
|
|
1667
|
+
return string3 ? string3.slice(0, trimmedEndIndex(string3) + 1).replace(reTrimStart, "") : string3;
|
|
1668
|
+
}
|
|
1669
|
+
function isObject(value) {
|
|
1670
|
+
var type4 = typeof value;
|
|
1671
|
+
return value != null && (type4 == "object" || type4 == "function");
|
|
1672
|
+
}
|
|
1673
|
+
var NAN = 0 / 0;
|
|
1674
|
+
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
|
1675
|
+
var reIsBinary = /^0b[01]+$/i;
|
|
1676
|
+
var reIsOctal = /^0o[0-7]+$/i;
|
|
1677
|
+
var freeParseInt = parseInt;
|
|
1678
|
+
function toNumber(value) {
|
|
1679
|
+
if (typeof value == "number") {
|
|
1680
|
+
return value;
|
|
1681
|
+
}
|
|
1682
|
+
if (isSymbol(value)) {
|
|
1683
|
+
return NAN;
|
|
1684
|
+
}
|
|
1685
|
+
if (isObject(value)) {
|
|
1686
|
+
var other = typeof value.valueOf == "function" ? value.valueOf() : value;
|
|
1687
|
+
value = isObject(other) ? other + "" : other;
|
|
1688
|
+
}
|
|
1689
|
+
if (typeof value != "string") {
|
|
1690
|
+
return value === 0 ? value : +value;
|
|
1691
|
+
}
|
|
1692
|
+
value = baseTrim(value);
|
|
1693
|
+
var isBinary = reIsBinary.test(value);
|
|
1694
|
+
return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
|
|
1695
|
+
}
|
|
1696
|
+
function toString(value) {
|
|
1697
|
+
return value == null ? "" : baseToString(value);
|
|
1698
|
+
}
|
|
1699
|
+
var now = function() {
|
|
1700
|
+
return root$1.Date.now();
|
|
1701
|
+
};
|
|
1702
|
+
var now$1 = now;
|
|
1703
|
+
var FUNC_ERROR_TEXT = "Expected a function";
|
|
1704
|
+
var nativeMax = Math.max, nativeMin = Math.min;
|
|
1705
|
+
function debounce(func, wait, options) {
|
|
1706
|
+
var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
|
|
1707
|
+
if (typeof func != "function") {
|
|
1708
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
1709
|
+
}
|
|
1710
|
+
wait = toNumber(wait) || 0;
|
|
1711
|
+
if (isObject(options)) {
|
|
1712
|
+
leading = !!options.leading;
|
|
1713
|
+
maxing = "maxWait" in options;
|
|
1714
|
+
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
|
|
1715
|
+
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
1716
|
+
}
|
|
1717
|
+
function invokeFunc(time) {
|
|
1718
|
+
var args = lastArgs, thisArg = lastThis;
|
|
1719
|
+
lastArgs = lastThis = void 0;
|
|
1720
|
+
lastInvokeTime = time;
|
|
1721
|
+
result = func.apply(thisArg, args);
|
|
1722
|
+
return result;
|
|
1723
|
+
}
|
|
1724
|
+
function leadingEdge(time) {
|
|
1725
|
+
lastInvokeTime = time;
|
|
1726
|
+
timerId = setTimeout(timerExpired, wait);
|
|
1727
|
+
return leading ? invokeFunc(time) : result;
|
|
1728
|
+
}
|
|
1729
|
+
function remainingWait(time) {
|
|
1730
|
+
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
|
|
1731
|
+
return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
1732
|
+
}
|
|
1733
|
+
function shouldInvoke(time) {
|
|
1734
|
+
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
|
|
1735
|
+
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
|
|
1736
|
+
}
|
|
1737
|
+
function timerExpired() {
|
|
1738
|
+
var time = now$1();
|
|
1739
|
+
if (shouldInvoke(time)) {
|
|
1740
|
+
return trailingEdge(time);
|
|
1741
|
+
}
|
|
1742
|
+
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
1743
|
+
}
|
|
1744
|
+
function trailingEdge(time) {
|
|
1745
|
+
timerId = void 0;
|
|
1746
|
+
if (trailing && lastArgs) {
|
|
1747
|
+
return invokeFunc(time);
|
|
1748
|
+
}
|
|
1749
|
+
lastArgs = lastThis = void 0;
|
|
1750
|
+
return result;
|
|
1751
|
+
}
|
|
1752
|
+
function cancel() {
|
|
1753
|
+
if (timerId !== void 0) {
|
|
1754
|
+
clearTimeout(timerId);
|
|
1755
|
+
}
|
|
1756
|
+
lastInvokeTime = 0;
|
|
1757
|
+
lastArgs = lastCallTime = lastThis = timerId = void 0;
|
|
1758
|
+
}
|
|
1759
|
+
function flush() {
|
|
1760
|
+
return timerId === void 0 ? result : trailingEdge(now$1());
|
|
1761
|
+
}
|
|
1762
|
+
function debounced() {
|
|
1763
|
+
var time = now$1(), isInvoking = shouldInvoke(time);
|
|
1764
|
+
lastArgs = arguments;
|
|
1765
|
+
lastThis = this;
|
|
1766
|
+
lastCallTime = time;
|
|
1767
|
+
if (isInvoking) {
|
|
1768
|
+
if (timerId === void 0) {
|
|
1769
|
+
return leadingEdge(lastCallTime);
|
|
1770
|
+
}
|
|
1771
|
+
if (maxing) {
|
|
1772
|
+
clearTimeout(timerId);
|
|
1773
|
+
timerId = setTimeout(timerExpired, wait);
|
|
1774
|
+
return invokeFunc(lastCallTime);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
if (timerId === void 0) {
|
|
1778
|
+
timerId = setTimeout(timerExpired, wait);
|
|
1779
|
+
}
|
|
1780
|
+
return result;
|
|
1781
|
+
}
|
|
1782
|
+
debounced.cancel = cancel;
|
|
1783
|
+
debounced.flush = flush;
|
|
1784
|
+
return debounced;
|
|
1785
|
+
}
|
|
1786
|
+
var idCounter = 0;
|
|
1787
|
+
function uniqueId(prefix) {
|
|
1788
|
+
var id = ++idCounter;
|
|
1789
|
+
return toString(prefix) + id;
|
|
1790
|
+
}
|
|
1791
|
+
var formControl = "";
|
|
1792
|
+
var FormControl = defineComponent({
|
|
1793
|
+
name: "DFormControl",
|
|
1794
|
+
props: formControlProps,
|
|
1795
|
+
setup(props, ctx2) {
|
|
1796
|
+
const formControl2 = ref();
|
|
1797
|
+
const dForm = reactive(inject(formInjectionKey, {}));
|
|
1798
|
+
const labelData = reactive(dForm.labelData);
|
|
1799
|
+
const isHorizontal = labelData.layout === "horizontal";
|
|
1800
|
+
const uid = uniqueId("dfc-");
|
|
1801
|
+
const showPopover = ref(false);
|
|
1802
|
+
const tipMessage = ref("");
|
|
1803
|
+
const popPosition = ref("bottom");
|
|
1804
|
+
let rectInfo = {
|
|
1805
|
+
width: 0,
|
|
1806
|
+
height: 0
|
|
1807
|
+
};
|
|
1808
|
+
let elOffset = {
|
|
1809
|
+
left: 0,
|
|
1810
|
+
top: 0
|
|
1811
|
+
};
|
|
1812
|
+
let popoverLeftPosition = 0;
|
|
1813
|
+
let popoverTopPosition = 0;
|
|
1814
|
+
onMounted(() => {
|
|
1815
|
+
const el = document.getElementById(uid);
|
|
1816
|
+
elOffset = getElOffset(el);
|
|
1817
|
+
EventBus.on("showPopoverErrorMessage", (data) => {
|
|
1818
|
+
if (uid === data.uid) {
|
|
1819
|
+
rectInfo = el.getBoundingClientRect();
|
|
1820
|
+
popoverLeftPosition = popPosition.value === "top" || popPosition.value === "bottom" ? rectInfo.right - rectInfo.width / 2 : rectInfo.right;
|
|
1821
|
+
popoverTopPosition = popPosition.value === "top" ? elOffset.top + rectInfo.height / 2 - rectInfo.height : elOffset.top + rectInfo.height / 2;
|
|
1822
|
+
showPopover.value = data.showPopover;
|
|
1823
|
+
tipMessage.value = data.message;
|
|
1824
|
+
popPosition.value = data.popPosition;
|
|
1825
|
+
}
|
|
1826
|
+
});
|
|
1827
|
+
});
|
|
1828
|
+
const iconData = computed(() => {
|
|
1829
|
+
switch (props.feedbackStatus) {
|
|
1830
|
+
case "pending":
|
|
1831
|
+
return {
|
|
1832
|
+
name: "priority",
|
|
1833
|
+
color: "#e9edfa"
|
|
1834
|
+
};
|
|
1835
|
+
case "success":
|
|
1836
|
+
return {
|
|
1837
|
+
name: "right-o",
|
|
1838
|
+
color: "rgb(61, 204, 166)"
|
|
1839
|
+
};
|
|
1840
|
+
case "error":
|
|
1841
|
+
return {
|
|
1842
|
+
name: "error-o",
|
|
1843
|
+
color: "rgb(249, 95, 91)"
|
|
1844
|
+
};
|
|
1845
|
+
default:
|
|
1846
|
+
return {
|
|
1847
|
+
name: "",
|
|
1848
|
+
color: ""
|
|
1849
|
+
};
|
|
1850
|
+
}
|
|
1851
|
+
});
|
|
1852
|
+
return () => {
|
|
1853
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1854
|
+
const {
|
|
1855
|
+
feedbackStatus,
|
|
1856
|
+
extraInfo
|
|
1857
|
+
} = props;
|
|
1858
|
+
return createVNode("div", {
|
|
1859
|
+
"class": "form-control",
|
|
1860
|
+
"ref": formControl2,
|
|
1861
|
+
"data-uid": uid
|
|
1862
|
+
}, [createVNode(Teleport, {
|
|
1863
|
+
"to": "body"
|
|
1864
|
+
}, {
|
|
1865
|
+
default: () => [createVNode("div", {
|
|
1866
|
+
"style": {
|
|
1867
|
+
position: "absolute",
|
|
1868
|
+
left: popoverLeftPosition + "px",
|
|
1869
|
+
top: popoverTopPosition + "px",
|
|
1870
|
+
width: rectInfo.width + "px",
|
|
1871
|
+
height: rectInfo.height + "px"
|
|
1872
|
+
}
|
|
1873
|
+
}, [createVNode(Popover, {
|
|
1874
|
+
"visible": showPopover.value,
|
|
1875
|
+
"content": tipMessage.value,
|
|
1876
|
+
"popType": "error",
|
|
1877
|
+
"position": popPosition.value
|
|
1878
|
+
}, null)])]
|
|
1879
|
+
}), createVNode("div", {
|
|
1880
|
+
"class": `devui-form-control-container${isHorizontal ? " devui-form-control-container-horizontal" : ""}${feedbackStatus ? " has-feedback" : ""}${feedbackStatus === "error" ? " feedback-error" : ""}`
|
|
1881
|
+
}, [createVNode("div", {
|
|
1882
|
+
"class": "devui-control-content-wrapper",
|
|
1883
|
+
"id": uid
|
|
1884
|
+
}, [(_b = (_a = ctx2.slots).default) == null ? void 0 : _b.call(_a)]), (feedbackStatus || ((_d = (_c = ctx2.slots).suffixTemplate) == null ? void 0 : _d.call(_c))) && createVNode("span", {
|
|
1885
|
+
"class": "feedback-status"
|
|
1886
|
+
}, [((_f = (_e = ctx2.slots).suffixTemplate) == null ? void 0 : _f.call(_e)) ? (_h = (_g = ctx2.slots).suffixTemplate) == null ? void 0 : _h.call(_g) : createVNode(Icon, {
|
|
1887
|
+
"name": iconData.value.name,
|
|
1888
|
+
"color": iconData.value.color
|
|
1889
|
+
}, null)])]), extraInfo && createVNode("div", {
|
|
1890
|
+
"class": "devui-form-control-extra-info"
|
|
1891
|
+
}, [extraInfo])]);
|
|
1892
|
+
};
|
|
1893
|
+
}
|
|
1894
|
+
});
|
|
1895
|
+
var formOperation = "";
|
|
1896
|
+
var FormOperation = defineComponent({
|
|
1897
|
+
name: "DFormOperation",
|
|
1898
|
+
props: {},
|
|
1899
|
+
setup(props, ctx2) {
|
|
1900
|
+
return () => {
|
|
1901
|
+
var _a, _b;
|
|
1902
|
+
return createVNode("div", {
|
|
1903
|
+
"class": "form-operation"
|
|
1904
|
+
}, [(_b = (_a = ctx2.slots).default) == null ? void 0 : _b.call(_a)]);
|
|
1905
|
+
};
|
|
1906
|
+
}
|
|
1907
|
+
});
|
|
1908
|
+
var style = "";
|
|
1909
|
+
var ErrorStrategyEnum;
|
|
1910
|
+
(function(ErrorStrategyEnum2) {
|
|
1911
|
+
ErrorStrategyEnum2["dirty"] = "dirty";
|
|
1912
|
+
ErrorStrategyEnum2["pristine"] = "pristine";
|
|
1913
|
+
})(ErrorStrategyEnum || (ErrorStrategyEnum = {}));
|
|
1914
|
+
var UpdateOnEnum;
|
|
1915
|
+
(function(UpdateOnEnum2) {
|
|
1916
|
+
UpdateOnEnum2["input"] = "input";
|
|
1917
|
+
UpdateOnEnum2["focus"] = "focus";
|
|
1918
|
+
UpdateOnEnum2["change"] = "change";
|
|
1919
|
+
UpdateOnEnum2["blur"] = "blur";
|
|
1920
|
+
UpdateOnEnum2["submit"] = "submit";
|
|
1921
|
+
})(UpdateOnEnum || (UpdateOnEnum = {}));
|
|
1922
|
+
var MessageShowTypeEnum;
|
|
1923
|
+
(function(MessageShowTypeEnum2) {
|
|
1924
|
+
MessageShowTypeEnum2["popover"] = "popover";
|
|
1925
|
+
MessageShowTypeEnum2["text"] = "text";
|
|
1926
|
+
MessageShowTypeEnum2["none"] = "none";
|
|
1927
|
+
MessageShowTypeEnum2["toast"] = "toast";
|
|
1928
|
+
})(MessageShowTypeEnum || (MessageShowTypeEnum = {}));
|
|
1929
|
+
function getAvaliableRuleObj(ruleName, value) {
|
|
1930
|
+
if (!ruleName) {
|
|
1931
|
+
console.error("[v-d-validate] validator's key is invalid");
|
|
1932
|
+
return null;
|
|
1933
|
+
}
|
|
1934
|
+
switch (ruleName) {
|
|
1935
|
+
case "maxlength":
|
|
1936
|
+
return {
|
|
1937
|
+
type: "string",
|
|
1938
|
+
max: value,
|
|
1939
|
+
asyncValidator: (rule, val) => {
|
|
1940
|
+
return new Promise((resolve, reject) => {
|
|
1941
|
+
if (val.length > value) {
|
|
1942
|
+
reject("\u6700\u5927\u957F\u5EA6\u4E3A" + value);
|
|
1943
|
+
} else {
|
|
1944
|
+
resolve("\u6821\u9A8C\u901A\u8FC7");
|
|
1945
|
+
}
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1949
|
+
case "minlength":
|
|
1950
|
+
return {
|
|
1951
|
+
type: "string",
|
|
1952
|
+
min: value,
|
|
1953
|
+
asyncValidator: (rule, val) => {
|
|
1954
|
+
return new Promise((resolve, reject) => {
|
|
1955
|
+
if (val.length < value) {
|
|
1956
|
+
reject("\u6700\u5C0F\u957F\u5EA6\u4E3A" + value);
|
|
1957
|
+
} else {
|
|
1958
|
+
resolve("\u6821\u9A8C\u901A\u8FC7");
|
|
1959
|
+
}
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
};
|
|
1963
|
+
case "min":
|
|
1964
|
+
return {
|
|
1965
|
+
type: "number",
|
|
1966
|
+
asyncValidator: (rule, val) => {
|
|
1967
|
+
return new Promise((resolve, reject) => {
|
|
1968
|
+
if (val < value) {
|
|
1969
|
+
reject("\u6700\u5C0F\u503C\u4E3A" + value);
|
|
1970
|
+
} else {
|
|
1971
|
+
resolve("\u6821\u9A8C\u901A\u8FC7");
|
|
1972
|
+
}
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
};
|
|
1976
|
+
case "max":
|
|
1977
|
+
return {
|
|
1978
|
+
type: "number",
|
|
1979
|
+
asyncValidator: (rule, val) => {
|
|
1980
|
+
return new Promise((resolve, reject) => {
|
|
1981
|
+
if (val > value) {
|
|
1982
|
+
reject("\u6700\u5927\u503C\u4E3A" + value);
|
|
1983
|
+
} else {
|
|
1984
|
+
resolve("\u6821\u9A8C\u901A\u8FC7");
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
};
|
|
1989
|
+
case "required":
|
|
1990
|
+
return {
|
|
1991
|
+
reqiured: true,
|
|
1992
|
+
asyncValidator: (rule, val) => {
|
|
1993
|
+
return new Promise((resolve, reject) => {
|
|
1994
|
+
if (!val) {
|
|
1995
|
+
reject("\u5FC5\u586B\u9879");
|
|
1996
|
+
} else {
|
|
1997
|
+
resolve("\u6821\u9A8C\u901A\u8FC7");
|
|
1998
|
+
}
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
case "requiredTrue":
|
|
2003
|
+
return {
|
|
2004
|
+
asyncValidator: (rule, val) => {
|
|
2005
|
+
return new Promise((resolve, reject) => {
|
|
2006
|
+
if (!val) {
|
|
2007
|
+
reject("\u5FC5\u987B\u4E3Atrue\u503C");
|
|
2008
|
+
} else {
|
|
2009
|
+
resolve("\u6821\u9A8C\u901A\u8FC7");
|
|
2010
|
+
}
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
};
|
|
2014
|
+
case "email":
|
|
2015
|
+
return {
|
|
2016
|
+
type: "email",
|
|
2017
|
+
message: "\u90AE\u7BB1\u683C\u5F0F\u4E0D\u6B63\u786E"
|
|
2018
|
+
};
|
|
2019
|
+
case "pattern":
|
|
2020
|
+
return {
|
|
2021
|
+
type: "regexp",
|
|
2022
|
+
pattern: value,
|
|
2023
|
+
message: "\u53EA\u80FD\u5305\u542B\u6570\u5B57\u4E0E\u5927\u5C0F\u5199\u5B57\u7B26",
|
|
2024
|
+
validator: (rule, val) => value.test(val)
|
|
2025
|
+
};
|
|
2026
|
+
case "whitespace":
|
|
2027
|
+
return {
|
|
2028
|
+
message: "\u8F93\u5165\u4E0D\u80FD\u5168\u90E8\u4E3A\u7A7A\u683C\u6216\u7A7A\u5B57\u7B26",
|
|
2029
|
+
validator: (rule, val) => !!val.trim()
|
|
2030
|
+
};
|
|
2031
|
+
default:
|
|
2032
|
+
return {
|
|
2033
|
+
[ruleName]: value
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
function getKeyValueOfObjectList(obj) {
|
|
2038
|
+
const kvArr = [];
|
|
2039
|
+
for (const key in obj) {
|
|
2040
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
2041
|
+
kvArr.push({
|
|
2042
|
+
key,
|
|
2043
|
+
value: obj[key]
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
return kvArr;
|
|
2048
|
+
}
|
|
2049
|
+
function handleErrorStrategy(el) {
|
|
2050
|
+
const classList = [...el.classList];
|
|
2051
|
+
classList.push("d-validate-rules-error-pristine");
|
|
2052
|
+
el.setAttribute("class", classList.join(" "));
|
|
2053
|
+
}
|
|
2054
|
+
function handleErrorStrategyPass(el) {
|
|
2055
|
+
const classList = [...el.classList];
|
|
2056
|
+
const index2 = classList.indexOf("d-validate-rules-error-pristine");
|
|
2057
|
+
index2 !== -1 && classList.splice(index2, 1);
|
|
2058
|
+
el.setAttribute("class", classList.join(" "));
|
|
2059
|
+
}
|
|
2060
|
+
function handleValidateError({ el, tipEl, message, isFormTag, messageShowType, dfcUID, popPosition = "right-bottom" }) {
|
|
2061
|
+
if (isFormTag && messageShowType === MessageShowTypeEnum.toast) {
|
|
2062
|
+
alert(message);
|
|
2063
|
+
return;
|
|
2064
|
+
}
|
|
2065
|
+
if (MessageShowTypeEnum.popover === messageShowType) {
|
|
2066
|
+
EventBus.emit("showPopoverErrorMessage", { showPopover: true, message, uid: dfcUID, popPosition });
|
|
2067
|
+
return;
|
|
2068
|
+
}
|
|
2069
|
+
tipEl.innerText = "" + message;
|
|
2070
|
+
tipEl.style.display = "inline-flex";
|
|
2071
|
+
tipEl.setAttribute("class", "d-validate-tip");
|
|
2072
|
+
handleErrorStrategy(el);
|
|
2073
|
+
}
|
|
2074
|
+
function handleValidatePass(el, tipEl) {
|
|
2075
|
+
tipEl.style.display = "none";
|
|
2076
|
+
handleErrorStrategyPass(el);
|
|
2077
|
+
}
|
|
2078
|
+
function getRefName(binding) {
|
|
2079
|
+
const _refs = binding.instance.$refs;
|
|
2080
|
+
const refName = Object.keys(_refs)[0];
|
|
2081
|
+
return refName;
|
|
2082
|
+
}
|
|
2083
|
+
function getFormName(binding) {
|
|
2084
|
+
const _refs = binding.instance.$refs;
|
|
2085
|
+
const key = Object.keys(_refs)[0];
|
|
2086
|
+
return _refs[key]["name"];
|
|
2087
|
+
}
|
|
2088
|
+
function validateFn({ validator, modelValue, el, tipEl, isFormTag, messageShowType, dfcUID, popPosition }) {
|
|
2089
|
+
validator.validate({ modelName: modelValue }).then(() => {
|
|
2090
|
+
handleValidatePass(el, tipEl);
|
|
2091
|
+
}).catch((err) => {
|
|
2092
|
+
const { errors } = err;
|
|
2093
|
+
if (!errors || errors.length === 0)
|
|
2094
|
+
return;
|
|
2095
|
+
let msg = "";
|
|
2096
|
+
if (typeof errors[0].message === "object") {
|
|
2097
|
+
msg = errors[0].message.default;
|
|
2098
|
+
} else {
|
|
2099
|
+
msg = errors[0].message;
|
|
2100
|
+
}
|
|
2101
|
+
handleValidateError({ el, tipEl, message: msg, isFormTag, messageShowType, dfcUID, popPosition });
|
|
2102
|
+
});
|
|
2103
|
+
}
|
|
2104
|
+
function checkValidPopsition(positionStr) {
|
|
2105
|
+
const validPosition = ["left", "right", "top", "bottom", "left-top", "left-bottom", "top-left", "top-right", "right-top", "right-bottom", "bottom-left", "bottom-right"];
|
|
2106
|
+
const isValid = validPosition.includes(positionStr);
|
|
2107
|
+
!isValid && console.warn(`invalid popPosition value '${positionStr}'.`);
|
|
2108
|
+
return isValid;
|
|
2109
|
+
}
|
|
2110
|
+
var dValidateRules = {
|
|
2111
|
+
mounted(el, binding, vnode) {
|
|
2112
|
+
var _a;
|
|
2113
|
+
const isFormTag = el.tagName === "FORM";
|
|
2114
|
+
const dfcUID = el.parentNode.parentNode.parentElement.dataset.uid;
|
|
2115
|
+
const refName = getRefName(binding);
|
|
2116
|
+
const hasOptions = isObject$1(binding.value) && hasKey(binding.value, "options");
|
|
2117
|
+
let {
|
|
2118
|
+
rules: bindingRules,
|
|
2119
|
+
options = {},
|
|
2120
|
+
messageShowType = MessageShowTypeEnum.popover
|
|
2121
|
+
} = binding.value;
|
|
2122
|
+
let { errorStrategy } = binding.value;
|
|
2123
|
+
if (refName) {
|
|
2124
|
+
messageShowType = (_a = binding.instance[refName]["messageShowType"]) != null ? _a : "popover";
|
|
2125
|
+
}
|
|
2126
|
+
let {
|
|
2127
|
+
updateOn = UpdateOnEnum.change,
|
|
2128
|
+
errorStrategy: ErrorStrategy = ErrorStrategyEnum.dirty,
|
|
2129
|
+
asyncDebounceTime = 300,
|
|
2130
|
+
popPosition = ["right", "bottom"]
|
|
2131
|
+
} = options;
|
|
2132
|
+
if (messageShowType === MessageShowTypeEnum.popover) {
|
|
2133
|
+
if (Array.isArray(popPosition)) {
|
|
2134
|
+
popPosition = popPosition.length > 1 ? popPosition.join("-") : popPosition[0];
|
|
2135
|
+
if (!checkValidPopsition(popPosition)) {
|
|
2136
|
+
popPosition = "right-bottom";
|
|
2137
|
+
}
|
|
2138
|
+
} else if (!checkValidPopsition(popPosition)) {
|
|
2139
|
+
popPosition = "right-bottom";
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
if (!errorStrategy) {
|
|
2143
|
+
errorStrategy = ErrorStrategy;
|
|
2144
|
+
}
|
|
2145
|
+
let customRule = {};
|
|
2146
|
+
if (hasOptions) {
|
|
2147
|
+
customRule = bindingRules != null ? bindingRules : binding.value;
|
|
2148
|
+
} else {
|
|
2149
|
+
customRule = binding.value;
|
|
2150
|
+
}
|
|
2151
|
+
const isCustomValidator = customRule && isObject$1(customRule) && (hasKey(customRule, "validators") || hasKey(customRule, "asyncValidators"));
|
|
2152
|
+
const rules2 = Array.isArray(customRule) ? customRule : [customRule];
|
|
2153
|
+
const tipEl = document.createElement("span");
|
|
2154
|
+
if (messageShowType !== MessageShowTypeEnum.none) {
|
|
2155
|
+
el.parentNode.append(tipEl);
|
|
2156
|
+
}
|
|
2157
|
+
const descriptor = {
|
|
2158
|
+
modelName: []
|
|
2159
|
+
};
|
|
2160
|
+
rules2.forEach((rule) => {
|
|
2161
|
+
const kvObjList = !Array.isArray(rule) && getKeyValueOfObjectList(rule);
|
|
2162
|
+
let ruleObj = {};
|
|
2163
|
+
let avaliableRuleObj = {};
|
|
2164
|
+
kvObjList.forEach((item) => {
|
|
2165
|
+
avaliableRuleObj = getAvaliableRuleObj(item.key, item.value);
|
|
2166
|
+
ruleObj = __spreadValues(__spreadValues({}, ruleObj), avaliableRuleObj);
|
|
2167
|
+
});
|
|
2168
|
+
descriptor.modelName.push(ruleObj);
|
|
2169
|
+
});
|
|
2170
|
+
if (isCustomValidator) {
|
|
2171
|
+
const { validators: validators2, asyncValidators } = customRule;
|
|
2172
|
+
validators2 && validators2.forEach((item) => {
|
|
2173
|
+
const ruleObj = {
|
|
2174
|
+
message: (item == null ? void 0 : item.message) || "",
|
|
2175
|
+
validator: (rule, value) => item.validator(rule, value)
|
|
2176
|
+
};
|
|
2177
|
+
descriptor.modelName.push(ruleObj);
|
|
2178
|
+
});
|
|
2179
|
+
asyncValidators && asyncValidators.forEach((item) => {
|
|
2180
|
+
const ruleObj = {
|
|
2181
|
+
message: (item == null ? void 0 : item.message) || "",
|
|
2182
|
+
asyncValidator: (rule, value) => {
|
|
2183
|
+
return new Promise(debounce((resolve, reject) => {
|
|
2184
|
+
const res = item.asyncValidator(rule, value);
|
|
2185
|
+
if (res) {
|
|
2186
|
+
resolve("");
|
|
2187
|
+
} else {
|
|
2188
|
+
reject(rule.message);
|
|
2189
|
+
}
|
|
2190
|
+
}, asyncDebounceTime));
|
|
2191
|
+
}
|
|
2192
|
+
};
|
|
2193
|
+
descriptor.modelName.push(ruleObj);
|
|
2194
|
+
});
|
|
2195
|
+
}
|
|
2196
|
+
const validator = new Schema(descriptor);
|
|
2197
|
+
const htmlEventValidateHandler = (e) => {
|
|
2198
|
+
const modelValue = e.target.value;
|
|
2199
|
+
if (messageShowType === MessageShowTypeEnum.popover) {
|
|
2200
|
+
EventBus.emit("showPopoverErrorMessage", { showPopover: false, message: "", uid: dfcUID, popPosition });
|
|
2201
|
+
}
|
|
2202
|
+
validateFn({ validator, modelValue, el, tipEl, isFormTag: false, messageShowType, dfcUID, popPosition });
|
|
2203
|
+
};
|
|
2204
|
+
vnode.children[0].el.addEventListener(updateOn, htmlEventValidateHandler);
|
|
2205
|
+
if (errorStrategy === ErrorStrategyEnum.pristine) {
|
|
2206
|
+
handleErrorStrategy(el);
|
|
2207
|
+
vnode.children[0].props.value = "" + vnode.children[0].props.value;
|
|
2208
|
+
}
|
|
2209
|
+
const formName = getFormName(binding);
|
|
2210
|
+
formName && EventBus.on(`formSubmit:${formName}`, () => {
|
|
2211
|
+
const modelValue = isFormTag ? "" : vnode.children[0].el.value;
|
|
2212
|
+
validateFn({ validator, modelValue, el, tipEl, isFormTag, messageShowType });
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
};
|
|
2216
|
+
Form.install = function(app) {
|
|
2217
|
+
app.component(Form.name, Form);
|
|
2218
|
+
app.directive("d-validate-rules", dValidateRules);
|
|
2219
|
+
};
|
|
2220
|
+
FormLabel.install = function(app) {
|
|
2221
|
+
app.component(FormLabel.name, FormLabel);
|
|
2222
|
+
};
|
|
2223
|
+
FormItem.install = function(app) {
|
|
2224
|
+
app.component(FormItem.name, FormItem);
|
|
2225
|
+
};
|
|
2226
|
+
FormControl.install = function(app) {
|
|
2227
|
+
app.component(FormControl.name, FormControl);
|
|
2228
|
+
};
|
|
2229
|
+
FormOperation.install = function(app) {
|
|
2230
|
+
app.component(FormOperation.name, FormOperation);
|
|
2231
|
+
};
|
|
2232
|
+
var index = {
|
|
2233
|
+
title: "Form \u8868\u5355",
|
|
2234
|
+
category: "\u6570\u636E\u5F55\u5165",
|
|
2235
|
+
status: "75%",
|
|
2236
|
+
install(app) {
|
|
2237
|
+
app.use(Form);
|
|
2238
|
+
app.use(FormLabel);
|
|
2239
|
+
app.use(FormItem);
|
|
2240
|
+
app.use(FormControl);
|
|
2241
|
+
app.use(FormOperation);
|
|
2242
|
+
}
|
|
2243
|
+
};
|
|
2244
|
+
export { Form, FormControl, FormItem, FormLabel, FormOperation, index as default };
|