From e1cee96b38805bcccf48e7bcb9d296f2bc54c720 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 24 一月 2025 11:10:32 +0800
Subject: [PATCH] 2025-01-24

---
 src/menu/components/table/base-table/columns/index.jsx |  210 +++++++++++++++++++++++++++-------------------------
 1 files changed, 109 insertions(+), 101 deletions(-)

diff --git a/src/menu/components/table/base-table/columns/index.jsx b/src/menu/components/table/base-table/columns/index.jsx
index c6b6e95..508f594 100644
--- a/src/menu/components/table/base-table/columns/index.jsx
+++ b/src/menu/components/table/base-table/columns/index.jsx
@@ -2,8 +2,8 @@
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
 import { DndProvider, DragSource, DropTarget } from 'react-dnd'
-import { Table, Popover, Modal, message, notification } from 'antd'
-import { PlusOutlined, PlusSquareOutlined, EditOutlined, CopyOutlined, DeleteOutlined, FontColorsOutlined, CloseCircleOutlined, AntDesignOutlined, InfoOutlined } from '@ant-design/icons'
+import { Table, Popover, Modal, message, notification, Typography } from 'antd'
+import { PlusOutlined, PlusSquareOutlined, EditOutlined, CopyOutlined, DeleteOutlined, FontColorsOutlined, CloseCircleOutlined, AntDesignOutlined } from '@ant-design/icons'
 
 import asyncComponent from '@/utils/asyncComponent'
 import asyncIconComponent from '@/utils/asyncIconComponent'
@@ -12,6 +12,7 @@
 import './index.scss'
 
 const { confirm } = Modal
+const { Paragraph } = Typography
 const EditColumn = asyncComponent(() => import('./editColumn'))
 const MarkColumn = asyncIconComponent(() => import('@/menu/components/share/markcomponent'))
 const CardCellComponent = asyncComponent(() => import('@/menu/components/card/cardcellcomponent'))
