index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <ContentWrap>
  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">
  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. </ContentWrap>
  32. </template>
  33. <script setup lang="ts" name="Build">
  34. import formCreate from '@form-create/element-ui'
  35. import { useClipboard } from '@vueuse/core'
  36. const { t } = useI18n()
  37. const message = useMessage()
  38. const designer = ref()
  39. const dialogVisible = ref(false)
  40. const dialogTitle = ref('')
  41. const err = ref(false)
  42. const type = ref(-1)
  43. const formValue = ref('')
  44. const openModel = (title: string) => {
  45. dialogVisible.value = true
  46. dialogTitle.value = title
  47. }
  48. const setJson = () => {
  49. openModel('导入JSON--未实现')
  50. }
  51. const setOption = () => {
  52. openModel('导入Options--未实现')
  53. }
  54. const showJson = () => {
  55. openModel('生成JSON')
  56. type.value = 0
  57. formValue.value = designer.value.getRule()
  58. }
  59. const showOption = () => {
  60. openModel('生成Options')
  61. type.value = 1
  62. formValue.value = designer.value.getOption()
  63. }
  64. const showTemplate = () => {
  65. openModel('生成组件')
  66. type.value = 2
  67. formValue.value = makeTemplate()
  68. }
  69. // const changeLocale = () => {
  70. // console.info('changeLocale')
  71. // }
  72. /** 复制 **/
  73. const copy = async (text: string) => {
  74. const { copy, copied, isSupported } = useClipboard({ source: text })
  75. if (!isSupported) {
  76. message.error(t('common.copyError'))
  77. } else {
  78. await copy()
  79. if (unref(copied)) {
  80. message.success(t('common.copySuccess'))
  81. }
  82. }
  83. }
  84. const makeTemplate = () => {
  85. const rule = designer.value.getRule()
  86. const opt = designer.value.getOption()
  87. return `<template>
  88. <form-create
  89. v-model="fapi"
  90. :rule="rule"
  91. :option="option"
  92. @submit="onSubmit"
  93. ></form-create>
  94. </template>
  95. <script setup lang=ts>
  96. import formCreate from "@form-create/element-ui";
  97. const faps = ref(null)
  98. const rule = ref('')
  99. const option = ref('')
  100. const init = () => {
  101. rule.value = formCreate.parseJson('${formCreate.toJson(rule).replaceAll('\\', '\\\\')}')
  102. option.value = formCreate.parseJson('${JSON.stringify(opt)}')
  103. }
  104. const onSubmit = (formData) => {
  105. //todo 提交表单
  106. }
  107. init()
  108. <\/script>`
  109. }
  110. </script>