index.vue 1.3 KB

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