d2-crud-plus icon indicating copy to clipboard operation
d2-crud-plus copied to clipboard

功能升级 | 表格操作栏自定义按钮提供统一触发事件

Open Onesimu opened this issue 2 years ago • 0 comments

目前表格操作栏的自定义按钮绑定事件需要为每个按钮添加监听事件, 当按钮较多时, 代码比较冗长啰嗦.

    custom:[//自定义按钮
      {
         //配置同上
         //点击事件,需要在<d2-crud-x @custom-emit="yourHandle"/>
         emit: 'custom-emit' 
      }
    ],
    <d2-crud-x ref="d2Crud" v-bind="_crudProps" v-on="_crudListeners" @audit="audit"
      @detail="detail" @edit="edit" @pub="pub" @apply="apply" @enable="enable" @adjust="adjust">

希望对这种情况, 能提供所有自定义按钮整体监听的方法, 用某个字段区分点击的按钮. 业务代码里可以根据不同的按钮调用不同功能. 查看源码, 目前并没有将按钮配置向外传递, 因此外层无法知道点击的是哪个按钮. 希望这里可以进行一些改进. 谢谢

// d2-crud-plus/packages/d2-crud-x/src/mixin/handleRow.js : 118
      if (this.rowHandle.custom && this.rowHandle.custom.length > 0) {
        for (const item of this.rowHandle.custom) {
          btns.push({
            doClick: (scope) => {
              scope = this.getCellScope(scope)
              scope.self = item
              if (!item.emit) {
                logger.warn('该按钮还未配置emit')
                return
              }
              this.$emit(item.emit, scope)
            },
            order: 4,
            ...item
          })
        }
      }

Onesimu avatar Jul 14 '22 06:07 Onesimu