index.vue 1.4 KB

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