Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7463eea2
authored
Mar 25, 2023
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Vue3 重构:REVIEW 表单构建
parent
2abc7eca
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
72 deletions
+67
-72
src/views/infra/build/index.vue
+67
-72
No files found.
src/views/infra/build/index.vue
View file @
7463eea2
...
@@ -3,77 +3,99 @@
...
@@ -3,77 +3,99 @@
<el-row>
<el-row>
<el-col>
<el-col>
<div
class=
"mb-2 float-right"
>
<div
class=
"mb-2 float-right"
>
<el-button
size=
"small"
@
click=
"setJson"
>
导入JSON
</el-button>
<el-button
size=
"small"
type=
"primary"
@
click=
"showJson"
>
生成 JSON
</el-button>
<el-button
size=
"small"
@
click=
"setOption"
>
导入Options
</el-button>
<el-button
size=
"small"
type=
"success"
@
click=
"showOption"
>
生成O ptions
</el-button>
<el-button
size=
"small"
type=
"primary"
@
click=
"showJson"
>
生成JSON
</el-button>
<el-button
size=
"small"
type=
"success"
@
click=
"showOption"
>
生成Options
</el-button>
<el-button
size=
"small"
type=
"danger"
@
click=
"showTemplate"
>
生成组件
</el-button>
<el-button
size=
"small"
type=
"danger"
@
click=
"showTemplate"
>
生成组件
</el-button>
<!--
<el-button
size=
"small"
@
click=
"changeLocale"
>
中英切换
</el-button>
-->
</div>
</div>
</el-col>
</el-col>
<!-- 表单设计器 -->
<el-col>
<el-col>
<fc-designer
ref=
"designer"
height=
"780px"
/>
<fc-designer
ref=
"designer"
height=
"780px"
/>
</el-col>
</el-col>
</el-row>
</el-row>
<Dialog
:title=
"dialogTitle"
v-model=
"dialogVisible"
maxHeight=
"600"
>
<div
ref=
"editor"
v-if=
"dialogVisible"
>
<XTextButton
style=
"float: right"
:title=
"t('common.copy')"
@
click=
"copy(formValue)"
/>
<el-scrollbar
height=
"580"
>
<div
v-highlight
>
<code
class=
"hljs"
>
{{
formValue
}}
</code>
</div>
</el-scrollbar>
</div>
<span
style=
"color: red"
v-if=
"err"
>
输入内容格式有误!
</span>
</Dialog>
</ContentWrap>
</ContentWrap>
<!-- 弹窗:表单预览 -->
<Dialog
:title=
"dialogTitle"
v-model=
"dialogVisible"
max-height=
"600"
>
<div
ref=
"editor"
v-if=
"dialogVisible"
>
<el-button
style=
"float: right"
@
click=
"copy(formData)"
>
{{
t
(
'common.copy'
)
}}
</el-button>
<el-scrollbar
height=
"580"
>
<div
v-highlight
>
<code
class=
"hljs"
>
{{
formData
}}
</code>
</div>
</el-scrollbar>
</div>
</Dialog>
</
template
>
</
template
>
<
script
setup
lang=
"ts"
name=
"Build"
>
<
script
setup
lang=
"ts"
name=
"Build"
>
import
formCreate
from
'@form-create/element-ui'
import
formCreate
from
'@form-create/element-ui'
import
{
useClipboard
}
from
'@vueuse/core'
import
{
useClipboard
}
from
'@vueuse/core'
const
{
t
}
=
useI18n
()
// 国际化
const
message
=
useMessage
()
// 消息
const
{
t
}
=
useI18n
()
const
designer
=
ref
()
// 表单设计器
const
message
=
useMessage
()
const
dialogVisible
=
ref
(
false
)
// 弹窗的是否展示
const
dialogTitle
=
ref
(
''
)
// 弹窗的标题
const
designer
=
ref
()
const
formType
=
ref
(
-
1
)
// 表单的类型:0 - 生成 JSON;1 - 生成 Options;2 - 生成组件
const
formData
=
ref
(
''
)
// 表单数据
const
dialogVisible
=
ref
(
false
)
const
dialogTitle
=
ref
(
''
)
const
err
=
ref
(
false
)
const
type
=
ref
(
-
1
)
const
formValue
=
ref
(
''
)
/** 打开弹窗 */
const
openModel
=
(
title
:
string
)
=>
{
const
openModel
=
(
title
:
string
)
=>
{
dialogVisible
.
value
=
true
dialogVisible
.
value
=
true
dialogTitle
.
value
=
title
dialogTitle
.
value
=
title
}
}
const
setJson
=
()
=>
{
/** 生成 JSON */
openModel
(
'导入JSON--未实现'
)
}
const
setOption
=
()
=>
{
openModel
(
'导入Options--未实现'
)
}
const
showJson
=
()
=>
{
const
showJson
=
()
=>
{
openModel
(
'生成JSON'
)
openModel
(
'生成
JSON'
)
t
ype
.
value
=
0
formT
ype
.
value
=
0
form
Value
.
value
=
designer
.
value
.
getRule
()
form
Data
.
value
=
designer
.
value
.
getRule
()
}
}
/** 生成 Options */
const
showOption
=
()
=>
{
const
showOption
=
()
=>
{
openModel
(
'生成Options'
)
openModel
(
'生成
Options'
)
t
ype
.
value
=
1
formT
ype
.
value
=
1
form
Value
.
value
=
designer
.
value
.
getOption
()
form
Data
.
value
=
designer
.
value
.
getOption
()
}
}
/** 生成组件 */
const
showTemplate
=
()
=>
{
const
showTemplate
=
()
=>
{
openModel
(
'生成组件'
)
openModel
(
'生成组件'
)
type
.
value
=
2
formType
.
value
=
2
formValue
.
value
=
makeTemplate
()
formData
.
value
=
makeTemplate
()
}
const
makeTemplate
=
()
=>
{
const
rule
=
designer
.
value
.
getRule
()
const
opt
=
designer
.
value
.
getOption
()
return
`<template>
<form-create
v-model="fapi"
:rule="rule"
:option="option"
@submit="onSubmit"
></form-create>
</template>
<script setup lang=ts>
import formCreate from "@form-create/element-ui";
const faps = ref(null)
const rule = ref('')
const option = ref('')
const init = () => {
rule.value = formCreate.parseJson('
${
formCreate
.
toJson
(
rule
).
replaceAll
(
'\\'
,
'\\\\'
)}
')
option.value = formCreate.parseJson('
${
JSON
.
stringify
(
opt
)}
')
}
const onSubmit = (formData) => {
//todo 提交表单
}
init()
<\/script>`
}
}
// const changeLocale = () => {
// console.info('changeLocale')
// }
/** 复制 **/
/** 复制 **/
const
copy
=
async
(
text
:
string
)
=>
{
const
copy
=
async
(
text
:
string
)
=>
{
...
@@ -87,31 +109,4 @@ const copy = async (text: string) => {
...
@@ -87,31 +109,4 @@ const copy = async (text: string) => {
}
}
}
}
}
}
const
makeTemplate
=
()
=>
{
const
rule
=
designer
.
value
.
getRule
()
const
opt
=
designer
.
value
.
getOption
()
return
`<template>
<form-create
v-model="fapi"
:rule="rule"
:option="option"
@submit="onSubmit"
></form-create>
</template>
<script setup lang=ts>
import formCreate from "@form-create/element-ui";
const faps = ref(null)
const rule = ref('')
const option = ref('')
const init = () => {
rule.value = formCreate.parseJson('
${
formCreate
.
toJson
(
rule
).
replaceAll
(
'\\'
,
'\\\\'
)}
')
option.value = formCreate.parseJson('
${
JSON
.
stringify
(
opt
)}
')
}
const onSubmit = (formData) => {
//todo 提交表单
}
init()
<\/script>`
}
</
script
>
</
script
>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment