@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.
Files changed (126) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +98 -0
  3. package/dist/components.es.js +11424 -0
  4. package/dist/components.umd.js +878 -0
  5. package/dist/index.es.js +39113 -0
  6. package/dist/index.umd.js +1187 -0
  7. package/package.json +96 -0
  8. package/src/components/DragBox.vue +49 -0
  9. package/src/components/DragTool.vue +235 -0
  10. package/src/components/EventConfig.vue +557 -0
  11. package/src/components/FcDesigner.vue +2569 -0
  12. package/src/components/FcTitle.vue +69 -0
  13. package/src/components/FetchConfig.vue +415 -0
  14. package/src/components/FieldInput.vue +371 -0
  15. package/src/components/FnConfig.vue +315 -0
  16. package/src/components/FnEditor.vue +327 -0
  17. package/src/components/FnInput.vue +103 -0
  18. package/src/components/FormLabel.vue +47 -0
  19. package/src/components/HtmlEditor.vue +125 -0
  20. package/src/components/JsonPreview.vue +146 -0
  21. package/src/components/OptionsTextInput.vue +151 -0
  22. package/src/components/PropsInput.vue +72 -0
  23. package/src/components/Required.vue +75 -0
  24. package/src/components/Row.vue +26 -0
  25. package/src/components/SignaturePad.vue +176 -0
  26. package/src/components/Struct.vue +153 -0
  27. package/src/components/StructEditor.vue +121 -0
  28. package/src/components/StructTree.vue +209 -0
  29. package/src/components/TableOptions.vue +164 -0
  30. package/src/components/TreeOptions.vue +167 -0
  31. package/src/components/TypeSelect.vue +144 -0
  32. package/src/components/Validate.vue +302 -0
  33. package/src/components/ValueInput.vue +89 -0
  34. package/src/components/Warning.vue +46 -0
  35. package/src/components/ai/AiPanel.vue +1122 -0
  36. package/src/components/ai/MarkdownRenderer.vue +548 -0
  37. package/src/components/language/LanguageConfig.vue +174 -0
  38. package/src/components/language/LanguageInput.vue +191 -0
  39. package/src/components/style/BackgroundInput.vue +315 -0
  40. package/src/components/style/BorderInput.vue +242 -0
  41. package/src/components/style/BoxSizeInput.vue +166 -0
  42. package/src/components/style/BoxSpaceInput.vue +269 -0
  43. package/src/components/style/ColorInput.vue +90 -0
  44. package/src/components/style/ConfigItem.vue +118 -0
  45. package/src/components/style/FontInput.vue +197 -0
  46. package/src/components/style/PositionInput.vue +146 -0
  47. package/src/components/style/RadiusInput.vue +164 -0
  48. package/src/components/style/ShadowContent.vue +335 -0
  49. package/src/components/style/ShadowInput.vue +91 -0
  50. package/src/components/style/SizeInput.vue +118 -0
  51. package/src/components/style/StyleConfig.vue +307 -0
  52. package/src/components/table/Table.vue +252 -0
  53. package/src/components/table/TableView.vue +1058 -0
  54. package/src/components/tableForm/TableForm.vue +471 -0
  55. package/src/components/tableForm/TableFormColumnView.vue +103 -0
  56. package/src/components/tableForm/TableFormView.vue +46 -0
  57. package/src/components/tree/FcTree.vue +713 -0
  58. package/src/components/tree/FcTreeNode.vue +216 -0
  59. package/src/config/base/field.js +43 -0
  60. package/src/config/base/form.js +132 -0
  61. package/src/config/base/style.js +26 -0
  62. package/src/config/base/validate.js +15 -0
  63. package/src/config/index.js +70 -0
  64. package/src/config/menu.js +24 -0
  65. package/src/config/rule/alert.js +45 -0
  66. package/src/config/rule/button.js +49 -0
  67. package/src/config/rule/card.js +40 -0
  68. package/src/config/rule/cascader.js +121 -0
  69. package/src/config/rule/checkbox.js +68 -0
  70. package/src/config/rule/col.js +86 -0
  71. package/src/config/rule/collapse.js +30 -0
  72. package/src/config/rule/collapseItem.js +36 -0
  73. package/src/config/rule/color.js +53 -0
  74. package/src/config/rule/date.js +66 -0
  75. package/src/config/rule/dateRange.js +60 -0
  76. package/src/config/rule/divider.js +31 -0
  77. package/src/config/rule/editor.js +31 -0
  78. package/src/config/rule/group.js +86 -0
  79. package/src/config/rule/html.js +43 -0
  80. package/src/config/rule/image.js +32 -0
  81. package/src/config/rule/input.js +62 -0
  82. package/src/config/rule/number.js +49 -0
  83. package/src/config/rule/password.js +52 -0
  84. package/src/config/rule/radio.js +43 -0
  85. package/src/config/rule/rate.js +44 -0
  86. package/src/config/rule/row.js +46 -0
  87. package/src/config/rule/select.js +70 -0
  88. package/src/config/rule/signaturePad.js +59 -0
  89. package/src/config/rule/slider.js +53 -0
  90. package/src/config/rule/space.js +44 -0
  91. package/src/config/rule/subForm.js +47 -0
  92. package/src/config/rule/switch.js +46 -0
  93. package/src/config/rule/tabPane.js +29 -0
  94. package/src/config/rule/table.js +37 -0
  95. package/src/config/rule/tableForm.js +115 -0
  96. package/src/config/rule/tableFormColumn.js +55 -0
  97. package/src/config/rule/tabs.js +38 -0
  98. package/src/config/rule/tag.js +69 -0
  99. package/src/config/rule/text.js +41 -0
  100. package/src/config/rule/textarea.js +63 -0
  101. package/src/config/rule/time.js +58 -0
  102. package/src/config/rule/timeRange.js +49 -0
  103. package/src/config/rule/title.js +37 -0
  104. package/src/config/rule/transfer.js +59 -0
  105. package/src/config/rule/tree.js +70 -0
  106. package/src/config/rule/treeSelect.js +77 -0
  107. package/src/config/rule/upload.js +107 -0
  108. package/src/form/index.js +19 -0
  109. package/src/index.js +173 -0
  110. package/src/locale/en.js +981 -0
  111. package/src/locale/zh-cn.js +983 -0
  112. package/src/style/fonts/fc-icons.woff +0 -0
  113. package/src/style/icon.css +1052 -0
  114. package/src/style/index.css +836 -0
  115. package/src/utils/form.js +9 -0
  116. package/src/utils/highlight/highlight.min.js +307 -0
  117. package/src/utils/highlight/javascript.min.js +80 -0
  118. package/src/utils/highlight/style.css +1 -0
  119. package/src/utils/highlight/xml.min.js +29 -0
  120. package/src/utils/hintStubs.js +120 -0
  121. package/src/utils/index.js +544 -0
  122. package/src/utils/jsonDiff.js +173 -0
  123. package/src/utils/locale.js +23 -0
  124. package/src/utils/message.js +19 -0
  125. package/src/utils/template.js +105 -0
  126. package/types/index.d.ts +575 -0
