index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <!-- 代码构建 -->
  2. <script setup lang="ts">
  3. const props = defineProps({
  4. showBtn: {
  5. type: Boolean,
  6. default: false
  7. },
  8. formJson: {
  9. type: Object,
  10. default: undefined
  11. }
  12. })
  13. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  14. const buildRef = ref();
  15. const emits = defineEmits(['reJson', 'saveDesign']);
  16. //获取表单json
  17. const getJson = () => {
  18. const formJson = JSON.stringify(buildRef.value.getFormJson())
  19. const fieldJson = JSON.stringify(buildRef.value.getFieldWidgets())
  20. let data = {
  21. formJson, fieldJson
  22. }
  23. emits("saveDesign", data)
  24. }
  25. onMounted(() => {
  26. if (props.formJson) {
  27. buildRef.value.setFormJson(props.formJson)
  28. }
  29. })
  30. </script>
  31. <template>
  32. <div>
  33. <v-form-designer
  34. class="build"
  35. ref="buildRef"
  36. :designer-config="{ importJsonButton: true, exportJsonButton: true, exportCodeButton: true, generateSFCButton: true, formTemplates: true }"
  37. >
  38. <template #customToolButtons v-if="showBtn">
  39. <el-button link type="primary" icon="Select" @click="getJson">保存</el-button>
  40. </template>
  41. </v-form-designer>
  42. </div>
  43. </template>
  44. <style lang="scss">
  45. .build {
  46. margin: 0 !important;
  47. overflow-y: auto !important;
  48. & header.main-header {
  49. display: none;
  50. }
  51. & .right-toolbar-con {
  52. text-align: right !important;
  53. }
  54. }
  55. </style>