houzhongjian
2024-07-11 759b1c71011abd6b58c37d2566f3f3c208c2f1b2
提交 | 用户 | 时间
759b1c 1 <template>
H 2   <div class="right-board">
3     <el-tabs v-model="currentTab" class="center-tabs">
4       <el-tab-pane label="组件属性" name="field" />
5       <el-tab-pane label="表单属性" name="form" />
6     </el-tabs>
7     <div class="field-box">
8       <a class="document-link" target="_blank" :href="documentLink" title="查看组件文档">
9         <i class="el-icon-link" />
10       </a>
11       <el-scrollbar class="right-scrollbar">
12         <!-- 组件属性 -->
13         <el-form v-show="currentTab==='field' && showField" size="small" label-width="90px">
14           <el-form-item v-if="activeData.__config__.changeTag" label="组件类型">
15             <el-select
16               v-model="activeData.__config__.tagIcon"
17               placeholder="请选择组件类型"
18               :style="{width: '100%'}"
19               @change="tagChange"
20             >
21               <el-option-group v-for="group in tagList" :key="group.label" :label="group.label">
22                 <el-option
23                   v-for="item in group.options"
24                   :key="item.__config__.label"
25                   :label="item.__config__.label"
26                   :value="item.__config__.tagIcon"
27                 >
28                   <svg-icon class="node-icon" :icon-class="item.__config__.tagIcon" />
29                   <span> {{ item.__config__.label }}</span>
30                 </el-option>
31               </el-option-group>
32             </el-select>
33           </el-form-item>
34           <el-form-item v-if="activeData.__vModel__!==undefined" label="字段名">
35             <el-input v-model="activeData.__vModel__" placeholder="请输入字段名(v-model)" />
36           </el-form-item>
37           <el-form-item v-if="activeData.__config__.componentName!==undefined" label="组件名">
38             {{ activeData.__config__.componentName }}
39           </el-form-item>
40           <el-form-item v-if="activeData.__config__.label!==undefined" label="标题">
41             <el-input v-model="activeData.__config__.label" placeholder="请输入标题" @input="changeRenderKey" />
42           </el-form-item>
43           <el-form-item v-if="activeData.placeholder!==undefined" label="占位提示">
44             <el-input v-model="activeData.placeholder" placeholder="请输入占位提示" @input="changeRenderKey" />
45           </el-form-item>
46           <el-form-item v-if="activeData['start-placeholder']!==undefined" label="开始占位">
47             <el-input v-model="activeData['start-placeholder']" placeholder="请输入占位提示" />
48           </el-form-item>
49           <el-form-item v-if="activeData['end-placeholder']!==undefined" label="结束占位">
50             <el-input v-model="activeData['end-placeholder']" placeholder="请输入占位提示" />
51           </el-form-item>
52           <el-form-item v-if="activeData.__config__.span!==undefined" label="表单栅格">
53             <el-slider v-model="activeData.__config__.span" :max="24" :min="1" :marks="{12:''}" @change="spanChange" />
54           </el-form-item>
55           <el-form-item v-if="activeData.__config__.layout==='rowFormItem'&&activeData.gutter!==undefined" label="栅格间隔">
56             <el-input-number v-model="activeData.gutter" :min="0" placeholder="栅格间隔" />
57           </el-form-item>
58           <el-form-item v-if="activeData.__config__.layout==='rowFormItem'&&activeData.type!==undefined" label="布局模式">
59             <el-radio-group v-model="activeData.type">
60               <el-radio-button label="default" />
61               <el-radio-button label="flex" />
62             </el-radio-group>
63           </el-form-item>
64           <el-form-item v-if="activeData.justify!==undefined&&activeData.type==='flex'" label="水平排列">
65             <el-select v-model="activeData.justify" placeholder="请选择水平排列" :style="{width: '100%'}">
66               <el-option
67                 v-for="(item, index) in justifyOptions"
68                 :key="index"
69                 :label="item.label"
70                 :value="item.value"
71               />
72             </el-select>
73           </el-form-item>
74           <el-form-item v-if="activeData.align!==undefined&&activeData.type==='flex'" label="垂直排列">
75             <el-radio-group v-model="activeData.align">
76               <el-radio-button label="top" />
77               <el-radio-button label="middle" />
78               <el-radio-button label="bottom" />
79             </el-radio-group>
80           </el-form-item>
81           <el-form-item v-if="activeData.__config__.labelWidth!==undefined" label="标签宽度">
82             <el-input v-model.number="activeData.__config__.labelWidth" type="number" placeholder="请输入标签宽度" />
83           </el-form-item>
84           <el-form-item v-if="activeData.style&&activeData.style.width!==undefined" label="组件宽度">
85             <el-input v-model="activeData.style.width" placeholder="请输入组件宽度" clearable />
86           </el-form-item>
87           <el-form-item v-if="activeData.__vModel__!==undefined" label="默认值">
88             <el-input
89               :value="setDefaultValue(activeData.__config__.defaultValue)"
90               placeholder="请输入默认值"
91               @input="onDefaultValueInput"
92             />
93           </el-form-item>
94           <el-form-item v-if="activeData.__config__.tag==='el-checkbox-group'" label="至少应选">
95             <el-input-number
96               :value="activeData.min"
97               :min="0"
98               placeholder="至少应选"
99               @input="$set(activeData, 'min', $event?$event:undefined)"
100             />
101           </el-form-item>
102           <el-form-item v-if="activeData.__config__.tag==='el-checkbox-group'" label="最多可选">
103             <el-input-number
104               :value="activeData.max"
105               :min="0"
106               placeholder="最多可选"
107               @input="$set(activeData, 'max', $event?$event:undefined)"
108             />
109           </el-form-item>
110           <el-form-item v-if="activeData.__slot__&&activeData.__slot__.prepend!==undefined" label="前缀">
111             <el-input v-model="activeData.__slot__.prepend" placeholder="请输入前缀" />
112           </el-form-item>
113           <el-form-item v-if="activeData.__slot__&&activeData.__slot__.append!==undefined" label="后缀">
114             <el-input v-model="activeData.__slot__.append" placeholder="请输入后缀" />
115           </el-form-item>
116           <el-form-item v-if="activeData['prefix-icon']!==undefined" label="前图标">
117             <el-input v-model="activeData['prefix-icon']" placeholder="请输入前图标名称">
118               <el-button slot="append" icon="el-icon-thumb" @click="openIconsDialog('prefix-icon')">
119                 选择
120               </el-button>
121             </el-input>
122           </el-form-item>
123           <el-form-item v-if="activeData['suffix-icon'] !== undefined" label="后图标">
124             <el-input v-model="activeData['suffix-icon']" placeholder="请输入后图标名称">
125               <el-button slot="append" icon="el-icon-thumb" @click="openIconsDialog('suffix-icon')">
126                 选择
127               </el-button>
128             </el-input>
129           </el-form-item>
130           <el-form-item
131             v-if="activeData['icon']!==undefined && activeData.__config__.tag === 'el-button'"
132             label="按钮图标"
133           >
134             <el-input v-model="activeData['icon']" placeholder="请输入按钮图标名称">
135               <el-button slot="append" icon="el-icon-thumb" @click="openIconsDialog('icon')">
136                 选择
137               </el-button>
138             </el-input>
139           </el-form-item>
140           <el-form-item v-if="activeData.__config__.tag === 'el-cascader'" label="选项分隔符">
141             <el-input v-model="activeData.separator" placeholder="请输入选项分隔符" />
142           </el-form-item>
143           <el-form-item v-if="activeData.autosize !== undefined" label="最小行数">
144             <el-input-number v-model="activeData.autosize.minRows" :min="1" placeholder="最小行数" />
145           </el-form-item>
146           <el-form-item v-if="activeData.autosize !== undefined" label="最大行数">
147             <el-input-number v-model="activeData.autosize.maxRows" :min="1" placeholder="最大行数" />
148           </el-form-item>
149           <el-form-item v-if="isShowMin" label="最小值">
150             <el-input-number v-model="activeData.min" placeholder="最小值" />
151           </el-form-item>
152           <el-form-item v-if="isShowMax" label="最大值">
153             <el-input-number v-model="activeData.max" placeholder="最大值" />
154           </el-form-item>
155           <el-form-item v-if="activeData.height!==undefined" label="组件高度">
156             <el-input-number v-model="activeData.height" placeholder="高度" @input="changeRenderKey" />
157           </el-form-item>
158           <el-form-item v-if="isShowStep" label="步长">
159             <el-input-number v-model="activeData.step" placeholder="步数" />
160           </el-form-item>
161           <el-form-item v-if="activeData.__config__.tag === 'el-input-number'" label="精度">
162             <el-input-number v-model="activeData.precision" :min="0" placeholder="精度" />
163           </el-form-item>
164           <el-form-item v-if="activeData.__config__.tag === 'el-input-number'" label="按钮位置">
165             <el-radio-group v-model="activeData['controls-position']">
166               <el-radio-button label="">
167                 默认
168               </el-radio-button>
169               <el-radio-button label="right">
170                 右侧
171               </el-radio-button>
172             </el-radio-group>
173           </el-form-item>
174           <el-form-item v-if="activeData.maxlength !== undefined" label="最多输入">
175             <el-input v-model="activeData.maxlength" placeholder="请输入字符长度">
176               <template slot="append">
177                 个字符
178               </template>
179             </el-input>
180           </el-form-item>
181           <el-form-item v-if="activeData['active-text'] !== undefined" label="开启提示">
182             <el-input v-model="activeData['active-text']" placeholder="请输入开启提示" />
183           </el-form-item>
184           <el-form-item v-if="activeData['inactive-text'] !== undefined" label="关闭提示">
185             <el-input v-model="activeData['inactive-text']" placeholder="请输入关闭提示" />
186           </el-form-item>
187           <el-form-item v-if="activeData['active-value'] !== undefined" label="开启值">
188             <el-input
189               :value="setDefaultValue(activeData['active-value'])"
190               placeholder="请输入开启值"
191               @input="onSwitchValueInput($event, 'active-value')"
192             />
193           </el-form-item>
194           <el-form-item v-if="activeData['inactive-value'] !== undefined" label="关闭值">
195             <el-input
196               :value="setDefaultValue(activeData['inactive-value'])"
197               placeholder="请输入关闭值"
198               @input="onSwitchValueInput($event, 'inactive-value')"
199             />
200           </el-form-item>
201           <el-form-item
202             v-if="activeData.type !== undefined && 'el-date-picker' === activeData.__config__.tag"
203             label="时间类型"
204           >
205             <el-select
206               v-model="activeData.type"
207               placeholder="请选择时间类型"
208               :style="{ width: '100%' }"
209               @change="dateTypeChange"
210             >
211               <el-option
212                 v-for="(item, index) in dateOptions"
213                 :key="index"
214                 :label="item.label"
215                 :value="item.value"
216               />
217             </el-select>
218           </el-form-item>
219           <el-form-item v-if="activeData.name !== undefined" label="文件字段名">
220             <el-input v-model="activeData.name" placeholder="请输入上传文件字段名" />
221           </el-form-item>
222           <el-form-item v-if="activeData.accept !== undefined" label="文件类型">
223             <el-select
224               v-model="activeData.accept"
225               placeholder="请选择文件类型"
226               :style="{ width: '100%' }"
227               clearable
228             >
229               <el-option label="图片" value="image/*" />
230               <el-option label="视频" value="video/*" />
231               <el-option label="音频" value="audio/*" />
232               <el-option label="excel" value=".xls,.xlsx" />
233               <el-option label="word" value=".doc,.docx" />
234               <el-option label="pdf" value=".pdf" />
235               <el-option label="txt" value=".txt" />
236             </el-select>
237           </el-form-item>
238           <el-form-item v-if="activeData.__config__.fileSize !== undefined" label="文件大小">
239             <el-input v-model.number="activeData.__config__.fileSize" placeholder="请输入文件大小">
240               <el-select slot="append" v-model="activeData.__config__.sizeUnit" :style="{ width: '66px' }">
241                 <el-option label="KB" value="KB" />
242                 <el-option label="MB" value="MB" />
243                 <el-option label="GB" value="GB" />
244               </el-select>
245             </el-input>
246           </el-form-item>
247           <el-form-item v-if="activeData.action !== undefined" label="上传地址">
248             <el-input v-model="activeData.action" placeholder="请输入上传地址" clearable />
249           </el-form-item>
250           <el-form-item v-if="activeData['list-type'] !== undefined" label="列表类型">
251             <el-radio-group v-model="activeData['list-type']" size="small">
252               <el-radio-button label="text">
253                 text
254               </el-radio-button>
255               <el-radio-button label="picture">
256                 picture
257               </el-radio-button>
258               <el-radio-button label="picture-card">
259                 picture-card
260               </el-radio-button>
261             </el-radio-group>
262           </el-form-item>
263           <el-form-item
264             v-if="activeData.type !== undefined && activeData.__config__.tag === 'el-button'"
265             label="按钮类型"
266           >
267             <el-select v-model="activeData.type" :style="{ width: '100%' }">
268               <el-option label="primary" value="primary" />
269               <el-option label="success" value="success" />
270               <el-option label="warning" value="warning" />
271               <el-option label="danger" value="danger" />
272               <el-option label="info" value="info" />
273               <el-option label="text" value="text" />
274             </el-select>
275           </el-form-item>
276           <el-form-item
277             v-if="activeData.__config__.buttonText !== undefined"
278             v-show="'picture-card' !== activeData['list-type']"
279             label="按钮文字"
280           >
281             <el-input v-model="activeData.__config__.buttonText" placeholder="请输入按钮文字" />
282           </el-form-item>
283           <el-form-item
284             v-if="activeData.__config__.tag === 'el-button'"
285             label="按钮文字"
286           >
287             <el-input v-model="activeData.__slot__.default" placeholder="请输入按钮文字" />
288           </el-form-item>
289           <el-form-item v-if="activeData['range-separator'] !== undefined" label="分隔符">
290             <el-input v-model="activeData['range-separator']" placeholder="请输入分隔符" />
291           </el-form-item>
292           <el-form-item v-if="activeData['picker-options'] !== undefined" label="时间段">
293             <el-input
294               v-model="activeData['picker-options'].selectableRange"
295               placeholder="请输入时间段"
296             />
297           </el-form-item>
298           <el-form-item v-if="activeData.format !== undefined" label="时间格式">
299             <el-input
300               :value="activeData.format"
301               placeholder="请输入时间格式"
302               @input="setTimeValue($event)"
303             />
304           </el-form-item>
305           <template v-if="['el-checkbox-group', 'el-radio-group', 'el-select'].indexOf(activeData.__config__.tag) > -1">
306             <el-divider>选项</el-divider>
307             <draggable
308               :list="activeData.__slot__.options"
309               :animation="340"
310               group="selectItem"
311               handle=".option-drag"
312             >
313               <div v-for="(item, index) in activeData.__slot__.options" :key="index" class="select-item">
314                 <div class="select-line-icon option-drag">
315                   <i class="el-icon-s-operation" />
316                 </div>
317                 <el-input v-model="item.label" placeholder="选项名" size="small" />
318                 <el-input
319                   placeholder="选项值"
320                   size="small"
321                   :value="item.value"
322                   @input="setOptionValue(item, $event)"
323                 />
324                 <div class="close-btn select-line-icon" @click="activeData.__slot__.options.splice(index, 1)">
325                   <i class="el-icon-remove-outline" />
326                 </div>
327               </div>
328             </draggable>
329             <div style="margin-left: 20px;">
330               <el-button
331                 style="padding-bottom: 0"
332                 icon="el-icon-circle-plus-outline"
333                 type="text"
334                 @click="addSelectItem"
335               >
336                 添加选项
337               </el-button>
338             </div>
339             <el-divider />
340           </template>
341
342           <template v-if="['el-cascader', 'el-table'].includes(activeData.__config__.tag)">
343             <el-divider>选项</el-divider>
344             <el-form-item v-if="activeData.__config__.dataType" label="数据类型">
345               <el-radio-group v-model="activeData.__config__.dataType" size="small">
346                 <el-radio-button label="dynamic">
347                   动态数据
348                 </el-radio-button>
349                 <el-radio-button label="static">
350                   静态数据
351                 </el-radio-button>
352               </el-radio-group>
353             </el-form-item>
354
355             <template v-if="activeData.__config__.dataType === 'dynamic'">
356               <el-form-item label="接口地址">
357                 <el-input
358                   v-model="activeData.__config__.url"
359                   :title="activeData.__config__.url"
360                   placeholder="请输入接口地址"
361                   clearable
362                   @blur="$emit('fetch-data', activeData)"
363                 >
364                   <el-select
365                     slot="prepend"
366                     v-model="activeData.__config__.method"
367                     :style="{width: '85px'}"
368                     @change="$emit('fetch-data', activeData)"
369                   >
370                     <el-option label="get" value="get" />
371                     <el-option label="post" value="post" />
372                     <el-option label="put" value="put" />
373                     <el-option label="delete" value="delete" />
374                   </el-select>
375                 </el-input>
376               </el-form-item>
377               <el-form-item label="数据位置">
378                 <el-input
379                   v-model="activeData.__config__.dataPath"
380                   placeholder="请输入数据位置"
381                   @blur="$emit('fetch-data', activeData)"
382                 />
383               </el-form-item>
384
385               <template v-if="activeData.props && activeData.props.props">
386                 <el-form-item label="标签键名">
387                   <el-input v-model="activeData.props.props.label" placeholder="请输入标签键名" />
388                 </el-form-item>
389                 <el-form-item label="值键名">
390                   <el-input v-model="activeData.props.props.value" placeholder="请输入值键名" />
391                 </el-form-item>
392                 <el-form-item label="子级键名">
393                   <el-input v-model="activeData.props.props.children" placeholder="请输入子级键名" />
394                 </el-form-item>
395               </template>
396             </template>
397
398             <!-- 级联选择静态树 -->
399             <el-tree
400               v-if="activeData.__config__.dataType === 'static'"
401               draggable
402               :data="activeData.options"
403               node-key="id"
404               :expand-on-click-node="false"
405               :render-content="renderContent"
406             />
407             <div v-if="activeData.__config__.dataType === 'static'" style="margin-left: 20px">
408               <el-button
409                 style="padding-bottom: 0"
410                 icon="el-icon-circle-plus-outline"
411                 type="text"
412                 @click="addTreeItem"
413               >
414                 添加父级
415               </el-button>
416             </div>
417             <el-divider />
418           </template>
419
420           <el-form-item v-if="activeData.__config__.optionType !== undefined" label="选项样式">
421             <el-radio-group v-model="activeData.__config__.optionType">
422               <el-radio-button label="default">
423                 默认
424               </el-radio-button>
425               <el-radio-button label="button">
426                 按钮
427               </el-radio-button>
428             </el-radio-group>
429           </el-form-item>
430           <el-form-item v-if="activeData['active-color'] !== undefined" label="开启颜色">
431             <el-color-picker v-model="activeData['active-color']" />
432           </el-form-item>
433           <el-form-item v-if="activeData['inactive-color'] !== undefined" label="关闭颜色">
434             <el-color-picker v-model="activeData['inactive-color']" />
435           </el-form-item>
436
437           <el-form-item v-if="activeData.__config__.showLabel !== undefined
438             && activeData.__config__.labelWidth !== undefined" label="显示标签"
439           >
440             <el-switch v-model="activeData.__config__.showLabel" />
441           </el-form-item>
442           <el-form-item v-if="activeData.branding !== undefined" label="品牌烙印">
443             <el-switch v-model="activeData.branding" @input="changeRenderKey" />
444           </el-form-item>
445           <el-form-item v-if="activeData['allow-half'] !== undefined" label="允许半选">
446             <el-switch v-model="activeData['allow-half']" />
447           </el-form-item>
448           <el-form-item v-if="activeData['show-text'] !== undefined" label="辅助文字">
449             <el-switch v-model="activeData['show-text']" @change="rateTextChange" />
450           </el-form-item>
451           <el-form-item v-if="activeData['show-score'] !== undefined" label="显示分数">
452             <el-switch v-model="activeData['show-score']" @change="rateScoreChange" />
453           </el-form-item>
454           <el-form-item v-if="activeData['show-stops'] !== undefined" label="显示间断点">
455             <el-switch v-model="activeData['show-stops']" />
456           </el-form-item>
457           <el-form-item v-if="activeData.range !== undefined" label="范围选择">
458             <el-switch v-model="activeData.range" @change="rangeChange" />
459           </el-form-item>
460           <el-form-item
461             v-if="activeData.__config__.border !== undefined && activeData.__config__.optionType === 'default'"
462             label="是否带边框"
463           >
464             <el-switch v-model="activeData.__config__.border" />
465           </el-form-item>
466           <el-form-item v-if="activeData.__config__.tag === 'el-color-picker'" label="颜色格式">
467             <el-select
468               v-model="activeData['color-format']"
469               placeholder="请选择颜色格式"
470               :style="{ width: '100%' }"
471               clearable
472               @change="colorFormatChange"
473             >
474               <el-option
475                 v-for="(item, index) in colorFormatOptions"
476                 :key="index"
477                 :label="item.label"
478                 :value="item.value"
479               />
480             </el-select>
481           </el-form-item>
482           <el-form-item
483             v-if="activeData.size !== undefined &&
484               (activeData.__config__.optionType === 'button' ||
485                 activeData.__config__.border ||
486                 activeData.__config__.tag === 'el-color-picker' ||
487                 activeData.__config__.tag === 'el-button')"
488             label="组件尺寸"
489           >
490             <el-radio-group v-model="activeData.size">
491               <el-radio-button label="medium">
492                 中等
493               </el-radio-button>
494               <el-radio-button label="small">
495                 较小
496               </el-radio-button>
497               <el-radio-button label="mini">
498                 迷你
499               </el-radio-button>
500             </el-radio-group>
501           </el-form-item>
502           <el-form-item v-if="activeData['show-word-limit'] !== undefined" label="输入统计">
503             <el-switch v-model="activeData['show-word-limit']" />
504           </el-form-item>
505           <el-form-item v-if="activeData.__config__.tag === 'el-input-number'" label="严格步数">
506             <el-switch v-model="activeData['step-strictly']" />
507           </el-form-item>
508           <el-form-item v-if="activeData.__config__.tag === 'el-cascader'" label="任选层级">
509             <el-switch v-model="activeData.props.props.checkStrictly" />
510           </el-form-item>
511           <el-form-item v-if="activeData.__config__.tag === 'el-cascader'" label="是否多选">
512             <el-switch v-model="activeData.props.props.multiple" />
513           </el-form-item>
514           <el-form-item v-if="activeData.__config__.tag === 'el-cascader'" label="展示全路径">
515             <el-switch v-model="activeData['show-all-levels']" />
516           </el-form-item>
517           <el-form-item v-if="activeData.__config__.tag === 'el-cascader'" label="可否筛选">
518             <el-switch v-model="activeData.filterable" />
519           </el-form-item>
520           <el-form-item v-if="activeData.clearable !== undefined" label="能否清空">
521             <el-switch v-model="activeData.clearable" />
522           </el-form-item>
523           <el-form-item v-if="activeData.__config__.showTip !== undefined" label="显示提示">
524             <el-switch v-model="activeData.__config__.showTip" />
525           </el-form-item>
526           <el-form-item v-if="activeData.__config__.tag === 'el-upload'" label="多选文件">
527             <el-switch v-model="activeData.multiple" />
528           </el-form-item>
529           <el-form-item v-if="activeData['auto-upload'] !== undefined" label="自动上传">
530             <el-switch v-model="activeData['auto-upload']" />
531           </el-form-item>
532           <el-form-item v-if="activeData.readonly !== undefined" label="是否只读">
533             <el-switch v-model="activeData.readonly" />
534           </el-form-item>
535           <el-form-item v-if="activeData.disabled !== undefined" label="是否禁用">
536             <el-switch v-model="activeData.disabled" />
537           </el-form-item>
538           <el-form-item v-if="activeData.__config__.tag === 'el-select'" label="能否搜索">
539             <el-switch v-model="activeData.filterable" />
540           </el-form-item>
541           <el-form-item v-if="activeData.__config__.tag === 'el-select'" label="是否多选">
542             <el-switch v-model="activeData.multiple" @change="multipleChange" />
543           </el-form-item>
544           <el-form-item v-if="activeData.__config__.required !== undefined" label="是否必填">
545             <el-switch v-model="activeData.__config__.required" />
546           </el-form-item>
547
548           <template v-if="activeData.__config__.layoutTree" v-slot="{ node, data }">
549             <el-divider>布局结构树</el-divider>
550             <el-tree
551               :data="[activeData.__config__]"
552               :props="layoutTreeProps"
553               node-key="renderKey"
554               default-expand-all
555               draggable
556             >
557               <span slot-scope="{ node, data }">
558                 <span class="node-label">
559                   <svg-icon class="node-icon" :icon-class="data.__config__?data.__config__.tagIcon:data.tagIcon" />
560                   {{ node.label }}
561                 </span>
562               </span>
563             </el-tree>
564           </template>
565
566           <template v-if="Array.isArray(activeData.__config__.regList)">
567             <el-divider>正则校验</el-divider>
568             <div
569               v-for="(item, index) in activeData.__config__.regList"
570               :key="index"
571               class="reg-item"
572             >
573               <span class="close-btn" @click="activeData.__config__.regList.splice(index, 1)">
574                 <i class="el-icon-close" />
575               </span>
576               <el-form-item label="表达式">
577                 <el-input v-model="item.pattern" placeholder="请输入正则" />
578               </el-form-item>
579               <el-form-item label="错误提示" style="margin-bottom:0">
580                 <el-input v-model="item.message" placeholder="请输入错误提示" />
581               </el-form-item>
582             </div>
583             <div style="margin-left: 20px">
584               <el-button icon="el-icon-circle-plus-outline" type="text" @click="addReg">
585                 添加规则
586               </el-button>
587             </div>
588           </template>
589         </el-form>
590         <!-- 表单属性 -->
591         <el-form v-show="currentTab === 'form'" size="small" label-width="90px">
592           <el-form-item label="表单名">
593             <el-input v-model="formConf.formRef" placeholder="请输入表单名(ref)" />
594           </el-form-item>
595           <el-form-item label="表单模型">
596             <el-input v-model="formConf.formModel" placeholder="请输入数据模型" />
597           </el-form-item>
598           <el-form-item label="校验模型">
599             <el-input v-model="formConf.formRules" placeholder="请输入校验模型" />
600           </el-form-item>
601           <el-form-item label="表单尺寸">
602             <el-radio-group v-model="formConf.size">
603               <el-radio-button label="medium">
604                 中等
605               </el-radio-button>
606               <el-radio-button label="small">
607                 较小
608               </el-radio-button>
609               <el-radio-button label="mini">
610                 迷你
611               </el-radio-button>
612             </el-radio-group>
613           </el-form-item>
614           <el-form-item label="标签对齐">
615             <el-radio-group v-model="formConf.labelPosition">
616               <el-radio-button label="left">
617                 左对齐
618               </el-radio-button>
619               <el-radio-button label="right">
620                 右对齐
621               </el-radio-button>
622               <el-radio-button label="top">
623                 顶部对齐
624               </el-radio-button>
625             </el-radio-group>
626           </el-form-item>
627           <el-form-item label="标签宽度">
628             <el-input v-model.number="formConf.labelWidth" type="number" placeholder="请输入标签宽度" />
629           </el-form-item>
630           <el-form-item label="栅格间隔">
631             <el-input-number v-model="formConf.gutter" :min="0" placeholder="栅格间隔" />
632           </el-form-item>
633           <el-form-item label="禁用表单">
634             <el-switch v-model="formConf.disabled" />
635           </el-form-item>
636           <el-form-item label="表单按钮">
637             <el-switch v-model="formConf.formBtns" />
638           </el-form-item>
639           <el-form-item label="显示未选中组件边框">
640             <el-switch v-model="formConf.unFocusedComponentBorder" />
641           </el-form-item>
642         </el-form>
643       </el-scrollbar>
644     </div>
645
646     <treeNode-dialog :visible.sync="dialogVisible" title="添加选项" @commit="addNode" />
647     <icons-dialog :visible.sync="iconsVisible" :current="activeData[currentIconModel]" @select="setIcon" />
648   </div>
649 </template>
650
651 <script>
652 import { isArray } from 'util'
653 import TreeNodeDialog from './TreeNodeDialog'
654 import { isNumberStr } from '@/utils'
655 import IconsDialog from './IconsDialog'
656 import {
657   inputComponents, selectComponents
658 } from '@/components/generator/config'
659 import { saveFormConf } from '@/utils/db'
660
661 const dateTimeFormat = {
662   date: 'yyyy-MM-dd',
663   week: 'yyyy 第 WW 周',
664   month: 'yyyy-MM',
665   year: 'yyyy',
666   datetime: 'yyyy-MM-dd HH:mm:ss',
667   daterange: 'yyyy-MM-dd',
668   monthrange: 'yyyy-MM',
669   datetimerange: 'yyyy-MM-dd HH:mm:ss'
670 }
671
672 // 使changeRenderKey在目标组件改变时可用
673 const needRerenderList = ['tinymce']
674
675 export default {
676   components: {
677     TreeNodeDialog,
678     IconsDialog
679   },
680   props: ['showField', 'activeData', 'formConf'],
681   data() {
682     return {
683       currentTab: 'field',
684       currentNode: null,
685       dialogVisible: false,
686       iconsVisible: false,
687       currentIconModel: null,
688       dateTypeOptions: [
689         {
690           label: '日(date)',
691           value: 'date'
692         },
693         {
694           label: '周(week)',
695           value: 'week'
696         },
697         {
698           label: '月(month)',
699           value: 'month'
700         },
701         {
702           label: '年(year)',
703           value: 'year'
704         },
705         {
706           label: '日期时间(datetime)',
707           value: 'datetime'
708         }
709       ],
710       dateRangeTypeOptions: [
711         {
712           label: '日期范围(daterange)',
713           value: 'daterange'
714         },
715         {
716           label: '月范围(monthrange)',
717           value: 'monthrange'
718         },
719         {
720           label: '日期时间范围(datetimerange)',
721           value: 'datetimerange'
722         }
723       ],
724       colorFormatOptions: [
725         {
726           label: 'hex',
727           value: 'hex'
728         },
729         {
730           label: 'rgb',
731           value: 'rgb'
732         },
733         {
734           label: 'rgba',
735           value: 'rgba'
736         },
737         {
738           label: 'hsv',
739           value: 'hsv'
740         },
741         {
742           label: 'hsl',
743           value: 'hsl'
744         }
745       ],
746       justifyOptions: [
747         {
748           label: 'start',
749           value: 'start'
750         },
751         {
752           label: 'end',
753           value: 'end'
754         },
755         {
756           label: 'center',
757           value: 'center'
758         },
759         {
760           label: 'space-around',
761           value: 'space-around'
762         },
763         {
764           label: 'space-between',
765           value: 'space-between'
766         }
767       ],
768       layoutTreeProps: {
769         label(data, node) {
770           const config = data.__config__
771           return data.componentName || `${config.label}: ${data.__vModel__}`
772         }
773       }
774     }
775   },
776   computed: {
777     documentLink() {
778       return (
779         this.activeData.__config__.document
780         || 'https://element.eleme.cn/#/zh-CN/component/installation'
781       )
782     },
783     dateOptions() {
784       if (
785         this.activeData.type !== undefined
786         && this.activeData.__config__.tag === 'el-date-picker'
787       ) {
788         if (this.activeData['start-placeholder'] === undefined) {
789           return this.dateTypeOptions
790         }
791         return this.dateRangeTypeOptions
792       }
793       return []
794     },
795     tagList() {
796       return [
797         {
798           label: '输入型组件',
799           options: inputComponents
800         },
801         {
802           label: '选择型组件',
803           options: selectComponents
804         }
805       ]
806     },
807     activeTag() {
808       return this.activeData.__config__.tag
809     },
810     isShowMin() {
811       return ['el-input-number', 'el-slider'].indexOf(this.activeTag) > -1
812     },
813     isShowMax() {
814       return ['el-input-number', 'el-slider', 'el-rate'].indexOf(this.activeTag) > -1
815     },
816     isShowStep() {
817       return ['el-input-number', 'el-slider'].indexOf(this.activeTag) > -1
818     }
819   },
820   watch: {
821     formConf: {
822       handler(val) {
823         saveFormConf(val)
824       },
825       deep: true
826     }
827   },
828   methods: {
829     addReg() {
830       this.activeData.__config__.regList.push({
831         pattern: '',
832         message: ''
833       })
834     },
835     addSelectItem() {
836       this.activeData.__slot__.options.push({
837         label: '',
838         value: ''
839       })
840     },
841     addTreeItem() {
842       ++this.idGlobal
843       this.dialogVisible = true
844       this.currentNode = this.activeData.options
845     },
846     renderContent(h, { node, data, store }) {
847       return (
848         <div class="custom-tree-node">
849           <span>{node.label}</span>
850           <span class="node-operation">
851             <i on-click={() => this.append(data)}
852               class="el-icon-plus"
853               title="添加"
854             ></i>
855             <i on-click={() => this.remove(node, data)}
856               class="el-icon-delete"
857               title="删除"
858             ></i>
859           </span>
860         </div>
861       )
862     },
863     append(data) {
864       if (!data.children) {
865         this.$set(data, 'children', [])
866       }
867       this.dialogVisible = true
868       this.currentNode = data.children
869     },
870     remove(node, data) {
871       this.activeData.__config__.defaultValue = [] // 避免删除时报错
872       const { parent } = node
873       const children = parent.data.children || parent.data
874       const index = children.findIndex(d => d.id === data.id)
875       children.splice(index, 1)
876     },
877     addNode(data) {
878       this.currentNode.push(data)
879     },
880     setOptionValue(item, val) {
881       item.value = isNumberStr(val) ? +val : val
882     },
883     setDefaultValue(val) {
884       if (Array.isArray(val)) {
885         return val.join(',')
886       }
887       // if (['string', 'number'].indexOf(typeof val) > -1) {
888       //   return val
889       // }
890       if (typeof val === 'boolean') {
891         return `${val}`
892       }
893       return val
894     },
895     onDefaultValueInput(str) {
896       if (isArray(this.activeData.__config__.defaultValue)) {
897         // 数组
898         this.$set(
899           this.activeData.__config__,
900           'defaultValue',
901           str.split(',').map(val => (isNumberStr(val) ? +val : val))
902         )
903       } else if (['true', 'false'].indexOf(str) > -1) {
904         // 布尔
905         this.$set(this.activeData.__config__, 'defaultValue', JSON.parse(str))
906       } else {
907         // 字符串和数字
908         this.$set(
909           this.activeData.__config__,
910           'defaultValue',
911           isNumberStr(str) ? +str : str
912         )
913       }
914     },
915     onSwitchValueInput(val, name) {
916       if (['true', 'false'].indexOf(val) > -1) {
917         this.$set(this.activeData, name, JSON.parse(val))
918       } else {
919         this.$set(this.activeData, name, isNumberStr(val) ? +val : val)
920       }
921     },
922     setTimeValue(val, type) {
923       const valueFormat = type === 'week' ? dateTimeFormat.date : val
924       this.$set(this.activeData.__config__, 'defaultValue', null)
925       this.$set(this.activeData, 'value-format', valueFormat)
926       this.$set(this.activeData, 'format', val)
927     },
928     spanChange(val) {
929       this.formConf.span = val
930     },
931     multipleChange(val) {
932       this.$set(this.activeData.__config__, 'defaultValue', val ? [] : '')
933     },
934     dateTypeChange(val) {
935       this.setTimeValue(dateTimeFormat[val], val)
936     },
937     rangeChange(val) {
938       this.$set(
939         this.activeData.__config__,
940         'defaultValue',
941         val ? [this.activeData.min, this.activeData.max] : this.activeData.min
942       )
943     },
944     rateTextChange(val) {
945       if (val) this.activeData['show-score'] = false
946     },
947     rateScoreChange(val) {
948       if (val) this.activeData['show-text'] = false
949     },
950     colorFormatChange(val) {
951       this.activeData.__config__.defaultValue = null
952       this.activeData['show-alpha'] = val.indexOf('a') > -1
953       this.activeData.__config__.renderKey = +new Date() // 更新renderKey,重新渲染该组件
954     },
955     openIconsDialog(model) {
956       this.iconsVisible = true
957       this.currentIconModel = model
958     },
959     setIcon(val) {
960       this.activeData[this.currentIconModel] = val
961     },
962     tagChange(tagIcon) {
963       let target = inputComponents.find(item => item.__config__.tagIcon === tagIcon)
964       if (!target) target = selectComponents.find(item => item.__config__.tagIcon === tagIcon)
965       this.$emit('tag-change', target)
966     },
967     changeRenderKey() {
968       if (needRerenderList.includes(this.activeData.__config__.tag)) {
969         this.activeData.__config__.renderKey = +new Date()
970       }
971     }
972   }
973 }
974 </script>
975
976 <style lang="scss" scoped>
977 .right-board {
978   width: 350px;
979   position: absolute;
980   right: 0;
981   top: 0;
982   padding-top: 3px;
983   .field-box {
984     position: relative;
985     height: calc(100vh - 42px);
986     box-sizing: border-box;
987     overflow: hidden;
988   }
989   .el-scrollbar {
990     height: 100%;
991   }
992 }
993 .select-item {
994   display: flex;
995   border: 1px dashed #fff;
996   box-sizing: border-box;
997   & .close-btn {
998     cursor: pointer;
999     color: #f56c6c;
1000   }
1001   & .el-input + .el-input {
1002     margin-left: 4px;
1003   }
1004 }
1005 .select-item + .select-item {
1006   margin-top: 4px;
1007 }
1008 .select-item.sortable-chosen {
1009   border: 1px dashed #409eff;
1010 }
1011 .select-line-icon {
1012   line-height: 32px;
1013   font-size: 22px;
1014   padding: 0 4px;
1015   color: #777;
1016 }
1017 .option-drag {
1018   cursor: move;
1019 }
1020 .time-range {
1021   .el-date-editor {
1022     width: 227px;
1023   }
1024   :deep(.el-icon-time) {
1025     display: none;
1026   }
1027 }
1028 .document-link {
1029   position: absolute;
1030   display: block;
1031   width: 26px;
1032   height: 26px;
1033   top: 0;
1034   left: 0;
1035   cursor: pointer;
1036   background: #409eff;
1037   z-index: 1;
1038   border-radius: 0 0 6px 0;
1039   text-align: center;
1040   line-height: 26px;
1041   color: #fff;
1042   font-size: 18px;
1043 }
1044 .node-label{
1045   font-size: 14px;
1046 }
1047 .node-icon{
1048   color: #bebfc3;
1049 }
1050 </style>