田源
2024-03-26 55fdd88d12e656fae07f54e53af60fcf3bb19c8a
动态按钮封装方法-表格树添加默认新增子级按钮
已修改3个文件
已添加2个文件
359 ■■■■ 文件已修改
Source/ProjectWeb/src/components/dynamic-components/dynamic-TreeTable.vue 175 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/components/dynamic-components/dynamic-button.vue 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/components/dynamic-components/dynamic-custom.vue 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/views/base/buttonForm.js 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/views/base/buttonTable.js 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/components/dynamic-components/dynamic-TreeTable.vue
@@ -12,14 +12,14 @@
      </template>
      <!--top区域按钮-->
      <template slot="menuLeft" slot-scope="scope">
        <dynamic-button :butttonList="componentVO.buttons" :selectList="selectList" LocationType="top"
                        type="table"></dynamic-button>
        <dynamic-button :butttonList="componentVO.buttons" :selectList="TreeSelectList" LocationType="top"
                        type="TreeTable"></dynamic-button>
      </template>
      <!--menu区域按钮-->
      <template slot="menu" slot-scope="scope">
        <dynamic-button :butttonList="componentVO.buttons" :scope="scope" :selectList="selectList" LocationType="menu"
                        type="table"></dynamic-button>
        <dynamic-button :butttonList="componentVO.buttons" :scope="scope" :selectList="TreeSelectList" LocationType="menu" default="default"
                        type="TreeTable"></dynamic-button>
      </template>
    </avue-crud>
  </div>
@@ -180,7 +180,170 @@
          comment: '无'
        },
      ],
      TreeSelectList: []
      TreeSelectList: [],
      // è¡¨å•数据
      formList: [
        {
          comboxKey: null,
          customClass: null,
          data: null,
          dateFormate: null,
          defaultValue: "",
          displayExtension: "",
          extendAttrMap: null,
          extendAttrString: null,
          field: "name",
          hidden: false,
          keyAttr: true,
          prefix: null,
          readOnly: false,
          referConfig: null,
          required: true,
          selectLibFlag: null,
          showField: null,
          suffix: '$',
          text: "名称",
          tooltips: '名称',
          type: "text",
          unique: false,
          verify: ""
        },
        {
          comboxKey: null,
          customClass: null,
          data: null,
          dateFormate: null,
          defaultValue: "",
          displayExtension: "",
          extendAttrMap: null,
          extendAttrString: null,
          field: "code",
          hidden: false,
          keyAttr: false,
          prefix: null,
          readOnly: false,
          referConfig: null,
          required: false,
          selectLibFlag: null,
          showField: null,
          suffix: null,
          disabled: true,
          text: "编码",
          tooltips: null,
          type: "text",
          unique: false,
          verify: ""
        },
        {
          comboxKey: "EnumReviewType",
          customClass: null,
          data: null,
          dateFormate: null,
          defaultValue: "department",
          displayExtension: "",
          extendAttrMap: null,
          extendAttrString: null,
          field: "reviewtype",
          hidden: false,
          keyAttr: false,
          prefix: null,
          readOnly: false,
          referConfig: null,
          required: false,
          selectLibFlag: null,
          showField: null,
          suffix: null,
          text: "类型",
          tooltips: null,
          type: "combox",
          unique: false,
          verify: "",
          dicData: [{
            label: '测试1',
            value: 'department'
          }, {
            label: '测试2',
            value: 'departments'
          }]
        },
        {
          comboxKey: null,
          customClass: null,
          data: null,
          dateFormate: null,
          defaultValue: "",
          displayExtension: "",
          extendAttrMap: null,
          extendAttrString: null,
          field: "creator",
          hidden: true,
          keyAttr: false,
          prefix: null,
          readOnly: true,
          referConfig: null,
          required: false,
          selectLibFlag: null,
          showField: null,
          suffix: null,
          text: "创建人",
          tooltips: null,
          type: "text",
          unique: false,
          verify: ""
        },
        {
          comboxKey: null,
          customClass: null,
          data: null,
          dateFormate: "yyyy-MM-dd HH:mm:ss",
          defaultValue: "",
          displayExtension: "",
          extendAttrMap: null,
          extendAttrString: null,
          field: "createtime",
          hidden: true,
          keyAttr: false,
          prefix: null,
          readOnly: false,
          referConfig: null,
          required: false,
          selectLibFlag: null,
          showField: null,
          suffix: null,
          text: "创建时间",
          tooltips: null,
          type: "datetime",
          unique: false,
          verify: ""
        },
        {
          comboxKey: null,
          customClass: null,
          data: null,
          dateFormate: null,
          defaultValue: "",
          displayExtension: "",
          extendAttrMap: null,
          extendAttrString: null,
          field: "content",
          hidden: false,
          keyAttr: false,
          prefix: null,
          readOnly: false,
          referConfig: null,
          required: false,
          selectLibFlag: null,
          showField: null,
          suffix: null,
          text: "备注",
          tooltips: null,
          type: "textarea",
          unique: false,
          verify: ""
        },
      ],
      formName: '',
      visible:false
    }
  },
  watch: {
@@ -220,7 +383,7 @@
  methods: {
    TreeSelectChange(row) {
      this.TreeSelectList = row;
    }
    },
  }
}
</script>
Source/ProjectWeb/src/components/dynamic-components/dynamic-button.vue
@@ -1,8 +1,8 @@
<template>
  <div>
    <!--表格基础按钮-->
    <div v-if="type === 'table'">
      <!--top展示表格上方区域 menu展示表格操作栏区域 -->
    <div v-if="type === 'table' || type === 'TreeTable'">
      <!--top展示表格上方区域 menu展示表格操作栏区域 æ— å°±æ˜¯é»˜è®¤ -->
      <el-button v-for="item in basicButtonList.top"
                 v-if="LocationType === 'top'"
                 :key="item.oid" :icon="item.paramVOS.webUiButtonIcon"