@@ -20,12 +21,12 @@
 
 class HeaderCol extends Component {
   deleteCol = () => {
-    const _this = this
+    const that = this
 
     confirm({
       content: '纭畾鍒犻櫎鏄剧ず鍒楀悧锛�',
       onOk() {
-        _this.props.deleteCol(_this.props.column)
+        that.props.deleteCol(that.props.column)
       },
       onCancel() {}
     })
@@ -51,68 +52,40 @@
   }
 
   render() {
-    const { connectDragSource, connectDropTarget, moveCol, addElement, dropCol, updateCol, editColumn, pasteCell, changeStyle, deleteCol, index, column, align, fields, children, ...restProps } = this.props
+    const { connectDragSource, connectDropTarget, moveCol, componentId, addElement, dropCol, updateCol, editColumn, pasteCell, changeStyle, deleteCol, index, column, align, fields, children, ...restProps } = this.props
 
-    if (index !== undefined && column) {
-      let style = {cursor: 'move', textAlign: align}
-      if (column.Width) {
-        style.width = column.Width
-        style.minWidth = column.Width
-      }
+    if (!column) return (
+      <th {...restProps}>{children}</th>
+    )
 
-      if (window.GLOB.columnId === column.uuid) {
-        style.color = '#1890ff'
-      }
-
-      return connectDragSource(
-        connectDropTarget(<th {...restProps} index={index} style={style} onDoubleClick={() => this.props.editColumn(column)}>
-          <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
-            <div className="mk-popover-control" onDoubleClick={(e) => e.stopPropagation()}>
-              {column.type === 'colspan' ? <PlusOutlined className="plus" title="娣诲姞鍒�" onClick={() => this.props.addElement(column)} /> : null}
-              {column.type === 'custom' ? <PlusOutlined className="plus" title="娣诲姞鍏冪礌" onClick={() => this.props.addElement(column)} /> : null}
-              {column.type === 'custom' ? <PlusSquareOutlined className="plus" title="娣诲姞鎸夐挳" onClick={() => this.props.addElement(column, 'button')} /> : null}
-              <EditOutlined className="edit" title="缂栬緫" onClick={() => this.props.editColumn(column)} />
-              {column.type === 'custom' ? <PasteComponent options={['customCardElement', 'action']} updateConfig={(res, resolve) => this.props.pasteCell(column, res, resolve)} /> : null}
-              {column.type === 'custom' ? <FontColorsOutlined className="style" title="璋冩暣鏍峰紡" onClick={() => this.props.changeStyle(column)}/> : null}
-              <DeleteOutlined className="close" title="鍒犻櫎" onClick={this.deleteCol} />
-              {['text', 'number', 'formula'].includes(column.type) ? <MarkColumn field={column.field || ''} columns={fields} marks={column.marks} onSubmit={this.updateMarks} /> : null }
-            </div>
-          } trigger="hover">
-            {children}
-          </Popover>
-        </th>),
-      )
-    } else if (column) {
-      let style = {textAlign: align}
-      if (column.Width) {
-        style.width = column.Width
-        style.minWidth = column.Width
-      }
-
-      if (window.GLOB.columnId === column.uuid) {
-        style.color = '#1890ff'
-      }
-
-      return (
-        <th {...restProps} style={style} key={column.uuid} onDoubleClick={() => this.props.editColumn(column)}>
-          <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
-            <div className="mk-popover-control" onDoubleClick={(e) => e.stopPropagation()}>
-              {column.type === 'colspan' ? <PlusOutlined className="plus" title="娣诲姞鍒�" onClick={() => this.props.addElement(column)} /> : null}
-              {column.type === 'custom' ? <PlusOutlined className="plus" title="娣诲姞鍏冪礌" onClick={() => this.props.addElement(column)} /> : null}
-              {column.type === 'custom' ? <PlusSquareOutlined className="plus" title="娣诲姞鎸夐挳" onClick={() => this.props.addElement(column, 'button')} /> : null}
-              <EditOutlined className="edit" title="缂栬緫" onClick={() => this.props.editColumn(column)} />
-              {column.type === 'custom' ? <PasteComponent options={['customCardElement', 'action']} updateConfig={(res, resolve) => this.props.pasteCell(column, res, resolve)} /> : null}
-              <DeleteOutlined className="close" title="鍒犻櫎" onClick={this.deleteCol} />
-              {['text', 'number', 'formula'].includes(column.type) ? <MarkColumn field={column.field || ''} columns={fields} marks={column.marks} onSubmit={this.updateMarks} /> : null }
-            </div>
-          } trigger="hover">
-            {children}
-          </Popover>
-        </th>
-      )
-    } else {
-      return (<th {...restProps}>{children}</th>)
+    let style = {cursor: 'move', textAlign: align}
+    if (column.Width) {
+      style.width = column.Width
+      style.minWidth = column.Width
     }
+
+    if (window.GLOB.columnId === column.uuid) {
+      style.color = '#1890ff'
+    }
+
+    return connectDragSource(
+      connectDropTarget(<th {...restProps} index={index} style={style} onDoubleClick={() => this.props.editColumn(column)}>
+        <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
+          <div className="mk-popover-control" onDoubleClick={(e) => e.stopPropagation()}>
+            {column.type === 'colspan' ? <PlusOutlined className="plus" title="娣诲姞鍒�" onClick={() => this.props.addElement(column)} /> : null}
+            {column.type === 'custom' ? <PlusOutlined className="plus" title="娣诲姞鍏冪礌" onClick={() => this.props.addElement(column)} /> : null}
+            {column.type === 'custom' ? <PlusSquareOutlined className="plus" title="娣诲姞鎸夐挳" onClick={() => this.props.addElement(column, 'button')} /> : null}
+            <EditOutlined className="edit" title="缂栬緫" onClick={() => this.props.editColumn(column)} />
+            {column.type === 'custom' ? <PasteComponent options={['customCardElement', 'action']} updateConfig={(res, resolve) => this.props.pasteCell(column, res, resolve)} /> : null}
+            {column.type === 'custom' ? <FontColorsOutlined className="style" title="璋冩暣鏍峰紡" onClick={() => this.props.changeStyle(column)}/> : null}
+            <DeleteOutlined className="close" title="鍒犻櫎" onClick={this.deleteCol} />
+            {['text', 'number', 'formula'].includes(column.type) ? <MarkColumn field={column.field || ''} columns={fields} marks={column.marks} onSubmit={this.updateMarks} /> : null }
+          </div>
+        } trigger="hover">
+          {children}
+        </Popover>
+      </th>),
+    )
   }
 }
 
