@houaoran/designer 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +98 -0
- package/dist/components.es.js +11424 -0
- package/dist/components.umd.js +878 -0
- package/dist/index.es.js +39113 -0
- package/dist/index.umd.js +1187 -0
- package/package.json +96 -0
- package/src/components/DragBox.vue +49 -0
- package/src/components/DragTool.vue +235 -0
- package/src/components/EventConfig.vue +557 -0
- package/src/components/FcDesigner.vue +2569 -0
- package/src/components/FcTitle.vue +69 -0
- package/src/components/FetchConfig.vue +415 -0
- package/src/components/FieldInput.vue +371 -0
- package/src/components/FnConfig.vue +315 -0
- package/src/components/FnEditor.vue +327 -0
- package/src/components/FnInput.vue +103 -0
- package/src/components/FormLabel.vue +47 -0
- package/src/components/HtmlEditor.vue +125 -0
- package/src/components/JsonPreview.vue +146 -0
- package/src/components/OptionsTextInput.vue +151 -0
- package/src/components/PropsInput.vue +72 -0
- package/src/components/Required.vue +75 -0
- package/src/components/Row.vue +26 -0
- package/src/components/SignaturePad.vue +176 -0
- package/src/components/Struct.vue +153 -0
- package/src/components/StructEditor.vue +121 -0
- package/src/components/StructTree.vue +209 -0
- package/src/components/TableOptions.vue +164 -0
- package/src/components/TreeOptions.vue +167 -0
- package/src/components/TypeSelect.vue +144 -0
- package/src/components/Validate.vue +302 -0
- package/src/components/ValueInput.vue +89 -0
- package/src/components/Warning.vue +46 -0
- package/src/components/ai/AiPanel.vue +1122 -0
- package/src/components/ai/MarkdownRenderer.vue +548 -0
- package/src/components/language/LanguageConfig.vue +174 -0
- package/src/components/language/LanguageInput.vue +191 -0
- package/src/components/style/BackgroundInput.vue +315 -0
- package/src/components/style/BorderInput.vue +242 -0
- package/src/components/style/BoxSizeInput.vue +166 -0
- package/src/components/style/BoxSpaceInput.vue +269 -0
- package/src/components/style/ColorInput.vue +90 -0
- package/src/components/style/ConfigItem.vue +118 -0
- package/src/components/style/FontInput.vue +197 -0
- package/src/components/style/PositionInput.vue +146 -0
- package/src/components/style/RadiusInput.vue +164 -0
- package/src/components/style/ShadowContent.vue +335 -0
- package/src/components/style/ShadowInput.vue +91 -0
- package/src/components/style/SizeInput.vue +118 -0
- package/src/components/style/StyleConfig.vue +307 -0
- package/src/components/table/Table.vue +252 -0
- package/src/components/table/TableView.vue +1058 -0
- package/src/components/tableForm/TableForm.vue +471 -0
- package/src/components/tableForm/TableFormColumnView.vue +103 -0
- package/src/components/tableForm/TableFormView.vue +46 -0
- package/src/components/tree/FcTree.vue +713 -0
- package/src/components/tree/FcTreeNode.vue +216 -0
- package/src/config/base/field.js +43 -0
- package/src/config/base/form.js +132 -0
- package/src/config/base/style.js +26 -0
- package/src/config/base/validate.js +15 -0
- package/src/config/index.js +70 -0
- package/src/config/menu.js +24 -0
- package/src/config/rule/alert.js +45 -0
- package/src/config/rule/button.js +49 -0
- package/src/config/rule/card.js +40 -0
- package/src/config/rule/cascader.js +121 -0
- package/src/config/rule/checkbox.js +68 -0
- package/src/config/rule/col.js +86 -0
- package/src/config/rule/collapse.js +30 -0
- package/src/config/rule/collapseItem.js +36 -0
- package/src/config/rule/color.js +53 -0
- package/src/config/rule/date.js +66 -0
- package/src/config/rule/dateRange.js +60 -0
- package/src/config/rule/divider.js +31 -0
- package/src/config/rule/editor.js +31 -0
- package/src/config/rule/group.js +86 -0
- package/src/config/rule/html.js +43 -0
- package/src/config/rule/image.js +32 -0
- package/src/config/rule/input.js +62 -0
- package/src/config/rule/number.js +49 -0
- package/src/config/rule/password.js +52 -0
- package/src/config/rule/radio.js +43 -0
- package/src/config/rule/rate.js +44 -0
- package/src/config/rule/row.js +46 -0
- package/src/config/rule/select.js +70 -0
- package/src/config/rule/signaturePad.js +59 -0
- package/src/config/rule/slider.js +53 -0
- package/src/config/rule/space.js +44 -0
- package/src/config/rule/subForm.js +47 -0
- package/src/config/rule/switch.js +46 -0
- package/src/config/rule/tabPane.js +29 -0
- package/src/config/rule/table.js +37 -0
- package/src/config/rule/tableForm.js +115 -0
- package/src/config/rule/tableFormColumn.js +55 -0
- package/src/config/rule/tabs.js +38 -0
- package/src/config/rule/tag.js +69 -0
- package/src/config/rule/text.js +41 -0
- package/src/config/rule/textarea.js +63 -0
- package/src/config/rule/time.js +58 -0
- package/src/config/rule/timeRange.js +49 -0
- package/src/config/rule/title.js +37 -0
- package/src/config/rule/transfer.js +59 -0
- package/src/config/rule/tree.js +70 -0
- package/src/config/rule/treeSelect.js +77 -0
- package/src/config/rule/upload.js +107 -0
- package/src/form/index.js +19 -0
- package/src/index.js +173 -0
- package/src/locale/en.js +981 -0
- package/src/locale/zh-cn.js +983 -0
- package/src/style/fonts/fc-icons.woff +0 -0
- package/src/style/icon.css +1052 -0
- package/src/style/index.css +836 -0
- package/src/utils/form.js +9 -0
- package/src/utils/highlight/highlight.min.js +307 -0
- package/src/utils/highlight/javascript.min.js +80 -0
- package/src/utils/highlight/style.css +1 -0
- package/src/utils/highlight/xml.min.js +29 -0
- package/src/utils/hintStubs.js +120 -0
- package/src/utils/index.js +544 -0
- package/src/utils/jsonDiff.js +173 -0
- package/src/utils/locale.js +23 -0
- package/src/utils/message.js +19 -0
- package/src/utils/template.js +105 -0
- package/types/index.d.ts +575 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="_fd-tree-opt">
|
|
3
|
+
<el-tree
|
|
4
|
+
:data="value"
|
|
5
|
+
node-key="index"
|
|
6
|
+
:expand-on-click-node="false">
|
|
7
|
+
<template #default="{ node, data }">
|
|
8
|
+
<div class="_fd-tree-opt-node">
|
|
9
|
+
<el-input class="_fd-tree-opt-first" v-model="data[overColumns.label]" :disabled="disabled"
|
|
10
|
+
@blur="change"/>
|
|
11
|
+
<ValueInput class="_fd-tree-opt-last" v-model="data[overColumns.value]" @blur="change" :disabled="disabled"
|
|
12
|
+
@change-type="change">
|
|
13
|
+
<template #append v-if="!disabled">
|
|
14
|
+
<div class="_fd-tree-opt-btn" @click="add(node, data)">
|
|
15
|
+
<i class="fc-icon icon-add"></i>
|
|
16
|
+
</div>
|
|
17
|
+
<div class="_fd-tree-opt-btn" @click="append(data)">
|
|
18
|
+
<i class="fc-icon icon-add-child"></i>
|
|
19
|
+
</div>
|
|
20
|
+
<div class="_fd-tree-opt-btn _fd-tree-opt-danger" @click="remove(node, data)">
|
|
21
|
+
<i class="fc-icon icon-delete"></i>
|
|
22
|
+
</div>
|
|
23
|
+
</template>
|
|
24
|
+
</ValueInput>
|
|
25
|
+
</div>
|
|
26
|
+
</template>
|
|
27
|
+
</el-tree>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
</template>
|
|
31
|
+
|
|
32
|
+
<script>
|
|
33
|
+
|
|
34
|
+
import {defineComponent} from 'vue';
|
|
35
|
+
import {deepCopy} from '@form-create/utils/lib/deepextend';
|
|
36
|
+
import ValueInput from './ValueInput.vue';
|
|
37
|
+
|
|
38
|
+
export default defineComponent({
|
|
39
|
+
name: 'TreeOptions',
|
|
40
|
+
emits: ['update:modelValue'],
|
|
41
|
+
components: {
|
|
42
|
+
ValueInput
|
|
43
|
+
},
|
|
44
|
+
props: {
|
|
45
|
+
modelValue: Array,
|
|
46
|
+
columns: Object,
|
|
47
|
+
disabled: Boolean,
|
|
48
|
+
},
|
|
49
|
+
inject: ['designer'],
|
|
50
|
+
data() {
|
|
51
|
+
return {
|
|
52
|
+
value: [...deepCopy(this.modelValue || [])],
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
computed: {
|
|
56
|
+
t() {
|
|
57
|
+
return this.designer.setupState.t;
|
|
58
|
+
},
|
|
59
|
+
overColumns() {
|
|
60
|
+
if (!this.columns) {
|
|
61
|
+
return {
|
|
62
|
+
label: 'label',
|
|
63
|
+
value: 'value',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
label: this.columns.label || 'label',
|
|
68
|
+
value: this.columns.value || 'value',
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
created() {
|
|
73
|
+
if (!this.value.length) {
|
|
74
|
+
this.value = [{}]
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
methods: {
|
|
78
|
+
tidyValue() {
|
|
79
|
+
return deepCopy(this.value);
|
|
80
|
+
},
|
|
81
|
+
change() {
|
|
82
|
+
this.$emit('update:modelValue', this.tidyValue());
|
|
83
|
+
},
|
|
84
|
+
add(node) {
|
|
85
|
+
const parent = node.parent;
|
|
86
|
+
const children = parent.data.children || parent.data;
|
|
87
|
+
children.push({});
|
|
88
|
+
},
|
|
89
|
+
append(data) {
|
|
90
|
+
if (!data.children) {
|
|
91
|
+
data.children = [];
|
|
92
|
+
}
|
|
93
|
+
data.children.push({});
|
|
94
|
+
},
|
|
95
|
+
remove(node, data) {
|
|
96
|
+
const parent = node.parent;
|
|
97
|
+
if (parent.data.children) {
|
|
98
|
+
parent.data.children.splice(parent.data.children.indexOf(data), 1);
|
|
99
|
+
if (!parent.data.children.length) {
|
|
100
|
+
delete parent.data.children;
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
parent.data.splice(parent.data.indexOf(data), 1);
|
|
104
|
+
}
|
|
105
|
+
this.change();
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
</script>
|
|
110
|
+
|
|
111
|
+
<style>
|
|
112
|
+
._fd-tree-opt ._fd-tree-opt-btn {
|
|
113
|
+
height: 19px;
|
|
114
|
+
width: 18px;
|
|
115
|
+
color: #fff;
|
|
116
|
+
text-align: center;
|
|
117
|
+
line-height: 20px;
|
|
118
|
+
padding-bottom: 1px;
|
|
119
|
+
float: left;
|
|
120
|
+
cursor: pointer;
|
|
121
|
+
justify-content: center;
|
|
122
|
+
background-color: #2f73ff;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
._fd-tree-opt-node {
|
|
126
|
+
display: flex;
|
|
127
|
+
align-items: center;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
._fd-tree-opt-first {
|
|
131
|
+
width: 60px;
|
|
132
|
+
margin-right: 5px;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
._fd-tree-opt-last {
|
|
136
|
+
width: 165px;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
._fd-tree-opt-last._label {
|
|
140
|
+
width: 175px;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
._fd-tree-opt-last._label .el-input-group__append {
|
|
144
|
+
width: 65px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
._fd-tree-opt ._fd-tree-opt-danger {
|
|
148
|
+
background-color: #ff2d2e;
|
|
149
|
+
border-radius: 0 2px 2px 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
._fd-tree-opt .el-tree-node__content {
|
|
153
|
+
margin-bottom: 3px;
|
|
154
|
+
height: 28px;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
._fd-tree-opt .el-input__inner {
|
|
158
|
+
border-right: 0 none;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
._fd-tree-opt .el-input-group__append {
|
|
162
|
+
width: 90px;
|
|
163
|
+
padding-right: 2px;
|
|
164
|
+
padding-left: 1px;
|
|
165
|
+
background: #fff;
|
|
166
|
+
}
|
|
167
|
+
</style>
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-dropdown class="_fd-type-select" trigger="click" size="default" popper-class="_fd-type-select-pop"
|
|
3
|
+
:disabled="disabled || !menus.length" @command="handleCommand">
|
|
4
|
+
<el-tag type="success" effect="plain" disable-transitions>
|
|
5
|
+
<template v-if="activeRule">
|
|
6
|
+
{{ t('com.' + (activeRule._menu.name) + '.name') || activeRule._menu.label }} <i
|
|
7
|
+
class="fc-icon icon-down" v-if="!disabled && menus.length"></i>
|
|
8
|
+
</template>
|
|
9
|
+
<template v-else>
|
|
10
|
+
{{
|
|
11
|
+
t('com.' + (customForm.config.name) + '.name') || customForm.config.label || customForm.config.name
|
|
12
|
+
}}
|
|
13
|
+
</template>
|
|
14
|
+
</el-tag>
|
|
15
|
+
<template #dropdown>
|
|
16
|
+
<el-dropdown-menu>
|
|
17
|
+
<el-dropdown-item :command="item" v-for="item in menus" :key="item.name">
|
|
18
|
+
<div><i class="fc-icon" :class="item.icon || 'icon-input'"></i>{{ t('com.' + (item.name) + '.name') || item.label }}</div>
|
|
19
|
+
</el-dropdown-item>
|
|
20
|
+
</el-dropdown-menu>
|
|
21
|
+
</template>
|
|
22
|
+
</el-dropdown>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script>
|
|
26
|
+
import {defineComponent} from 'vue';
|
|
27
|
+
|
|
28
|
+
export default defineComponent({
|
|
29
|
+
name: 'TypeSelect',
|
|
30
|
+
inject: ['designer'],
|
|
31
|
+
props: {
|
|
32
|
+
disabled: Boolean,
|
|
33
|
+
},
|
|
34
|
+
computed: {
|
|
35
|
+
t() {
|
|
36
|
+
return this.designer.setupState.t;
|
|
37
|
+
},
|
|
38
|
+
activeRule() {
|
|
39
|
+
return this.designer.setupState.activeRule;
|
|
40
|
+
},
|
|
41
|
+
customForm() {
|
|
42
|
+
return this.designer.setupState.customForm;
|
|
43
|
+
},
|
|
44
|
+
menus() {
|
|
45
|
+
let menus = [];
|
|
46
|
+
const designer = this.designer.setupState;
|
|
47
|
+
if (this.activeRule) {
|
|
48
|
+
const name = this.activeRule._menu.name;
|
|
49
|
+
const switchConfig = designer.getConfig('switchType', []);
|
|
50
|
+
if (switchConfig === false) {
|
|
51
|
+
return menus;
|
|
52
|
+
}
|
|
53
|
+
let switchs = [];
|
|
54
|
+
switchConfig.forEach(lst => {
|
|
55
|
+
if (lst.indexOf(name) > -1) {
|
|
56
|
+
switchs.push(...lst);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
switchs = switchs.filter((key, idx) => {
|
|
60
|
+
return key !== name && switchs.indexOf(key) === idx;
|
|
61
|
+
});
|
|
62
|
+
if (switchs.length) {
|
|
63
|
+
designer.menuList.forEach(item => {
|
|
64
|
+
item.list.forEach(menu => {
|
|
65
|
+
if (switchs.indexOf(menu.name) > -1) {
|
|
66
|
+
menus.push(menu);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
designer.menuList.forEach(item => {
|
|
72
|
+
if (item.name === this.activeRule._menu.menu) {
|
|
73
|
+
item.list.forEach(menu => {
|
|
74
|
+
if (menu.name !== name) {
|
|
75
|
+
menus.push(menu);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return menus.filter(menu => this.designer.setupState.hiddenItem.indexOf(menu.name) === -1);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
methods: {
|
|
86
|
+
handleCommand(item) {
|
|
87
|
+
let activeRule = this.activeRule;
|
|
88
|
+
let rule = this.activeRule;
|
|
89
|
+
if (!rule._menu.inside) {
|
|
90
|
+
rule = rule.__fc__.parent.rule;
|
|
91
|
+
}
|
|
92
|
+
const children = rule.__fc__.parent.rule.children;
|
|
93
|
+
const replaceRule = this.designer.setupState.makeRule(item);
|
|
94
|
+
let newRule = replaceRule;
|
|
95
|
+
if (replaceRule.type === 'DragTool') {
|
|
96
|
+
newRule = replaceRule.children[0];
|
|
97
|
+
}
|
|
98
|
+
if (newRule.field && activeRule.field) {
|
|
99
|
+
['title', 'info', 'field', 'validate', 'control', '$required'].forEach(k => {
|
|
100
|
+
newRule[k] = activeRule[k];
|
|
101
|
+
});
|
|
102
|
+
} else if (activeRule?.computed?.hidden) {
|
|
103
|
+
newRule.computed = {hidden: activeRule.computed.hidden}
|
|
104
|
+
}
|
|
105
|
+
if (activeRule.name) {
|
|
106
|
+
newRule.name = activeRule.name;
|
|
107
|
+
}
|
|
108
|
+
['name', 'id', 'on'].forEach(k => {
|
|
109
|
+
if (activeRule[k]) {
|
|
110
|
+
newRule[k] = activeRule[k];
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
children.splice(children.indexOf(rule), 1, replaceRule);
|
|
114
|
+
this.$nextTick(() => {
|
|
115
|
+
this.designer.setupState.updateTree();
|
|
116
|
+
this.designer.setupState.triggerActive(newRule);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
</script>
|
|
122
|
+
|
|
123
|
+
<style>
|
|
124
|
+
._fd-type-select {
|
|
125
|
+
cursor: pointer;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
._fd-type-select.is-disabled {
|
|
129
|
+
cursor: default;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
._fd-type-select .fc-icon {
|
|
133
|
+
font-size: 14px;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
._fd-type-select-pop {
|
|
137
|
+
max-height: 500px;
|
|
138
|
+
overflow: auto;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
._fd-type-select-pop .fc-icon {
|
|
142
|
+
font-size: 14px;
|
|
143
|
+
}
|
|
144
|
+
</style>
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="_fd-validate">
|
|
3
|
+
<template v-for="(item, idx) in validate">
|
|
4
|
+
<div class="_fd-validate-item">
|
|
5
|
+
<div class="_fd-validate-title">
|
|
6
|
+
<div>
|
|
7
|
+
<span>{{ idx + 1 }}</span>
|
|
8
|
+
{{ modes[item.mode] }}
|
|
9
|
+
</div>
|
|
10
|
+
<i class="fc-icon icon-delete-circle" @click="remove(idx)"></i>
|
|
11
|
+
</div>
|
|
12
|
+
<el-row>
|
|
13
|
+
<el-col :span="getSpan(item)">
|
|
14
|
+
<el-form-item :label="t('validate.mode')">
|
|
15
|
+
<el-select v-model="item.trigger" @change="onInput">
|
|
16
|
+
<el-option v-for="item in triggers" :key="item.value" :label="item.label" :value="item.value" />
|
|
17
|
+
</el-select>
|
|
18
|
+
</el-form-item>
|
|
19
|
+
</el-col>
|
|
20
|
+
<el-col
|
|
21
|
+
:span="getSpan(item)"
|
|
22
|
+
v-if="
|
|
23
|
+
[
|
|
24
|
+
'required',
|
|
25
|
+
'uppercase',
|
|
26
|
+
'lowercase',
|
|
27
|
+
'email',
|
|
28
|
+
'url',
|
|
29
|
+
'ip',
|
|
30
|
+
'phone',
|
|
31
|
+
'positive',
|
|
32
|
+
'negative',
|
|
33
|
+
'integer',
|
|
34
|
+
'number',
|
|
35
|
+
].indexOf(item.mode) === -1
|
|
36
|
+
"
|
|
37
|
+
>
|
|
38
|
+
<el-form-item :label="modes[item.mode]">
|
|
39
|
+
<template v-if="item.mode === 'pattern'">
|
|
40
|
+
<elInput v-model="item[item.mode]" @change="onInput"></elInput>
|
|
41
|
+
</template>
|
|
42
|
+
<template v-else-if="item.mode === 'validator'">
|
|
43
|
+
<FnInput
|
|
44
|
+
v-model="item[item.mode]"
|
|
45
|
+
name="validator"
|
|
46
|
+
:args="item.adapter ? ['value', 'callback'] : ['rule', 'value', 'callback']"
|
|
47
|
+
@change="onInput"
|
|
48
|
+
>{{ t('validate.modes.validator') }}
|
|
49
|
+
</FnInput>
|
|
50
|
+
</template>
|
|
51
|
+
<template v-else>
|
|
52
|
+
<el-input-number v-model="item[item.mode]" @change="onInput"></el-input-number>
|
|
53
|
+
</template>
|
|
54
|
+
</el-form-item>
|
|
55
|
+
</el-col>
|
|
56
|
+
<el-col :span="24">
|
|
57
|
+
<el-form-item :label="t('validate.message')">
|
|
58
|
+
<LanguageInput v-model="item.message" :placeholder="t('validate.requiredPlaceholder')" @change="onInput">
|
|
59
|
+
</LanguageInput>
|
|
60
|
+
</el-form-item>
|
|
61
|
+
</el-col>
|
|
62
|
+
</el-row>
|
|
63
|
+
</div>
|
|
64
|
+
</template>
|
|
65
|
+
|
|
66
|
+
<el-dropdown trigger="click" size="default" popper-class="_fd-validate-pop" @command="handleCommand">
|
|
67
|
+
<el-button class="_fd-validate-btn" plain size="small">{{ t('validate.rule') }} + </el-button>
|
|
68
|
+
<template #dropdown>
|
|
69
|
+
<el-dropdown-menu>
|
|
70
|
+
<el-dropdown-item :command="value" v-for="(label, value) in modes" :key="value">
|
|
71
|
+
<div>{{ label }}</div>
|
|
72
|
+
</el-dropdown-item>
|
|
73
|
+
</el-dropdown-menu>
|
|
74
|
+
</template>
|
|
75
|
+
</el-dropdown>
|
|
76
|
+
</div>
|
|
77
|
+
</template>
|
|
78
|
+
|
|
79
|
+
<script>
|
|
80
|
+
import {defineComponent} from 'vue';
|
|
81
|
+
import {localeOptions} from '../utils';
|
|
82
|
+
import FnInput from './FnInput.vue';
|
|
83
|
+
import {deepCopy} from '@form-create/utils/lib/deepextend';
|
|
84
|
+
import LanguageInput from './language/LanguageInput.vue';
|
|
85
|
+
|
|
86
|
+
export default defineComponent({
|
|
87
|
+
name: 'Validate',
|
|
88
|
+
inject: ['designer'],
|
|
89
|
+
emits: ['update:modelValue'],
|
|
90
|
+
props: {
|
|
91
|
+
modelValue: Array,
|
|
92
|
+
},
|
|
93
|
+
components: {
|
|
94
|
+
LanguageInput,
|
|
95
|
+
FnInput,
|
|
96
|
+
},
|
|
97
|
+
watch: {
|
|
98
|
+
modelValue(n) {
|
|
99
|
+
this.validate = this.parseValue(n || []);
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
data() {
|
|
103
|
+
return {
|
|
104
|
+
validate: this.parseValue(this.modelValue || []),
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
computed: {
|
|
108
|
+
t() {
|
|
109
|
+
return this.designer.setupState.t;
|
|
110
|
+
},
|
|
111
|
+
modes() {
|
|
112
|
+
const activeRule = this.designer.setupState.activeRule;
|
|
113
|
+
if (activeRule && activeRule._menu.subForm === 'object') {
|
|
114
|
+
return {
|
|
115
|
+
validator: this.t('validate.modes.validator'),
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
return {
|
|
119
|
+
len: this.t('validate.modes.len'),
|
|
120
|
+
maxLen: this.t('validate.modes.maxLen'),
|
|
121
|
+
minLen: this.t('validate.modes.minLen'),
|
|
122
|
+
pattern: this.t('validate.modes.pattern'),
|
|
123
|
+
uppercase: this.t('validate.modes.uppercase'),
|
|
124
|
+
lowercase: this.t('validate.modes.lowercase'),
|
|
125
|
+
email: this.t('validate.modes.email'),
|
|
126
|
+
url: this.t('validate.modes.url'),
|
|
127
|
+
ip: this.t('validate.modes.ip'),
|
|
128
|
+
phone: this.t('validate.modes.phone'),
|
|
129
|
+
min: this.t('validate.modes.min'),
|
|
130
|
+
max: this.t('validate.modes.max'),
|
|
131
|
+
positive: this.t('validate.modes.positive'),
|
|
132
|
+
negative: this.t('validate.modes.negative'),
|
|
133
|
+
integer: this.t('validate.modes.integer'),
|
|
134
|
+
number: this.t('validate.modes.number'),
|
|
135
|
+
validator: this.t('validate.modes.validator'),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
triggers() {
|
|
140
|
+
return localeOptions(this.t, [
|
|
141
|
+
{label: 'blur', value: 'blur'},
|
|
142
|
+
{label: 'change', value: 'change'},
|
|
143
|
+
{label: 'submit', value: 'submit'},
|
|
144
|
+
]);
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
methods: {
|
|
148
|
+
handleCommand(mode) {
|
|
149
|
+
const newItem = {
|
|
150
|
+
mode,
|
|
151
|
+
trigger: 'blur',
|
|
152
|
+
adapter: true,
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// 为不同类型的验证规则设置默认值
|
|
156
|
+
if (['uppercase', 'lowercase', 'email', 'url', 'ip', 'phone', 'positive', 'negative', 'integer', 'number'].includes(mode)) {
|
|
157
|
+
newItem[mode] = true;
|
|
158
|
+
} else if (['min', 'max', 'len', 'minLen', 'maxLen'].includes(mode)) {
|
|
159
|
+
newItem[mode] = 0;
|
|
160
|
+
} else if (mode === 'pattern') {
|
|
161
|
+
newItem[mode] = '';
|
|
162
|
+
}
|
|
163
|
+
this.validate.push(newItem);
|
|
164
|
+
this.onInput();
|
|
165
|
+
},
|
|
166
|
+
autoMessage(item) {
|
|
167
|
+
const title = this.designer.setupState.activeRule.title;
|
|
168
|
+
if (this.designer.setupState.activeRule) {
|
|
169
|
+
item.message = this.t('validate.autoRequired', {title});
|
|
170
|
+
this.onInput();
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
getSpan(item) {
|
|
174
|
+
return [
|
|
175
|
+
'pattern',
|
|
176
|
+
'validator',
|
|
177
|
+
'required',
|
|
178
|
+
'uppercase',
|
|
179
|
+
'lowercase',
|
|
180
|
+
'email',
|
|
181
|
+
'url',
|
|
182
|
+
'ip',
|
|
183
|
+
'phone',
|
|
184
|
+
'positive',
|
|
185
|
+
'negative',
|
|
186
|
+
'integer',
|
|
187
|
+
'number',
|
|
188
|
+
].indexOf(item.mode) > -1
|
|
189
|
+
? 24
|
|
190
|
+
: 12;
|
|
191
|
+
},
|
|
192
|
+
onInput: function () {
|
|
193
|
+
this.$emit(
|
|
194
|
+
'update:modelValue',
|
|
195
|
+
this.validate.map(item => {
|
|
196
|
+
item = {...item};
|
|
197
|
+
if (!item.message) {
|
|
198
|
+
delete item.message;
|
|
199
|
+
}
|
|
200
|
+
return item;
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
},
|
|
204
|
+
remove(idx) {
|
|
205
|
+
this.validate.splice(idx, 1);
|
|
206
|
+
this.onInput();
|
|
207
|
+
},
|
|
208
|
+
parseValue(val) {
|
|
209
|
+
return deepCopy(
|
|
210
|
+
val.map(v => {
|
|
211
|
+
if (v.validator) {
|
|
212
|
+
v.mode = 'validator';
|
|
213
|
+
}
|
|
214
|
+
if (!v.mode) {
|
|
215
|
+
Object.keys(v).forEach(k => {
|
|
216
|
+
if (['message', 'type', 'trigger', 'mode'].indexOf(k) < 0) {
|
|
217
|
+
v.mode = k;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return v;
|
|
222
|
+
})
|
|
223
|
+
);
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
</script>
|
|
228
|
+
|
|
229
|
+
<style>
|
|
230
|
+
._fd-validate {
|
|
231
|
+
display: flex;
|
|
232
|
+
flex-direction: column;
|
|
233
|
+
width: 100%;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
._fd-validate-btn {
|
|
237
|
+
font-weight: 400;
|
|
238
|
+
width: 100%;
|
|
239
|
+
border-color: #2E73FF;
|
|
240
|
+
color: #2E73FF;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
._fd-validate-pop .el-dropdown-menu__item {
|
|
244
|
+
width: 248px;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
._fd-validate-item {
|
|
248
|
+
border-bottom: 1px dashed #ECECEC;
|
|
249
|
+
margin-bottom: 10px;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
._fd-validate-item .el-col-12:first-child {
|
|
253
|
+
padding-right: 5px;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
._fd-validate-item .el-col-12 + .el-col-12 {
|
|
257
|
+
padding-left: 5px;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
._fd-validate-item .el-input-number {
|
|
261
|
+
width: 100%;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
._fd-validate-title {
|
|
265
|
+
display: flex;
|
|
266
|
+
flex-direction: row;
|
|
267
|
+
justify-content: space-between;
|
|
268
|
+
margin-bottom: 10px;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
._fd-validate-title > div {
|
|
272
|
+
display: flex;
|
|
273
|
+
align-items: center;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
._fd-validate-title > div > span {
|
|
277
|
+
width: 16px;
|
|
278
|
+
height: 16px;
|
|
279
|
+
background: #ECECEC;
|
|
280
|
+
text-align: center;
|
|
281
|
+
font-size: 12px;
|
|
282
|
+
line-height: 16px;
|
|
283
|
+
border-radius: 15px;
|
|
284
|
+
margin-right: 5px;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
._fd-validate-title i {
|
|
288
|
+
cursor: pointer;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
._fd-validate-title i:hover {
|
|
292
|
+
color: #FF2E2E;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
._fd-validate .append-msg {
|
|
296
|
+
cursor: pointer;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
._fd-validate .el-input-group__append {
|
|
300
|
+
padding: 0 10px;
|
|
301
|
+
}
|
|
302
|
+
</style>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-input class="_fd-value-input" :disabled="disabled" v-model="value" @blur="onBlur" @keydown.enter="updateValue(value)" v-bind="$attrs">
|
|
3
|
+
<template #prepend>
|
|
4
|
+
<el-select v-model="type" style="width: 60px" :disabled="disabled">
|
|
5
|
+
<el-option :label="t('validate.types.string')" value="1"/>
|
|
6
|
+
<el-option :label="t('validate.types.number')" value="2"/>
|
|
7
|
+
<el-option :label="t('validate.types.boolean')" value="3"/>
|
|
8
|
+
</el-select>
|
|
9
|
+
</template>
|
|
10
|
+
<template #append v-if="$slots.append">
|
|
11
|
+
<slot name="append"></slot>
|
|
12
|
+
</template>
|
|
13
|
+
</el-input>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script>
|
|
17
|
+
import {defineComponent} from 'vue';
|
|
18
|
+
|
|
19
|
+
export default defineComponent({
|
|
20
|
+
name: 'ValueInput',
|
|
21
|
+
emits: ['update:modelValue', 'change', 'change-type', 'blur'],
|
|
22
|
+
inject: ['designer'],
|
|
23
|
+
props: {
|
|
24
|
+
modelValue: [String, Number, Boolean],
|
|
25
|
+
disabled: Boolean,
|
|
26
|
+
},
|
|
27
|
+
data() {
|
|
28
|
+
return {
|
|
29
|
+
type: '1',
|
|
30
|
+
value: '',
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
computed: {
|
|
34
|
+
t() {
|
|
35
|
+
return this.designer.setupState.t;
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
watch: {
|
|
39
|
+
modelValue: {
|
|
40
|
+
handler: function (val) {
|
|
41
|
+
if (typeof val === 'number') {
|
|
42
|
+
this.type = '2';
|
|
43
|
+
} else if (typeof val === 'boolean') {
|
|
44
|
+
this.type = '3';
|
|
45
|
+
} else {
|
|
46
|
+
this.type = '1';
|
|
47
|
+
}
|
|
48
|
+
this.value = null == val ? '' : ('' + val);
|
|
49
|
+
},
|
|
50
|
+
immediate: true,
|
|
51
|
+
},
|
|
52
|
+
type() {
|
|
53
|
+
this.updateValue(this.value);
|
|
54
|
+
this.$emit('change-type', this.type);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
methods: {
|
|
58
|
+
onBlur(...args) {
|
|
59
|
+
if (this.value !== this.toValue(this.modelValue)) {
|
|
60
|
+
this.updateValue(this.value);
|
|
61
|
+
}
|
|
62
|
+
this.$emit('blur', ...args);
|
|
63
|
+
},
|
|
64
|
+
updateValue(val) {
|
|
65
|
+
const value = this.toValue(val);
|
|
66
|
+
this.$emit('update:modelValue', value);
|
|
67
|
+
this.$emit('change', value);
|
|
68
|
+
},
|
|
69
|
+
toValue(val) {
|
|
70
|
+
if (this.type === '1') {
|
|
71
|
+
return '' + val;
|
|
72
|
+
} else if (this.type === '2') {
|
|
73
|
+
return parseFloat(val) || 0;
|
|
74
|
+
}
|
|
75
|
+
return val === 'true';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<style>
|
|
82
|
+
._fd-value-input .el-input__validateIcon {
|
|
83
|
+
display: none;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
._fd-value-input .el-select, ._fd-value-input .el-select__wrapper {
|
|
87
|
+
height: 100%;
|
|
88
|
+
}
|
|
89
|
+
</style>
|