@@ -12,6 +12,7 @@
        {{ item.name }}
      </el-button>
      <el-button type="text" @click="handleDefaultAddChildren(scope.row)" v-if="(LocationType === 'menu' && this.default === 'default')">新增子级</el-button>
      <el-button v-for="item in basicButtonList.menu"
                 v-if="LocationType === 'menu'"
                 :key="item.oid"
@@ -21,6 +22,8 @@
                 @click="buttonClick(item)">
        {{ item.name }}
      </el-button>
      <!-- è¡¨æ ¼å†…按钮操作对话框表单   -->
      <dynamic-table-form ref="dynamicForm" :formList="formList" :title="formName" :visible.sync="visible"
                          style="display: none"></dynamic-table-form>
@@ -59,7 +62,11 @@
      type: Array
    },
    selectList: {
      type: Array
      type: Array,
      default: []
    },
    default:{
      type:String,
    }
  },
  data() {
@@ -235,7 +242,7 @@
      if (this.type === 'form') {
        return basicColumn;
      } else if (this.type === 'table') {
      } else if (this.type === 'table' || this.type === 'TreeTable') {
        const top = basicColumn.filter(item => item.paramVOS.webUiButtonLocation === 'top' || func.isEmpty(item.paramVOS.webUiButtonLocation)); // è¿‡æ»¤å‡ºæ¥è¡¨æ ¼ä¸Šé¢åŒºåŸŸå±•示的按钮
        const menu = basicColumn.filter(item => item.paramVOS.webUiButtonLocation === 'menu'); // è¿‡æ»¤å‡ºæ¥æ“ä½œæ å±•示的按钮
        return {
@@ -246,55 +253,27 @@
    }
  },
  methods: {
    //表格树默认新增子项
    handleDefaultAddChildren(row){
      this.visible = true;
      this.formName = '新增子级'
      this.$refs.dynamicForm.form = row;
    },
    buttonClick(item) {
      this.formName = item.name;
      function handleAdd() {
        this.visible = true;
      }
      function handleEdit() {
        const location = item.paramVOS.webUiButtonLocation;
        if (location === 'menu') {
          this.visible = true;
          this.$refs.dynamicForm.form = this.scope.row;
        } else if (location === 'top' && this.selectList.length === 1) {
          this.visible = true;
          this.$refs.dynamicForm.form = this.selectList[0];
        } else {
          const messageText = this.selectList.length > 1 ? '只能选择一条数据进行编辑!' : '请选择一条数据进行编辑!';
          this.$message.warning(messageText);
        }
      }
      function handleDelete() {
        const location = item.paramVOS.webUiButtonLocation;
        if (location === 'top') {
          if (this.selectList.length <= 0) {
            this.$message.warning('请至少选择一条数据!')
          } else {
            this.$message.success('删除成功!');
          }
        } else if (location === 'menu') {
          this.$message.success('删除成功!');
        }
      }
      const methodHandlers = {
        add: handleAdd.bind(this),
        edit: handleEdit.bind(this),
        delete: handleDelete.bind(this),
      };
      const method = item.paramVOS.webUiButtonMethods;
      const handler = methodHandlers[method];
      if (handler) {
        handler();
      } else {
        this.$message.error('请重新配置按钮!')
      // æ ¹æ® type æ¡ä»¶åŠ¨æ€å¼•å…¥ä¸åŒçš„JS文件,并传递 item this å‚æ•°
      if (this.type === 'table') {
        import('@/views/base/buttonTable').then(module => {
          const buttonClickTable = module.default;
          buttonClickTable.buttonClick(item,this);
        })
      } else if (this.type === 'form') {
        import('@/views/base/buttonForm').then(module => {
          const buttonClickForm = module.default;
          buttonClickForm.buttonClick(item,this);
        })
      }
    }
  }
  },
}
</script>
Source/ProjectWeb/src/components/dynamic-components/dynamic-custom.vue
@@ -108,8 +108,8 @@
    }
  },
  created() {
    debugger;
    this.components["my-dynamic-component"] = import(this.componentPath);
    // debugger;
    // this.components["my-dynamic-component"] = import(this.componentPath);
  }
}
</script>
Source/ProjectWeb/src/views/base/buttonForm.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,31 @@
export default {
  buttonClick(item,that) {
    this.formName = item.name;
    const method = item.paramVOS.webUiButtonMethods;
    const handlers = {
      add: () => this.handleAdd(that),
      edit: () => this.handleEdit(that),
      delete: () => this.handleDelete(that),
    };
    const handler = handlers[method];
    if (handler) {
      handler();
    } else {
      that.$message.error('请重新配置按钮!');
    }
  },
  handleAdd(that) {
    that.$message.success('表单添加')
  },
  handleEdit(that) {
    that.$message.success('表单编辑')
  },
  handleDelete(that) {
    that.$message.success('表单删除')
  },
}
Source/ProjectWeb/src/views/base/buttonTable.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,70 @@
export default {
  buttonClick(item,that) {
    that.formName = item.name;
    const location = item.paramVOS.webUiButtonLocation;
    const method = item.paramVOS.webUiButtonMethods;
    const messageOnlyText = that.selectList.length > 1 ? '只能选择一条数据进行编辑!' : '请选择一条数据进行编辑!';
    const messageAllText = '请至少选择一条数据!'
    const handlers = {
      add: () => this.handleAdd(that,location),
      edit: () => this.handleEdit(that,location, messageOnlyText),
      delete: () => this.handleDelete(that,location, messageAllText),
    };
    const handler = handlers[method];
    if (handler) {
      handler();
    } else {
      that.$message.error('请重新配置按钮!');
    }
  },
  handleAdd(that,location) {
    if (location === 'top') {
      that.visible = true;
    } else {
      that.$message.warning('请重新配置按钮至上方区域!');
    }
  },
  handleEdit(that,location, messageOnlyText) {
    if (location === 'menu') {
      that.visible = true;
      that.$refs.dynamicForm.form = that.scope.row;
      console.log(that.scope.row)
    } else if (location === 'top' && that.selectList.length === 1) {
      that.visible = true;
      that.$refs.dynamicForm.form = that.selectList[0];
    } else {
      that.$message.warning(messageOnlyText);
    }
  },
  handleDelete(that,location, messageAllText) {
    if (location === 'top') {
      if (that.selectList.length <= 0) {
        that.$message.warning(messageAllText);
      } else {
        that.$message.success('删除成功!');
      }
    } else if (location === 'menu') {
      that.$message.success('删除成功!');
    }
  },
  menuConfigurationWarning(location) {
    if (location === 'menu') {
      this.$message.warning('请重新配置按钮至上方区域');
      return
    }
  },
  topConfigurationWarning(location) {
    if (location === ' top') {
      this.$message.warning('请重新配置按钮至操作区域');
      return
    }
  }
}