@@ -127,17 +100,28 @@
 const ColTarget = {
   drop(props, monitor) {
     const item = monitor.getItem()
-    const dragIndex = item.index
-    const hoverIndex = props.index
+    let dragIndex = item.index
+    let hoverIndex = props.index
 
     if (item.$init) {
-      props.dropCol(item, hoverIndex)
+      if (/sub_/.test(hoverIndex)) {
+        message.warning('鍚堝苟鍒楀瓙鍏冪礌鏆備笉鏀寔鎷栨嫿娣诲姞銆�')
+      } else {
+        props.dropCol(item, hoverIndex.replace(new RegExp(props.componentId + '@', 'ig'), ''))
+      }
       return
     } else if (dragIndex === undefined || hoverIndex === undefined || dragIndex === hoverIndex) {
       return
+    } else {
+      let reg = new RegExp(props.componentId + '@', 'ig')
+      if (reg.test(dragIndex)) {
+        props.moveCol(dragIndex.replace(reg, ''), hoverIndex.replace(reg, ''))
+      } else {
+        message.warning('鎷栧姩鍏冪礌涓嶅湪褰撳墠缁勪欢涓��')
+        return
+      }
     }
 
-    props.moveCol(dragIndex, hoverIndex)
     monitor.getItem().index = hoverIndex
   },
 }
@@ -209,14 +193,14 @@
         val = '$Index'
       } else if (column.type === 'formula') {
         val = column.formula
-        if (column.eval === 'false') {
-          val = val.replace(/\n/ig, '<br/>').replace(/\s/ig, '&nbsp;')
-          val = <span style={{fontWeight: 'inherit'}} dangerouslySetInnerHTML={{__html: val}}></span>
-        }
+        // if (column.eval === 'false') {
+        //   val = val.replace(/\n/ig, '<br/>').replace(/\s/ig, '&nbsp;')
+        //   val = <span style={{fontWeight: 'inherit'}} dangerouslySetInnerHTML={{__html: val}}></span>
+        // }
       }
       return (
         <td style={{...style}} className={className}>
-          {val}
+          {column.field ? <Paragraph className="col-copy" copyable={{ text: column.field }}>{val}</Paragraph> : val}
           {column.Hide === 'true' ? <CloseCircleOutlined style={{marginLeft: '5px', color: 'orange', fontSize: '12px'}}/> : null}
           {column.marks && column.marks.length ? <AntDesignOutlined className="profile"/> : null}
         </td>
@@ -304,12 +288,32 @@
   moveCol = (dragIndex, hoverIndex) => {
     let _columns = fromJS(this.state.columns).toJS()
 
-    _columns.splice(hoverIndex, 0, ..._columns.splice(dragIndex, 1))
+    if (/^sub_/.test(dragIndex) || /^sub_/.test(hoverIndex)) {
+      let sign1 = dragIndex.split('_')
+      let sign2 = hoverIndex.split('_')
+      if (sign1[1] !== sign2[1]) {
+        message.warning('鎷栧姩鍏冪礌涓嶅湪鍚屼竴涓悎骞跺垪涓��')
+        return
+      }
+      this.loopMoveCol(_columns, sign1[1], sign1[2], sign2[2])
+    } else {
+      _columns.splice(hoverIndex, 0, ..._columns.splice(dragIndex, 1))
+    }
 
     this.setState({
       columns: _columns
     }, () => {
       this.props.updatecolumn({...this.props.config, cols: _columns})
+    })
+  }
+
+  loopMoveCol = (columns, colId, dragIndex, hoverIndex) => {
+    columns.forEach(column => {
+      if (column.type === 'colspan' && column.uuid === colId) {
+        column.subcols.splice(hoverIndex, 0, ...column.subcols.splice(dragIndex, 1))
+      } else if (column.type === 'colspan') {
+        this.loopMoveCol(column.subcols, colId, dragIndex, hoverIndex)
+      }
     })
   }
 
@@ -321,9 +325,17 @@
       col.subcols = []
     } else if (col.type === 'index') {
       col.label = '搴忓彿'
+    } else if (col.type === 'number') {
+      col.Width = 80
     }
 
