vue+ant-design+formBuiler表单构建器——技能提升——form design——亲测有效

最近看到后端同事在弄一个后台管理系统,额,前端真的是夹缝中生存啊,AI抢饭碗,后端也想干前端的活儿。。。

他用到了表单构建器,具体效果如下:
在这里插入图片描述
网上有很多适用于ElementUiant-designform design插件,下面介绍一套完整的适用于ant-design的使用方法

步骤1:form-builder组件封装

components中添加form-builder文件夹
文件夹内容如下:
在这里插入图片描述
稍后我会把整个文件夹压缩上传到资源中,有需要的可自行下载。

步骤2:在页面中使用

我这边是在个弹窗中使用的,所以需要在弹窗中引入

<template>
  <a-modal
    width="100%"
    :title="title"
    :visible="visible"
    :confirm-loading="confirmLoading"
    :footer="null"
    @cancel="handleCancel"
  >
    <div style="height: 600px;overflow-y:auto;">
      <FormBuilder v-model="data" :gateway="gateway" :userModel="{}" @getData="saveData" />
    </div>
  </a-modal>
</template>

对应的script中的代码:

<script>
import FormBuilder from '@/components/form-builder/FormBuilder';
import { addProp, updateProp, getPropDetail } from '@/services/project/propTemplate';//这个是接口,具体得让后端同事处理了。
export default {
  components: {
    FormBuilder
  },
  data() {
    return {
      title: '新增属性',
      visible: false,
      confirmLoading: false,
      data: {
        propName: '',
        list: [],
        config: {}
      },
      gateway: this.$store.state.setting.gateway,//gateway: "http://192.168.16.100:9001",也是后端同事提供
      templateId: '',
      id: ''
    }
  },
  methods: {
    showModal(templateId, record) {
      this.templateId = templateId;
      if (record) {
        this.title = '编辑属性';
        this.id = record.id;
        this.getDetail();
      } else {
        this.title = '新增属性';
        this.id = '';
        this.data = {
          propName: '',
          list: [],
          config: {}
        }
      }
      this.visible = true;
    },
    getDetail() {
      getPropDetail({
        propertyTemplateId: this.templateId,
        templateId: this.id
      })
        .then(res => {
          this.data = {
            propName: res.data.name,
            list: res.data.templateFiled && JSON.parse(res.data.templateFiled),
            config: res.data.templateText && JSON.parse(res.data.templateText)
          }
        })
    },
    saveData(v) {
      this.visible = false;
      if (this.id) {
        updateProp({
          propertyTemplateId: this.templateId,
          templateId: this.id,//模板属性id
        }, {
          name: v.propName,
          templateText: JSON.stringify(v.config),
          templateFiled: JSON.stringify(v.data)
        })
          .then(res => {
            this.$message.success('保存成功');
            this.$emit('ok');
          })
      } else {
        addProp(this.templateId, {
          name: v.propName,
          templateText: JSON.stringify(v.config),
          templateFiled: JSON.stringify(v.data)
        })
          .then(res => {
            this.$message.success('保存成功');
            this.$emit('ok');
          })
      }
    },
    handleCancel() {
      this.visible = false;
    }
  }
}
</script>

步骤3:步骤2弹窗的使用

import PropEdit from './PropEdit';
export default {
  components: {
    PropEdit
  },
}

页面使用

<a-button type="primary" @click="$refs.propEdit.showModal(templateId)">新增</a-button>
<PropEdit ref="propEdit" @ok="getPropList"></PropEdit>

最近更新

  1. TCP协议是安全的吗?

    2024-05-12 03:34:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-12 03:34:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-12 03:34:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-12 03:34:02       20 阅读

热门阅读

  1. 人工智能是什么

    2024-05-12 03:34:02       12 阅读
  2. Vue 监控变化watch

    2024-05-12 03:34:02       10 阅读
  3. 事件组理论

    2024-05-12 03:34:02       8 阅读
  4. Python正则表达式入门指南

    2024-05-12 03:34:02       10 阅读
  5. RN使用js让输入框取消和获取焦点(及键盘的监听)

    2024-05-12 03:34:02       11 阅读
  6. Oracle完整截取汉字的方法

    2024-05-12 03:34:02       13 阅读
  7. python格式化显示复杂对象例如字典

    2024-05-12 03:34:02       9 阅读
  8. 线段树(以区间和为例)

    2024-05-12 03:34:02       13 阅读
  9. python的deap库使用记录

    2024-05-12 03:34:02       10 阅读
  10. AI绘画已如此厉害,为何我们仍需学习绘画?

    2024-05-12 03:34:02       13 阅读