gbformdesign 0.1.0 → 0.1.1

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.
@@ -1,374 +1,374 @@
1
- <template>
2
- <el-container style="height: 100%">
3
- <el-header height="40px" class="_fc-r-tabs">
4
- <div
5
- v-if="component"
6
- class="_fc-r-tab"
7
- :class="{ active: activeTab === 'props' }"
8
- @click="activeTab = 'props'"
9
- >
10
- 组件
11
- </div>
12
- <div class="_fc-r-tab" :class="{ active: activeTab === 'form' || !component }" @click="activeTab = 'form'">
13
- 表单
14
- </div>
15
- </el-header>
16
-
17
- <el-main v-if="activeTab === 'props' && component" class="_fc-r-tab-props">
18
- <div class="_fc-r-tools-close" @click="$emit('close')">
19
- <i class="fc-icon icon-add2"></i>
20
- </div>
21
- <p class="_fc-r-title">组件类型</p>
22
- <el-select v-model="typeProxy" style="width: 100%">
23
- <el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" />
24
- </el-select>
25
-
26
- <p class="_fc-r-title">字段名</p>
27
- <el-input v-model="component.props.variableName" class="_fc-r-name-input">
28
- <template #suffix>
29
- <i class="fc-icon icon-group" title="复制字段名" @click="copyName"></i>
30
- </template>
31
- <template #append>
32
- <i class="fc-icon icon-auto" title="根据标题生成" @click="updateName"></i>
33
- </template>
34
- </el-input>
35
-
36
- <div class="_fd-config-item" style="margin-top: 12px">
37
- <div class="_fd-ci-head">
38
- <div class="_fd-ci-label">隐藏</div>
39
- <div class="_fd-ci-con">
40
- <el-switch v-model="component.hidden" size="small" />
41
- </div>
42
- </div>
43
- </div>
44
-
45
- <div class="_fc-r-config">
46
- <div style="grid-area: base">
47
- <el-divider>规则</el-divider>
48
- <div class="_fd-config-item" v-if="!isRow">
49
- <div class="_fd-ci-head">
50
- <div class="_fd-ci-label"><span>必填</span></div>
51
- <div class="_fd-ci-con">
52
- <el-switch v-model="component.required" size="small" />
53
- </div>
54
- </div>
55
- </div>
56
- <div class="_fd-config-item" v-if="!isRow">
57
- <div class="_fd-ci-head">
58
- <div class="_fd-ci-label"><span>字段宽度</span></div>
59
- <div class="_fd-ci-con">
60
- <el-select v-model="widthProxy" size="small" style="width: 120px" @change="changeWidth">
61
- <el-option label="整行" value="100%" />
62
- <el-option label="1/2" value="50%" />
63
- <el-option label="1/3" value="33.33%" />
64
- <el-option label="1/4" value="25%" />
65
- <el-option label="自定义" value="custom" />
66
- </el-select>
67
- </div>
68
- </div>
69
- <div v-if="widthProxy === 'custom'" style="display: flex; justify-content: flex-end; margin-top: 6px">
70
- <el-input-number v-model="customWidth" :min="10" :max="100" :step="5" size="small" @change="applyCustomWidth" />
71
- </div>
72
- </div>
73
- <div class="_fd-config-item" v-if="!isRow">
74
- <div class="_fd-ci-head">
75
- <div class="_fd-ci-label"><span>默认值</span></div>
76
- <div class="_fd-ci-con">
77
- <el-select
78
- v-if="['radio-group', 'select'].includes(component.type)"
79
- v-model="component.defaultValue"
80
- size="small"
81
- clearable
82
- style="width: 180px"
83
- >
84
- <el-option v-for="option in options" :key="optionValue(option)" :label="optionLabel(option)" :value="optionValue(option)" />
85
- </el-select>
86
- <el-select
87
- v-else-if="component.type === 'checkbox-group'"
88
- v-model="component.defaultValue"
89
- size="small"
90
- multiple
91
- clearable
92
- style="width: 180px"
93
- >
94
- <el-option v-for="option in options" :key="optionValue(option)" :label="optionLabel(option)" :value="optionValue(option)" />
95
- </el-select>
96
- <el-switch v-else-if="component.type === 'switch'" v-model="component.defaultValue" size="small" />
97
- <el-select v-else-if="component.type === 'date-picker'" v-model="component.defaultValue" size="small" clearable style="width: 120px">
98
- <el-option label="今天" value="today" />
99
- <el-option label="明天" value="tomorrow" />
100
- <el-option label="无" value="" />
101
- </el-select>
102
- <el-input-number
103
- v-else-if="component.type === 'input-number'"
104
- v-model="component.defaultValue"
105
- size="small"
106
- style="width: 140px"
107
- />
108
- <el-input v-else v-model="component.defaultValue" size="small" style="width: 180px" />
109
- </div>
110
- </div>
111
- </div>
112
- </div>
113
-
114
- <div style="grid-area: props">
115
- <el-divider>属性</el-divider>
116
- <div class="_fd-config-item" v-if="['input', 'textarea', 'select'].includes(component.type)">
117
- <div class="_fd-ci-head">
118
- <div class="_fd-ci-label"><span>提示文字</span></div>
119
- <div class="_fd-ci-con">
120
- <el-input v-model="component.props.placeholder" size="small" style="width: 180px" />
121
- </div>
122
- </div>
123
- </div>
124
- <template v-if="component.type === 'input-number'">
125
- <div class="_fd-config-item">
126
- <div class="_fd-ci-head">
127
- <div class="_fd-ci-label"><span>最小值</span></div>
128
- <div class="_fd-ci-con">
129
- <el-input-number v-model="component.min" size="small" style="width: 140px" />
130
- </div>
131
- </div>
132
- </div>
133
- <div class="_fd-config-item">
134
- <div class="_fd-ci-head">
135
- <div class="_fd-ci-label"><span>最大值</span></div>
136
- <div class="_fd-ci-con">
137
- <el-input-number v-model="component.max" size="small" style="width: 140px" />
138
- </div>
139
- </div>
140
- </div>
141
- </template>
142
- <div class="_fd-config-item" v-if="hasOptions">
143
- <div class="_fd-ci-head">
144
- <div class="_fd-ci-label"><span>选项配置</span></div>
145
- </div>
146
- <div class="_fd-ci-append" style="display: block">
147
- <div v-for="(option, index) in options" :key="index" class="gb-fc-option">
148
- <el-input v-model="option.label" size="small" placeholder="选项名称" />
149
- <el-input v-model="option.value" size="small" placeholder="选项值" />
150
- <el-button type="danger" plain size="small" :icon="Delete" @click="removeOption(index)" />
151
- </div>
152
- <el-button type="primary" plain size="small" :icon="Plus" style="width: 100%" @click="addOption">
153
- 添加选项
154
- </el-button>
155
- </div>
156
- </div>
157
- <template v-if="isRow">
158
- <div class="_fd-config-item">
159
- <div class="_fd-ci-head">
160
- <div class="_fd-ci-label"><span>列间距</span></div>
161
- <div class="_fd-ci-con">
162
- <el-input-number v-model="component.props.gutter" :min="0" :max="100" size="small" style="width: 140px" />
163
- </div>
164
- </div>
165
- </div>
166
- <div class="_fd-config-item">
167
- <div class="_fd-ci-head">
168
- <div class="_fd-ci-label"><span>列配置</span></div>
169
- </div>
170
- <div class="_fd-ci-append" style="display: block">
171
- <div v-for="(column, index) in component.props.columns" :key="index" class="gb-fc-option">
172
- <span style="font-size: 12px; color: #666; width: 60px">第{{ index + 1 }}列</span>
173
- <el-input-number v-model="column.span" :min="1" :max="24" size="small" />
174
- <el-button
175
- type="danger"
176
- plain
177
- size="small"
178
- :icon="Delete"
179
- :disabled="(component.props.columns || []).length <= 1"
180
- @click="removeColumn(index)"
181
- />
182
- </div>
183
- <el-button type="primary" plain size="small" :icon="Plus" style="width: 100%" @click="addColumn">
184
- 添加列
185
- </el-button>
186
- </div>
187
- </div>
188
- </template>
189
- </div>
190
- </div>
191
- </el-main>
192
-
193
- <el-main v-show="activeTab === 'form' || !component" class="_fc-r-tab-form">
194
- <div class="_fc-r-config">
195
- <div style="grid-area: base">
196
- <el-divider>表单配置</el-divider>
197
- <div class="_fd-config-item">
198
- <div class="_fd-ci-head">
199
- <div class="_fd-ci-label"><span>表单名称</span></div>
200
- <div class="_fd-ci-con">
201
- <el-input v-model="formOptions.name" size="small" style="width: 180px" />
202
- </div>
203
- </div>
204
- </div>
205
- <div class="_fd-config-item">
206
- <div class="_fd-ci-head">
207
- <div class="_fd-ci-label"><span>表单描述</span></div>
208
- <div class="_fd-ci-con">
209
- <el-input v-model="formOptions.description" size="small" style="width: 180px" />
210
- </div>
211
- </div>
212
- </div>
213
- <div class="_fd-config-item">
214
- <div class="_fd-ci-head">
215
- <div class="_fd-ci-label"><span>标签宽度</span></div>
216
- <div class="_fd-ci-con">
217
- <el-input v-model="formOptions.labelWidth" size="small" style="width: 120px" />
218
- </div>
219
- </div>
220
- </div>
221
- <div class="_fd-config-item">
222
- <div class="_fd-ci-head">
223
- <div class="_fd-ci-label"><span>组件尺寸</span></div>
224
- <div class="_fd-ci-con">
225
- <el-select v-model="formOptions.size" size="small" style="width: 120px">
226
- <el-option label="较大" value="large" />
227
- <el-option label="默认" value="default" />
228
- <el-option label="较小" value="small" />
229
- </el-select>
230
- </div>
231
- </div>
232
- </div>
233
- </div>
234
- </div>
235
- </el-main>
236
- </el-container>
237
- </template>
238
-
239
- <script setup>
240
- import { computed, ref, watch } from 'vue'
241
- import { ElMessage } from 'element-plus'
242
- import { Delete, Plus } from '@element-plus/icons-vue'
243
- import { COMPONENT_TYPE_LABELS, COMPONENT_TYPES, OPTION_COMPONENT_TYPES } from '../../design/constants/componentTypes.js'
244
- import { ensureComponentId, generateComponentId, parseWidth } from '../../design/utils/componentUtils.js'
245
-
246
- defineOptions({ name: 'FcPropsPanel' })
247
-
248
- const props = defineProps({
249
- component: { type: Object, default: null },
250
- formOptions: { type: Object, required: true }
251
- })
252
-
253
- const emit = defineEmits(['close'])
254
-
255
- const activeTab = ref('props')
256
-
257
- const isRow = computed(() => props.component?.type === COMPONENT_TYPES.ROW)
258
- const hasOptions = computed(() => OPTION_COMPONENT_TYPES.includes(props.component?.type))
259
- const options = computed(() => {
260
- if (!props.component?.props) return []
261
- if (!Array.isArray(props.component.props.options)) props.component.props.options = []
262
- return props.component.props.options
263
- })
264
-
265
- const typeOptions = Object.entries(COMPONENT_TYPE_LABELS)
266
- .filter(([value]) => value !== COMPONENT_TYPES.BUTTON)
267
- .map(([value, label]) => ({ value, label }))
268
-
269
- const typeProxy = computed({
270
- get: () => props.component?.type,
271
- set: (type) => {
272
- if (!type || !props.component) return
273
- props.component.type = type
274
- if (!props.component.props) props.component.props = {}
275
- if (OPTION_COMPONENT_TYPES.includes(type) && !props.component.props.options?.length) {
276
- props.component.props.options = [
277
- { label: '选项1', value: '1' },
278
- { label: '选项2', value: '2' }
279
- ]
280
- }
281
- if (type === COMPONENT_TYPES.ROW) {
282
- if (!props.component.props.columns) props.component.props.columns = [{ span: 12 }, { span: 12 }]
283
- if (!props.component.children) props.component.children = [[], []]
284
- props.component.props.gutter = props.component.props.gutter || 20
285
- ensureComponentId(props.component)
286
- }
287
- }
288
- })
289
-
290
- const widthProxy = ref('100%')
291
- const customWidth = ref(100)
292
-
293
- const syncWidth = () => {
294
- const width = props.component?.style?.width
295
- const presets = ['100%', '50%', '33.33%', '25%']
296
- if (!width) {
297
- widthProxy.value = '100%'
298
- return
299
- }
300
- widthProxy.value = presets.includes(width) ? width : 'custom'
301
- if (widthProxy.value === 'custom') customWidth.value = parseWidth(width)
302
- }
303
-
304
- syncWidth()
305
- watch(() => props.component?.id, syncWidth)
306
-
307
- const changeWidth = (value) => {
308
- if (!props.component) return
309
- if (!props.component.style) props.component.style = {}
310
- if (value === 'custom') {
311
- props.component.style.width = `${customWidth.value}%`
312
- } else {
313
- props.component.style.width = value
314
- }
315
- }
316
-
317
- const applyCustomWidth = (value) => {
318
- if (!props.component) return
319
- if (!props.component.style) props.component.style = {}
320
- props.component.style.width = `${value}%`
321
- }
322
-
323
- const optionLabel = (option) => (typeof option === 'string' ? option : option.label)
324
- const optionValue = (option) => (typeof option === 'string' ? option : option.value)
325
-
326
- const addOption = () => {
327
- options.value.push({ label: `选项${options.value.length + 1}`, value: `${options.value.length + 1}` })
328
- }
329
-
330
- const removeOption = (index) => {
331
- options.value.splice(index, 1)
332
- }
333
-
334
- const addColumn = () => {
335
- const columns = props.component.props.columns
336
- columns.push({ span: Math.max(1, Math.round(24 / (columns.length + 1))) })
337
- if (!props.component.children) props.component.children = []
338
- props.component.children.push([])
339
- }
340
-
341
- const removeColumn = (index) => {
342
- props.component.props.columns.splice(index, 1)
343
- props.component.children?.splice(index, 1)
344
- }
345
-
346
- const copyName = async () => {
347
- const name = props.component?.props?.variableName
348
- if (!name) return
349
- try {
350
- await navigator.clipboard.writeText(name)
351
- ElMessage.success('字段名已复制')
352
- } catch {
353
- ElMessage.warning('复制失败')
354
- }
355
- }
356
-
357
- const updateName = () => {
358
- if (!props.component) return
359
- props.component.props.variableName = `field_${generateComponentId().split('_').pop()}`
360
- }
361
- </script>
362
-
363
- <style lang="scss">
364
- .gb-fc-option {
365
- display: flex;
366
- align-items: center;
367
- gap: 6px;
368
- margin-bottom: 6px;
369
-
370
- .el-input {
371
- flex: 1;
372
- }
373
- }
1
+ <template>
2
+ <el-container style="height: 100%">
3
+ <el-header height="40px" class="_fc-r-tabs">
4
+ <div
5
+ v-if="component"
6
+ class="_fc-r-tab"
7
+ :class="{ active: activeTab === 'props' }"
8
+ @click="activeTab = 'props'"
9
+ >
10
+ 组件
11
+ </div>
12
+ <div class="_fc-r-tab" :class="{ active: activeTab === 'form' || !component }" @click="activeTab = 'form'">
13
+ 表单
14
+ </div>
15
+ </el-header>
16
+
17
+ <el-main v-if="activeTab === 'props' && component" class="_fc-r-tab-props">
18
+ <div class="_fc-r-tools-close" @click="$emit('close')">
19
+ <i class="fc-icon icon-add2"></i>
20
+ </div>
21
+ <p class="_fc-r-title">组件类型</p>
22
+ <el-select v-model="typeProxy" style="width: 100%">
23
+ <el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" />
24
+ </el-select>
25
+
26
+ <p class="_fc-r-title">字段名</p>
27
+ <el-input v-model="component.props.variableName" class="_fc-r-name-input">
28
+ <template #suffix>
29
+ <i class="fc-icon icon-group" title="复制字段名" @click="copyName"></i>
30
+ </template>
31
+ <template #append>
32
+ <i class="fc-icon icon-auto" title="根据标题生成" @click="updateName"></i>
33
+ </template>
34
+ </el-input>
35
+
36
+ <div class="_fd-config-item" style="margin-top: 12px">
37
+ <div class="_fd-ci-head">
38
+ <div class="_fd-ci-label">隐藏</div>
39
+ <div class="_fd-ci-con">
40
+ <el-switch v-model="component.hidden" size="small" />
41
+ </div>
42
+ </div>
43
+ </div>
44
+
45
+ <div class="_fc-r-config">
46
+ <div style="grid-area: base">
47
+ <el-divider>规则</el-divider>
48
+ <div class="_fd-config-item" v-if="!isRow">
49
+ <div class="_fd-ci-head">
50
+ <div class="_fd-ci-label"><span>必填</span></div>
51
+ <div class="_fd-ci-con">
52
+ <el-switch v-model="component.required" size="small" />
53
+ </div>
54
+ </div>
55
+ </div>
56
+ <div class="_fd-config-item" v-if="!isRow">
57
+ <div class="_fd-ci-head">
58
+ <div class="_fd-ci-label"><span>字段宽度</span></div>
59
+ <div class="_fd-ci-con">
60
+ <el-select v-model="widthProxy" size="small" style="width: 120px" @change="changeWidth">
61
+ <el-option label="整行" value="100%" />
62
+ <el-option label="1/2" value="50%" />
63
+ <el-option label="1/3" value="33.33%" />
64
+ <el-option label="1/4" value="25%" />
65
+ <el-option label="自定义" value="custom" />
66
+ </el-select>
67
+ </div>
68
+ </div>
69
+ <div v-if="widthProxy === 'custom'" style="display: flex; justify-content: flex-end; margin-top: 6px">
70
+ <el-input-number v-model="customWidth" :min="10" :max="100" :step="5" size="small" @change="applyCustomWidth" />
71
+ </div>
72
+ </div>
73
+ <div class="_fd-config-item" v-if="!isRow">
74
+ <div class="_fd-ci-head">
75
+ <div class="_fd-ci-label"><span>默认值</span></div>
76
+ <div class="_fd-ci-con">
77
+ <el-select
78
+ v-if="['radio-group', 'select'].includes(component.type)"
79
+ v-model="component.defaultValue"
80
+ size="small"
81
+ clearable
82
+ style="width: 180px"
83
+ >
84
+ <el-option v-for="option in options" :key="optionValue(option)" :label="optionLabel(option)" :value="optionValue(option)" />
85
+ </el-select>
86
+ <el-select
87
+ v-else-if="component.type === 'checkbox-group'"
88
+ v-model="component.defaultValue"
89
+ size="small"
90
+ multiple
91
+ clearable
92
+ style="width: 180px"
93
+ >
94
+ <el-option v-for="option in options" :key="optionValue(option)" :label="optionLabel(option)" :value="optionValue(option)" />
95
+ </el-select>
96
+ <el-switch v-else-if="component.type === 'switch'" v-model="component.defaultValue" size="small" />
97
+ <el-select v-else-if="component.type === 'date-picker'" v-model="component.defaultValue" size="small" clearable style="width: 120px">
98
+ <el-option label="今天" value="today" />
99
+ <el-option label="明天" value="tomorrow" />
100
+ <el-option label="无" value="" />
101
+ </el-select>
102
+ <el-input-number
103
+ v-else-if="component.type === 'input-number'"
104
+ v-model="component.defaultValue"
105
+ size="small"
106
+ style="width: 140px"
107
+ />
108
+ <el-input v-else v-model="component.defaultValue" size="small" style="width: 180px" />
109
+ </div>
110
+ </div>
111
+ </div>
112
+ </div>
113
+
114
+ <div style="grid-area: props">
115
+ <el-divider>属性</el-divider>
116
+ <div class="_fd-config-item" v-if="['input', 'textarea', 'select'].includes(component.type)">
117
+ <div class="_fd-ci-head">
118
+ <div class="_fd-ci-label"><span>提示文字</span></div>
119
+ <div class="_fd-ci-con">
120
+ <el-input v-model="component.props.placeholder" size="small" style="width: 180px" />
121
+ </div>
122
+ </div>
123
+ </div>
124
+ <template v-if="component.type === 'input-number'">
125
+ <div class="_fd-config-item">
126
+ <div class="_fd-ci-head">
127
+ <div class="_fd-ci-label"><span>最小值</span></div>
128
+ <div class="_fd-ci-con">
129
+ <el-input-number v-model="component.min" size="small" style="width: 140px" />
130
+ </div>
131
+ </div>
132
+ </div>
133
+ <div class="_fd-config-item">
134
+ <div class="_fd-ci-head">
135
+ <div class="_fd-ci-label"><span>最大值</span></div>
136
+ <div class="_fd-ci-con">
137
+ <el-input-number v-model="component.max" size="small" style="width: 140px" />
138
+ </div>
139
+ </div>
140
+ </div>
141
+ </template>
142
+ <div class="_fd-config-item" v-if="hasOptions">
143
+ <div class="_fd-ci-head">
144
+ <div class="_fd-ci-label"><span>选项配置</span></div>
145
+ </div>
146
+ <div class="_fd-ci-append" style="display: block">
147
+ <div v-for="(option, index) in options" :key="index" class="gb-fc-option">
148
+ <el-input v-model="option.label" size="small" placeholder="选项名称" />
149
+ <el-input v-model="option.value" size="small" placeholder="选项值" />
150
+ <el-button type="danger" plain size="small" :icon="Delete" @click="removeOption(index)" />
151
+ </div>
152
+ <el-button type="primary" plain size="small" :icon="Plus" style="width: 100%" @click="addOption">
153
+ 添加选项
154
+ </el-button>
155
+ </div>
156
+ </div>
157
+ <template v-if="isRow">
158
+ <div class="_fd-config-item">
159
+ <div class="_fd-ci-head">
160
+ <div class="_fd-ci-label"><span>列间距</span></div>
161
+ <div class="_fd-ci-con">
162
+ <el-input-number v-model="component.props.gutter" :min="0" :max="100" size="small" style="width: 140px" />
163
+ </div>
164
+ </div>
165
+ </div>
166
+ <div class="_fd-config-item">
167
+ <div class="_fd-ci-head">
168
+ <div class="_fd-ci-label"><span>列配置</span></div>
169
+ </div>
170
+ <div class="_fd-ci-append" style="display: block">
171
+ <div v-for="(column, index) in component.props.columns" :key="index" class="gb-fc-option">
172
+ <span style="font-size: 12px; color: #666; width: 60px">第{{ index + 1 }}列</span>
173
+ <el-input-number v-model="column.span" :min="1" :max="24" size="small" />
174
+ <el-button
175
+ type="danger"
176
+ plain
177
+ size="small"
178
+ :icon="Delete"
179
+ :disabled="(component.props.columns || []).length <= 1"
180
+ @click="removeColumn(index)"
181
+ />
182
+ </div>
183
+ <el-button type="primary" plain size="small" :icon="Plus" style="width: 100%" @click="addColumn">
184
+ 添加列
185
+ </el-button>
186
+ </div>
187
+ </div>
188
+ </template>
189
+ </div>
190
+ </div>
191
+ </el-main>
192
+
193
+ <el-main v-show="activeTab === 'form' || !component" class="_fc-r-tab-form">
194
+ <div class="_fc-r-config">
195
+ <div style="grid-area: base">
196
+ <el-divider>表单配置</el-divider>
197
+ <div class="_fd-config-item">
198
+ <div class="_fd-ci-head">
199
+ <div class="_fd-ci-label"><span>表单名称</span></div>
200
+ <div class="_fd-ci-con">
201
+ <el-input v-model="formOptions.name" size="small" style="width: 180px" />
202
+ </div>
203
+ </div>
204
+ </div>
205
+ <div class="_fd-config-item">
206
+ <div class="_fd-ci-head">
207
+ <div class="_fd-ci-label"><span>表单描述</span></div>
208
+ <div class="_fd-ci-con">
209
+ <el-input v-model="formOptions.description" size="small" style="width: 180px" />
210
+ </div>
211
+ </div>
212
+ </div>
213
+ <div class="_fd-config-item">
214
+ <div class="_fd-ci-head">
215
+ <div class="_fd-ci-label"><span>标签宽度</span></div>
216
+ <div class="_fd-ci-con">
217
+ <el-input v-model="formOptions.labelWidth" size="small" style="width: 120px" />
218
+ </div>
219
+ </div>
220
+ </div>
221
+ <div class="_fd-config-item">
222
+ <div class="_fd-ci-head">
223
+ <div class="_fd-ci-label"><span>组件尺寸</span></div>
224
+ <div class="_fd-ci-con">
225
+ <el-select v-model="formOptions.size" size="small" style="width: 120px">
226
+ <el-option label="较大" value="large" />
227
+ <el-option label="默认" value="default" />
228
+ <el-option label="较小" value="small" />
229
+ </el-select>
230
+ </div>
231
+ </div>
232
+ </div>
233
+ </div>
234
+ </div>
235
+ </el-main>
236
+ </el-container>
237
+ </template>
238
+
239
+ <script setup>
240
+ import { computed, ref, watch } from 'vue'
241
+ import { ElMessage } from 'element-plus'
242
+ import { Delete, Plus } from 'gbicons'
243
+ import { COMPONENT_TYPE_LABELS, COMPONENT_TYPES, OPTION_COMPONENT_TYPES } from '../../design/constants/componentTypes.js'
244
+ import { ensureComponentId, generateComponentId, parseWidth } from '../../design/utils/componentUtils.js'
245
+
246
+ defineOptions({ name: 'FcPropsPanel' })
247
+
248
+ const props = defineProps({
249
+ component: { type: Object, default: null },
250
+ formOptions: { type: Object, required: true }
251
+ })
252
+
253
+ const emit = defineEmits(['close'])
254
+
255
+ const activeTab = ref('props')
256
+
257
+ const isRow = computed(() => props.component?.type === COMPONENT_TYPES.ROW)
258
+ const hasOptions = computed(() => OPTION_COMPONENT_TYPES.includes(props.component?.type))
259
+ const options = computed(() => {
260
+ if (!props.component?.props) return []
261
+ if (!Array.isArray(props.component.props.options)) props.component.props.options = []
262
+ return props.component.props.options
263
+ })
264
+
265
+ const typeOptions = Object.entries(COMPONENT_TYPE_LABELS)
266
+ .filter(([value]) => value !== COMPONENT_TYPES.BUTTON)
267
+ .map(([value, label]) => ({ value, label }))
268
+
269
+ const typeProxy = computed({
270
+ get: () => props.component?.type,
271
+ set: (type) => {
272
+ if (!type || !props.component) return
273
+ props.component.type = type
274
+ if (!props.component.props) props.component.props = {}
275
+ if (OPTION_COMPONENT_TYPES.includes(type) && !props.component.props.options?.length) {
276
+ props.component.props.options = [
277
+ { label: '选项1', value: '1' },
278
+ { label: '选项2', value: '2' }
279
+ ]
280
+ }
281
+ if (type === COMPONENT_TYPES.ROW) {
282
+ if (!props.component.props.columns) props.component.props.columns = [{ span: 12 }, { span: 12 }]
283
+ if (!props.component.children) props.component.children = [[], []]
284
+ props.component.props.gutter = props.component.props.gutter || 20
285
+ ensureComponentId(props.component)
286
+ }
287
+ }
288
+ })
289
+
290
+ const widthProxy = ref('100%')
291
+ const customWidth = ref(100)
292
+
293
+ const syncWidth = () => {
294
+ const width = props.component?.style?.width
295
+ const presets = ['100%', '50%', '33.33%', '25%']
296
+ if (!width) {
297
+ widthProxy.value = '100%'
298
+ return
299
+ }
300
+ widthProxy.value = presets.includes(width) ? width : 'custom'
301
+ if (widthProxy.value === 'custom') customWidth.value = parseWidth(width)
302
+ }
303
+
304
+ syncWidth()
305
+ watch(() => props.component?.id, syncWidth)
306
+
307
+ const changeWidth = (value) => {
308
+ if (!props.component) return
309
+ if (!props.component.style) props.component.style = {}
310
+ if (value === 'custom') {
311
+ props.component.style.width = `${customWidth.value}%`
312
+ } else {
313
+ props.component.style.width = value
314
+ }
315
+ }
316
+
317
+ const applyCustomWidth = (value) => {
318
+ if (!props.component) return
319
+ if (!props.component.style) props.component.style = {}
320
+ props.component.style.width = `${value}%`
321
+ }
322
+
323
+ const optionLabel = (option) => (typeof option === 'string' ? option : option.label)
324
+ const optionValue = (option) => (typeof option === 'string' ? option : option.value)
325
+
326
+ const addOption = () => {
327
+ options.value.push({ label: `选项${options.value.length + 1}`, value: `${options.value.length + 1}` })
328
+ }
329
+
330
+ const removeOption = (index) => {
331
+ options.value.splice(index, 1)
332
+ }
333
+
334
+ const addColumn = () => {
335
+ const columns = props.component.props.columns
336
+ columns.push({ span: Math.max(1, Math.round(24 / (columns.length + 1))) })
337
+ if (!props.component.children) props.component.children = []
338
+ props.component.children.push([])
339
+ }
340
+
341
+ const removeColumn = (index) => {
342
+ props.component.props.columns.splice(index, 1)
343
+ props.component.children?.splice(index, 1)
344
+ }
345
+
346
+ const copyName = async () => {
347
+ const name = props.component?.props?.variableName
348
+ if (!name) return
349
+ try {
350
+ await navigator.clipboard.writeText(name)
351
+ ElMessage.success('字段名已复制')
352
+ } catch {
353
+ ElMessage.warning('复制失败')
354
+ }
355
+ }
356
+
357
+ const updateName = () => {
358
+ if (!props.component) return
359
+ props.component.props.variableName = `field_${generateComponentId().split('_').pop()}`
360
+ }
361
+ </script>
362
+
363
+ <style lang="scss">
364
+ .gb-fc-option {
365
+ display: flex;
366
+ align-items: center;
367
+ gap: 6px;
368
+ margin-bottom: 6px;
369
+
370
+ .el-input {
371
+ flex: 1;
372
+ }
373
+ }
374
374
  </style>