@@ -0,0 +1,2569 @@
1
+ <template>
2
+ <el-container class="_fc-designer" :style="height ? `height:${dragHeight};flex:0;` : ''" @dragenter="handleDragenter" @dragleave="handleDragleave" @drop="handleDrop">
3
+ <el-main>
4
+ <el-container style="height: 100%;" :key="locale && locale.name">
5
+ <el-aside class="_fc-l-menu" v-show="!hiddenLeft" width="40px" v-if="false !== getConfig('showMenuBar')">
6
+ <el-tooltip
7
+ effect="dark"
8
+ :content="t('designer.comList')"
9
+ placement="right"
10
+ :hide-after="0"
11
+ >
12
+ <div class="_fc-l-menu-item" :class="{active: activeModule === 'base'}"
13
+ @click="activeModule = 'base'">
14
+ <i class="fc-icon icon-menu"></i>
15
+ </div>
16
+ </el-tooltip>
17
+ <el-tooltip
18
+ v-if="getConfig('showLanguage', true)"
19
+ effect="dark"
20
+ :content="t('language.name')"
21
+ placement="right"
22
+ :hide-after="0"
23
+ >
24
+ <div class="_fc-l-menu-item" :class="{active: activeModule === 'language'}"
25
+ @click="activeModule = 'language'">
26
+ <i class="fc-icon icon-language"></i>
27
+ </div>
28
+ </el-tooltip>
29
+ <el-tooltip
30
+ v-if="getConfig('showJsonPreview', true)"
31
+ effect="dark"
32
+ content="JSON"
33
+ placement="right"
34
+ :hide-after="0"
35
+ >
36
+ <div class="_fc-l-menu-item" :class="{active: activeModule === 'json'}"
37
+ @click="activeModule = 'json'">
38
+ <i class="fc-icon icon-script"></i>
39
+ </div>
40
+ </el-tooltip>
41
+ <el-tooltip
42
+ v-if="getConfig('showAi', true)"
43
+ effect="dark"
44
+ :content="t('ai.name')"
45
+ placement="right"
46
+ :hide-after="0"
47
+ >
48
+ <div class="_fc-l-menu-item" :class="{ active: activeModule === 'ai' }" @click="activeModule = 'ai'">
49
+ <i class="fc-icon icon-ai bright"></i>
50
+ </div>
51
+ </el-tooltip>
52
+ </el-aside>
53
+ <el-aside class="_fc-l" v-if="!hiddenLeft" :width="activeModule === 'language' || activeModule === 'ai' ? '450px' : '266px'">
54
+ <div class="_fc-l-close" @click="hiddenLeft = true"><i class="fc-icon icon-arrow"></i></div>
55
+ <FcAiPanel v-show="activeModule === 'ai'"></FcAiPanel>
56
+ <LanguageConfig v-if="activeModule === 'language'"></LanguageConfig>
57
+ <JsonPreview v-if="activeModule === 'json'"></JsonPreview>
58
+ <el-container style="height: 100%;" v-if="activeModule === 'base'">
59
+ <el-header height="40px" class="_fc-l-tabs">
60
+ <div class="_fc-l-tab" :class="{active: activeMenuTab==='menu'}"
61
+ @click="activeMenuTab='menu'"> {{ t('menu.component') }}
62
+ </div>
63
+ <div class="_fc-l-tab" :class="{active: activeMenuTab==='tree'}"
64
+ @click="activeMenuTab='tree'"> {{ t('menu.tree') }}
65
+ </div>
66
+ </el-header>
67
+ <el-main v-show="activeMenuTab === 'menu'">
68
+ <template v-for="(item, index) in menuList">
69
+ <div class="_fc-l-group" :key="index"
70
+ v-if="hiddenMenu.indexOf(item.name) === -1">
71
+ <h4 class="_fc-l-title" @click="item.hidden = !item.hidden">
72
+ {{ t('menu.' + item.name) || item.title }}
73
+ <i class="fc-icon icon-arrow" :class="{down: !item.hidden}"/>
74
+ </h4>
75
+ <fcDraggable :group="{name:'default', pull:'clone', put:false}" :sort="false"
76
+ itemKey="name"
77
+ class="_fc-l-list"
78
+ :list="item.list" v-show="!item.hidden">
79
+ <template #item="{element}">
80
+ <div class="_fc-l-item" v-if="hiddenItem.indexOf(element.name) === -1"
81
+ @click="clickMenu(element)">
82
+ <div class="_fc-l-icon">
83
+ <i class="fc-icon" :class="element.icon || 'icon-input'"></i>
84
+ </div>
85
+ <span class="_fc-l-name">{{
86
+ t('com.' + element.name + '.name') || element.label
87
+ }}</span>
88
+ </div>
89
+ </template>
90
+ </fcDraggable>
91
+ </div>
92
+ </template>
93
+ </el-main>
94
+ <el-main v-if="activeMenuTab === 'tree'">
95
+ <StructTree ref="treeRef">
96
+ <template #default="{ node, data }">
97
+ <div class="_fc-tree-node" :class="{active: activeRule === data.rule}">
98
+ <div class="_fc-tree-label">
99
+ <i class="fc-icon"
100
+ :class="(data.rule._menu && data.rule._menu.icon) || 'icon-cell'"></i>
101
+ <span>{{
102
+ (data.rule?.__fc__?.refRule?.__$title?.value || data.rule.title || '').trim() || (data.rule.props && data.rule.props.label) || t('com.' + (data.rule._menu && data.rule._menu.name) + '.name') || (data.rule._menu && data.rule._menu.label) || data.rule.type
103
+ }}</span>
104
+ </div>
105
+ <div class="_fc-tree-more" @click.stop v-if="!data.slot">
106
+ <el-dropdown trigger="click" size="default">
107
+ <i class="fc-icon icon-more"></i>
108
+ <template #dropdown>
109
+ <el-dropdown-menu>
110
+ <el-dropdown-item v-if="data.rule._fc_drag_tag !== '_'" key="1"
111
+ @click="toolHandle(data.rule ,'copy')">
112
+ {{ t('props.copy') }}
113
+ </el-dropdown-item>
114
+ <el-dropdown-item
115
+ v-if="data.rule._menu && data.rule._menu.children && data.rule._fc_drag_tag !== '_'"
116
+ key="2"
117
+ @click="toolHandle(data.rule, 'addChild')">
118
+ {{ t('form.appendChild') }}
119
+ </el-dropdown-item>
120
+ <el-dropdown-item key="3"
121
+ @click="toolHandle(data.rule, 'delete')">
122
+ {{ t('props.delete') }}
123
+ </el-dropdown-item>
124
+ </el-dropdown-menu>
125
+ </template>
126
+ </el-dropdown>
127
+ </div>
128
+ </div>
129
+ </template>
130
+ </StructTree>
131
+ </el-main>
132
+ </el-container>
133
+ </el-aside>
134
+ <el-container class="_fc-m">
135
+ <el-header class="_fc-m-tools" height="45">
136
+ <div class="_fc-m-tools-l">
137
+ <template v-if="!inputForm.state">
138
+ <template v-if="getConfig('showDevice') !== false">
139
+ <div class="devices">
140
+ <i class="fc-icon icon-pc" :class="{active: device === 'pc'}"
141
+ @click="setDevice('pc')"></i>
142
+ <i class="fc-icon icon-pad" :class="{active: device === 'pad'}"
143
+ @click="setDevice('pad')"></i>
144
+ <i class="fc-icon icon-mobile" :class="{active: device === 'mobile'}"
145
+ @click="setDevice('mobile')"></i>
146
+ </div>
147
+ <div class="line"></div>
148
+ </template>
149
+ <div>
150
+ <i class="fc-icon icon-pre-step"
151
+ :class="{disabled: !operation.list[operation.idx - 1]}"
152
+ @click="prevOperationRecord"></i>
153
+ <i class="fc-icon icon-next-step"
154
+ :class="{disabled: !operation.list[operation.idx + 1]}"
155
+ @click="nextOperationRecord"></i>
156
+ </div>
157
+ </template>
158
+ </div>
159
+ <div class="_fc-m-tools-r">
160
+ <template v-if="!inputForm.state">
161
+ <slot name="handle"></slot>
162
+ <el-button v-if="getConfig('showSaveBtn', false)" type="success" plain size="small"
163
+ @click="handleSave"><i class="fc-icon icon-save-online"></i> {{
164
+ t('props.save')
165
+ }}
166
+ </el-button>
167
+ <el-button v-if="false !== getConfig('showPreviewBtn')" type="primary" plain size="small"
168
+ @click="openPreview"><i class="fc-icon icon-preview"></i> {{
169
+ t('props.preview')
170
+ }}
171
+ </el-button>
172
+ <el-popconfirm
173
+ :title="t('designer.clearWarn')"
174
+ width="200px"
175
+ :confirm-button-text="t('props.clear')"
176
+ :cancel-button-text="t('props.cancel')"
177
+ @confirm="clearDragRule">
178
+ <template #reference>
179
+ <el-button type="danger" plain size="small"><i
180
+ class="fc-icon icon-delete"></i>{{ t('props.clear') }}
181
+ </el-button>
182
+ </template>
183
+ </el-popconfirm>
184
+ <el-dropdown trigger="click" size="default" v-if="handle && handle.length">
185
+ <el-button class="_fd-m-extend" plain size="small">
186
+ <i class="fc-icon icon-more"></i>
187
+ </el-button>
188
+ <template #dropdown>
189
+ <el-dropdown-menu>
190
+ <el-dropdown-item v-for="item in handle" @click.stop="triggerHandle(item)">
191
+ <div>{{ item.label }}</div>
192
+ </el-dropdown-item>
193
+ </el-dropdown-menu>
194
+ </template>
195
+ </el-dropdown>
196
+
197
+ </template>
198
+ <template v-if="getConfig('showInputData', true)">
199
+ <div class="line"></div>
200
+ <div class="_fd-input-btn">
201
+ <el-switch size="default" :model-value="inputForm.state" inline-prompt @update:model-value="openInputData">
202
+ <template #active-action>
203
+ <i class="fc-icon icon-edit2" style="font-size: 12px;color:#fff;"></i>
204
+ </template>
205
+ <template #inactive-action>
206
+ <i class="fc-icon icon-edit2" style="font-size: 12px;color:#333;"></i>
207
+ </template>
208
+ </el-switch>
209
+ </div>
210
+ </template>
211
+ </div>
212
+ </el-header>
213
+ <el-main class="_fc-m-con">
214
+ <a :key="activeRule ? activeRule._fc_id : ''" style="background-image: url(data:image/png;base64,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) !important;background-repeat: no-repeat !important;background-size: cover !important;background-position: center !important;position: absolute !important;overflow: hidden !important;left: 50% !important;width: 160px!important;right: 0 !important;top: auto !important;bottom: 9px !important;display: block !important;height: 17px !important;text-align: center !important;opacity: 1 !important;visibility: visible !important;margin: 0 0 0 -80px !important;padding: 0 !important;" target="_blank" href="https://form-create.com/"></a>
215
+ <div class="_fc-m-drag" :class="device"
216
+ ref="dragCon"
217
+ :style="{'--fc-drag-empty': `'${t('designer.dragEmpty')}'`,'--fc-child-empty': `'${t('designer.childEmpty')}'`}">
218
+ <slot name="header"></slot>
219
+ <div class="_fc-m-input" v-if="inputForm.state">
220
+ <ViewForm :key="inputForm.key" :rule="inputForm.rule" :option="inputForm.option"
221
+ :locale="locale?.name"
222
+ v-model:api="inputForm.api" :disabled="false"></ViewForm>
223
+ </div>
224
+ <DragForm v-else :rule="dragForm.rule" :option="formOptions"
225
+ :locale="locale?.name"
226
+ v-model:api="dragForm.api"></DragForm>
227
+ </div>
228
+ <div class="_fc-m-input-handle" v-if="inputForm.state">
229
+ <el-button plain @click="inputClear()">{{ t('props.clear') }}</el-button>
230
+ <el-button plain @click="inputReset()">{{ t('props.reset') }}</el-button>
231
+ <el-button type="primary" plain @click="inputSave()">{{ t('props.save') }}</el-button>
232
+ </div>
233
+ </el-main>
234
+ </el-container>
235
+ <el-aside class="_fc-r" width="320px" v-show="!hiddenRight" v-if="!config || config.showConfig !== false">
236
+ <div class="_fc-r-close" @click="hiddenRight = true"><i class="fc-icon icon-arrow"></i></div>
237
+ <el-container style="height: 100%;">
238
+ <el-header height="40px" class="_fc-r-tabs">
239
+ <div class="_fc-r-tab" :class="{active: activeTab==='props'}"
240
+ v-if="!!activeRule || customForm.isShow || (config && config.showFormConfig === false)"
241
+ @click="activeTab='props'"> {{ t('designer.component') }}
242
+ </div>
243
+ <div class="_fc-r-tab" v-if="!config || config.showFormConfig !== false"
244
+ :class="{active: activeTab==='form' && (!!activeRule || customForm.isShow)}"
245
+ @click="activeTab='form'">{{ t('designer.form') }}
246
+ </div>
247
+ </el-header>
248
+ <el-main class="_fc-r-tab-form" v-show="activeTab==='form'"
249
+ v-if="!config || config.showFormConfig !== false">
250
+ <DragForm :rule="form.rule" :option="form.option"
251
+ :modelValue="form.value" @change="formOptChange"
252
+ v-model:api="form.api" @mounted="formMounted">
253
+ <template #title="scope">
254
+ <FormLabel :rule="scope.rule"></FormLabel>
255
+ </template>
256
+ </DragForm>
257
+ </el-main>
258
+ <el-main class="_fc-r-tab-props" v-show="activeTab==='props'"
259
+ :key="activeRule ? activeRule._fc_id: (customForm.config ? customForm.key : '')">
260
+ <div class="_fc-r-tools-close" @click="clearActiveRule">
261
+ <i class="fc-icon icon-add2"></i>
262
+ </div>
263
+ <template
264
+ v-if="activeRule || (customForm.config && (customForm.config.name || customForm.config.label))">
265
+ <p class="_fc-r-title">{{ t('designer.type') }}</p>
266
+ <TypeSelect :disabled="activePermission.switchType === false"></TypeSelect>
267
+ <template
268
+ v-if="activePermission.name !== false && (activeRule && activeRule._menu.aide !== true && config.showComponentName !== false)">
269
+ <p class="_fc-r-title">
270
+ <Warning :tooltip="t('warning.name')">
271
+ {{ t('designer.name') }}
272
+ </Warning>
273
+ </p>
274
+ <el-input size="small" class="_fc-r-name-input"
275
+ v-model.trim="activeRule.name"
276
+ @change="changeName"
277
+ :readonly="getConfig('nameReadonly') !== false">
278
+ <template #suffix>
279
+ <i class="fc-icon icon-group" @click="copyName"></i>
280
+ </template>
281
+ <template #append>
282
+ <i class="fc-icon icon-auto" @click="updateName"></i>
283
+ </template>
284
+ </el-input>
285
+ </template>
286
+ <template v-if="activeRule">
287
+ <ConfigItem :label="t('props.hide')">
288
+ <el-switch size="small" :modelValue="activeRule._hidden" @update:modelValue="toolHidden(activeRule)"></el-switch>
289
+ </ConfigItem>
290
+ </template>
291
+ </template>
292
+ <div class="_fc-r-config" :style="{'grid-template-areas': configFormOrderStyle}">
293
+ <div style="grid-area: base;">
294
+ <el-divider v-if="baseForm.isShow">{{ t('designer.rule') }}</el-divider>
295
+ <DragForm v-show="baseForm.isShow" v-model:api="baseForm.api"
296
+ :rule="baseForm.rule"
297
+ :option="baseForm.options"
298
+ :modelValue="baseForm.value"
299
+ @change="baseChange">
300
+ <template #title="scope">
301
+ <template v-if="scope.rule.warning">
302
+ <Warning :tooltip="scope.rule.warning">
303
+ {{ scope.rule.title }}
304
+ </Warning>
305
+ </template>
306
+ <template v-else>
307
+ {{scope.rule.title}}
308
+ </template>
309
+ </template>
310
+ </DragForm>
311
+ </div>
312
+ <div style="grid-area: props;">
313
+ <el-divider v-if="propsForm.isShow">{{ t('designer.props') }}
314
+ <PropsInput
315
+ v-if="activeRule && getConfig('showCustomProps', true)"></PropsInput>
316
+ </el-divider>
317
+ <DragForm v-show="propsForm.isShow" v-model:api="propsForm.api"
318
+ :rule="propsForm.rule"
319
+ :option="propsForm.options"
320
+ :modelValue="propsForm.value"
321
+ @change="propChange" @removeField="propRemoveField">
322
+ <template #title="scope">
323
+ <FormLabel :rule="scope.rule"></FormLabel>
324
+ </template>
325
+ </DragForm>
326
+ <el-divider v-if="customForm.isShow && customForm.propsShow">
327
+ {{ t('designer.props') }}
328
+ </el-divider>
329
+ <DragForm v-if="customForm.isShow && customForm.propsShow"
330
+ v-model:api="customForm.api"
331
+ :rule="customForm.rule"
332
+ :option="customForm.options" :key="customForm.key"
333
+ @change="customFormChange"></DragForm>
334
+ </div>
335
+ <div style="grid-area: style;">
336
+ <el-divider v-if="styleForm.isShow" id="_fd-config-style">{{
337
+ t('designer.style')
338
+ }}
339
+ </el-divider>
340
+ <DragForm v-show="styleForm.isShow" :rule="styleForm.rule"
341
+ :option="styleForm.options"
342
+ :modelValue="styleForm.value"
343
+ @change="styleChange" v-model:api="styleForm.api"></DragForm>
344
+ </div>
345
+ <div style="grid-area: event;">
346
+ <el-divider
347
+ v-if="eventShow">
348
+ {{ t('designer.event') }}
349
+ </el-divider>
350
+ <EventConfig
351
+ v-if="eventShow"
352
+ :event-name="(activeRule && activeRule._menu.event) || []"
353
+ :component-name="(activeRule && activeRule._menu.name) || ''"
354
+ :model-value="(activeRule && activeRule._on) || {}"
355
+ @update:modelValue="changeEvent"></EventConfig>
356
+ </div>
357
+ <div v-if="activeRule" style="grid-area: validate;">
358
+ <el-divider v-if="validateForm.isShow">{{
359
+ t('designer.validate')
360
+ }}
361
+ </el-divider>
362
+ <DragForm v-if="validateForm.isShow" v-model:api="validateForm.api"
363
+ :rule="validateForm.rule"
364
+ :option="validateForm.options"
365
+ :modelValue="validateForm.value"
366
+ @change="validateChange"
367
+ :key="activeRule._fc_id"></DragForm>
368
+ </div>
369
+ </div>
370
+ </el-main>
371
+ </el-container>
372
+ </el-aside>
373
+ <div class="_fc-l-open" v-if="hiddenLeft" @click="hiddenLeft = false"><i class="fc-icon icon-arrow"></i></div>
374
+ <div class="_fc-r-open" v-if="hiddenRight" @click="hiddenRight = false"><i class="fc-icon icon-arrow"></i></div>
375
+ <el-dialog v-model="preview.state" width="80%" class="_fd-preview-dialog" append-to-body>
376
+ <el-tabs class="_fd-preview-tabs" v-model="previewStatus">
377
+ <el-tab-pane :label="t('form.formMode')" name="form"></el-tab-pane>
378
+ <el-tab-pane :label="t('form.componentMode')" name="component"></el-tab-pane>
379
+ <el-tab-pane :label="t('form.htmlMode')" name="html"></el-tab-pane>
380
+ </el-tabs>
381
+ <div class="_fd-preview-copy" v-if="['component', 'html'].indexOf(previewStatus) > -1"
382
+ @click="copyCode">
383
+ <i class="fc-icon icon-copy"></i>
384
+ </div>
385
+ <template v-if="previewStatus === 'form'">
386
+ <ViewForm :rule="preview.rule" :option="preview.option" v-model:api="preview.api"
387
+ @submit="previewSubmit"
388
+ @reset="previewReset"
389
+ :locale="locale?.name"
390
+ v-if="preview.state">
391
+ <template v-for="(_, name) in $slots" #[name]="scope">
392
+ <slot :name="name" v-bind="scope ?? {}"/>
393
+ </template>
394
+ </ViewForm>
395
+ </template>
396
+ <pre class="_fd-preview-code" ref="previewCode" v-else-if="previewStatus === 'component'"><code v-html="preview.component"></code></pre>
397
+ <pre class="_fd-preview-code" ref="previewCode" v-else><code v-html="preview.html"></code></pre>
398
+ </el-dialog>
399
+ </el-container>
400
+ </el-main>
401
+ </el-container>
402
+ </template>
403
+
404
+ <style>
405
+
406
+ </style>
407
+
408
+ <script>
409
+ import form from '../config/base/form';
410
+ import field from '../config/base/field';
411
+ import style from '../config/base/style';
412
+ import validate from '../config/base/validate';
413
+ import {deepCopy} from '@form-create/utils/lib/deepextend';
414
+ import is, {hasProperty} from '@form-create/utils/lib/type';
415
+ import {lower} from '@form-create/utils/lib/tocase';
416
+ import toArray from '@form-create/utils/lib/toarray';
417
+ import Mitt from '@form-create/utils/lib/mitt';
418
+ import ruleList, {defaultDrag} from '../config';
419
+ import fcDraggable from 'vuedraggable/src/vuedraggable';
420
+ import menus from '../config/menu';
421
+ import {
422
+ copyTextToClipboard,
423
+ formTemplate,
424
+ formTemplateV3,
425
+ getFormRuleDescription,
426
+ getRuleDescription,
427
+ getRuleTree,
428
+ htmlTemplate,
429
+ isNull,
430
+ throttle,
431
+ uniqueArray,
432
+ upper,
433
+ useLocale,
434
+ } from '../utils/index';
435
+ import viewForm, {designerForm} from '../utils/form';
436
+ import {t as globalT} from '../utils/locale';
437
+ import EventConfig from './EventConfig.vue';
438
+ import {
439
+ computed,
440
+ defineComponent,
441
+ getCurrentInstance,
442
+ markRaw,
443
+ nextTick,
444
+ provide,
445
+ reactive,
446
+ ref,
447
+ toRef,
448
+ toRefs,
449
+ watch
450
+ } from 'vue';
451
+ import uniqueId from '@form-create/utils/lib/unique';
452
+ import debounce from '@form-create/utils/lib/debounce';
453
+ import errorMessage from '../utils/message';
454
+ import hljs from '../utils/highlight/highlight.min';
455
+ import xml from '../utils/highlight/xml.min';
456
+ import javascript from '../utils/highlight/javascript.min';
457
+ import TypeSelect from './TypeSelect.vue';
458
+ import PropsInput from './PropsInput.vue';
459
+ import LanguageConfig from './language/LanguageConfig.vue';
460
+ import FcAiPanel from './ai/AiPanel.vue';
461
+ import JsonPreview from './JsonPreview.vue';
462
+ import Warning from './Warning.vue';
463
+ import FormLabel from './FormLabel.vue';
464
+ import StructTree from './StructTree.vue';
465
+ import mergeProps from '@form-create/utils/lib/mergeprops';
466
+ import ConfigItem from './style/ConfigItem.vue';
467
+
468
+ hljs.registerLanguage('javascript', javascript);
469
+ hljs.registerLanguage('xml', xml);
470
+
471
+ function flatOptionValue(value, prefix, data) {
472
+ if (data == null || typeof data !== 'object' || Array.isArray(data)) {
473
+ if (prefix) {
474
+ value[prefix] = data;
475
+ value['formCreate' + upper(prefix)] = data;
476
+ }
477
+ return;
478
+ }
479
+ if (prefix) {
480
+ value['formCreate' + upper(prefix)] = data;
481
+ }
482
+ Object.keys(data).forEach(k => {
483
+ flatOptionValue(value, prefix ? `${prefix}>${k}` : k, data[k]);
484
+ });
485
+ }
486
+
487
+ export default defineComponent({
488
+ name: 'FcDesigner',
489
+ components: {
490
+ ConfigItem,
491
+ Warning,
492
+ StructTree,
493
+ FormLabel,
494
+ JsonPreview,
495
+ FcAiPanel,
496
+ LanguageConfig,
497
+ PropsInput,
498
+ TypeSelect,
499
+ fcDraggable,
500
+ DragForm: designerForm.$form(),
501
+ ViewForm: viewForm.$form(),
502
+ EventConfig,
503
+ },
504
+ props: {
505
+ menu: Array,
506
+ height: [String, Number],
507
+ config: {
508
+ type: Object,
509
+ default: () => ({})
510
+ },
511
+ mask: {
512
+ type: Boolean,
513
+ default: undefined,
514
+ },
515
+ locale: Object,
516
+ handle: Array
517
+ },
518
+ emits: ['active', 'create', 'copy', 'delete', 'drag', 'inputData', 'save', 'clear', 'copyRule', 'pasteRule', 'sortUp', 'sortDown', 'changeDevice', 'previewSubmit', 'previewReset', 'changeField'],
519
+ setup(props) {
520
+ const {menu, height, mask, locale, handle} = toRefs(props);
521
+ const vm = getCurrentInstance();
522
+ const fcx = reactive({active: null});
523
+ provide('fcx', fcx);
524
+ provide('designer', vm);
525
+
526
+ const configRef = toRef(props, 'config', {});
527
+ const baseRule = toRef(configRef.value, 'baseRule', null);
528
+ const componentRule = toRef(configRef.value, 'componentRule', {});
529
+ const validateRule = toRef(configRef.value, 'validateRule', null);
530
+ const formRule = toRef(configRef.value, 'formRule', null);
531
+ const updateDefaultRule = toRef(configRef.value, 'updateDefaultRule', {});
532
+
533
+ const dragHeight = computed(() => {
534
+ const h = height.value;
535
+ if (!h) return '100%';
536
+ return is.Number(h) ? `${h}px` : h;
537
+ })
538
+ const fieldReadonly = computed(() => {
539
+ return configRef.value.fieldReadonly !== false;
540
+ })
541
+ const hiddenMenu = computed(() => {
542
+ return configRef.value.hiddenMenu || [];
543
+ });
544
+ const hiddenItem = computed(() => {
545
+ return configRef.value.hiddenItem || [];
546
+ });
547
+ const hiddenDragMenu = computed(() => {
548
+ return configRef.value.hiddenDragMenu === true;
549
+ });
550
+ const hiddenDragBtn = computed(() => {
551
+ return configRef.value.hiddenDragBtn === true;
552
+ });
553
+ const configFormOrderStyle = computed(() => {
554
+ const def = ['base', 'props', 'style', 'event', 'validate'];
555
+ let sort = configRef.value.configFormOrder ? [...configRef.value.configFormOrder] : [];
556
+ let value = [];
557
+ if (!sort.length) {
558
+ value = def;
559
+ } else {
560
+ [...sort, ...def].forEach(v => {
561
+ if (value.indexOf(v) === -1 && def.indexOf(v) > -1) {
562
+ value.push(v);
563
+ }
564
+ });
565
+ }
566
+ return value.map(v => {
567
+ return `"${v}"`;
568
+ }).join(' ');
569
+ });
570
+ let _t = globalT;
571
+ if (locale.value) {
572
+ _t = useLocale(locale).t
573
+ }
574
+ const t = (...args) => _t(...args);
575
+
576
+ const analysisMenuProps = (props, ...args) => {
577
+ if (Array.isArray(props)) {
578
+ return deepCopy(props);
579
+ } else if (typeof props === 'function') {
580
+ return props(...args);
581
+ } else {
582
+ return [];
583
+ }
584
+ };
585
+
586
+ const tidyRuleConfig = (orgRule, configRule, ...args) => {
587
+ const org = analysisMenuProps(orgRule, ...args);
588
+ if (configRule) {
589
+ if (is.Function(configRule)) {
590
+ return configRule(...args);
591
+ }
592
+ if (configRule.rule) {
593
+ let rule = configRule.rule(...args);
594
+ if (configRule.prepend) {
595
+ rule = [...rule, ...org];
596
+ } else if (configRule.append) {
597
+ rule = [...org, ...rule];
598
+ }
599
+ return rule;
600
+ }
601
+ }
602
+ return org;
603
+ }
604
+
605
+ const defaultMenus = ref(deepCopy(menus));
606
+
607
+ const data = reactive({
608
+ cacheProps: {},
609
+ operation: {
610
+ idx: -1,
611
+ list: []
612
+ },
613
+ hiddenLeft: false,
614
+ hiddenRight: false,
615
+ moveRule: null,
616
+ addRule: null,
617
+ added: null,
618
+ bus: Mitt(),
619
+ device: configRef.value?.device || 'pc',
620
+ activeModule: 'base',
621
+ activeTab: 'form',
622
+ activeMenuTab: 'menu',
623
+ activeRule: null,
624
+ activePermission: {},
625
+ children: ref([]),
626
+ treeInfo: [],
627
+ dragRuleList: {},
628
+ eventShow: false,
629
+ unloadStatus: false,
630
+ previewStatus: 'form',
631
+ t,
632
+ preview: {
633
+ state: false,
634
+ rule: [],
635
+ option: {},
636
+ api: {},
637
+ },
638
+ inputForm: {
639
+ state: false,
640
+ rule: [],
641
+ option: {},
642
+ api: {},
643
+ data: {},
644
+ key: '',
645
+ },
646
+ dragForm: ref({
647
+ rule: [],
648
+ api: {},
649
+ }),
650
+ formOptions: {},
651
+ oldOptionsKeys: [],
652
+ form: {
653
+ rule: tidyRuleConfig(form, formRule.value, {t}),
654
+ api: {},
655
+ option: {
656
+ global: {
657
+ input: configRef.value?.updateConfigOnBlur !== false ? {
658
+ modelEmit: 'blur'
659
+ } : {},
660
+ select: {
661
+ props: {
662
+ clearable: true,
663
+ }
664
+ }
665
+ },
666
+ form: {
667
+ labelPosition: 'top',
668
+ size: 'small'
669
+ },
670
+ submitBtn: false
671
+ },
672
+ value: {
673
+ form: {},
674
+ submitBtn: false
675
+ }
676
+ },
677
+ baseForm: {
678
+ isShow: false,
679
+ rule: tidyRuleConfig(field, baseRule.value, {t}),
680
+ api: {},
681
+ value: {},
682
+ options: {
683
+ global: {
684
+ input: configRef.value?.updateConfigOnBlur !== false ? {
685
+ modelEmit: 'blur'
686
+ } : {},
687
+ },
688
+ form: {
689
+ labelPosition: 'top',
690
+ size: 'small'
691
+ },
692
+ submitBtn: false,
693
+ mounted: (fapi) => {
694
+ fapi.activeRule = data.activeRule;
695
+ fapi.setValue(fapi.options.formData || {});
696
+ }
697
+ }
698
+ },
699
+ styleForm: {
700
+ isShow: false,
701
+ rule: style({t}),
702
+ api: {},
703
+ value: {},
704
+ options: {
705
+ form: {
706
+ labelPosition: 'left',
707
+ size: 'small',
708
+ },
709
+ submitBtn: false,
710
+ mounted: (fapi) => {
711
+ fapi.activeRule = data.activeRule;
712
+ fapi.setValue(fapi.options.formData || {});
713
+ }
714
+ }
715
+ },
716
+ validateForm: {
717
+ isShow: false,
718
+ rule: tidyRuleConfig(validate, validateRule.value, {t}),
719
+ api: {},
720
+ value: [],
721
+ options: {
722
+ global: {
723
+ input: configRef.value?.updateConfigOnBlur !== false ? {
724
+ modelEmit: 'blur'
725
+ } : {},
726
+ },
727
+ form: {
728
+ labelPosition: 'top',
729
+ size: 'small'
730
+ },
731
+ submitBtn: false,
732
+ mounted: (fapi) => {
733
+ fapi.activeRule = data.activeRule;
734
+ fapi.setValue(fapi.options.formData || {});
735
+ }
736
+ }
737
+ },
738
+ propsForm: {
739
+ isShow: false,
740
+ rule: [],
741
+ api: {},
742
+ value: {},
743
+ options: {
744
+ global: {
745
+ input: configRef.value?.updateConfigOnBlur !== false ? {
746
+ modelEmit: 'blur'
747
+ } : {},
748
+ inputNumber: {
749
+ props: {
750
+ controlsPosition: 'right'
751
+ }
752
+ }
753
+ },
754
+ form: {
755
+ labelPosition: 'top',
756
+ size: 'small'
757
+ },
758
+ submitBtn: false,
759
+ mounted: (fapi) => {
760
+ fapi.activeRule = data.activeRule;
761
+ fapi.setValue(fapi.options.formData || {});
762
+ }
763
+ }
764
+ },
765
+ customForm: {
766
+ isShow: false,
767
+ config: null,
768
+ key: '',
769
+ rule: [],
770
+ api: {},
771
+ options: {
772
+ global: {
773
+ input: configRef.value?.updateConfigOnBlur !== false ? {
774
+ modelEmit: 'blur'
775
+ } : {},
776
+ },
777
+ form: {
778
+ labelPosition: 'top',
779
+ size: 'small'
780
+ },
781
+ submitBtn: false,
782
+ }
783
+ },
784
+ });
785
+
786
+ watch(() => data.preview.state, function (n) {
787
+ if (!n) {
788
+ nextTick(() => {
789
+ data.previewStatus = 'form';
790
+ data.preview.rule = data.preview.option = null;
791
+ });
792
+ }
793
+ })
794
+
795
+ let unWatchActiveRule = null;
796
+
797
+ const propFieldDeepFn = (field, call) => {
798
+ if (field[10] !== '>') {
799
+ field = field.replace('formCreate', '');
800
+ if (!field) return;
801
+ field = lower(field);
802
+ } else {
803
+ field = field.replace('formCreate>', '');
804
+ }
805
+ const split = field.split('>');
806
+ const lastField = split.pop();
807
+ let source = data.activeRule;
808
+ split.forEach((id, idx) => {
809
+ if (!idx) {
810
+ id = lower(id);
811
+ }
812
+ if (!source[id]) {
813
+ source[id] = {};
814
+ }
815
+ source = source[id];
816
+ });
817
+ call({source, field: lastField});
818
+ }
819
+
820
+ watch(() => locale.value, (n) => {
821
+ _t = n ? useLocale(locale).t : globalT;
822
+ methods.clearActiveRule();
823
+ const formVal = data.form.api.formData && data.form.api.formData();
824
+ const baseFormVal = data.baseForm.api.formData && data.baseForm.api.formData();
825
+ const validateFormVal = data.validateForm.api.formData && data.validateForm.api.formData();
826
+ data.validateForm.rule = tidyRuleConfig(validate, validateRule.value, {t});
827
+ data.baseForm.rule = tidyRuleConfig(field, baseRule.value, {t});
828
+ data.form.rule = tidyRuleConfig(form, formRule.value, {t});
829
+ data.cacheProps = {};
830
+ const rule = data.activeRule;
831
+ let propsVal = null;
832
+ if (rule) {
833
+ propsVal = data.propsForm.api.formData && data.propsForm.api.formData();
834
+ data.propsForm.rule = data.cacheProps[rule._fc_id] = methods.getPropsRule(rule);
835
+ }
836
+ nextTick(() => {
837
+ formVal && data.form.api.setValue(formVal);
838
+ baseFormVal && data.baseForm.api.setValue(baseFormVal);
839
+ validateFormVal && data.validateForm.api.setValue(validateFormVal);
840
+ propsVal && data.propsForm.api.setValue(propsVal);
841
+ });
842
+ });
843
+
844
+ const menuList = computed(() => {
845
+ return Array.isArray(menu.value) ? menu.value : defaultMenus.value;
846
+ });
847
+
848
+ const initMenuDefaultCollapse = () => {
849
+ const collapseMenu = configRef.value?.collapseMenu || [];
850
+ if (Array.isArray(collapseMenu)) {
851
+ menuList.value.forEach(item => {
852
+ if (!item) return;
853
+ if (item.hidden === undefined && collapseMenu.indexOf(item.name) > -1) {
854
+ item.hidden = true;
855
+ }
856
+ });
857
+ }
858
+ };
859
+
860
+ const methods = {
861
+ setDevice(device) {
862
+ data.device = device;
863
+ vm.emit('changeDevice', device);
864
+ },
865
+ unWatchActiveRule() {
866
+ unWatchActiveRule && unWatchActiveRule();
867
+ unWatchActiveRule = null;
868
+ },
869
+ watchActiveRule() {
870
+ methods.unWatchActiveRule();
871
+ unWatchActiveRule = watch(
872
+ () => data.activeRule,
873
+ function (n, o) {
874
+ if (n) {
875
+ methods.updateRuleFormData();
876
+ if (n === o) {
877
+ methods.addOperationRecordThrottle(methods.getJson());
878
+ }
879
+ }
880
+ },
881
+ {deep: true, flush: 'post'}
882
+ );
883
+ },
884
+ makeChildren(children) {
885
+ return reactive({children}).children;
886
+ },
887
+ addMenu(config) {
888
+ if (!config.name) return;
889
+ if (!config.list) {
890
+ config.list = [];
891
+ }
892
+ let flag = true;
893
+ menuList.value.forEach((v, i) => {
894
+ if (v.name === config.name) {
895
+ menuList.value[i] = config
896
+ flag = false;
897
+ }
898
+ });
899
+ if (flag) {
900
+ if (config.before) {
901
+ menuList.value.unshift(config);
902
+ } else {
903
+ menuList.value.push(config);
904
+ }
905
+ }
906
+ },
907
+ removeMenu(name) {
908
+ [...menuList.value].forEach((v, i) => {
909
+ if (v.name === name) {
910
+ menuList.value.splice(i, 1);
911
+ }
912
+ });
913
+ },
914
+ setMenuItem(name, list) {
915
+ menuList.value.forEach(v => {
916
+ if (v.name === name) {
917
+ v.list = list;
918
+ }
919
+ });
920
+ },
921
+ appendMenuItem(name, item) {
922
+ menuList.value.forEach(v => {
923
+ if (v.name === name) {
924
+ if (!v.list) {
925
+ v.list = [];
926
+ }
927
+ v.list.push(...(Array.isArray(item) ? item : [item]));
928
+ }
929
+ });
930
+ },
931
+ removeMenuItem(item) {
932
+ menuList.value.forEach(v => {
933
+ let idx;
934
+ if (is.String(item)) {
935
+ [...v.list].forEach((menu, idx) => {
936
+ if (menu.name === item) {
937
+ v.list.splice(idx, 1);
938
+ }
939
+ });
940
+ } else {
941
+ if ((idx = v.list.indexOf(item)) > -1) {
942
+ v.list.splice(idx, 1);
943
+ }
944
+ }
945
+ });
946
+ },
947
+ addComponent(component) {
948
+ if (Array.isArray(component)) {
949
+ component.forEach(v => {
950
+ data.dragRuleList[v.name] = v;
951
+ v.menu && methods.appendMenuItem(v.menu, v);
952
+ });
953
+ } else {
954
+ data.dragRuleList[component.name] = component;
955
+ component.menu && methods.appendMenuItem(component.menu, component);
956
+ }
957
+ },
958
+ openInputData(state) {
959
+ data.inputForm.state = state === undefined ? !data.inputForm.state : !!state;
960
+ if (data.inputForm.state) {
961
+ data.inputForm.rule = designerForm.parseJson(methods.getJson());
962
+ data.inputForm.option = designerForm.parseJson(methods.getOptionsJson());
963
+ data.inputForm.option.formData = deepCopy(data.inputForm.data);
964
+ data.inputForm.option.appendValue = false;
965
+ data.inputForm.option.submitBtn.show = false;
966
+ data.inputForm.option.resetBtn.show = false;
967
+ methods.clearActiveRule();
968
+ }
969
+ },
970
+ inputSave() {
971
+ const formData = data.inputForm.api.formData();
972
+ Object.keys(formData).forEach(k => {
973
+ if (isNull(formData[k])) {
974
+ delete formData[k];
975
+ }
976
+ });
977
+ const flag = JSON.stringify(data.inputForm.data) !== JSON.stringify(formData);
978
+ data.inputForm.data = formData;
979
+ data.inputForm.state = false;
980
+ vm.emit('inputData', formData);
981
+ flag && methods.addOperationRecord();
982
+ },
983
+ inputClear() {
984
+ methods.inputReset({});
985
+ },
986
+ inputReset(formData) {
987
+ data.inputForm.rule = designerForm.parseJson(methods.getJson());
988
+ data.inputForm.option.formData = formData || deepCopy(data.inputForm.data);
989
+ data.inputForm.key = uniqueId();
990
+ },
991
+ setFormData(formData) {
992
+ data.inputForm.data = formData || {};
993
+ },
994
+ getFormData() {
995
+ return data.inputForm.data;
996
+ },
997
+ getParent(rule) {
998
+ let parent = rule.__fc__.parent.rule;
999
+ const config = parent._menu;
1000
+ if (config && config.inside) {
1001
+ rule = parent;
1002
+ parent = parent.__fc__.parent.rule;
1003
+ }
1004
+ return {root: parent, parent: rule};
1005
+ },
1006
+ copyName() {
1007
+ copyTextToClipboard(data.activeRule.name);
1008
+ },
1009
+ updateName() {
1010
+ data.activeRule.name = 'ref_' + uniqueId();
1011
+ },
1012
+ changeName() {
1013
+ if (!data.activeRule.name) {
1014
+ methods.updateName();
1015
+ }
1016
+ },
1017
+ makeDrag(group, tag, children, on, slot) {
1018
+ return {
1019
+ type: 'DragBox',
1020
+ wrap: {
1021
+ show: false
1022
+ },
1023
+ col: {
1024
+ show: false
1025
+ },
1026
+ inject: true,
1027
+ props: {
1028
+ rule: {
1029
+ props: {
1030
+ tag: 'el-col',
1031
+ group: {
1032
+ name: group === true ? 'default' : group,
1033
+ put(...args) {
1034
+ return methods.dragPut(...args);
1035
+ }
1036
+ },
1037
+ swapThreshold: tag === 'draggable' ? 0.25 : 0.8,
1038
+ ghostClass: 'ghost',
1039
+ animation: 150,
1040
+ handle: '._fd-drag-btn',
1041
+ emptyInsertThreshold: 0,
1042
+ direction: 'auto',
1043
+ itemKey: '_fc_id',
1044
+ }
1045
+ },
1046
+ tag,
1047
+ },
1048
+ children,
1049
+ slot,
1050
+ on
1051
+ };
1052
+ },
1053
+ clearDragRule() {
1054
+ methods.setRule([]);
1055
+ methods.addOperationRecord();
1056
+ data.unloadStatus = false;
1057
+ vm.emit('clear');
1058
+ },
1059
+ makeDragRule(children) {
1060
+ return methods.makeChildren([methods.makeDrag(true, 'draggable', children, {
1061
+ add: (inject, evt) => methods.dragAdd(children, evt),
1062
+ end: (inject, evt) => methods.dragEnd(children, evt),
1063
+ start: (inject, evt) => methods.dragStart(children, evt),
1064
+ unchoose: (inject, evt) => methods.dragUnchoose(children, evt),
1065
+ })]);
1066
+ },
1067
+ handleSave() {
1068
+ vm.emit('save', {
1069
+ rule: methods.getJson(),
1070
+ options: methods.getOptionsJson(),
1071
+ });
1072
+ },
1073
+ previewSubmit(...args) {
1074
+ vm.emit('previewSubmit', ...args);
1075
+ },
1076
+ previewReset(...args) {
1077
+ vm.emit('previewReset', ...args);
1078
+ },
1079
+ openPreview() {
1080
+ data.preview.state = true;
1081
+ const rule = methods.getJson();
1082
+ const options = methods.getOptionsJson();
1083
+ data.preview.rule = designerForm.parseJson(rule);
1084
+ data.preview.option = designerForm.parseJson(options);
1085
+ const useV2 = methods.getConfig('useTemplate', false);
1086
+ data.preview.component = hljs.highlight(
1087
+ useV2 ? formTemplate(rule, options) : formTemplateV3(rule, options),
1088
+ {language: 'xml'}
1089
+ ).value
1090
+ data.preview.html = hljs.highlight(
1091
+ htmlTemplate(rule, options),
1092
+ {language: 'xml'}
1093
+ ).value
1094
+ },
1095
+ copyCode() {
1096
+ copyTextToClipboard(this.$refs.previewCode.innerText);
1097
+ },
1098
+ getHtml() {
1099
+ return htmlTemplate(methods.getJson(), methods.getOptionsJson());
1100
+ },
1101
+ getRule() {
1102
+ return methods.parseRule(deepCopy(data.dragForm.rule[0].children));
1103
+ },
1104
+ getJson() {
1105
+ return designerForm.toJson(methods.getRule());
1106
+ },
1107
+ getOption() {
1108
+ const options = deepCopy(data.formOptions);
1109
+ ['onReset', 'onSubmit', 'beforeSubmit', 'onCreated', 'onMounted', 'onBeforeUnmount', 'onReload', 'onChange', 'beforeFetch'].forEach(key => {
1110
+ delete options[key];
1111
+ });
1112
+ Object.keys(options._event || {}).forEach(k => {
1113
+ if (options._event[k]) {
1114
+ options[k] = options._event[k];
1115
+ }
1116
+ });
1117
+ delete options._event;
1118
+ options.submitBtn = options._submitBtn;
1119
+ options.resetBtn = options._resetBtn;
1120
+ if (!options.resetBtn.innerText) {
1121
+ options.resetBtn.innerText = t('props.reset');
1122
+ }
1123
+ if (!options.submitBtn.innerText) {
1124
+ options.submitBtn.innerText = t('props.submit');
1125
+ }
1126
+ const formData = deepCopy(data.inputForm.data);
1127
+ if (Object.keys(formData).length > 0) {
1128
+ options.formData = formData;
1129
+ }
1130
+ if (options.language) {
1131
+ Object.keys(options.language).forEach(k => {
1132
+ Object.keys(options.language[k]).forEach(id => {
1133
+ if (!options.language[k][id]) {
1134
+ delete options.language[k][id];
1135
+ }
1136
+ })
1137
+ if (!Object.keys(options.language[k]).length) {
1138
+ delete options.language[k];
1139
+ }
1140
+ })
1141
+ }
1142
+ Object.keys(options).forEach(k => {
1143
+ Object.keys(options[k]).forEach(key => {
1144
+ if (isNull(options[k][key]) || (typeof options[k][key] === 'object' && !Object.keys(options[k][key]).length)) {
1145
+ delete options[k][key];
1146
+ }
1147
+ });
1148
+ if (is.Object(options[k]) && !Object.keys(options[k]).length) {
1149
+ delete options[k];
1150
+ }
1151
+ })
1152
+ delete options._submitBtn;
1153
+ delete options._resetBtn;
1154
+ return options;
1155
+ },
1156
+ getOptions() {
1157
+ return methods.getOption();
1158
+ },
1159
+ getOptionsJson() {
1160
+ return designerForm.toJson([methods.getOption()]).slice(1).slice(0, -1);
1161
+ },
1162
+ setRule(rules) {
1163
+ if (!rules) {
1164
+ rules = [];
1165
+ }
1166
+ data.children = ref(methods.loadRule(is.String(rules) ? designerForm.parseJson(rules) : deepCopy(rules)));
1167
+ methods.clearActiveRule();
1168
+ data.dragForm.rule = methods.makeDragRule(methods.makeChildren(data.children));
1169
+ methods.updateTree();
1170
+ },
1171
+ setBaseRuleConfig(rule, append) {
1172
+ baseRule.value = {rule, append};
1173
+ data.baseForm.rule = tidyRuleConfig(field, baseRule.value, {t});
1174
+ },
1175
+ setComponentRuleConfig(name, rule, append) {
1176
+ componentRule.value[name] = {rule, append};
1177
+ data.cacheProps = {};
1178
+ const activeRule = data.activeRule;
1179
+ if (activeRule) {
1180
+ const propsVal = data.propsForm.api.formData && data.propsForm.api.formData();
1181
+ data.propsForm.rule = data.cacheProps[activeRule._fc_id] =
1182
+ tidyRuleConfig(activeRule._menu.props, componentRule.value && componentRule.value[activeRule._menu.name], activeRule, {
1183
+ t,
1184
+ api: data.dragForm.api
1185
+ });
1186
+ nextTick(() => {
1187
+ propsVal && data.propsForm.api.setValue(propsVal);
1188
+ });
1189
+ }
1190
+ },
1191
+ setValidateRuleConfig(rule, append) {
1192
+ validateRule.value = {rule, append};
1193
+ data.validateForm.rule = tidyRuleConfig(field, validateRule.value, {t});
1194
+ },
1195
+ setFormRuleConfig(rule, append) {
1196
+ formRule.value = {rule, append};
1197
+ data.form.rule = tidyRuleConfig(field, formRule.value, {t});
1198
+ },
1199
+ clearActiveRule() {
1200
+ data.activeRule = null;
1201
+ data.activePermission = {};
1202
+ data.customForm.config = null;
1203
+ data.activeTab = 'form';
1204
+ fcx.active = '';
1205
+ },
1206
+ setOption(opt) {
1207
+ const defOptions = deepCopy(methods.getConfig('formOptions', {}));
1208
+ const defForm = defOptions.form || {};
1209
+ delete defOptions.form;
1210
+ let options = {...defOptions, ...is.String(opt) ? JSON.parse(opt) : deepCopy(opt || {})};
1211
+ options.form = {
1212
+ inline: false,
1213
+ hideRequiredAsterisk: false,
1214
+ labelPosition: 'right',
1215
+ size: 'default',
1216
+ labelWidth: '125px',
1217
+ ...defForm,
1218
+ ...options.form || {}
1219
+ };
1220
+ options._event = {
1221
+ onReset: options.onReset || '',
1222
+ onSubmit: options.onSubmit || '',
1223
+ onCreated: options.onCreated || '',
1224
+ onMounted: options.onMounted || '',
1225
+ onBeforeUnmount: options.onBeforeUnmount || '',
1226
+ beforeSubmit: options.beforeSubmit || '',
1227
+ onReload: options.onReload || '',
1228
+ onChange: options.onChange || '',
1229
+ beforeFetch: options.beforeFetch || '',
1230
+ }
1231
+ if (!hasProperty(options, 'language')) {
1232
+ options.language = {};
1233
+ }
1234
+ options._resetBtn = typeof options.resetBtn === 'object' ? options.resetBtn : {show: options.resetBtn === true};
1235
+ options._submitBtn = typeof options.submitBtn === 'object' ? options.submitBtn : {show: options.submitBtn !== false};
1236
+ options.submitBtn = options.resetBtn = false;
1237
+ data.inputForm.data = options.formData || {};
1238
+ data.oldOptionsKeys = Object.keys(data.form.value);
1239
+ delete options.formData;
1240
+ data.formOptions = options;
1241
+ methods.updateOptionsValue();
1242
+ },
1243
+ setOptions(opt) {
1244
+ methods.setOption(opt);
1245
+ },
1246
+ mergeOptions(options) {
1247
+ ['form'].forEach((key) => {
1248
+ if (options[key]) {
1249
+ data.formOptions[key] = {...(data.formOptions[key] || {}), ...options[key]};
1250
+ }
1251
+ });
1252
+ if(options.style && (!data.formOptions.style || data.formOptions.style.indexOf(options.style) === -1)) {
1253
+ data.formOptions.style = (data.formOptions.style || '') + '\n' + options.style;
1254
+ }
1255
+ if (!data.formOptions.language) {
1256
+ data.formOptions.language = {};
1257
+ }
1258
+ if (options.language) {
1259
+ Object.keys(options.language).forEach((key) => {
1260
+ data.formOptions.language[key] = {...(data.formOptions.language[key] || {}), ...options.language[key]};
1261
+ })
1262
+ }
1263
+ if(options.languageKey) {
1264
+ const language = methods.getConfig('localeOptions', [
1265
+ {value: 'zh-cn', label: '简体中文'},
1266
+ {value: 'en', label: 'English'},
1267
+ ]);
1268
+ options.languageKey.forEach((key) => {
1269
+ language.forEach(({value}) => {
1270
+ if(!data.formOptions.language[value]){
1271
+ data.formOptions.language[value] = {};
1272
+ }
1273
+ if(!data.formOptions.language[value][key]){
1274
+ data.formOptions.language[value][key] = '';
1275
+ }
1276
+ })
1277
+ })
1278
+ }
1279
+ },
1280
+ updateOptionsValue() {
1281
+ const old = {};
1282
+ data.oldOptionsKeys.forEach(k => {
1283
+ old[k] = undefined;
1284
+ });
1285
+ const value = {...old, ...data.formOptions.form};
1286
+ Object.keys(data.formOptions).forEach(key => {
1287
+ const item = data.formOptions[key];
1288
+ value['>' + key] = item;
1289
+ value['formCreate' + upper(key)] = item;
1290
+ if (item != null && typeof item === 'object' && !Array.isArray(item)) {
1291
+ flatOptionValue(value, key, item);
1292
+ }
1293
+ });
1294
+ data.form.value = value;
1295
+ },
1296
+ loadRule(rules, pConfig, template) {
1297
+ const loadRule = [];
1298
+ rules.forEach(rule => {
1299
+ if (is.String(rule)) {
1300
+ return loadRule.push(rule);
1301
+ }
1302
+ let config = data.dragRuleList[rule._fc_drag_tag] || data.dragRuleList[rule.type];
1303
+ if (!config) {
1304
+ config = defaultDrag(rule);
1305
+ rule._fc_drag_tag = '_';
1306
+ }
1307
+ if (template) {
1308
+ rule._fc_template = template;
1309
+ }
1310
+ config && config.loadRule && config.loadRule(rule);
1311
+ rule.children = methods.loadRule(rule.children || [], config, template);
1312
+ const alias = ['control', 'computed', 'on', 'hidden', 'display', 'hook'];
1313
+ alias.forEach(k => {
1314
+ if (rule[k] != null) {
1315
+ rule['_' + k] = rule[k];
1316
+ delete rule[k];
1317
+ }
1318
+ });
1319
+ if (config) {
1320
+ const slot = rule.slot;
1321
+ let _config;
1322
+ if (pConfig && pConfig.slot && slot && slot !== 'default') {
1323
+ _config = methods.getSlotConfig(pConfig, slot, config)
1324
+ }
1325
+ delete rule.slot;
1326
+ rule = methods.makeRule(_config || config, rule);
1327
+ if (slot) {
1328
+ rule.slot = slot;
1329
+ }
1330
+ }
1331
+ loadRule.push(rule);
1332
+ });
1333
+ return loadRule;
1334
+ },
1335
+ parseRule(children, pSlot) {
1336
+ return [...children].reduce((initial, rule) => {
1337
+ let slot = pSlot;
1338
+ if (is.String(rule)) {
1339
+ initial.push(rule);
1340
+ return initial;
1341
+ } else if (rule.type === 'DragBox') {
1342
+ initial.push(...methods.parseRule(rule.children, slot || rule.slot));
1343
+ return initial;
1344
+ } else if (rule.type === 'DragTool') {
1345
+ slot = rule.slot || pSlot;
1346
+ rule = rule.children[0];
1347
+ if (is.String(rule)) {
1348
+ initial.push(rule);
1349
+ return initial;
1350
+ }
1351
+ if (rule.type === 'DragBox') {
1352
+ initial.push(...methods.parseRule(rule.children, slot || rule.slot));
1353
+ return initial;
1354
+ }
1355
+ }
1356
+ if (!rule) return initial;
1357
+ rule = {...rule};
1358
+ if (slot && slot !== 'default') {
1359
+ rule.slot = slot;
1360
+ }
1361
+ if (rule.children && rule.children.length) {
1362
+ rule.children = methods.parseRule(rule.children);
1363
+ }
1364
+
1365
+ delete rule.key;
1366
+ delete rule.component;
1367
+ if (rule._menu) {
1368
+ rule._menu.parseRule && rule._menu.parseRule(rule);
1369
+ delete rule._menu;
1370
+ }
1371
+ if (rule._fc_drag_tag === '_') {
1372
+ delete rule._fc_drag_tag;
1373
+ }
1374
+ const alias = ['control', 'computed', 'on', 'hidden', 'display', 'hook'];
1375
+ alias.forEach(k => {
1376
+ if (rule['_' + k] != null && rule['_' + k] !== '') {
1377
+ rule[k] = rule['_' + k];
1378
+ }
1379
+ delete rule['_' + k];
1380
+ });
1381
+ if (!rule.slot) {
1382
+ delete rule.slot;
1383
+ }
1384
+ rule.props && Object.keys(rule.props).forEach(k => {
1385
+ const v = rule.props[k];
1386
+ if (isNull(v)) {
1387
+ delete rule.props[k];
1388
+ }
1389
+ });
1390
+ Object.keys(rule).filter(k => k.indexOf('__') === 0 || (Array.isArray(rule[k]) && rule[k].length === 0) || (is.Object(rule[k]) && Object.keys(rule[k]).length === 0)).forEach(k => {
1391
+ delete rule[k];
1392
+ });
1393
+ initial.push(rule);
1394
+ return initial;
1395
+ }, []);
1396
+ },
1397
+ fields() {
1398
+ return data.dragForm.api.all().map(rule => rule.field).filter(id => !!id);
1399
+ },
1400
+ formMounted() {
1401
+ data.form.api.hidden(true, configRef.value.hiddenFormConfig || []);
1402
+ data.form.api.disabled(true, configRef.value.disabledFormConfig || []);
1403
+ },
1404
+ baseChange(field, value, _, fapi) {
1405
+ methods.handleChange('', field, value, _, fapi);
1406
+ },
1407
+ formOptChange(field, value) {
1408
+ data.form.value[field] = value;
1409
+ if (field.indexOf('formCreate') === 0) {
1410
+ field = '>' + lower(field.replace('formCreate', ''));
1411
+ }
1412
+ if (field.indexOf('>') === -1) {
1413
+ field = 'form>' + field;
1414
+ }
1415
+ let source = data.formOptions;
1416
+ const split = field.split('>');
1417
+ const lastField = split.pop();
1418
+ split.forEach(k => {
1419
+ if (k) {
1420
+ if (!source[k]) {
1421
+ source[k] = {};
1422
+ }
1423
+ source = source[k];
1424
+ }
1425
+ });
1426
+ source[lastField] = value;
1427
+ },
1428
+ propRemoveField(field, _, fapi) {
1429
+ if (data.activeRule && fapi[data.activeRule._fc_id] === data.activeRule) {
1430
+ methods.unWatchActiveRule();
1431
+ const org = field;
1432
+ data.dragForm.api.sync(data.activeRule);
1433
+ if (field.indexOf('__') !== 0) {
1434
+ if (field === 'formCreateChild') {
1435
+ delete data.activeRule.children[0];
1436
+ } else if (field.indexOf('formCreate') === 0 || field.indexOf('>') > 0) {
1437
+ if (field.indexOf('formCreate') < 0) {
1438
+ field = 'props>' + field;
1439
+ }
1440
+ propFieldDeepFn(field, ({source, field}) => {
1441
+ delete source[field];
1442
+ })
1443
+ } else {
1444
+ delete data.activeRule.props[field];
1445
+ }
1446
+ }
1447
+ methods.watchActiveRule();
1448
+ data.activeRule._menu?.watch?.[org]?.({
1449
+ field: org,
1450
+ value: undefined,
1451
+ api: fapi,
1452
+ rule: data.activeRule,
1453
+ ctx: vm,
1454
+ });
1455
+ }
1456
+ },
1457
+ propChange(field, value, _, fapi) {
1458
+ methods.handleChange('props', field, value, _, fapi);
1459
+ },
1460
+ styleChange(field, value, _, fapi) {
1461
+ if (data.customForm.config) {
1462
+ return data.customForm.config.style.change(field, value);
1463
+ }
1464
+ methods.handleChange('', field, value, _, fapi);
1465
+ },
1466
+ handleChange(key, field, value, _, fapi) {
1467
+ if (data.activeRule && fapi[data.activeRule._fc_id] === data.activeRule) {
1468
+ methods.unWatchActiveRule();
1469
+ const org = field;
1470
+ if (field.indexOf('__') !== 0) {
1471
+ if (field === 'formCreateChild') {
1472
+ data.activeRule.children[0] = value;
1473
+ } else if (field.indexOf('formCreate') === 0 || field.indexOf('>') > 0) {
1474
+ if (field.indexOf('formCreate') < 0) {
1475
+ field = (key ? key + '>' : '') + field;
1476
+ }
1477
+ propFieldDeepFn(field, ({source, field}) => {
1478
+ if (isNull(value)) {
1479
+ delete source[field];
1480
+ } else {
1481
+ source[field] = value;
1482
+ }
1483
+ })
1484
+ } else {
1485
+ if (key && isNull(value)) {
1486
+ delete data.activeRule[key][field];
1487
+ } else {
1488
+ (key ? data.activeRule[key] : data.activeRule)[field] = value;
1489
+ }
1490
+ }
1491
+ }
1492
+ methods.watchActiveRule();
1493
+ data.activeRule._menu?.watch?.[org]?.({
1494
+ field: org,
1495
+ value,
1496
+ api: fapi,
1497
+ rule: data.activeRule,
1498
+ ctx: vm,
1499
+ });
1500
+ methods.addOperationRecordThrottle(methods.getJson());
1501
+ }
1502
+ },
1503
+ validateChange(field, value, _, fapi) {
1504
+ if (!data.activeRule || data.validateForm.api[data.activeRule._fc_id] !== data.activeRule) return;
1505
+ methods.handleChange('', field, value, _, fapi);
1506
+ data.dragForm.api.refreshValidate();
1507
+ data.dragForm.api.nextTick(() => {
1508
+ data.dragForm.api.clearValidateState(data.activeRule.__fc__.id);
1509
+ });
1510
+ },
1511
+ triggerActive(rule) {
1512
+ let dragTool;
1513
+ if (is.String(rule)) {
1514
+ rule = methods.findRule(rule);
1515
+ }
1516
+ if (!rule) {
1517
+ return;
1518
+ }
1519
+ if (rule._menu.inside) {
1520
+ dragTool = rule.children[0];
1521
+ } else {
1522
+ dragTool = rule.__fc__.parent.rule;
1523
+ }
1524
+ if (dragTool && dragTool.type === 'DragTool') {
1525
+ const el = data.dragForm.api.el(dragTool.__fc__.id);
1526
+ if (el) {
1527
+ fcx.active = el.id;
1528
+ vm.emit('active', rule);
1529
+ methods.toolActive(rule);
1530
+ }
1531
+ }
1532
+ },
1533
+ customFormChange(field, value) {
1534
+ if (data.customForm.config) {
1535
+ data.customForm.config.change(field, value);
1536
+ }
1537
+ },
1538
+ customActive(config) {
1539
+ data.baseForm.isShow = false;
1540
+ data.propsForm.isShow = false;
1541
+ data.eventShow = false;
1542
+ data.validateForm.isShow = false;
1543
+ data.styleForm.isShow = !!config.style && methods.getConfig('showStyleForm') !== false;
1544
+ data.activeRule = null;
1545
+ data.activePermission = {};
1546
+ fcx.active = '';
1547
+
1548
+ data.customForm.config = config;
1549
+ data.customForm.isShow = true;
1550
+ data.customForm.propsShow = config.props && methods.getConfig('showPropsForm') !== false;
1551
+ data.customForm.key = uniqueId();
1552
+ data.customForm.rule = data.customForm.propsShow ? config.props({t}) : [];
1553
+ data.customForm.options.formData = config.formData;
1554
+ if (config.style) {
1555
+ data.styleForm.value = config.style.formData || {};
1556
+ }
1557
+ nextTick(() => {
1558
+ data.activeTab = 'props';
1559
+ });
1560
+ },
1561
+ getPropsRule(rule) {
1562
+ let propsRule = tidyRuleConfig(rule._menu.props, componentRule.value && componentRule.value[rule._menu.name], rule, {
1563
+ t,
1564
+ api: data.dragForm.api
1565
+ });
1566
+ if (componentRule.value && componentRule.value.default) {
1567
+ const def = componentRule.value.default;
1568
+ propsRule = tidyRuleConfig(() => propsRule, is.Function(def) ? {
1569
+ rule: def,
1570
+ append: true
1571
+ } : def, rule, {
1572
+ t,
1573
+ api: data.dragForm.api
1574
+ });
1575
+ }
1576
+ return propsRule;
1577
+ },
1578
+ findRule(id) {
1579
+ let rule = undefined;
1580
+ const findTree = children => {
1581
+ children.forEach(item => {
1582
+ if ([item.rule.field, item.rule.name, item.rule._fc_id].indexOf(id) > -1) {
1583
+ rule = item.rule;
1584
+ } else if (item.children) {
1585
+ findTree(item.children);
1586
+ }
1587
+ })
1588
+ }
1589
+ findTree(data.treeInfo);
1590
+ return rule;
1591
+ },
1592
+ toolActive(rule) {
1593
+ if (configRef.value.beforeActiveRule && false === configRef.value.beforeActiveRule({rule})) {
1594
+ return;
1595
+ }
1596
+ methods.unWatchActiveRule();
1597
+ data.customForm.isShow = false;
1598
+ data.customForm.config = null;
1599
+ if (data.activeRule) {
1600
+ delete data.propsForm.api[data.activeRule._fc_id];
1601
+ delete data.baseForm.api[data.activeRule._fc_id];
1602
+ delete data.validateForm.api[data.activeRule._fc_id];
1603
+ delete data.styleForm.api[data.activeRule._fc_id];
1604
+ delete data.dragForm.api.activeRule;
1605
+ }
1606
+ const permission = methods.getPermission(rule);
1607
+ data.activeRule = rule;
1608
+ data.activePermission = permission;
1609
+ data.dragForm.api.activeRule = rule;
1610
+
1611
+ nextTick(() => {
1612
+ data.activeTab = 'props';
1613
+ nextTick(() => {
1614
+ data.propsForm.api[data.activeRule._fc_id] = data.activeRule;
1615
+ data.baseForm.api[data.activeRule._fc_id] = data.activeRule;
1616
+ data.validateForm.api[data.activeRule._fc_id] = data.activeRule;
1617
+ data.styleForm.api[data.activeRule._fc_id] = data.activeRule;
1618
+ });
1619
+ });
1620
+ if (!data.cacheProps[rule._fc_id]) {
1621
+ data.cacheProps[rule._fc_id] = methods.getPropsRule(rule);
1622
+ }
1623
+ const hiddenItemConfig = methods.getConfig('hiddenItemConfig', {});
1624
+ const disabledItemConfig = methods.getConfig('disabledItemConfig', {});
1625
+ const hiddenField = uniqueArray([...permission.hiddenConfig || [], ...hiddenItemConfig?.default || [], ...hiddenItemConfig?.[rule._menu.name] || []]);
1626
+ const hiddenBaseField = [...hiddenField, ...rule._menu.hiddenBaseField || []];
1627
+ const disabledField = uniqueArray([...permission.disabledConfig || [], ...disabledItemConfig?.default || [], ...disabledItemConfig?.[rule._menu.name] || []]);
1628
+ data.baseForm.api.disabled(false);
1629
+ data.baseForm.api.hidden(false);
1630
+ nextTick(() => {
1631
+ data.baseForm.api.all().forEach((item) => {
1632
+ if (item.name || item.field) {
1633
+ item.hidden = hiddenBaseField.indexOf(item.name) !== -1 || hiddenBaseField.indexOf(item.field) !== -1;
1634
+ }
1635
+ })
1636
+ data.propsForm.api.hidden(true, hiddenField);
1637
+ if (!methods.getConfig('showControl', true)) {
1638
+ data.baseForm.api.hidden(true, '_control');
1639
+ }
1640
+ });
1641
+ if (disabledField.length) {
1642
+ data.baseForm.api.disabled(true, disabledField);
1643
+ nextTick(() => {
1644
+ data.propsForm.api.disabled(true, disabledField);
1645
+ });
1646
+ }
1647
+ const input = hasProperty(rule, 'field');
1648
+ data.baseForm.isShow = permission.base !== false && input && rule.input !== false && methods.getConfig('showBaseForm') !== false;
1649
+ data.propsForm.isShow = permission.props !== false && data.cacheProps[rule._fc_id].length > 0 && methods.getConfig('showPropsForm') !== false;
1650
+ data.styleForm.isShow = permission.style !== false && rule._menu.style !== false && methods.getConfig('showStyleForm') !== false;
1651
+ data.eventShow = permission.event !== false && rule._menu.event !== false && methods.getConfig('showEventForm') !== false;
1652
+ const showValidateForm = methods.getConfig('showValidateForm');
1653
+ data.validateForm.isShow = permission.validate !== false && ((data.baseForm.isShow && showValidateForm !== false) || showValidateForm === true) && rule._menu.validate !== false;
1654
+ data.propsForm.rule = data.cacheProps[rule._fc_id];
1655
+ if (data.validateForm.isShow) {
1656
+ nextTick(() => {
1657
+ data.validateForm.api.hidden(methods.getConfig('validateOnlyRequired') === true || rule._menu.validate === 'required', ['validate']);
1658
+ })
1659
+ }
1660
+ methods.updateRuleFormData();
1661
+ methods.watchActiveRule();
1662
+ },
1663
+ getConfig(key, def) {
1664
+ return configRef.value ? (hasProperty(configRef.value, key) ? configRef.value[key] : def) : def;
1665
+ },
1666
+ getPermission(rule) {
1667
+ let permission = {};
1668
+ (configRef.value?.componentPermission || []).forEach(item => {
1669
+ let flag = false
1670
+ if (item.field && (Array.isArray(item.field) ? item.field.indexOf(rule.field) > -1 : item.field === rule.field)) {
1671
+ flag = true;
1672
+ } else if (item.name && (Array.isArray(item.name) ? item.name.indexOf(rule.name) > -1 : item.name === rule.name)) {
1673
+ flag = true;
1674
+ } else if (item.id && (Array.isArray(item.id) ? item.id.indexOf(rule._fc_id) > -1 : item.id === rule._fc_id)) {
1675
+ flag = true;
1676
+ } else if (item.tag && (Array.isArray(item.tag) ? item.tag.indexOf(rule._fc_drag_tag) > -1 : item.tag === rule._fc_drag_tag)) {
1677
+ flag = true;
1678
+ }
1679
+ if (flag) {
1680
+ permission = item.permission || {};
1681
+ }
1682
+ })
1683
+ return permission;
1684
+ },
1685
+ updateRuleFormData() {
1686
+ const rule = data.activeRule;
1687
+ let formData = {
1688
+ formCreateChild: '' + rule.children[0],
1689
+ 'formCreateWrap>labelWidth': ''
1690
+ };
1691
+ const appendConfigData = configRef.value.appendConfigData;
1692
+ if (is.Function(appendConfigData)) {
1693
+ formData = {...formData, ...appendConfigData(rule)};
1694
+ } else if (Array.isArray(appendConfigData)) {
1695
+ appendConfigData.forEach(v => {
1696
+ formData[v] = undefined;
1697
+ propFieldDeepFn(v, ({ source, field }) => {
1698
+ formData[v] = source[field];
1699
+ });
1700
+ });
1701
+ }
1702
+ Object.keys(rule).forEach(k => {
1703
+ if (['effect', 'config', 'payload', 'id', 'type', '_menu'].indexOf(k) < 0)
1704
+ formData['formCreate' + upper(k)] = deepCopy(rule[k]);
1705
+ });
1706
+ Object.keys(rule.props).forEach(k => {
1707
+ const item = rule.props[k];
1708
+ formData[k] = deepCopy(item);
1709
+ if (is.Object(item)) {
1710
+ Object.keys(item).forEach(sub => {
1711
+ formData[k + '>' + sub] = deepCopy(item[sub]);
1712
+ });
1713
+ }
1714
+ });
1715
+ ['props', 'effect', 'attrs', 'style', 'wrap'].forEach(name => {
1716
+ rule[name] && (typeof rule[name] === 'object') && Object.keys(rule[name]).forEach(k => {
1717
+ formData['formCreate' + upper(name) + '>' + k] = deepCopy(rule[name][k]);
1718
+ });
1719
+ });
1720
+ const configAttrs = rule._menu.attrs || {};
1721
+ Object.keys(configAttrs).forEach(k => {
1722
+ formData['__' + k] = configAttrs[k]({rule});
1723
+ });
1724
+ data.propsForm.value = formData;
1725
+ data.styleForm.value = {
1726
+ style: rule.style,
1727
+ class: rule.class,
1728
+ id: rule.id,
1729
+ };
1730
+
1731
+ if (data.baseForm.isShow) {
1732
+ data.baseForm.value = {
1733
+ ...formData,
1734
+ field: rule.field,
1735
+ title: rule.title || '',
1736
+ info: rule.info,
1737
+ _control: rule._control,
1738
+ };
1739
+ data.validateForm.value = {
1740
+ validate: rule.validate ? [...rule.validate] : [],
1741
+ $required: formData.formCreate$required
1742
+ };
1743
+ data.dragForm.api.refreshValidate();
1744
+ data.dragForm.api.nextTick(() => {
1745
+ data.dragForm.api.clearValidateState(rule.__fc__.id);
1746
+ });
1747
+ }
1748
+ },
1749
+ dragStart(children) {
1750
+ // console.log('top dragStart')
1751
+ data.moveRule = children;
1752
+ data.added = false;
1753
+ },
1754
+ dragUnchoose(children, evt) {
1755
+ // console.log('top dragUnchoose')
1756
+ data.addRule = {
1757
+ children,
1758
+ oldIndex: evt.oldIndex
1759
+ };
1760
+ },
1761
+ clickMenu(menu) {
1762
+ if (this.checkDragToContainer(menu)) {
1763
+ methods.dragMenu({menu, children: data.children, index: data.children.length});
1764
+ }
1765
+ },
1766
+ checkOnly(menu) {
1767
+ let flag = false;
1768
+ data.dragForm.api.all().forEach(rule => {
1769
+ flag = flag || rule._fc_template === menu.name || (rule._menu && rule._menu.name === menu.name);
1770
+ });
1771
+ if (flag) {
1772
+ errorMessage(data.t('struct.only', {label: t('com.' + menu.name + '.name') || menu.label}));
1773
+ }
1774
+ return flag;
1775
+ },
1776
+ mergeRule(rule, update) {
1777
+ Object.keys(update).forEach(k => {
1778
+ if (k === 'required') {
1779
+ rule.$required = !!update.required;
1780
+ } else if (k === 'disabled') {
1781
+ if (!rule.props) {
1782
+ rule.props = {};
1783
+ }
1784
+ rule.props.disabled = !!update.disabled;
1785
+ } else if (k === 'props') {
1786
+ rule.props = {...(rule.props || {}), ...deepCopy(update[k])};
1787
+ } else {
1788
+ rule[k] = deepCopy(update[k]);
1789
+ }
1790
+ });
1791
+ },
1792
+ dragMenu({menu, children, index, slot}) {
1793
+ if (data.inputForm.state) {
1794
+ return;
1795
+ }
1796
+ if (menu.only && methods.checkOnly(menu)) {
1797
+ return;
1798
+ }
1799
+ methods.handleAddBefore();
1800
+ const dragRule = data.dragRuleList[menu.name];
1801
+ vm.emit('drag', {
1802
+ item: menu, dragRule
1803
+ });
1804
+ const rule = methods.makeRule(data.dragRuleList[dragRule.name]);
1805
+ if (slot) {
1806
+ rule.slot = slot;
1807
+ }
1808
+ children.splice(index, 0, rule);
1809
+ const firstRule = (rule.type === 'DragTool') ? rule.children[0] : rule;
1810
+ methods.handleAddAfter({rule});
1811
+ if (firstRule && methods.getConfig('autoActive', true)) {
1812
+ nextTick(() => {
1813
+ methods.triggerActive(firstRule);
1814
+ });
1815
+ }
1816
+ },
1817
+ replaceField(rule) {
1818
+ const flag = ['array', 'object'].indexOf(rule._menu.subForm) > -1;
1819
+ let temp = methods.parseRule(deepCopy([rule]))[0];
1820
+ const autoResetName = false !== methods.getConfig('autoResetName');
1821
+ if (flag) {
1822
+ temp.field = uniqueId();
1823
+ if (autoResetName) {
1824
+ temp.name = 'ref_' + uniqueId();
1825
+ }
1826
+ }
1827
+ temp = designerForm.toJson(temp);
1828
+ if (flag) {
1829
+ temp = methods.batchReplaceUni(temp);
1830
+ } else {
1831
+ temp = methods.batchReplaceField(temp);
1832
+ if (autoResetName) {
1833
+ temp = methods.batchReplaceName(temp);
1834
+ }
1835
+ }
1836
+ return methods.loadRule([designerForm.parseJson(temp)])[0];
1837
+ },
1838
+ batchReplaceField(json) {
1839
+ const regex = /"field"\s*:\s*"(\w[\w\d]+)"/g;
1840
+ const matches = [];
1841
+ json = json.replace(regex, (match, p1) => {
1842
+ const key = uniqueId();
1843
+ matches.push({old: p1, key: key});
1844
+ return `"field":"${key}"`;
1845
+ });
1846
+ return methods.batchReplaceUni(json);
1847
+ },
1848
+ batchReplaceUni(json) {
1849
+ const regex = /"_fc_id"\s*:\s*"(\w[\w\d]+)"/g;
1850
+ json = json.replace(regex, () => {
1851
+ return `"_fc_id":"id_${uniqueId()}"`;
1852
+ });
1853
+ return json;
1854
+ },
1855
+ batchReplaceName(json) {
1856
+ const regex = /"name"\s*:\s*"ref_(\w[\w\d]+)"/g;
1857
+ json = json.replace(regex, () => {
1858
+ return `"name":"ref_${uniqueId()}"`;
1859
+ });
1860
+ return json;
1861
+ },
1862
+ getTrueRule(rule) {
1863
+ if (!rule) {
1864
+ return;
1865
+ }
1866
+ if (rule._menu) {
1867
+ return rule._menu._get();
1868
+ }
1869
+ if (rule._config) {
1870
+ return rule._config._get();
1871
+ }
1872
+ },
1873
+ checkDragToContainer(menu) {
1874
+ return !menu.allowDragTo || (Array.isArray(menu.allowDragTo) ? menu.allowDragTo.indexOf('draggable') > -1 : menu.allowDragTo === 'draggable');
1875
+ },
1876
+ dragPut(to, from, dragEl) {
1877
+ const toRule = methods.getTrueRule(to.el.__rule__);
1878
+ const _menu = dragEl._underlying_vm_.__fc__ ? (dragEl._underlying_vm_._config || dragEl._underlying_vm_._menu) : dragEl._underlying_vm_;
1879
+ if (!toRule) {
1880
+ return !_menu || this.checkDragToContainer(_menu);
1881
+ }
1882
+ const toMenu = toRule._menu;
1883
+ const _fc_allow_drag = dragEl._fc_allow_drag || {};
1884
+ if (_fc_allow_drag[toRule._fc_id] === undefined) {
1885
+ const _rule = methods.getTrueRule(dragEl._underlying_vm_);
1886
+ _fc_allow_drag[toRule._fc_id] = !(_menu && toMenu && !methods.checkDrag({
1887
+ menu: _menu,
1888
+ toMenu,
1889
+ rule: _rule,
1890
+ toRule
1891
+ }));
1892
+ dragEl._fc_allow_drag = _fc_allow_drag;
1893
+ }
1894
+ return dragEl._fc_allow_drag[toRule._fc_id];
1895
+ },
1896
+ checkDrag({menu, toMenu, rule, toRule}) {
1897
+ if (!methods.checkAllowDrag(menu, toMenu)) {
1898
+ return false;
1899
+ }
1900
+
1901
+ let parentRule = toRule;
1902
+
1903
+ while (parentRule) {
1904
+ parentRule = parentRule?.__fc__?.parent?.rule;
1905
+ if (parentRule && parentRule._menu) {
1906
+ if (!methods.checkAllowDrag(menu, parentRule._menu)) {
1907
+ return false;
1908
+ }
1909
+ }
1910
+ }
1911
+
1912
+ if (toRule.children && toMenu.maxChildren && toMenu.maxChildren <= toRule.children[0]?.children?.length) {
1913
+ return false;
1914
+ }
1915
+ if (menu.checkDrag && false === menu.checkDrag({
1916
+ menu,
1917
+ toMenu,
1918
+ rule,
1919
+ toRule,
1920
+ designer: vm
1921
+ })) {
1922
+ return false;
1923
+ }
1924
+ if (toMenu.checkDrag && false === toMenu.checkDrag({
1925
+ menu,
1926
+ toMenu,
1927
+ rule,
1928
+ toRule,
1929
+ designer: vm
1930
+ })) {
1931
+ return false;
1932
+ }
1933
+ if (configRef.value.checkDrag && false === configRef.value.checkDrag({
1934
+ menu,
1935
+ toMenu,
1936
+ rule,
1937
+ toRule
1938
+ })) {
1939
+ return false;
1940
+ }
1941
+ return true;
1942
+ },
1943
+ checkAllowDrag(from, to) {
1944
+ function checkDragCondition(tmp) {
1945
+ if (Array.isArray(tmp)) {
1946
+ tmp = {item: tmp};
1947
+ }
1948
+ if (toArray(tmp.item).indexOf(from.name) > -1) {
1949
+ return true;
1950
+ }
1951
+ return toArray(tmp.menu).indexOf(from.menu) > -1;
1952
+ }
1953
+
1954
+ const globalAllowDrag = methods.getConfig('allowDrag', {})[to.name];
1955
+ const globalDenyDrag = methods.getConfig('denyDrag', {})[to.name];
1956
+ if (from.allowDragTo && (Array.isArray(from.allowDragTo) ? from.allowDragTo.indexOf(to.name) === -1 : from.allowDragTo !== to.name)) {
1957
+ return false;
1958
+ }
1959
+ if (to.allowDrag && checkDragCondition(to.allowDrag)) {
1960
+ return true;
1961
+ }
1962
+ if (globalAllowDrag && checkDragCondition(globalAllowDrag)) {
1963
+ return true;
1964
+ }
1965
+ if (to.allowDrag || globalAllowDrag) {
1966
+ return false;
1967
+ }
1968
+ if (to.denyDrag && checkDragCondition(to.denyDrag)) {
1969
+ return false;
1970
+ }
1971
+ return !(globalDenyDrag && checkDragCondition(globalDenyDrag));
1972
+ },
1973
+ dragAdd(children, evt, slot) {
1974
+ // console.log('top dragAdd')
1975
+ delete evt.item._fc_allow_drag;
1976
+ const newIndex = evt.newIndex;
1977
+ const menu = evt.item._underlying_vm_ || evt.item.__rule__;
1978
+ data.added = true;
1979
+ if (menu && menu.__fc__) {
1980
+ if (data.addRule) {
1981
+ methods.handleSortBefore();
1982
+ const rule = data.addRule.children.splice(data.addRule.children.indexOf(menu), 1)[0];
1983
+ if (slot) {
1984
+ rule.slot = slot;
1985
+ } else {
1986
+ delete rule.slot;
1987
+ }
1988
+ children.splice(newIndex, 0, rule);
1989
+ methods.handleSortAfter({rule: rule});
1990
+ }
1991
+ } else {
1992
+ methods.dragMenu({menu, children, index: newIndex, slot});
1993
+ }
1994
+ // data.dragForm.api.refresh();
1995
+ },
1996
+ dragEnd(children, {item, newIndex, oldIndex}, slot) {
1997
+ delete item._fc_allow_drag;
1998
+ if (!data.added && !(data.moveRule === children && newIndex === oldIndex)) {
1999
+ methods.handleSortBefore();
2000
+ const rule = data.moveRule.splice(oldIndex, 1);
2001
+ if (slot) {
2002
+ rule.slot = slot;
2003
+ }
2004
+ children.splice(newIndex, 0, rule[0]);
2005
+ methods.handleSortAfter({rule: rule[0]});
2006
+ }
2007
+ data.moveRule = null;
2008
+ data.addRule = null;
2009
+ data.added = false;
2010
+ // data.dragForm.api.refresh();
2011
+ },
2012
+ getSlotConfig(pConfig, slot, config) {
2013
+ let slotConfig = {};
2014
+ (pConfig.slot || []).forEach(item => {
2015
+ if (item.name === slot) {
2016
+ slotConfig = item.config || {};
2017
+ }
2018
+ });
2019
+ return {...config, dragBtn: false, handleBtn: config.children ? ['addChild'] : false, ...slotConfig}
2020
+ },
2021
+ makeRule(config, _rule) {
2022
+ let rule = _rule || config.rule({t});
2023
+ const updateRule = updateDefaultRule.value && updateDefaultRule.value[config.name];
2024
+ if (!_rule && updateRule) {
2025
+ if (typeof updateRule === 'function') {
2026
+ try{
2027
+ updateRule(rule);
2028
+ }catch (e) {
2029
+ console.error(e);
2030
+ }
2031
+ } else {
2032
+ let _rule = deepCopy(updateRule);
2033
+ delete _rule.children;
2034
+ delete _rule.component;
2035
+ rule = mergeProps([rule, _rule]);
2036
+ }
2037
+ }
2038
+ rule._menu = markRaw({...config});
2039
+ rule._menu._get = () => {
2040
+ return rule;
2041
+ }
2042
+ if (!rule._fc_id) {
2043
+ rule._fc_id = 'id_' + uniqueId();
2044
+ }
2045
+ if (!rule.name) {
2046
+ rule.name = 'ref_' + uniqueId();
2047
+ }
2048
+ if (config.component) {
2049
+ rule.component = markRaw(config.component);
2050
+ }
2051
+ if (!rule._computed) {
2052
+ rule._computed = {};
2053
+ }
2054
+ if (!rule.effect) {
2055
+ rule.effect = {};
2056
+ }
2057
+ if (config.input && !rule.field) {
2058
+ rule.field = uniqueId();
2059
+ }
2060
+ if (config.languageKey) {
2061
+ methods.mergeOptions({
2062
+ languageKey: config.languageKey
2063
+ })
2064
+ }
2065
+ if (!hasProperty(rule, 'display')) {
2066
+ rule.display = true;
2067
+ }
2068
+ if (!hasProperty(rule, 'hidden')) {
2069
+ rule.hidden = false;
2070
+ }
2071
+ if (!rule.children) {
2072
+ rule.children = [];
2073
+ }
2074
+ rule._fc_drag_tag = config.name;
2075
+ let only = config.only === true;
2076
+ let drag;
2077
+
2078
+ const children = rule.children || [];
2079
+ if (config.drag) {
2080
+ rule.children = [drag = methods.makeDrag(config.drag, rule._menu ? rule._menu.name : rule.type, children, {
2081
+ end: (inject, evt) => methods.dragEnd(inject.self.children, evt),
2082
+ add: (inject, evt) => methods.dragAdd(inject.self.children, evt),
2083
+ start: (inject, evt) => methods.dragStart(inject.self.children, evt),
2084
+ unchoose: (inject, evt) => methods.dragUnchoose(inject.self.children, evt),
2085
+ })];
2086
+ drag._config = rule._menu;
2087
+ }
2088
+
2089
+ if (config.children && !_rule && !children.length) {
2090
+ for (let i = 0; i < (config.childrenLen || 1); i++) {
2091
+ const child = methods.makeRule(data.dragRuleList[config.children]);
2092
+ (drag || rule).children.push(child);
2093
+ }
2094
+ }
2095
+ const dragMask = mask.value !== undefined ? mask.value !== false : config.mask !== false;
2096
+ if (config.tool === false) {
2097
+ return rule;
2098
+ }
2099
+ if (config.inside) {
2100
+ rule.children = methods.makeChildren([{
2101
+ type: 'DragTool',
2102
+ props: {
2103
+ dragBtn: config.dragBtn !== false,
2104
+ children: config.children,
2105
+ mask: dragMask,
2106
+ hidden: rule._hidden === true || rule._display === false,
2107
+ handleBtn: config.handleBtn,
2108
+ only,
2109
+ },
2110
+ inject: true,
2111
+ on: {
2112
+ delete: ({self}) => {
2113
+ const parent = methods.getParent(self).parent;
2114
+ if (methods.handleRemoveBefore({parent, rule: parent}) !== false) {
2115
+ parent.__fc__.rm();
2116
+ vm.emit('delete', parent);
2117
+ if (data.activeRule === parent) {
2118
+ methods.clearActiveRule();
2119
+ }
2120
+ methods.handleRemoveAfter({rule: parent});
2121
+ }
2122
+ },
2123
+ create: ({self}) => {
2124
+ methods.handleAddBefore();
2125
+ const top = methods.getParent(self);
2126
+ vm.emit('create', top.parent);
2127
+ const rule = methods.makeRule(top.parent._menu);
2128
+ if (top.parent.slot) {
2129
+ rule.slot = top.parent.slot;
2130
+ }
2131
+ top.root.children.splice(top.root.children.indexOf(top.parent) + 1, 0, rule);
2132
+ methods.handleAddAfter({rule: top.parent});
2133
+ },
2134
+ addChild: ({self}) => {
2135
+ methods.handleAddBefore();
2136
+ const top = methods.getParent(self);
2137
+ const config = top.parent._menu;
2138
+ const item = data.dragRuleList[config.children];
2139
+ if (!item) return;
2140
+ const rule = methods.makeRule(item);
2141
+ (!config.drag ? top.parent : top.parent.children[0]).children[0].children.push(rule);
2142
+ methods.handleAddAfter({rule});
2143
+ },
2144
+ copy: ({self}) => {
2145
+ methods.handleCopyBefore();
2146
+ const top = methods.getParent(self);
2147
+ vm.emit('copy', top.parent);
2148
+ const temp = methods.replaceField(top.parent);
2149
+ top.root.children.splice(top.root.children.indexOf(top.parent) + 1, 0, temp);
2150
+ methods.handleCopyAfter({rule: top.parent});
2151
+ },
2152
+ active: ({self}) => {
2153
+ const top = methods.getParent(self);
2154
+ vm.emit('active', top.parent);
2155
+ setTimeout(() => {
2156
+ methods.toolActive(top.parent);
2157
+ }, 10);
2158
+ }
2159
+ },
2160
+ _config: rule._menu,
2161
+ children: rule.children
2162
+ }]);
2163
+ return rule;
2164
+ } else {
2165
+ return {
2166
+ type: 'DragTool',
2167
+ props: {
2168
+ dragBtn: config.dragBtn !== false,
2169
+ children: config.children,
2170
+ mask: dragMask,
2171
+ hidden: rule._hidden === true || rule._display === false,
2172
+ handleBtn: config.handleBtn,
2173
+ only,
2174
+ },
2175
+ inject: true,
2176
+ display: !!rule.display,
2177
+ on: {
2178
+ delete: ({self}) => {
2179
+ if (methods.handleRemoveBefore({parent: self, rule: self.children[0]}) !== false) {
2180
+ vm.emit('delete', self.children[0]);
2181
+ self.__fc__.rm();
2182
+ if (data.activeRule === self.children[0]) {
2183
+ methods.clearActiveRule();
2184
+ }
2185
+ methods.handleRemoveAfter({rule: self.children[0]});
2186
+ }
2187
+ },
2188
+ create: ({self}) => {
2189
+ methods.handleAddBefore();
2190
+ vm.emit('create', self.children[0]);
2191
+ const top = methods.getParent(self);
2192
+ const rule = methods.makeRule(self.children[0]._menu);
2193
+ if (top.parent.slot) {
2194
+ rule.slot = top.parent.slot;
2195
+ }
2196
+ top.root.children.splice(top.root.children.indexOf(top.parent) + 1, 0, rule);
2197
+ methods.handleAddAfter({rule})
2198
+ },
2199
+ addChild: ({self}) => {
2200
+ methods.handleAddBefore();
2201
+ const config = self.children[0]._menu;
2202
+ const item = data.dragRuleList[config.children];
2203
+ if (!item) return;
2204
+ const rule = methods.makeRule(item);
2205
+ (!config.drag ? self : self.children[0]).children[0].children.push(rule);
2206
+ methods.handleAddAfter({rule})
2207
+ },
2208
+ copy: ({self}) => {
2209
+ methods.handleCopyBefore();
2210
+ vm.emit('copy', self.children[0]);
2211
+ const top = methods.getParent(self);
2212
+ const temp = methods.replaceField(self.children[0]);
2213
+ if(self.slot) {
2214
+ temp.slot = self.slot;
2215
+ }
2216
+ top.root.children.splice(top.root.children.indexOf(top.parent) + 1, 0, temp);
2217
+ methods.handleCopyAfter({rule: self.children[0]});
2218
+ },
2219
+ active: ({self}) => {
2220
+ vm.emit('active', self.children[0]);
2221
+ setTimeout(() => {
2222
+ methods.toolActive(self.children[0]);
2223
+ }, 10);
2224
+ }
2225
+ },
2226
+ _config: rule._menu,
2227
+ children: methods.makeChildren([rule])
2228
+ };
2229
+ }
2230
+ },
2231
+ toolHidden(rule) {
2232
+ const status = !(rule._hidden === undefined ? false : rule._hidden);
2233
+ if (rule._menu.inside) {
2234
+ rule.children[0].props.hidden = status;
2235
+ } else {
2236
+ rule.__fc__.parent.rule.props.hidden = status;
2237
+ }
2238
+ rule._hidden = status;
2239
+ if (!status) {
2240
+ rule._display = true;
2241
+ }
2242
+ },
2243
+ toolHandle(rule, event) {
2244
+ if (!rule._fc_drag_tag || rule._menu.tool === false) {
2245
+ rule.__fc__.rm();
2246
+ return;
2247
+ }
2248
+ let toolVm;
2249
+ if (rule._menu.inside) {
2250
+ toolVm = rule.children[0].__fc__.exportEl;
2251
+ } else {
2252
+ toolVm = rule.__fc__.parent.exportEl;
2253
+ }
2254
+ toolVm.$emit(event);
2255
+ },
2256
+ handleAddBefore() {
2257
+ },
2258
+ handleRemoveBefore({rule}) {
2259
+ if (configRef.value.beforeRemoveRule && false === configRef.value.beforeRemoveRule({rule})) {
2260
+ return false;
2261
+ }
2262
+ },
2263
+ handleCopyBefore() {
2264
+ },
2265
+ handleSortBefore() {
2266
+ },
2267
+ addOperationRecord(_rule) {
2268
+ const rule = _rule || methods.getJson();
2269
+ const formData = deepCopy(data.inputForm.data);
2270
+ const list = data.operation.list.slice(0, data.operation.idx + 1);
2271
+ list.push({rule, formData});
2272
+ const maxRecords = 20;
2273
+ if (list.length > maxRecords) {
2274
+ list.splice(0, list.length - maxRecords);
2275
+ data.operation.idx = maxRecords - 1;
2276
+ } else {
2277
+ data.operation.idx = list.length - 1;
2278
+ }
2279
+ data.operation.list = list;
2280
+ data.unloadStatus = list.length !== 1;
2281
+ },
2282
+ addOperationRecordThrottle: throttle(rule => {
2283
+ methods.addOperationRecord(rule);
2284
+ }, 3000),
2285
+ prevOperationRecord() {
2286
+ if (!data.operation.list[data.operation.idx - 1]) {
2287
+ return;
2288
+ }
2289
+ const item = data.operation.list[--data.operation.idx];
2290
+ methods.useOperationRecord(item);
2291
+ methods.clearActiveRule();
2292
+ },
2293
+ nextOperationRecord() {
2294
+ if (!data.operation.list[data.operation.idx + 1]) {
2295
+ return;
2296
+ }
2297
+ const item = data.operation.list[++data.operation.idx];
2298
+ methods.useOperationRecord(item);
2299
+ methods.clearActiveRule();
2300
+ },
2301
+ useOperationRecord(item) {
2302
+ data.inputForm.data = item.formData;
2303
+ methods.setRule(item.rule);
2304
+ },
2305
+ handleAddAfter() {
2306
+ methods.addOperationRecord();
2307
+ methods.updateTree();
2308
+ },
2309
+ handleRemoveAfter() {
2310
+ methods.addOperationRecord();
2311
+ methods.updateTree();
2312
+ },
2313
+ handleCopyAfter() {
2314
+ methods.addOperationRecord();
2315
+ methods.updateTree();
2316
+ },
2317
+ handleSortAfter() {
2318
+ methods.addOperationRecord();
2319
+ methods.updateTree();
2320
+ },
2321
+ getFormDescription() {
2322
+ return getFormRuleDescription(methods.getDescription());
2323
+ },
2324
+ getDescription() {
2325
+ return getRuleDescription(data.dragForm.rule[0].children);
2326
+ },
2327
+ getSubFormDescription(rule) {
2328
+ let ctx = rule.__fc__ && rule.__fc__.parent;
2329
+ while (ctx) {
2330
+ if (ctx.rule._menu && ['array', 'object'].indexOf(ctx.rule._menu.subForm) > -1) {
2331
+ return getFormRuleDescription(getRuleDescription(ctx.rule.children));
2332
+ } else {
2333
+ ctx = ctx.parent;
2334
+ }
2335
+ }
2336
+ return null;
2337
+ },
2338
+ getSubFormChildren(rule) {
2339
+ let ctx = rule.__fc__ && rule.__fc__.parent;
2340
+ while (ctx) {
2341
+ if (ctx.rule._menu && ['array', 'object'].indexOf(ctx.rule._menu.subForm) > -1) {
2342
+ return ctx.rule.children || [];
2343
+ } else {
2344
+ ctx = ctx.parent;
2345
+ }
2346
+ }
2347
+ return null;
2348
+ },
2349
+ updateTree: debounce(function () {
2350
+ nextTick(() => {
2351
+ data.treeInfo = getRuleTree(data.dragForm.rule[0].children);
2352
+ });
2353
+ }, 300),
2354
+ findTree(field) {
2355
+ let tree = undefined;
2356
+ const findTree = children => {
2357
+ children.forEach(item => {
2358
+ if (item.rule.field === field) {
2359
+ tree = item.children;
2360
+ } else if (item.children) {
2361
+ findTree(item.children);
2362
+ }
2363
+ })
2364
+ }
2365
+ findTree(data.treeInfo);
2366
+ return tree || [];
2367
+
2368
+ },
2369
+ handleDragenter(e) {
2370
+ data.bus.$emit('dragenter', e);
2371
+ },
2372
+ handleDragleave(e) {
2373
+ data.bus.$emit('dragleave', e);
2374
+ },
2375
+ handleDrop(e) {
2376
+ data.bus.$emit('drop', e);
2377
+ },
2378
+ changeEvent(on) {
2379
+ data.activeRule._on = on;
2380
+ },
2381
+ triggerHandle(item) {
2382
+ item.handle();
2383
+ },
2384
+ bindHotkey(event) {
2385
+ const isCtrlOrCmd = event.ctrlKey || event.metaKey;
2386
+ if (!getSelection().toString() && isCtrlOrCmd && event.target.tagName === 'BODY' && ['ArrowUp', 'ArrowDown', 'Backspace', 'c', 'x', 'z', 'p', '1', '2', '3', '4'].indexOf(event.key) > -1) {
2387
+ event.preventDefault();
2388
+ if (data.inputForm.state) {
2389
+ return;
2390
+ }
2391
+ if (hotKey[event.key]) {
2392
+ hotKey[event.key](event)
2393
+ } else if ('1234'.indexOf(event.key) > -1) {
2394
+ hotKey.num(event);
2395
+ }
2396
+ }
2397
+ },
2398
+ bindPaste(event) {
2399
+ if (data.inputForm.state) {
2400
+ return;
2401
+ }
2402
+ let content = event.clipboardData.getData('text/plain');
2403
+ if (content && content.indexOf('FormCreate:') === 0) {
2404
+ let children = data.children;
2405
+ content = content.slice(11, content.length);
2406
+ if (methods.getConfig('autoResetField') !== false) {
2407
+ content = methods.batchReplaceField(content);
2408
+ }
2409
+ if (methods.getConfig('autoResetName') !== false) {
2410
+ content = methods.batchReplaceName(content);
2411
+ }
2412
+ const copyRule = methods.loadRule([designerForm.parseJson(content)])[0];
2413
+ let flag = true;
2414
+ if (data.activeRule && data.activeRule._menu.drag) {
2415
+ const _rule = methods.getTrueRule(copyRule);
2416
+ if (_rule && !methods.checkDrag({
2417
+ rule: _rule,
2418
+ menu: _rule._menu,
2419
+ toRule: data.activeRule,
2420
+ toMenu: data.activeRule._menu
2421
+ })) {
2422
+ return;
2423
+ }
2424
+ if (data.activeRule._menu.inside) {
2425
+ children = data.activeRule.children[0].children[0].children;
2426
+ } else {
2427
+ children = data.activeRule.children[0].children;
2428
+ }
2429
+ } else if (data.customForm.config && data.customForm.config.onPaste) {
2430
+ data.customForm.config.onPaste(copyRule)
2431
+ flag = false;
2432
+ }
2433
+ if (flag) {
2434
+ children.push(copyRule);
2435
+ }
2436
+ methods.updateTree();
2437
+ methods.addOperationRecord();
2438
+ vm.emit('pasteRule', {event, copyRule});
2439
+ }
2440
+ }
2441
+ }
2442
+ methods.addDragRule = methods.addComponent;
2443
+
2444
+ const hotKey = {
2445
+ z(e) {
2446
+ if (e.shiftKey) {
2447
+ methods.nextOperationRecord();
2448
+ } else {
2449
+ methods.prevOperationRecord();
2450
+ }
2451
+ },
2452
+ Backspace() {
2453
+ if (!data.activeRule) {
2454
+ return;
2455
+ }
2456
+ methods.toolHandle(data.activeRule, 'delete');
2457
+ },
2458
+ c(event) {
2459
+ const rule = data.activeRule;
2460
+ if (!rule) {
2461
+ return;
2462
+ }
2463
+ copyTextToClipboard('FormCreate:' + designerForm.toJson(methods.parseRule([rule])[0]));
2464
+ vm.emit('copyRule', {event, rule});
2465
+ },
2466
+ x(e) {
2467
+ if (!data.activeRule) {
2468
+ return;
2469
+ }
2470
+ hotKey.c(e);
2471
+ methods.toolHandle(data.activeRule, 'delete');
2472
+ },
2473
+ p() {
2474
+ methods.openPreview();
2475
+ },
2476
+ num(event) {
2477
+ const num = event.key;
2478
+ if (event.key === '1') {
2479
+ data.activeModule = 'base';
2480
+ data.activeMenuTab = 'menu';
2481
+ } else if (event.key === '2') {
2482
+ data.activeModule = 'base';
2483
+ data.activeMenuTab = 'tree';
2484
+ } else if (event.key === '3') {
2485
+ data.activeModule = 'json';
2486
+ } else if (event.key === '4') {
2487
+ data.activeModule = 'language';
2488
+ }
2489
+ },
2490
+ ArrowUp(event) {
2491
+ let rule = data.activeRule;
2492
+ if (!rule) {
2493
+ return;
2494
+ }
2495
+ if (!rule._menu.inside) {
2496
+ rule = rule.__fc__.parent.rule;
2497
+ }
2498
+ const parentRule = rule.__fc__.parent.rule;
2499
+ const idx = parentRule.children.indexOf(rule);
2500
+
2501
+ if (parentRule.children.length > 1 && idx >= 0) {
2502
+ const direction = event.key === 'ArrowUp' ? -1 : (event.key === 'ArrowDown' ? 1 : 0);
2503
+
2504
+ if (direction && idx + direction >= 0 && idx + direction < parentRule.children.length) {
2505
+ parentRule.children.splice(idx, 1);
2506
+ parentRule.children.splice(idx + direction, 0, rule);
2507
+ methods.updateTree();
2508
+ methods.addOperationRecord();
2509
+ vm.emit('sort' + (event.key === 'ArrowUp' ? 'Up' : 'Down'), {event, rule});
2510
+ }
2511
+ }
2512
+ },
2513
+ ArrowDown(event) {
2514
+ hotKey.ArrowUp(event);
2515
+ }
2516
+ }
2517
+ data.dragForm.rule = methods.makeDragRule(methods.makeChildren(data.children));
2518
+ methods.setOption({});
2519
+ initMenuDefaultCollapse();
2520
+ if (!menu.value) {
2521
+ methods.addComponent(ruleList);
2522
+ } else {
2523
+ ruleList.forEach(v => {
2524
+ data.dragRuleList[v.name] = v;
2525
+ });
2526
+ }
2527
+
2528
+ const inputCheckStatus = computed(() => {
2529
+ return Object.keys(data.inputForm.data).length > 0;
2530
+ })
2531
+
2532
+ return {
2533
+ ...toRefs(data), ...methods,
2534
+ dragHeight,
2535
+ t,
2536
+ handle,
2537
+ inputCheckStatus,
2538
+ fieldReadonly,
2539
+ hiddenMenu,
2540
+ hiddenItem,
2541
+ hiddenDragMenu,
2542
+ hiddenDragBtn,
2543
+ menuList,
2544
+ configFormOrderStyle,
2545
+ }
2546
+ },
2547
+ created() {
2548
+ document.body.ondrop = e => {
2549
+ e.preventDefault();
2550
+ e.stopPropagation();
2551
+ };
2552
+ window.onbeforeunload = (e) => {
2553
+ if (this.unloadStatus && this.config?.exitConfirm !== false) {
2554
+ e.returnValue = this.t('designer.unload');
2555
+ }
2556
+ }
2557
+ },
2558
+ mounted() {
2559
+ if (this.config?.hotKey !== false) {
2560
+ document.addEventListener('keydown', this.bindHotkey);
2561
+ document.addEventListener('paste', this.bindPaste);
2562
+ }
2563
+ },
2564
+ unmounted() {
2565
+ document.removeEventListener('keydown', this.bindHotkey);
2566
+ document.removeEventListener('paste', this.bindPaste);
2567
+ }
2568
+ });
2569
+ </script>