Commit af0178e8ff8afd6fabd322286c7f19cbde08e5c4

Authored by xingyu
1 parent b90b297e

perf: 优化表单构造器预览界面

yudao-ui-admin-vue3/src/views/infra/build/index.vue
@@ -16,13 +16,24 @@ @@ -16,13 +16,24 @@
16 </el-col> 16 </el-col>
17 </el-row> 17 </el-row>
18 <Dialog :title="dialogTitle" v-model="dialogVisible" maxHeight="600"> 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 <span style="color: red" v-if="err">输入内容格式有误!</span> 27 <span style="color: red" v-if="err">输入内容格式有误!</span>
21 </Dialog> 28 </Dialog>
22 </ContentWrap> 29 </ContentWrap>
23 </template> 30 </template>
24 <script setup lang="ts" name="Build"> 31 <script setup lang="ts" name="Build">
25 import formCreate from '@form-create/element-ui' 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 const designer = ref() 38 const designer = ref()
28 39
@@ -38,10 +49,10 @@ const openModel = (title: string) =&gt; { @@ -38,10 +49,10 @@ const openModel = (title: string) =&gt; {
38 } 49 }
39 50
40 const setJson = () => { 51 const setJson = () => {
41 - openModel('导入JSON') 52 + openModel('导入JSON--未实现')
42 } 53 }
43 const setOption = () => { 54 const setOption = () => {
44 - openModel('导入Options') 55 + openModel('导入Options--未实现')
45 } 56 }
46 const showJson = () => { 57 const showJson = () => {
47 openModel('生成JSON') 58 openModel('生成JSON')
@@ -61,6 +72,20 @@ const showTemplate = () =&gt; { @@ -61,6 +72,20 @@ const showTemplate = () =&gt; {
61 const changeLocale = () => { 72 const changeLocale = () => {
62 console.info('changeLocale') 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 const makeTemplate = () => { 89 const makeTemplate = () => {
65 const rule = designer.value.getRule() 90 const rule = designer.value.getRule()
66 const opt = designer.value.getOption() 91 const opt = designer.value.getOption()
@@ -75,11 +100,16 @@ const makeTemplate = () =&gt; { @@ -75,11 +100,16 @@ const makeTemplate = () =&gt; {
75 <script setup lang=ts> 100 <script setup lang=ts>
76 import formCreate from "@form-create/element-ui"; 101 import formCreate from "@form-create/element-ui";
77 const faps = ref(null) 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 const onSubmit = (formData) => { 109 const onSubmit = (formData) => {
81 //todo 提交表单 110 //todo 提交表单
82 } 111 }
  112 + init()
83 <\/script>` 113 <\/script>`
84 } 114 }
85 </script> 115 </script>