designForm.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <el-drawer v-model="visibleDialog" class="le-drawer" size="100%" @close="handleCancel">
  3. <template #header>
  4. <div class="flex flex-pack-justify flex_align-center -my-2">
  5. <span class="text-[16px]">查看详情</span>
  6. <el-button type="primary" @click="saveDesignEv">保存</el-button>
  7. </div>
  8. </template>
  9. <div>
  10. <er-form-editor
  11. v-if="myProps.modelValue"
  12. ref="EReditorRef"
  13. :is-show-i18n="false"
  14. :file-upload-u-r-i="uploadFileApi"
  15. @listener="handleListener"
  16. />
  17. </div>
  18. </el-drawer>
  19. </template>
  20. <script setup>
  21. import { computed, ref, watch, nextTick } from 'vue'
  22. import { erFormEditor } from '@ER/formEditor'
  23. import { ElMessage } from 'element-plus'
  24. import formtemplate from '@/api/flow/formtemplate'
  25. const { VITE_APP_BASE_API } = import.meta.env
  26. const EReditorRef = ref()
  27. const formOptions = ref({})
  28. const uploadFileApi = ref(`${VITE_APP_BASE_API}/v1/oss/upload`)
  29. // 同步值
  30. const $myEmit = defineEmits(['update:modelValue', 'successFn'])
  31. const myProps = defineProps({
  32. modelValue: {
  33. type: Boolean,
  34. default: false
  35. },
  36. record: {
  37. type: Object,
  38. default: () => {}
  39. }
  40. })
  41. const handleListener = obj => {}
  42. const handleCancel = () => {
  43. $myEmit('update:modelValue', false)
  44. }
  45. const saveDesignEv = async () => {
  46. const formStructure = EReditorRef.value.getData()
  47. const fields = formStructure?.fields || []
  48. const bool = fields.length
  49. if (!bool) {
  50. return ElMessage({
  51. message: '请设计您的表单模板内容',
  52. type: 'error'
  53. })
  54. }
  55. const content = JSON.stringify(formStructure)
  56. await formtemplate.formTemplateAddOrEditSaveApi({ ...myProps.record, content })
  57. ElMessage.success(`表单模板设计成功~`)
  58. handleCancel()
  59. $myEmit('successFn')
  60. }
  61. // computed
  62. const visibleDialog = computed({
  63. get() {
  64. return myProps.modelValue
  65. },
  66. set(val) {
  67. $myEmit('update:modelValue', val)
  68. }
  69. })
  70. watch(
  71. () => myProps.modelValue,
  72. (val, oldValue) => {
  73. if (val) {
  74. nextTick(() => {
  75. if (myProps.record?.content) {
  76. const formStructure = JSON.parse(myProps.record.content || '{}')
  77. EReditorRef.value.setData(formStructure || {})
  78. }
  79. })
  80. }
  81. }
  82. )
  83. </script>
  84. <style scoped lang="scss"></style>