3
3
<el-row >
4
4
<el-col >
5
5
<div class =" mb-2 float-right" >
6
- <el-button size =" small" @click =" setJson" > 导入JSON</el-button >
7
- <el-button size =" small" @click =" setOption" > 导入Options</el-button >
8
- <el-button size =" small" type =" primary" @click =" showJson" >生成JSON</el-button >
9
- <el-button size =" small" type =" success" @click =" showOption" >生成Options</el-button >
6
+ <el-button size =" small" type =" primary" @click =" showJson" >生成 JSON</el-button >
7
+ <el-button size =" small" type =" success" @click =" showOption" >生成O ptions</el-button >
10
8
<el-button size =" small" type =" danger" @click =" showTemplate" >生成组件</el-button >
11
- <!-- <el-button size="small" @click="changeLocale">中英切换</el-button> -->
12
9
</div >
13
10
</el-col >
11
+ <!-- 表单设计器 -->
14
12
<el-col >
15
13
<fc-designer ref =" designer" height =" 780px" />
16
14
</el-col >
17
15
</el-row >
18
- <Dialog :title =" dialogTitle" v-model =" dialogVisible" maxHeight =" 600" >
19
- <div ref =" editor" v-if =" dialogVisible" >
20
- <XTextButton style =" float : right " :title =" t('common.copy')" @click =" copy(formValue)" />
21
- <el-scrollbar height =" 580" >
22
- <div v-highlight >
23
- <code class =" hljs" >
24
- {{ formValue }}
25
- </code >
26
- </div >
27
- </el-scrollbar >
28
- </div >
29
- <span style =" color : red " v-if =" err" >输入内容格式有误!</span >
30
- </Dialog >
31
16
</ContentWrap >
17
+
18
+ <!-- 弹窗:表单预览 -->
19
+ <Dialog :title =" dialogTitle" v-model =" dialogVisible" max-height =" 600" >
20
+ <div ref =" editor" v-if =" dialogVisible" >
21
+ <el-button style =" float : right " @click =" copy(formData)" >
22
+ {{ t('common.copy') }}
23
+ </el-button >
24
+ <el-scrollbar height =" 580" >
25
+ <div v-highlight >
26
+ <code class =" hljs" >
27
+ {{ formData }}
28
+ </code >
29
+ </div >
30
+ </el-scrollbar >
31
+ </div >
32
+ </Dialog >
32
33
</template >
33
34
<script setup lang="ts" name="Build">
34
35
import formCreate from ' @form-create/element-ui'
35
36
import { useClipboard } from ' @vueuse/core'
37
+ const { t } = useI18n () // 国际化
38
+ const message = useMessage () // 消息
36
39
37
- const { t } = useI18n ()
38
- const message = useMessage ()
39
-
40
- const designer = ref ()
41
-
42
- const dialogVisible = ref (false )
43
- const dialogTitle = ref (' ' )
44
- const err = ref (false )
45
- const type = ref (- 1 )
46
- const formValue = ref (' ' )
40
+ const designer = ref () // 表单设计器
41
+ const dialogVisible = ref (false ) // 弹窗的是否展示
42
+ const dialogTitle = ref (' ' ) // 弹窗的标题
43
+ const formType = ref (- 1 ) // 表单的类型:0 - 生成 JSON;1 - 生成 Options;2 - 生成组件
44
+ const formData = ref (' ' ) // 表单数据
47
45
46
+ /** 打开弹窗 */
48
47
const openModel = (title : string ) => {
49
48
dialogVisible .value = true
50
49
dialogTitle .value = title
51
50
}
52
51
53
- const setJson = () => {
54
- openModel (' 导入JSON--未实现' )
55
- }
56
- const setOption = () => {
57
- openModel (' 导入Options--未实现' )
58
- }
52
+ /** 生成 JSON */
59
53
const showJson = () => {
60
- openModel (' 生成JSON ' )
61
- type .value = 0
62
- formValue .value = designer .value .getRule ()
54
+ openModel (' 生成 JSON ' )
55
+ formType .value = 0
56
+ formData .value = designer .value .getRule ()
63
57
}
58
+
59
+ /** 生成 Options */
64
60
const showOption = () => {
65
- openModel (' 生成Options ' )
66
- type .value = 1
67
- formValue .value = designer .value .getOption ()
61
+ openModel (' 生成 Options ' )
62
+ formType .value = 1
63
+ formData .value = designer .value .getOption ()
68
64
}
65
+
66
+ /** 生成组件 */
69
67
const showTemplate = () => {
70
68
openModel (' 生成组件' )
71
- type .value = 2
72
- formValue .value = makeTemplate ()
69
+ formType .value = 2
70
+ formData .value = makeTemplate ()
71
+ }
72
+
73
+ const makeTemplate = () => {
74
+ const rule = designer .value .getRule ()
75
+ const opt = designer .value .getOption ()
76
+ return ` <template>
77
+ <form-create
78
+ v-model="fapi"
79
+ :rule="rule"
80
+ :option="option"
81
+ @submit="onSubmit"
82
+ ></form-create>
83
+ </template>
84
+ <script setup lang=ts>
85
+ import formCreate from "@form-create/element-ui";
86
+ const faps = ref(null)
87
+ const rule = ref('')
88
+ const option = ref('')
89
+ const init = () => {
90
+ rule.value = formCreate.parseJson('${formCreate .toJson (rule ).replaceAll (' \\ ' , ' \\\\ ' )}')
91
+ option.value = formCreate.parseJson('${JSON .stringify (opt )}')
92
+ }
93
+ const onSubmit = (formData) => {
94
+ //todo 提交表单
95
+ }
96
+ init()
97
+ <\/ script> `
73
98
}
74
- // const changeLocale = () => {
75
- // console.info('changeLocale')
76
- // }
77
99
78
100
/** 复制 **/
79
101
const copy = async (text : string ) => {
@@ -87,31 +109,4 @@ const copy = async (text: string) => {
87
109
}
88
110
}
89
111
}
90
-
91
- const makeTemplate = () => {
92
- const rule = designer .value .getRule ()
93
- const opt = designer .value .getOption ()
94
- return ` <template>
95
- <form-create
96
- v-model="fapi"
97
- :rule="rule"
98
- :option="option"
99
- @submit="onSubmit"
100
- ></form-create>
101
- </template>
102
- <script setup lang=ts>
103
- import formCreate from "@form-create/element-ui";
104
- const faps = ref(null)
105
- const rule = ref('')
106
- const option = ref('')
107
- const init = () => {
108
- rule.value = formCreate.parseJson('${formCreate .toJson (rule ).replaceAll (' \\ ' , ' \\\\ ' )}')
109
- option.value = formCreate.parseJson('${JSON .stringify (opt )}')
110
- }
111
- const onSubmit = (formData) => {
112
- //todo 提交表单
113
- }
114
- init()
115
- <\/ script> `
116
- }
117
112
</script >
0 commit comments