-    _columns.splice(hoverIndex, 0, col)
+    let hIndex = +hoverIndex
+
+    if (_columns.length > 0 && hIndex + 1 === _columns.length) {
+      _columns.push(col)
+    } else {
+      _columns.splice(hIndex, 0, col)
+    }
 
     this.setState({
       columns: _columns
@@ -379,7 +391,7 @@
     if (!cell.eleType) {
       if (cell.copyType === 'action') {
         cell.eleType = 'button'
-        cell.width = cell.width || 12
+        cell.width = cell.width || cell.width === 0 ? cell.width : 12
       } else {
         cell.eleType = 'text'
       }
@@ -537,11 +549,6 @@
       cols: columns.filter(col => !col.origin)
     }
 
-    let srcid = localStorage.getItem(window.location.href.split('#')[0] + 'srcId')
-    if (srcid) {
-      val.$srcId = srcid
-    }
-
     oInput.value = window.btoa(window.encodeURIComponent(JSON.stringify(val)))
     document.body.appendChild(oInput)
     oInput.select()
@@ -554,7 +561,7 @@
     document.body.removeChild(oInput)
   }
 
-  handlecolumns = (columns, fields, config, isSub) => {
+  handlecolumns = (columns, fields, config, pId) => {
     return columns.map((col, index) => {
       return {
         title: col.label,
@@ -568,8 +575,9 @@
           upComponent: this.updateCol
         }),
         onHeaderCell: () => ({
-          index: isSub ? undefined : index,
+          index: pId ? config.uuid + '@sub_' + pId + '_' + index : config.uuid + '@' + index,
           column: col,
+          componentId: config.uuid,
           fields: fields,
           align: col.Align,
           moveCol: this.moveCol,
@@ -581,7 +589,7 @@
           changeStyle: this.changeStyle,
           deleteCol: this.deleteCol,
         }),
-        children: col.subcols && col.subcols.length ? this.handlecolumns(col.subcols, fields, config, true) : null,
+        children: col.subcols && col.subcols.length ? this.handlecolumns(col.subcols, fields, config, col.uuid) : null,
       }
     })
   }
@@ -603,26 +611,26 @@
     })
   }
 
-  copyFields = () => {
-    const { config } = this.props
-    let m = []
-    let n = []
+  // copyFields = () => {
+  //   const { config } = this.props
+  //   let m = []
+  //   let n = []
 
-    config.columns.forEach(col => {
-      m.push(`${col.field}(${col.label})`)
-      n.push(col.field)
-    })
+  //   config.columns.forEach(col => {
+  //     m.push(`${col.field} ${col.datatype}`)
+  //     n.push(col.field)
+  //   })
 
-    let oInput = document.createElement('input')
-    oInput.value = `/*${m.join(',')}*/
-      ${n.join(',')}`
-    document.body.appendChild(oInput)
-    oInput.select()
-    document.execCommand('Copy')
-    document.body.removeChild(oInput)
+  //   let oInput = document.createElement('input')
+  //   oInput.value = `/*${m.join(',')}*/
+  //     ${n.join(',')}`
+  //   document.body.appendChild(oInput)
+  //   oInput.select()
+  //   document.execCommand('Copy')
+  //   document.body.removeChild(oInput)
 
-    message.success('澶嶅埗鎴愬姛銆�')
-  }
+  //   message.success('澶嶅埗鎴愬姛銆�')
+  // }
 
   componentDidMount () {
     MKEmitter.addListener('plusColumns', this.plusColumns)
@@ -668,7 +676,7 @@
           <FieldsComponent config={config} type="columns" />
           <CopyOutlined title="澶嶅埗鏄剧ず鍒�" onClick={this.copycolumn} />
           <MarkColumn columns={fields} type="line" marks={lineMarks} onSubmit={this.updateLineMarks} />
-          <InfoOutlined title="澶嶅埗瀛楁" style={{color: 'orange'}} onClick={this.copyFields}/>
+          {/* <InfoOutlined title="澶嶅埗瀛楁" style={{color: 'orange'}} onClick={this.copyFields}/> */}
         </div>
         <DndProvider>
           {groups ? groups.map((group, i) => {

--
Gitblit v1.8.0