From c98e45bfac25e9110ad0383faac54a54d98ea9d5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 18 十一月 2021 20:47:04 +0800
Subject: [PATCH] 2021-11-18

---
 src/templates/sharecomponent/columncomponent/index.jsx |  100 ++++++++++++++++++++++----------------------------
 1 files changed, 44 insertions(+), 56 deletions(-)

diff --git a/src/templates/sharecomponent/columncomponent/index.jsx b/src/templates/sharecomponent/columncomponent/index.jsx
index a1e0242..357dfd8 100644
--- a/src/templates/sharecomponent/columncomponent/index.jsx
+++ b/src/templates/sharecomponent/columncomponent/index.jsx
@@ -1,7 +1,8 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Icon, Tooltip, Modal, notification, Switch, message, Spin } from 'antd'
+import { Tooltip, Modal, notification, Switch, message } from 'antd'
+import { QuestionCircleOutlined, CopyOutlined } from '@ant-design/icons'
 
 import zhCN from '@/locales/zh-CN/model.js'
 import enUS from '@/locales/en-US/model.js'
@@ -12,6 +13,7 @@
 import GridBtnForm from './gridbtnform'
 import DragElement from './dragcolumn'
 import MarkColumn from './markcolumn'
+import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
 const { confirm } = Modal
@@ -20,16 +22,13 @@
   static propTpyes = {
     menu: PropTypes.object,          // 涓夌骇鑿滃崟淇℃伅
     config: PropTypes.object,        // 閰嶇疆淇℃伅
-    pasteContent: PropTypes.object,  // 绮樿创閰嶇疆淇℃伅
-    sysRoles: PropTypes.array,       // 瑙掕壊鍒楄〃锛屾潈闄愬垎閰�
     updatecolumn: PropTypes.func     // 鏇存柊
   }
 
   state = {
-    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
+    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     columnlist: null,    // 鏄剧ず鍒�
-    loading: false,      // 鏌ヨ鏄剧ず鍒楄仈鍔ㄨ彍鍗�
-    showField: false,    // 鏄剧ず鍒楀瓧娈�
+    showField: true,     // 鏄剧ず鍒楀瓧娈�
     modaltype: '',       // 妯℃�佹鎺у埗
     card: null           // 缂栬緫涓厓绱�
   }
@@ -41,29 +40,6 @@
     this.setState({
       columnlist: fromJS(this.props.config.columns).toJS()
     })
-  }
-
-  /**
-   * @description 鐩戝惉鍒版樉绀哄垪澶嶅埗鏃讹紝瑙﹀彂鏄剧ず鍒楃紪杈�
-   */
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    const { config } = this.props
-    const { columnlist } = this.state
-
-    if (
-      nextProps.pasteContent &&
-      nextProps.pasteContent.columns &&
-      nextProps.pasteContent.copyType === 'columns' &&
-      nextProps.pasteContent.columns.length > 0
-    ) {
-      if (columnlist.filter(col => !col.origin).length === 0) {
-        this.setState({columnlist: nextProps.pasteContent.columns}, () => {
-          this.props.updatecolumn({...config, columns: nextProps.pasteContent.columns})
-        })
-      }
-    } else if (!is(fromJS(nextProps.config.columns), fromJS(config.columns)) && !is(fromJS(nextProps.config.columns), fromJS(columnlist))) {
-      this.setState({columnlist: fromJS(nextProps.config.columns).toJS()})
-    }
   }
 
   /**
@@ -87,6 +63,7 @@
    */
   handleColumn = (card) => {
     const { menu } = this.props
+    const { columnlist } = this.state
 
     if (card.type !== 'colspan') {
       let menulist = []
@@ -113,11 +90,20 @@
           return fst
         })
       }
