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.
- package/LICENSE +21 -21
- package/README.md +84 -84
- package/dist/gbformdesign.css +1 -1
- package/dist/gbformdesign.js +1146 -1051
- package/dist/gbformdesign.js.map +1 -1
- package/dist/gbformdesign.umd.cjs +6 -6
- package/dist/gbformdesign.umd.cjs.map +1 -1
- package/package.json +58 -57
- package/src/core/FormVariable.js +328 -328
- package/src/core/dynamicFormUtils.js +139 -139
- package/src/core/fileIO.js +90 -90
- package/src/core/formVariableTypeSystem.js +327 -327
- package/src/core/index.js +26 -26
- package/src/core/schema.js +192 -192
- package/src/design/composables/useDefaultValue.js +55 -55
- package/src/design/constants/componentTemplates.js +181 -190
- package/src/design/constants/componentTypes.js +70 -70
- package/src/design/utils/componentUtils.js +75 -75
- package/src/designer/fc/FcCanvasField.vue +277 -276
- package/src/designer/fc/FcJsonPanel.vue +113 -113
- package/src/designer/fc/FcPreviewDialog.vue +62 -62
- package/src/designer/fc/FcPropsPanel.vue +373 -373
- package/src/designer/fc/FormDesigner.vue +633 -633
- package/src/designer/fc/codegen.js +120 -120
- package/src/index.js +48 -48
- package/src/styles/config.scss +102 -102
- package/src/styles/fc/designer.css +837 -837
- package/src/styles/fc/icon.css +1053 -1053
- package/src/styles/index.scss +4 -4
- package/src/view/FormField.vue +301 -301
- package/src/view/FormViewer.vue +216 -216
- package/src/view/composables/useFormValidation.js +201 -201
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<el-container class="_fc-json-preview">
|
|
3
|
-
<el-header height="40px" class="_fc-l-tabs">
|
|
4
|
-
<div class="_fc-l-tab" :class="{ active: active === 'rule' }" @click="switchTab('rule')">表单规则</div>
|
|
5
|
-
<div class="_fc-l-tab" :class="{ active: active === 'options' }" @click="switchTab('options')">表单配置</div>
|
|
6
|
-
<div class="_fc-json-preview-down">
|
|
7
|
-
<el-tooltip effect="dark" content="导出 JSON" placement="top" :hide-after="0">
|
|
8
|
-
<i class="fc-icon icon-download" @click="downloadJson"></i>
|
|
9
|
-
</el-tooltip>
|
|
10
|
-
</div>
|
|
11
|
-
</el-header>
|
|
12
|
-
<el-main style="padding: 8px">
|
|
13
|
-
<textarea
|
|
14
|
-
v-model="text"
|
|
15
|
-
class="gb-fc-json-editor"
|
|
16
|
-
spellcheck="false"
|
|
17
|
-
@focus="onFocus"
|
|
18
|
-
@blur="onBlur"
|
|
19
|
-
></textarea>
|
|
20
|
-
<div v-if="error" class="gb-fc-json-error">{{ error }}</div>
|
|
21
|
-
</el-main>
|
|
22
|
-
</el-container>
|
|
23
|
-
</template>
|
|
24
|
-
|
|
25
|
-
<script setup>
|
|
26
|
-
import { ref } from 'vue'
|
|
27
|
-
import { ElMessage } from 'element-plus'
|
|
28
|
-
|
|
29
|
-
defineOptions({ name: 'FcJsonPanel' })
|
|
30
|
-
|
|
31
|
-
const props = defineProps({
|
|
32
|
-
components: { type: Array, required: true },
|
|
33
|
-
formOptions: { type: Object, required: true },
|
|
34
|
-
fileName: { type: String, default: 'form' }
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
const emit = defineEmits(['update:components', 'update:formOptions'])
|
|
38
|
-
|
|
39
|
-
const active = ref('rule')
|
|
40
|
-
const text = ref(JSON.stringify(props.components, null, 2))
|
|
41
|
-
const error = ref('')
|
|
42
|
-
let oldValue = ''
|
|
43
|
-
|
|
44
|
-
const serialize = () =>
|
|
45
|
-
active.value === 'rule'
|
|
46
|
-
? JSON.stringify(props.components, null, 2)
|
|
47
|
-
: JSON.stringify(props.formOptions, null, 2)
|
|
48
|
-
|
|
49
|
-
const switchTab = (tab) => {
|
|
50
|
-
active.value = tab
|
|
51
|
-
text.value = serialize()
|
|
52
|
-
error.value = ''
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const onFocus = () => {
|
|
56
|
-
oldValue = serialize()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const onBlur = () => {
|
|
60
|
-
error.value = ''
|
|
61
|
-
if (text.value.trim() === oldValue.trim()) return
|
|
62
|
-
try {
|
|
63
|
-
const parsed = JSON.parse(text.value)
|
|
64
|
-
if (active.value === 'rule') {
|
|
65
|
-
if (!Array.isArray(parsed)) throw new Error('表单规则必须是数组')
|
|
66
|
-
emit('update:components', parsed)
|
|
67
|
-
} else {
|
|
68
|
-
emit('update:formOptions', parsed || {})
|
|
69
|
-
}
|
|
70
|
-
ElMessage.success('JSON 已应用')
|
|
71
|
-
} catch (err) {
|
|
72
|
-
error.value = `JSON 解析失败:${err.message}`
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const downloadJson = () => {
|
|
77
|
-
const data =
|
|
78
|
-
active.value === 'rule'
|
|
79
|
-
? { rule: props.components, options: props.formOptions }
|
|
80
|
-
: { options: props.formOptions, rule: props.components }
|
|
81
|
-
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' })
|
|
82
|
-
const url = URL.createObjectURL(blob)
|
|
83
|
-
const link = document.createElement('a')
|
|
84
|
-
link.href = url
|
|
85
|
-
link.download = `fc-json-${Date.now()}.json`
|
|
86
|
-
link.click()
|
|
87
|
-
setTimeout(() => URL.revokeObjectURL(url), 0)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
defineExpose({ refresh: () => (text.value = serialize()) })
|
|
91
|
-
</script>
|
|
92
|
-
|
|
93
|
-
<style lang="scss">
|
|
94
|
-
.gb-fc-json-editor {
|
|
95
|
-
width: 100%;
|
|
96
|
-
height: 100%;
|
|
97
|
-
min-height: 400px;
|
|
98
|
-
box-sizing: border-box;
|
|
99
|
-
border: 1px solid #ececec;
|
|
100
|
-
outline: none;
|
|
101
|
-
resize: none;
|
|
102
|
-
padding: 8px;
|
|
103
|
-
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
|
104
|
-
font-size: 12px;
|
|
105
|
-
line-height: 1.6;
|
|
106
|
-
color: #262626;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
.gb-fc-json-error {
|
|
110
|
-
margin-top: 6px;
|
|
111
|
-
font-size: 12px;
|
|
112
|
-
color: var(--el-color-danger);
|
|
113
|
-
}
|
|
1
|
+
<template>
|
|
2
|
+
<el-container class="_fc-json-preview">
|
|
3
|
+
<el-header height="40px" class="_fc-l-tabs">
|
|
4
|
+
<div class="_fc-l-tab" :class="{ active: active === 'rule' }" @click="switchTab('rule')">表单规则</div>
|
|
5
|
+
<div class="_fc-l-tab" :class="{ active: active === 'options' }" @click="switchTab('options')">表单配置</div>
|
|
6
|
+
<div class="_fc-json-preview-down">
|
|
7
|
+
<el-tooltip effect="dark" content="导出 JSON" placement="top" :hide-after="0">
|
|
8
|
+
<i class="fc-icon icon-download" @click="downloadJson"></i>
|
|
9
|
+
</el-tooltip>
|
|
10
|
+
</div>
|
|
11
|
+
</el-header>
|
|
12
|
+
<el-main style="padding: 8px">
|
|
13
|
+
<textarea
|
|
14
|
+
v-model="text"
|
|
15
|
+
class="gb-fc-json-editor"
|
|
16
|
+
spellcheck="false"
|
|
17
|
+
@focus="onFocus"
|
|
18
|
+
@blur="onBlur"
|
|
19
|
+
></textarea>
|
|
20
|
+
<div v-if="error" class="gb-fc-json-error">{{ error }}</div>
|
|
21
|
+
</el-main>
|
|
22
|
+
</el-container>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script setup>
|
|
26
|
+
import { ref } from 'vue'
|
|
27
|
+
import { ElMessage } from 'element-plus'
|
|
28
|
+
|
|
29
|
+
defineOptions({ name: 'FcJsonPanel' })
|
|
30
|
+
|
|
31
|
+
const props = defineProps({
|
|
32
|
+
components: { type: Array, required: true },
|
|
33
|
+
formOptions: { type: Object, required: true },
|
|
34
|
+
fileName: { type: String, default: 'form' }
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const emit = defineEmits(['update:components', 'update:formOptions'])
|
|
38
|
+
|
|
39
|
+
const active = ref('rule')
|
|
40
|
+
const text = ref(JSON.stringify(props.components, null, 2))
|
|
41
|
+
const error = ref('')
|
|
42
|
+
let oldValue = ''
|
|
43
|
+
|
|
44
|
+
const serialize = () =>
|
|
45
|
+
active.value === 'rule'
|
|
46
|
+
? JSON.stringify(props.components, null, 2)
|
|
47
|
+
: JSON.stringify(props.formOptions, null, 2)
|
|
48
|
+
|
|
49
|
+
const switchTab = (tab) => {
|
|
50
|
+
active.value = tab
|
|
51
|
+
text.value = serialize()
|
|
52
|
+
error.value = ''
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const onFocus = () => {
|
|
56
|
+
oldValue = serialize()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const onBlur = () => {
|
|
60
|
+
error.value = ''
|
|
61
|
+
if (text.value.trim() === oldValue.trim()) return
|
|
62
|
+
try {
|
|
63
|
+
const parsed = JSON.parse(text.value)
|
|
64
|
+
if (active.value === 'rule') {
|
|
65
|
+
if (!Array.isArray(parsed)) throw new Error('表单规则必须是数组')
|
|
66
|
+
emit('update:components', parsed)
|
|
67
|
+
} else {
|
|
68
|
+
emit('update:formOptions', parsed || {})
|
|
69
|
+
}
|
|
70
|
+
ElMessage.success('JSON 已应用')
|
|
71
|
+
} catch (err) {
|
|
72
|
+
error.value = `JSON 解析失败:${err.message}`
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const downloadJson = () => {
|
|
77
|
+
const data =
|
|
78
|
+
active.value === 'rule'
|
|
79
|
+
? { rule: props.components, options: props.formOptions }
|
|
80
|
+
: { options: props.formOptions, rule: props.components }
|
|
81
|
+
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' })
|
|
82
|
+
const url = URL.createObjectURL(blob)
|
|
83
|
+
const link = document.createElement('a')
|
|
84
|
+
link.href = url
|
|
85
|
+
link.download = `fc-json-${Date.now()}.json`
|
|
86
|
+
link.click()
|
|
87
|
+
setTimeout(() => URL.revokeObjectURL(url), 0)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
defineExpose({ refresh: () => (text.value = serialize()) })
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
<style lang="scss">
|
|
94
|
+
.gb-fc-json-editor {
|
|
95
|
+
width: 100%;
|
|
96
|
+
height: 100%;
|
|
97
|
+
min-height: 400px;
|
|
98
|
+
box-sizing: border-box;
|
|
99
|
+
border: 1px solid #ececec;
|
|
100
|
+
outline: none;
|
|
101
|
+
resize: none;
|
|
102
|
+
padding: 8px;
|
|
103
|
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
|
104
|
+
font-size: 12px;
|
|
105
|
+
line-height: 1.6;
|
|
106
|
+
color: #262626;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.gb-fc-json-error {
|
|
110
|
+
margin-top: 6px;
|
|
111
|
+
font-size: 12px;
|
|
112
|
+
color: var(--el-color-danger);
|
|
113
|
+
}
|
|
114
114
|
</style>
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<el-dialog :model-value="modelValue" width="80%" class="_fd-preview-dialog" append-to-body @update:model-value="$emit('update:modelValue', $event)">
|
|
3
|
-
<div class="_fd-preview-tabs el-tabs">
|
|
4
|
-
<div class="el-tabs__header">
|
|
5
|
-
<div class="el-tabs__nav-wrap">
|
|
6
|
-
<div class="el-tabs__nav">
|
|
7
|
-
<div
|
|
8
|
-
v-for="tab in tabs"
|
|
9
|
-
:key="tab.value"
|
|
10
|
-
class="el-tabs__item"
|
|
11
|
-
:class="{ 'is-active': active === tab.value }"
|
|
12
|
-
@click="active = tab.value"
|
|
13
|
-
>
|
|
14
|
-
{{ tab.label }}
|
|
15
|
-
</div>
|
|
16
|
-
</div>
|
|
17
|
-
</div>
|
|
18
|
-
</div>
|
|
19
|
-
</div>
|
|
20
|
-
<div v-if="active !== 'form'" class="_fd-preview-copy" @click="copyCode">
|
|
21
|
-
<i class="fc-icon icon-copy"></i>
|
|
22
|
-
</div>
|
|
23
|
-
<FormViewer v-if="active === 'form'" :form-config="components" />
|
|
24
|
-
<pre v-else class="_fd-preview-code"><code>{{ active === 'component' ? componentCode : htmlCode }}</code></pre>
|
|
25
|
-
</el-dialog>
|
|
26
|
-
</template>
|
|
27
|
-
|
|
28
|
-
<script setup>
|
|
29
|
-
import { computed, ref } from 'vue'
|
|
30
|
-
import { ElMessage } from 'element-plus'
|
|
31
|
-
import FormViewer from '../../view/FormViewer.vue'
|
|
32
|
-
import { toHtml, toVueTemplate } from './codegen.js'
|
|
33
|
-
|
|
34
|
-
defineOptions({ name: 'FcPreviewDialog' })
|
|
35
|
-
|
|
36
|
-
const props = defineProps({
|
|
37
|
-
modelValue: { type: Boolean, default: false },
|
|
38
|
-
components: { type: Array, default: () => [] },
|
|
39
|
-
formOptions: { type: Object, default: () => ({}) }
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
defineEmits(['update:modelValue'])
|
|
43
|
-
|
|
44
|
-
const tabs = [
|
|
45
|
-
{ label: '表单模式', value: 'form' },
|
|
46
|
-
{ label: '组件模式', value: 'component' },
|
|
47
|
-
{ label: 'HTML 模式', value: 'html' }
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
const active = ref('form')
|
|
51
|
-
const componentCode = computed(() => toVueTemplate(props.components, props.formOptions))
|
|
52
|
-
const htmlCode = computed(() => toHtml(props.components, props.formOptions))
|
|
53
|
-
|
|
54
|
-
const copyCode = async () => {
|
|
55
|
-
const code = active.value === 'component' ? componentCode.value : htmlCode.value
|
|
56
|
-
try {
|
|
57
|
-
await navigator.clipboard.writeText(code)
|
|
58
|
-
ElMessage.success('代码已复制')
|
|
59
|
-
} catch {
|
|
60
|
-
ElMessage.warning('复制失败,请手动复制')
|
|
61
|
-
}
|
|
62
|
-
}
|
|
1
|
+
<template>
|
|
2
|
+
<el-dialog :model-value="modelValue" width="80%" class="_fd-preview-dialog" append-to-body @update:model-value="$emit('update:modelValue', $event)">
|
|
3
|
+
<div class="_fd-preview-tabs el-tabs">
|
|
4
|
+
<div class="el-tabs__header">
|
|
5
|
+
<div class="el-tabs__nav-wrap">
|
|
6
|
+
<div class="el-tabs__nav">
|
|
7
|
+
<div
|
|
8
|
+
v-for="tab in tabs"
|
|
9
|
+
:key="tab.value"
|
|
10
|
+
class="el-tabs__item"
|
|
11
|
+
:class="{ 'is-active': active === tab.value }"
|
|
12
|
+
@click="active = tab.value"
|
|
13
|
+
>
|
|
14
|
+
{{ tab.label }}
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
<div v-if="active !== 'form'" class="_fd-preview-copy" @click="copyCode">
|
|
21
|
+
<i class="fc-icon icon-copy"></i>
|
|
22
|
+
</div>
|
|
23
|
+
<FormViewer v-if="active === 'form'" :form-config="components" />
|
|
24
|
+
<pre v-else class="_fd-preview-code"><code>{{ active === 'component' ? componentCode : htmlCode }}</code></pre>
|
|
25
|
+
</el-dialog>
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<script setup>
|
|
29
|
+
import { computed, ref } from 'vue'
|
|
30
|
+
import { ElMessage } from 'element-plus'
|
|
31
|
+
import FormViewer from '../../view/FormViewer.vue'
|
|
32
|
+
import { toHtml, toVueTemplate } from './codegen.js'
|
|
33
|
+
|
|
34
|
+
defineOptions({ name: 'FcPreviewDialog' })
|
|
35
|
+
|
|
36
|
+
const props = defineProps({
|
|
37
|
+
modelValue: { type: Boolean, default: false },
|
|
38
|
+
components: { type: Array, default: () => [] },
|
|
39
|
+
formOptions: { type: Object, default: () => ({}) }
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
defineEmits(['update:modelValue'])
|
|
43
|
+
|
|
44
|
+
const tabs = [
|
|
45
|
+
{ label: '表单模式', value: 'form' },
|
|
46
|
+
{ label: '组件模式', value: 'component' },
|
|
47
|
+
{ label: 'HTML 模式', value: 'html' }
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
const active = ref('form')
|
|
51
|
+
const componentCode = computed(() => toVueTemplate(props.components, props.formOptions))
|
|
52
|
+
const htmlCode = computed(() => toHtml(props.components, props.formOptions))
|
|
53
|
+
|
|
54
|
+
const copyCode = async () => {
|
|
55
|
+
const code = active.value === 'component' ? componentCode.value : htmlCode.value
|
|
56
|
+
try {
|
|
57
|
+
await navigator.clipboard.writeText(code)
|
|
58
|
+
ElMessage.success('代码已复制')
|
|
59
|
+
} catch {
|
|
60
|
+
ElMessage.warning('复制失败,请手动复制')
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
63
|
</script>
|