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,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>