+
+      let fields = []
+      columnlist.forEach(col => {
+        if (!col.field) return
+        fields.push({
+          value: col.field,
+          text: col.label
+        })
+      })
       
       this.setState({
         modaltype: 'columns',
         card: card,
-        formlist: getColumnForm(card, this.props.sysRoles, menulist)
+        formlist: getColumnForm(card, menulist, fields)
       })
     } else {
       this.setState({
@@ -186,18 +172,12 @@
     if (modaltype === 'columns' || modaltype === 'colspan') {
       this.columnFormRef.handleConfirm().then(res => {
         let fieldrepet = false // 瀛楁閲嶅
-        let labelrepet = false // 鎻愮ず鏂囧瓧閲嶅
-        let rowspanLabel = ''  // 宸插瓨鍦ㄧ殑琛屽悎骞跺瓧娈�
 
         _columnlist = _columnlist.filter(item => !item.origin || item.uuid === res.uuid) // 鍘婚櫎鍒濆鍒�
         _columnlist = _columnlist.map(item => {
           if (item.uuid !== res.uuid && res.field && item.field) {
-            if (item.field === res.field) {
+            if (item.field.toLowerCase() === res.field.toLowerCase()) {
               fieldrepet = true
-            } else if (item.label === res.label) {
-              labelrepet = true
-            } else if (res.rowspan === 'true' && item.rowspan === 'true') {
-              rowspanLabel = item.label
             }
           }
 
@@ -211,21 +191,7 @@
         if (fieldrepet) {
           notification.warning({
             top: 92,
-            message: this.state.dict['model.field.exist'] + ' !',
-            duration: 5
-          })
-          return
-        } else if (labelrepet) {
-          notification.warning({
-            top: 92,
-            message: this.state.dict['model.name.exist'] + ' !',
-            duration: 5
-          })
-          return
-        } else if (rowspanLabel) {
-          notification.warning({
-            top: 92,
-            message: `宸插瓨鍦ㄨ鍚堝苟瀛楁銆�${rowspanLabel}銆�!`,
+            message: '瀛楁宸插瓨鍦�!',
             duration: 5
           })
           return
@@ -484,8 +450,31 @@
     })
   }
 
+  plusColumns = (MenuId, items) => {
+    const { config } = this.props
+    const { columnlist } = this.state
+
+    if (MenuId !== config.uuid) return
+
+    let list = [...columnlist, ...items]
+
+    if (list[0] && list[0].origin) {
+      list = list.filter(col => !col.origin)
+    }
+
+    this.setState({
+      columnlist: list
+    }, () => {
+      this.props.updatecolumn({...config, columns: list})
+    })
+  }
+
   shouldComponentUpdate (nextProps, nextState) {
     return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
+  }
+
+  componentDidMount () {
+    MKEmitter.addListener('plusColumns', this.plusColumns)
   }
 
   /**
@@ -495,6 +484,7 @@
     this.setState = () => {
       return
     }
+    MKEmitter.removeListener('plusColumns', this.plusColumns)
   }
 
   render() {
@@ -504,10 +494,10 @@
     return (
       <div className="model-table-column-list">
         <Tooltip placement="bottomLeft" overlayClassName="middle" title={dict['model.tooltip.column.guide']}>
-          <Icon type="question-circle" />
+          <QuestionCircleOutlined style={{color: '#c49f47', position: 'relative', left: '-15px', top: '5px'}} />
         </Tooltip>
         {columnlist && columnlist.length > 0 ?
-          <Icon className="column-copy" title="copy" type="copy" onClick={this.copycolumn} /> : null
+          <CopyOutlined className="column-copy" title="copy" onClick={this.copycolumn} /> : null
         }
         <Switch checkedChildren={dict['model.switch.open']} unCheckedChildren={dict['model.switch.close']} defaultChecked={this.state.showField} onChange={this.onFieldChange} />
         <DragElement
@@ -583,7 +573,6 @@
           visible={modaltype === 'mark'}
           width={'75vw'}
           maskClosable={false}
-          style={{minWidth: '900px', maxWidth: '1200px'}}
           okText={dict['model.submit']}
           onOk={this.markSubmit}
           onCancel={() => { this.setState({ modaltype: '' }) }}
@@ -596,7 +585,6 @@
             columns={columnlist}
           />
         </Modal>
-        {this.state.loading && <Spin size="large" />}
       </div>
     )
   }

--
Gitblit v1.8.0