1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
| <template>
| <div class="container" style="padding: 15px 30px 20px 0px">
| <VolHeader icon="el-icon-warning-outline" text="表单配置" style="margin: 0 0 20px 50px">
| <template #content>
| <div style="color: #909090; font-size: 13px">
| 表单集成了element多种组件,只需要简单配置,功能包括:表单只读、自定义验证、非空验证、下拉框自动绑定、render动态渲染等.<a href="http://www.volcore.xyz/document/api"
| target="_blank">查看文档
| </a>
| </div>
| </template>
| </VolHeader>
| <VolForm ref="myform" :loadKey="loadKey" :formFields="formFields" :formRules="formRules">
| <div style="text-align: center; margin-top: -30px">
| <el-button type="primary" size="small" @click="getForm">获取表单</el-button>
| <el-button type="success" size="small" @click="reset">重置表单</el-button>
| <el-button type="info" size="small" @click="setReadonlyStaus(true)">全部只读</el-button>
| <el-button type="waring" size="small" @click="setReadonlyStaus(false)">取消只读</el-button>
| </div>
| </VolForm>
| </div>
| </template>
| <script>
| import VolForm from "@/components/basic/VolForm.vue";
| import VolHeader from "@/components/basic/VolHeader.vue";
| export default {
| props: {
| showBtn: { type: Boolean, default: true },
| },
| components: {
| VolForm,
| VolHeader,
| },
| methods: {
| setReadonlyStaus(status) {
| this.formRules.forEach((rules) => {
| rules.forEach((option) => {
| option.readonly = status;
| });
| });
| },
| getForm() {
| this.$refs.myform.validate(() => {
| this.$message.error(JSON.stringify(this.formFields));
| })
| },
| reset() {
| //重置表单,重置时可指定重置的值,如果没有指定重置的值,默认全部清空
| let data = { Variety: "1", AvgPrice: 888 };
| this.$refs.myform.reset(data);
| this.$message.error("表单已重置");
| },
| popover() {
| this.$message.success("点击了提示");
| }
| },
| data() {
| return {
| model: false,
| loadKey: true,
| formFields: {
| Variety: "",
| AgeRange: "",
| DateRange: ["", ""],
| City: [], //注意多选这里默认是数组
| AvgPrice: 8.88, //input标签如果是数字,此处注意区分不要写成字符串了
| Date: "",
| IsTop: 0,
| Address: "北京市海淀区",
| Source: [],
| Source1: "5",
| Remark: "",
| cascader: [], //注意级联这里默认是数组
| monthValue: this.base.getDate().substr(0, 7), //'2022-10',
| phone: "",
| email: "",
| extra2: "",
| userVali: "",
| uploadFile: [
| {
| name: "exceltest.xlsx",
| path: "https://imgs-1256993465.cos.ap-chengdu.myqcloud.com/github/exceltest.xlsx",
| },
| ],
| img: [
| {
| name: "060222.jpg",
| path: "http://api.volcore.xyz/Upload/Tables/App_Expert/202103061753415708/060222.jpg",
| },
| ],
| },
| formRules: [
| //两列的表单,formRules数据格式为:[[{},{}]]
| [
| {
| dataKey: "age", //后台下拉框对应的数据字典编号
| data: [], //loadKey设置为true,会根据dataKey从后台的下拉框数据源中自动加载数据
| title: "下拉框",
| filter: true,
| required: true, //设置为必选项
| field: "AgeRange",
| type: "select",
| extra: {
| render: (h) => {
| return (
| <el-popover
| placement="top-start"
| title="Title"
| width="200"
| trigger="hover"
| content="this is content, this is content, this is content"
| >
| {{
| reference: (
| <i onClick={() => { this.popover() }}
| class="el-icon-warning-outline"
| ></i>
| ),
| }}
| </el-popover>
| );
| },
| },
| },
| {
| title: "自动完成",
| autocomplete: true, //设置为自动完成
| dataKey: "pz",
| placeholder: "不存的数据自动填充",
| //如果这里绑定了data数据,后台不会加载此数据源
| data: [
| { key: "北京市", value: "北京市" },
| { key: "上海市", value: "上海市" },
| ],
| required: false,
| field: "Variety",
| type: "select",
| },
| {
| dataKey: "city",
| title: "多选",
| required: true,
| data: [],
| field: "City",
| type: "selectList", //selectList属性为多选
| },
| {
| type: "decimal",
| title: "数字",
| required: true,
| placeholder: "你可以自己定义placeholder显示的文字",
| field: "AvgPrice",
| },
| ],
| [
| {
| title: "日期",
| required: true,
| placeholder: "限制时间范围",
| field: "Date",
| type: "datetime", //设置日期选择范围
| min: "2021-07-01",
| max: Date.now(),
| onChange: (val) => {
| console.log("选择日期:" + val);
| },
| },
| {
| title: "日期2",
| range: true, //设置为true可以选择开始与结束日期
| placeholder: "日期",
| field: "DateRange",
| type: "date",
| // colSize:6,//如果宽度不够,可以指定colSize,可选值,4,6,8,12
| onChange: (val) => {
| console.log("日期:" + val);
| },
| },
| {
| type: "text",
| title: "地址",
| required: false,
| field: "Address",
| },
| {
| title: "额外标签",
| field: "extra2",
| type: "text",
| extra: {
| style: "color:red;cursor: pointer;",
| icon: "el-icon-edit", //显示图标
| text: "点击", //显示文本
| //触发事件
| click: (item) => {
| this.$message.error("点击标签触发的事件");
| },
| },
| },
| ],
| [
| {
| title: "手机",
| required: true,
| field: "phoneNo",
| type: "phone",
| },
| {
| title: "邮箱",
| required: true,
| field: "email",
| type: "mail",
| },
| {
| title: "自定义验证",
| required: true,
| field: "userVali",
| placeholder: "只能输入值:123",
| type: "text",
| validator: (rule, val) => {
| if (val != "123") {
| return "自定设置必须输入123";
| }
| return "";
| },
| },
| {
| dataKey: "top",
| title: "是否",
| required: true,
| field: "IsTop",
| data: [],
| type: "switch",
| },
| ],
| [
| {
| title: "年月",
| field: "monthValue",
| placeholder: "年月",
| type: "month",
| },
| {
| title: "级联",
| field: "cascader", //注意上面formFields属性cascader是数组
| placeholder: "配置数据源后自动绑定级联",
| checkStrictly: true, //是否可以选择任意一级
| type: "cascader",
| data: [],
| dataKey: "tree_roles", //配置数据源(见菜单下拉框绑定设置中的级联角色自定义sql)
| colSize: 8, //设置宽度100%
| },
| ],
| [
| {
| title: "备注",
| required: true,
| field: "Remark",
| placeholder: "你可以设置colSize属性决定标签的长度,可选值12/8/6/4",
| min: 1,
| max: 3,
| type: "textarea",
| colSize: 12, //设置宽度100%
| },
| ],
| [
| {
| colSize: 12,
| render: (h) => {
| return h(
| "div",
| { style: { "padding-left": "48px", "margin-bottom": "-14px" } },
| [
| h(
| "div",
| {
| style: {
| "border-left": "10px solid #3095ff",
| "line-height": "17px",
| "padding-left": "4px",
| "font-weight": "bold",
| "font-size": "15px",
| },
| },
| "其他基础信息(通过render方法数据分栏)"
| ),
| ]
| );
| },
| },
| ],
| [
| {
| dataKey: "pz",
| title: "多选",
| required: true,
| data: [],
| min: 1,
| max: 4,
| field: "Source",
| type: "checkbox",
| colSize: 12, //设置宽度100%
| },
| ],
| [
| {
| dataKey: "pz",
| title: "Radio",
| required: true,
| data: [],
| min: 2,
| max: 4,
| field: "Source1",
| type: "radio",
| colSize: 12, //设置宽度100%
| },
| ],
| [
| {
| title: "只读",
| field: "Address",
| readonly: true,
| },
| {
| title: "只读文本",
| field: "Address",
| type: "label",
| inputStyle: { color: "red" }, //自定义样式,其他的input也生效
| },
| {
| title: "图片",
| required: true,
| field: "img",
| type: "img",
| multiple: true,
| maxFile: 2,
| maxSize: 5,
| url: "api/App_Appointment/Upload",
| // colSize: 6, //设置宽度50%
| },
| {
| title: "上传",
| required: true,
| field: "uploadFile",
| type: "excel", //指定上传类型excel/img/file
| multiple: true,
| maxFile: 5,
| maxSize: 3,
| url: "api/App_Appointment/Upload",
| // colSize: 6, //设置宽度50%
| },
| ],
| ],
| };
| },
| };
| </script>
|
|