Commit b90b297e6fa0f5ec63a09dddb3a88838b22d60a8
1 parent
bae44b45
feat: form designer
Showing
2 changed files
with
78 additions
and
2 deletions
yudao-ui-admin-vue3/src/types/auto-components.d.ts
| @@ -51,7 +51,6 @@ declare module '@vue/runtime-core' { | @@ -51,7 +51,6 @@ declare module '@vue/runtime-core' { | ||
| 51 | ElRadioButton: typeof import('element-plus/es')['ElRadioButton'] | 51 | ElRadioButton: typeof import('element-plus/es')['ElRadioButton'] |
| 52 | ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup'] | 52 | ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup'] |
| 53 | ElRow: typeof import('element-plus/es')['ElRow'] | 53 | ElRow: typeof import('element-plus/es')['ElRow'] |
| 54 | - ElScroll: typeof import('element-plus/es')['ElScroll'] | ||
| 55 | ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] | 54 | ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] |
| 56 | ElSelect: typeof import('element-plus/es')['ElSelect'] | 55 | ElSelect: typeof import('element-plus/es')['ElSelect'] |
| 57 | ElSkeleton: typeof import('element-plus/es')['ElSkeleton'] | 56 | ElSkeleton: typeof import('element-plus/es')['ElSkeleton'] |
yudao-ui-admin-vue3/src/views/infra/build/index.vue
| 1 | <template> | 1 | <template> |
| 2 | <ContentWrap> | 2 | <ContentWrap> |
| 3 | - <fc-designer ref="designer" height="780px" /> | 3 | + <el-row> |
| 4 | + <el-col> | ||
| 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> | ||
| 10 | + <el-button size="small" type="danger" @click="showTemplate">生成组件</el-button> | ||
| 11 | + <el-button size="small" @click="changeLocale">中英切换</el-button> | ||
| 12 | + </div> | ||
| 13 | + </el-col> | ||
| 14 | + <el-col> | ||
| 15 | + <fc-designer ref="designer" height="780px" /> | ||
| 16 | + </el-col> | ||
| 17 | + </el-row> | ||
| 18 | + <Dialog :title="dialogTitle" v-model="dialogVisible" maxHeight="600"> | ||
| 19 | + <div ref="editor" v-if="dialogVisible">{{ formValue }}</div> | ||
| 20 | + <span style="color: red" v-if="err">输入内容格式有误!</span> | ||
| 21 | + </Dialog> | ||
| 4 | </ContentWrap> | 22 | </ContentWrap> |
| 5 | </template> | 23 | </template> |
| 6 | <script setup lang="ts" name="Build"> | 24 | <script setup lang="ts" name="Build"> |
| 25 | +import formCreate from '@form-create/element-ui' | ||
| 26 | + | ||
| 7 | const designer = ref() | 27 | const designer = ref() |
| 28 | + | ||
| 29 | +const dialogVisible = ref(false) | ||
| 30 | +const dialogTitle = ref('') | ||
| 31 | +const err = ref(false) | ||
| 32 | +const type = ref(-1) | ||
| 33 | +const formValue = ref('') | ||
| 34 | + | ||
| 35 | +const openModel = (title: string) => { | ||
| 36 | + dialogVisible.value = true | ||
| 37 | + dialogTitle.value = title | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +const setJson = () => { | ||
| 41 | + openModel('导入JSON') | ||
| 42 | +} | ||
| 43 | +const setOption = () => { | ||
| 44 | + openModel('导入Options') | ||
| 45 | +} | ||
| 46 | +const showJson = () => { | ||
| 47 | + openModel('生成JSON') | ||
| 48 | + type.value = 0 | ||
| 49 | + formValue.value = designer.value.getRule() | ||
| 50 | +} | ||
| 51 | +const showOption = () => { | ||
| 52 | + openModel('生成Options') | ||
| 53 | + type.value = 1 | ||
| 54 | + formValue.value = designer.value.getOption() | ||
| 55 | +} | ||
| 56 | +const showTemplate = () => { | ||
| 57 | + openModel('生成组件') | ||
| 58 | + type.value = 2 | ||
| 59 | + formValue.value = makeTemplate() | ||
| 60 | +} | ||
| 61 | +const changeLocale = () => { | ||
| 62 | + console.info('changeLocale') | ||
| 63 | +} | ||
| 64 | +const makeTemplate = () => { | ||
| 65 | + const rule = designer.value.getRule() | ||
| 66 | + const opt = designer.value.getOption() | ||
| 67 | + return `<template> | ||
| 68 | + <form-create | ||
| 69 | + v-model="fapi" | ||
| 70 | + :rule="rule" | ||
| 71 | + :option="option" | ||
| 72 | + @submit="onSubmit" | ||
| 73 | + ></form-create> | ||
| 74 | +</template> | ||
| 75 | +<script setup lang=ts> | ||
| 76 | + import formCreate from "@form-create/element-ui"; | ||
| 77 | + const faps = ref(null) | ||
| 78 | + const rule = formCreate.parseJson('${formCreate.toJson(rule).replaceAll('\\', '\\\\')}') | ||
| 79 | + const option = formCreate.parseJson('${JSON.stringify(opt)}') | ||
| 80 | + const onSubmit = (formData) => { | ||
| 81 | + //todo 提交表单 | ||
| 82 | + } | ||
| 83 | +<\/script>` | ||
| 84 | +} | ||
| 8 | </script> | 85 | </script> |