Commit af0178e8ff8afd6fabd322286c7f19cbde08e5c4
1 parent
b90b297e
perf: 优化表单构造器预览界面
Showing
1 changed file
with
35 additions
and
5 deletions
yudao-ui-admin-vue3/src/views/infra/build/index.vue
| ... | ... | @@ -16,13 +16,24 @@ |
| 16 | 16 | </el-col> |
| 17 | 17 | </el-row> |
| 18 | 18 | <Dialog :title="dialogTitle" v-model="dialogVisible" maxHeight="600"> |
| 19 | - <div ref="editor" v-if="dialogVisible">{{ formValue }}</div> | |
| 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 | + <pre> | |
| 23 | + {{ formValue }} | |
| 24 | + </pre> | |
| 25 | + </el-scrollbar> | |
| 26 | + </div> | |
| 20 | 27 | <span style="color: red" v-if="err">输入内容格式有误!</span> |
| 21 | 28 | </Dialog> |
| 22 | 29 | </ContentWrap> |
| 23 | 30 | </template> |
| 24 | 31 | <script setup lang="ts" name="Build"> |
| 25 | 32 | import formCreate from '@form-create/element-ui' |
| 33 | +import { useClipboard } from '@vueuse/core' | |
| 34 | + | |
| 35 | +const { t } = useI18n() | |
| 36 | +const message = useMessage() | |
| 26 | 37 | |
| 27 | 38 | const designer = ref() |
| 28 | 39 | |
| ... | ... | @@ -38,10 +49,10 @@ const openModel = (title: string) => { |
| 38 | 49 | } |
| 39 | 50 | |
| 40 | 51 | const setJson = () => { |
| 41 | - openModel('导入JSON') | |
| 52 | + openModel('导入JSON--未实现') | |
| 42 | 53 | } |
| 43 | 54 | const setOption = () => { |
| 44 | - openModel('导入Options') | |
| 55 | + openModel('导入Options--未实现') | |
| 45 | 56 | } |
| 46 | 57 | const showJson = () => { |
| 47 | 58 | openModel('生成JSON') |
| ... | ... | @@ -61,6 +72,20 @@ const showTemplate = () => { |
| 61 | 72 | const changeLocale = () => { |
| 62 | 73 | console.info('changeLocale') |
| 63 | 74 | } |
| 75 | + | |
| 76 | +/** 复制 **/ | |
| 77 | +const copy = async (text: string) => { | |
| 78 | + const { copy, copied, isSupported } = useClipboard({ source: text }) | |
| 79 | + if (!isSupported) { | |
| 80 | + message.error(t('common.copyError')) | |
| 81 | + } else { | |
| 82 | + await copy() | |
| 83 | + if (unref(copied)) { | |
| 84 | + message.success(t('common.copySuccess')) | |
| 85 | + } | |
| 86 | + } | |
| 87 | +} | |
| 88 | + | |
| 64 | 89 | const makeTemplate = () => { |
| 65 | 90 | const rule = designer.value.getRule() |
| 66 | 91 | const opt = designer.value.getOption() |
| ... | ... | @@ -75,11 +100,16 @@ const makeTemplate = () => { |
| 75 | 100 | <script setup lang=ts> |
| 76 | 101 | import formCreate from "@form-create/element-ui"; |
| 77 | 102 | const faps = ref(null) |
| 78 | - const rule = formCreate.parseJson('${formCreate.toJson(rule).replaceAll('\\', '\\\\')}') | |
| 79 | - const option = formCreate.parseJson('${JSON.stringify(opt)}') | |
| 103 | + const rule = ref('') | |
| 104 | + const option = ref('') | |
| 105 | + const init = () => { | |
| 106 | + rule.value = formCreate.parseJson('${formCreate.toJson(rule).replaceAll('\\', '\\\\')}') | |
| 107 | + option.value = formCreate.parseJson('${JSON.stringify(opt)}') | |
| 108 | + } | |
| 80 | 109 | const onSubmit = (formData) => { |
| 81 | 110 | //todo 提交表单 |
| 82 | 111 | } |
| 112 | + init() | |
| 83 | 113 | <\/script>` |
| 84 | 114 | } |
| 85 | 115 | </script> | ... | ... |