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/edit-table/columns/index.jsx |   37 ++++++++++++++++++++++++++++++-------
 1 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/src/menu/components/table/edit-table/columns/index.jsx b/src/menu/components/table/edit-table/columns/index.jsx
index 50c3486..a13f19a 100644
--- a/src/menu/components/table/edit-table/columns/index.jsx
+++ b/src/menu/components/table/edit-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 (!column) return (
       <th {...restProps} index={index}>
@@ -93,10 +93,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
     }
 
@@ -259,6 +263,25 @@
     })
   }
 
+  dropCol = (item, hoverIndex) => {
+    let _columns = fromJS(this.state.columns).toJS()
+    let type = item.subType
+
+    if (item.subType === 'link' || item.subType === 'colspan' || item.subType === 'picture') {
+      type = 'text'
+    }
+
+    let col = { focus: true, uuid: Utils.getuuid(), label: 'label', field: '', type: type, elements: [] }
+
+    _columns.splice(hoverIndex, 0, col)
+
+    this.setState({
+      columns: _columns
+    }, () => {
+      this.editColumn(col)
+    })
+  }
+
   updateCol = (col, btn) => {
     let _columns = fromJS(this.state.columns).toJS()
     _columns = _columns.map(column => {
@@ -293,18 +316,17 @@
     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 === 'custom') {
       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(),
@@ -320,7 +342,7 @@
       }
 
       // 娉ㄥ唽浜嬩欢-娣诲姞鍏冪礌
-      MKEmitter.emit('cardAddElement', [config.uuid, column.uuid], newcard)
+      MKEmitter.emit('cardAddElement', column.uuid, newcard)
     }
   }
 
@@ -563,6 +585,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