From 66cc7818cf5e13c44f4372e7d47fb72df7d2f752 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 16 九月 2022 10:30:14 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/menu/components/table/normal-table/columns/index.jsx |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/menu/components/table/normal-table/columns/index.jsx b/src/menu/components/table/normal-table/columns/index.jsx
index 4240b49..aa68104 100644
--- a/src/menu/components/table/normal-table/columns/index.jsx
+++ b/src/menu/components/table/normal-table/columns/index.jsx
@@ -53,7 +53,7 @@
   }
 
   render() {
-    const { connectDragSource, connectDropTarget, moveCol, addElement, updateCol, editColumn, pasteCell, changeStyle, deleteCol, index, column, align, fields, children, ...restProps } = this.props
+    const { connectDragSource, connectDropTarget, moveCol, dropCol, addElement, updateCol, editColumn, pasteCell, changeStyle, deleteCol, index, column, align, fields, children, ...restProps } = this.props
 
     if (index !== undefined) {
       return connectDragSource(
@@ -109,10 +109,14 @@
 
 const ColTarget = {
   drop(props, monitor) {
-    const dragIndex = monitor.getItem().index
+    const item = monitor.getItem()
+    const dragIndex = item.index
     const hoverIndex = props.index
 
-    if (dragIndex === undefined || hoverIndex === undefined || dragIndex === hoverIndex) {
+    if (item.$init) {
+      props.dropCol(item, hoverIndex)
+      return
+    } else if (dragIndex === undefined || hoverIndex === undefined || dragIndex === hoverIndex) {
       return
     }
 
@@ -274,6 +278,20 @@
     })
   }
 
+  dropCol = (item, hoverIndex) => {
+    let _columns = fromJS(this.state.columns).toJS()
+
+    let col = { focus: true, uuid: Utils.getuuid(), label: 'label', field: '', type: item.subType, elements: [] }
+
+    _columns.splice(hoverIndex, 0, col)
+
+    this.setState({
+      columns: _columns
+    }, () => {
+      this.editColumn(col)
+    })
+  }
+
   loopCol = (columns, col) => {
     return columns.map(column => {
       if (column.type === 'colspan') {
@@ -315,11 +333,10 @@
     cell.uuid = Utils.getuuid()
     cell.focus = true
     
-    MKEmitter.emit('cardAddElement', [this.props.config.uuid, col.uuid], cell)
+    MKEmitter.emit('cardAddElement', col.uuid, cell)
   }
 
   addElement = (col) => {
-    const { config } = this.props
     let column = fromJS(col).toJS()
 
     if (column.type === 'colspan') {
@@ -335,7 +352,7 @@
       let newcard = {uuid: Utils.getuuid(), focus: true, width: 24, eleType: 'text', datatype: 'dynamic', style: {paddingLeft: '4px'}}
   
       // 娉ㄥ唽浜嬩欢-娣诲姞鍏冪礌
-      MKEmitter.emit('cardAddElement', [config.uuid, column.uuid], newcard)
+      MKEmitter.emit('cardAddElement', column.uuid, newcard)
     } else if (column.type === 'action') {
       let newcard = {
         uuid: Utils.getuuid(),
@@ -351,7 +368,7 @@
       }
 
       // 娉ㄥ唽浜嬩欢-娣诲姞鍏冪礌
-      MKEmitter.emit('cardAddElement', [config.uuid, column.uuid], newcard)
+      MKEmitter.emit('cardAddElement', column.uuid, newcard)
     }
   }
 
@@ -492,6 +509,7 @@
           fields: fields,
           align: col.Align,
           moveCol: this.moveCol,
+          dropCol: this.dropCol,
           updateCol: this.updateCol,
           addElement: this.addElement,
           editColumn: this.editColumn,

--
Gitblit v1.8.0