index.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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">{{ formValue }}</div>
  20. <span style="color: red" v-if="err">输入内容格式有误!</span>
  21. </Dialog>
  22. </ContentWrap>
  23. </template>
  24. <script setup lang="ts" name="Build">
  25. import formCreate from '@form-create/element-ui'
  26. const designer = ref()
  27. const dialogVisible = ref(false)
  28. const dialogTitle = ref('')
  29. const err = ref(false)
  30. const type = ref(-1)
  31. const formValue = ref('')
  32. const openModel = (title: string) => {
  33. dialogVisible.value = true
  34. dialogTitle.value = title
  35. }
  36. const setJson = () => {
  37. openModel('导入JSON')
  38. }
  39. const setOption = () => {
  40. openModel('导入Options')
  41. }
  42. const showJson = () => {
  43. openModel('生成JSON')
  44. type.value = 0
  45. formValue.value = designer.value.getRule()
  46. }
  47. const showOption = () => {
  48. openModel('生成Options')
  49. type.value = 1
  50. formValue.value = designer.value.getOption()
  51. }
  52. const showTemplate = () => {
  53. openModel('生成组件')
  54. type.value = 2
  55. formValue.value = makeTemplate()
  56. }
  57. const changeLocale = () => {
  58. console.info('changeLocale')
  59. }
  60. const makeTemplate = () => {
  61. const rule = designer.value.getRule()
  62. const opt = designer.value.getOption()
  63. return `<template>
  64. <form-create
  65. v-model="fapi"
  66. :rule="rule"
  67. :option="option"
  68. @submit="onSubmit"
  69. ></form-create>
  70. </template>
  71. <script setup lang=ts>
  72. import formCreate from "@form-create/element-ui";
  73. const faps = ref(null)
  74. const rule = formCreate.parseJson('${formCreate.toJson(rule).replaceAll('\\', '\\\\')}')
  75. const option = formCreate.parseJson('${JSON.stringify(opt)}')
  76. const onSubmit = (formData) => {
  77. //todo 提交表单
  78. }
  79. <\/script>`
  80. }
  81. </script>