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,277 +1,278 @@
1
- <template>
2
- <div
3
- class="_fc-draggable-item _fd-drag-item gb-fc-item"
4
- :class="{
5
- 'is-active': activeId === component.id,
6
- 'is-hidden': component.hidden,
7
- 'drag-over-top': dragOver === path.join('.') + ':top',
8
- 'drag-over-bottom': dragOver === path.join('.') + ':bottom'
9
- }"
10
- @dragover.prevent="onDragOver"
11
- @dragenter.prevent
12
- @dragleave="onDragLeave"
13
- @drop.stop.prevent="onDrop"
14
- >
15
- <template v-if="isRow">
16
- <div class="_fd-draggable-drag _fd-drag-box gb-fc-row-box">
17
- <el-row :gutter="component.props?.gutter || 20">
18
- <el-col
19
- v-for="(column, colIndex) in columnCount"
20
- :key="colIndex"
21
- :span="component.props?.columns?.[colIndex]?.span || 12"
22
- >
23
- <div
24
- class="gb-fc-column"
25
- :class="{
26
- '_fc-child-empty': !(component.children?.[colIndex] || []).length,
27
- 'has-child': (component.children?.[colIndex] || []).length
28
- }"
29
- @dragover.prevent.stop="onColumnDragOver(colIndex)"
30
- @drop.stop.prevent="onColumnDrop(colIndex, $event)"
31
- >
32
- <FcCanvasField
33
- v-for="(child, childIndex) in component.children?.[colIndex] || []"
34
- :key="child.id || childIndex"
35
- :component="child"
36
- :path="[...path, 'children', colIndex, childIndex]"
37
- :form-data="formData"
38
- :form-rules="formRules"
39
- :active-id="activeId"
40
- :depth="depth + 1"
41
- />
42
- </div>
43
- </el-col>
44
- </el-row>
45
- </div>
46
- </template>
47
- <FormField
48
- v-else
49
- :component="component"
50
- :form-data="formData"
51
- :form-rules="formRules"
52
- :readonly="true"
53
- />
54
-
55
- <div class="gb-fc-mask" @click.stop="ops.active(component, path)">
56
- <div class="gb-fc-tools">
57
- <i
58
- class="gb-fc-tool gb-fc-tool--handle"
59
- :title="'拖拽' + (component.props?.label || component.type)"
60
- draggable="true"
61
- @dragstart.stop="onDragStart"
62
- @dragend="onDragEnd"
63
- >
64
- <svg viewBox="0 0 1024 1024" width="14" height="14"><path fill="currentColor" d="M469.3 256a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.7a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.6a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.7a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zM661.3 256a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.7a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.6a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0zm0 170.7a53.3 53.3 0 1 1-106.6 0 53.3 53.3 0 0 1 106.6 0z"/></svg>
65
- </i>
66
- <i class="gb-fc-tool" :title="'复制'" @click.stop="ops.copy(path)">
67
- <svg viewBox="0 0 1024 1024" width="14" height="14"><path fill="currentColor" d="M768 832v-576H320v576h448zM320 192h448a64 64 0 0 1 64 64v576a64 64 0 0 1-64 64H320a64 64 0 0 1-64-64V256a64 64 0 0 1 64-64zm-128 64v640h64v64h-64a64 64 0 0 1-64-64V256h64z"/></svg>
68
- </i>
69
- <i class="gb-fc-tool gb-fc-tool--danger" :title="'删除'" @click.stop="ops.remove(path)">
70
- <svg viewBox="0 0 1024 1024" width="14" height="14"><path fill="currentColor" d="M512 455.1L761 206a15 15 0 0 1 21.2 0l35.8 35.8a15 15 0 0 1 0 21.2L569 512l249 249a15 15 0 0 1 0 21.2l-35.8 35.8a15 15 0 0 1-21.2 0L512 569l-249 249a15 15 0 0 1-21.2 0l-35.8-35.8a15 15 0 0 1 0-21.2L455 512 206 263a15 15 0 0 1 0-21.2l35.8-35.8a15 15 0 0 1 21.2 0z"/></svg>
71
- </i>
72
- </div>
73
- </div>
74
- </div>
75
- </template>
76
-
77
- <script setup>
78
- import { computed, inject } from 'vue'
79
- import FormField from '../../view/FormField.vue'
80
- import { COMPONENT_TYPES } from '../../design/constants/componentTypes.js'
81
-
82
- defineOptions({ name: 'FcCanvasField' })
83
-
84
- const props = defineProps({
85
- component: { type: Object, required: true },
86
- path: { type: Array, required: true },
87
- formData: { type: Object, required: true },
88
- formRules: { type: Object, required: true },
89
- activeId: { type: String, default: '' },
90
- depth: { type: Number, default: 0 }
91
- })
92
-
93
- const ops = inject('fcCanvasOps')
94
- const dragOver = inject('fcDragOver')
95
-
96
- const isRow = computed(() => props.component.type === COMPONENT_TYPES.ROW)
97
- const columnCount = computed(() => props.component.props?.columns?.length || 2)
98
- const isEmptyRow = computed(() =>
99
- (props.component.children || []).every((column) => !column || column.length === 0)
100
- )
101
-
102
- const dragPayload = {
103
- kind: 'existing',
104
- path: props.path
105
- }
106
-
107
- const onDragStart = (event) => {
108
- event.dataTransfer.effectAllowed = 'move'
109
- event.dataTransfer.setData('application/x-gb-field', JSON.stringify(dragPayload))
110
- event.dataTransfer.setData('text/plain', 'gb-field')
111
- ops.startDrag(props.path)
112
- }
113
-
114
- const onDragEnd = () => {
115
- ops.endDrag()
116
- }
117
-
118
- const onDragOver = (event) => {
119
- event.preventDefault()
120
- const rect = event.currentTarget.getBoundingClientRect()
121
- const position = event.clientY - rect.top < rect.height / 2 ? 'top' : 'bottom'
122
- dragOver.value = props.path.join('.') + ':' + position
123
- event.dataTransfer.dropEffect = 'move'
124
- }
125
-
126
- const onDragLeave = () => {
127
- if (dragOver.value?.startsWith(props.path.join('.'))) dragOver.value = ''
128
- }
129
-
130
- const onDrop = (event) => {
131
- event.preventDefault()
132
- event.stopPropagation()
133
- const position = dragOver.value?.endsWith(':top') ? 'top' : 'bottom'
134
- const payload = readPayload(event)
135
- dragOver.value = ''
136
- if (!payload) return
137
- ops.dropAt(payload, { path: props.path, position })
138
- }
139
-
140
- const onColumnDragOver = (colIndex) => {
141
- dragOver.value = props.path.join('.') + ':col' + colIndex
142
- }
143
-
144
- const onColumnDrop = (colIndex, event) => {
145
- const payload = readPayload(event)
146
- dragOver.value = ''
147
- if (!payload) return
148
- ops.dropAt(payload, { path: props.path, column: colIndex })
149
- }
150
-
151
- const readPayload = (event) => {
152
- const raw = event?.dataTransfer?.getData('application/x-gb-field')
153
- if (raw) {
154
- try {
155
- return JSON.parse(raw)
156
- } catch {
157
- return null
158
- }
159
- }
160
- return ops.getDragPayload()
161
- }
162
- </script>
163
-
164
- <style lang="scss">
165
- .gb-fc-item {
166
- position: relative;
167
- padding: 4px 0;
168
-
169
- &:hover {
170
- > .gb-fc-mask {
171
- display: block;
172
- }
173
- }
174
-
175
- &.is-active > ._fd-draggable-drag,
176
- &.is-active > .form-viewer {
177
- outline: 1px solid #2e73ff;
178
- }
179
-
180
- &.is-hidden {
181
- opacity: 0.55;
182
- }
183
-
184
- &.drag-over-top::before,
185
- &.drag-over-bottom::after {
186
- content: '';
187
- position: absolute;
188
- left: 0;
189
- right: 0;
190
- height: 2px;
191
- background: #2e73ff;
192
- z-index: 3;
193
- }
194
-
195
- &.drag-over-top::before {
196
- top: -1px;
197
- }
198
-
199
- &.drag-over-bottom::after {
200
- bottom: -1px;
201
- }
202
- }
203
-
204
- .gb-fc-mask {
205
- display: none;
206
- position: absolute;
207
- inset: 4px 0;
208
- z-index: 2;
209
- cursor: pointer;
210
-
211
- &::after {
212
- content: '';
213
- position: absolute;
214
- inset: 0;
215
- border: 1px solid #2e73ff;
216
- background: rgba(46, 115, 255, 0.03);
217
- pointer-events: none;
218
- }
219
- }
220
-
221
- .gb-fc-tools {
222
- position: absolute;
223
- right: 2px;
224
- top: 2px;
225
- z-index: 3;
226
- display: flex;
227
- align-items: center;
228
- gap: 2px;
229
- background: #fff;
230
- border: 1px solid #2e73ff;
231
- border-radius: 3px;
232
- box-shadow: 0 2px 8px rgba(46, 115, 255, 0.25);
233
- padding: 2px;
234
- }
235
-
236
- .gb-fc-tool {
237
- display: inline-flex;
238
- align-items: center;
239
- justify-content: center;
240
- width: 20px;
241
- height: 20px;
242
- color: #2e73ff;
243
- cursor: pointer;
244
- border-radius: 3px;
245
-
246
- &:hover {
247
- background: rgba(46, 115, 255, 0.12);
248
- }
249
-
250
- &--handle {
251
- cursor: move;
252
- }
253
-
254
- &--danger:hover {
255
- background: rgba(245, 74, 74, 0.12);
256
- color: #f54a4a;
257
- }
258
- }
259
-
260
- .gb-fc-column {
261
- min-height: 60px;
262
- border: 1px dashed transparent;
263
- transition: border-color 0.2s ease;
264
-
265
- &.has-child {
266
- border-color: transparent;
267
- }
268
-
269
- &:hover {
270
- border-color: #c0c4cc;
271
- }
272
- }
273
-
274
- .gb-fc-row-box {
275
- padding: 4px;
276
- }
1
+ <template>
2
+ <div
3
+ class="_fc-draggable-item _fd-drag-item gb-fc-item"
4
+ :class="{
5
+ 'is-active': activeId === component.id,
6
+ 'is-hidden': component.hidden,
7
+ 'drag-over-top': dragOver === path.join('.') + ':top',
8
+ 'drag-over-bottom': dragOver === path.join('.') + ':bottom'
9
+ }"
10
+ @dragover.prevent="onDragOver"
11
+ @dragenter.prevent
12
+ @dragleave="onDragLeave"
13
+ @drop.stop.prevent="onDrop"
14
+ >
15
+ <template v-if="isRow">
16
+ <div class="_fd-draggable-drag _fd-drag-box gb-fc-row-box">
17
+ <el-row :gutter="component.props?.gutter || 20">
18
+ <el-col
19
+ v-for="(column, colIndex) in columnCount"
20
+ :key="colIndex"
21
+ :span="component.props?.columns?.[colIndex]?.span || 12"
22
+ >
23
+ <div
24
+ class="gb-fc-column"
25
+ :class="{
26
+ '_fc-child-empty': !(component.children?.[colIndex] || []).length,
27
+ 'has-child': (component.children?.[colIndex] || []).length
28
+ }"
29
+ @dragover.prevent.stop="onColumnDragOver(colIndex)"
30
+ @drop.stop.prevent="onColumnDrop(colIndex, $event)"
31
+ >
32
+ <FcCanvasField
33
+ v-for="(child, childIndex) in component.children?.[colIndex] || []"
34
+ :key="child.id || childIndex"
35
+ :component="child"
36
+ :path="[...path, 'children', colIndex, childIndex]"
37
+ :form-data="formData"
38
+ :form-rules="formRules"
39
+ :active-id="activeId"
40
+ :depth="depth + 1"
41
+ />
42
+ </div>
43
+ </el-col>
44
+ </el-row>
45
+ </div>
46
+ </template>
47
+ <FormField
48
+ v-else
49
+ :component="component"
50
+ :form-data="formData"
51
+ :form-rules="formRules"
52
+ :readonly="true"
53
+ />
54
+
55
+ <div class="gb-fc-mask" @click.stop="ops.active(component, path)">
56
+ <div class="gb-fc-tools">
57
+ <i
58
+ class="gb-fc-tool gb-fc-tool--handle"
59
+ :title="'拖拽' + (component.props?.label || component.type)"
60
+ draggable="true"
61
+ @dragstart.stop="onDragStart"
62
+ @dragend="onDragEnd"
63
+ >
64
+ <Rank style="width: 14px; height: 14px" />
65
+ </i>
66
+ <i class="gb-fc-tool" :title="'复制'" @click.stop="ops.copy(path)">
67
+ <CopyDocument style="width: 14px; height: 14px" />
68
+ </i>
69
+ <i class="gb-fc-tool gb-fc-tool--danger" :title="'删除'" @click.stop="ops.remove(path)">
70
+ <Close style="width: 14px; height: 14px" />
71
+ </i>
72
+ </div>
73
+ </div>
74
+ </div>
75
+ </template>
76
+
77
+ <script setup>
78
+ import { computed, inject } from 'vue'
79
+ import { Close, CopyDocument, Rank } from 'gbicons'
80
+ import FormField from '../../view/FormField.vue'
81
+ import { COMPONENT_TYPES } from '../../design/constants/componentTypes.js'
82
+
83
+ defineOptions({ name: 'FcCanvasField' })
84
+
85
+ const props = defineProps({
86
+ component: { type: Object, required: true },
87
+ path: { type: Array, required: true },
88
+ formData: { type: Object, required: true },
89
+ formRules: { type: Object, required: true },
90
+ activeId: { type: String, default: '' },
91
+ depth: { type: Number, default: 0 }
92
+ })
93
+
94
+ const ops = inject('fcCanvasOps')
95
+ const dragOver = inject('fcDragOver')
96
+
97
+ const isRow = computed(() => props.component.type === COMPONENT_TYPES.ROW)
98
+ const columnCount = computed(() => props.component.props?.columns?.length || 2)
99
+ const isEmptyRow = computed(() =>
100
+ (props.component.children || []).every((column) => !column || column.length === 0)
101
+ )
102
+
103
+ const dragPayload = {
104
+ kind: 'existing',
105
+ path: props.path
106
+ }
107
+
108
+ const onDragStart = (event) => {
109
+ event.dataTransfer.effectAllowed = 'move'
110
+ event.dataTransfer.setData('application/x-gb-field', JSON.stringify(dragPayload))
111
+ event.dataTransfer.setData('text/plain', 'gb-field')
112
+ ops.startDrag(props.path)
113
+ }
114
+
115
+ const onDragEnd = () => {
116
+ ops.endDrag()
117
+ }
118
+
119
+ const onDragOver = (event) => {
120
+ event.preventDefault()
121
+ const rect = event.currentTarget.getBoundingClientRect()
122
+ const position = event.clientY - rect.top < rect.height / 2 ? 'top' : 'bottom'
123
+ dragOver.value = props.path.join('.') + ':' + position
124
+ event.dataTransfer.dropEffect = 'move'
125
+ }
126
+
127
+ const onDragLeave = () => {
128
+ if (dragOver.value?.startsWith(props.path.join('.'))) dragOver.value = ''
129
+ }
130
+
131
+ const onDrop = (event) => {
132
+ event.preventDefault()
133
+ event.stopPropagation()
134
+ const position = dragOver.value?.endsWith(':top') ? 'top' : 'bottom'
135
+ const payload = readPayload(event)
136
+ dragOver.value = ''
137
+ if (!payload) return
138
+ ops.dropAt(payload, { path: props.path, position })
139
+ }
140
+
141
+ const onColumnDragOver = (colIndex) => {
142
+ dragOver.value = props.path.join('.') + ':col' + colIndex
143
+ }
144
+
145
+ const onColumnDrop = (colIndex, event) => {
146
+ const payload = readPayload(event)
147
+ dragOver.value = ''
148
+ if (!payload) return
149
+ ops.dropAt(payload, { path: props.path, column: colIndex })
150
+ }
151
+
152
+ const readPayload = (event) => {
153
+ const raw = event?.dataTransfer?.getData('application/x-gb-field')
154
+ if (raw) {
155
+ try {
156
+ return JSON.parse(raw)
157
+ } catch {
158
+ return null
159
+ }
160
+ }
161
+ return ops.getDragPayload()
162
+ }
163
+ </script>
164
+
165
+ <style lang="scss">
166
+ .gb-fc-item {
167
+ position: relative;
168
+ padding: 4px 0;
169
+
170
+ &:hover {
171
+ > .gb-fc-mask {
172
+ display: block;
173
+ }
174
+ }
175
+
176
+ &.is-active > ._fd-draggable-drag,
177
+ &.is-active > .form-viewer {
178
+ outline: 1px solid #2e73ff;
179
+ }
180
+
181
+ &.is-hidden {
182
+ opacity: 0.55;
183
+ }
184
+
185
+ &.drag-over-top::before,
186
+ &.drag-over-bottom::after {
187
+ content: '';
188
+ position: absolute;
189
+ left: 0;
190
+ right: 0;
191
+ height: 2px;
192
+ background: #2e73ff;
193
+ z-index: 3;
194
+ }
195
+
196
+ &.drag-over-top::before {
197
+ top: -1px;
198
+ }
199
+
200
+ &.drag-over-bottom::after {
201
+ bottom: -1px;
202
+ }
203
+ }
204
+
205
+ .gb-fc-mask {
206
+ display: none;
207
+ position: absolute;
208
+ inset: 4px 0;
209
+ z-index: 2;
210
+ cursor: pointer;
211
+
212
+ &::after {
213
+ content: '';
214
+ position: absolute;
215
+ inset: 0;
216
+ border: 1px solid #2e73ff;
217
+ background: rgba(46, 115, 255, 0.03);
218
+ pointer-events: none;
219
+ }
220
+ }
221
+
222
+ .gb-fc-tools {
223
+ position: absolute;
224
+ right: 2px;
225
+ top: 2px;
226
+ z-index: 3;
227
+ display: flex;
228
+ align-items: center;
229
+ gap: 2px;
230
+ background: #fff;
231
+ border: 1px solid #2e73ff;
232
+ border-radius: 3px;
233
+ box-shadow: 0 2px 8px rgba(46, 115, 255, 0.25);
234
+ padding: 2px;
235
+ }
236
+
237
+ .gb-fc-tool {
238
+ display: inline-flex;
239
+ align-items: center;
240
+ justify-content: center;
241
+ width: 20px;
242
+ height: 20px;
243
+ color: #2e73ff;
244
+ cursor: pointer;
245
+ border-radius: 3px;
246
+
247
+ &:hover {
248
+ background: rgba(46, 115, 255, 0.12);
249
+ }
250
+
251
+ &--handle {
252
+ cursor: move;
253
+ }
254
+
255
+ &--danger:hover {
256
+ background: rgba(245, 74, 74, 0.12);
257
+ color: #f54a4a;
258
+ }
259
+ }
260
+
261
+ .gb-fc-column {
262
+ min-height: 60px;
263
+ border: 1px dashed transparent;
264
+ transition: border-color 0.2s ease;
265
+
266
+ &.has-child {
267
+ border-color: transparent;
268
+ }
269
+
270
+ &:hover {
271
+ border-color: #c0c4cc;
272
+ }
273
+ }
274
+
275
+ .gb-fc-row-box {
276
+ padding: 4px;
277
+ }
277
278
  </style>