From b3547d1c531e479021219fda5df153a11b9b52a3 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 31 八月 2020 17:28:09 +0800
Subject: [PATCH] 2020-08-31

---
 src/templates/sharecomponent/tabscomponent/index.jsx |   69 +++++++++++++++++++++++++++-------
 1 files changed, 54 insertions(+), 15 deletions(-)

diff --git a/src/templates/sharecomponent/tabscomponent/index.jsx b/src/templates/sharecomponent/tabscomponent/index.jsx
index 5749ffe..901b1b0 100644
--- a/src/templates/sharecomponent/tabscomponent/index.jsx
+++ b/src/templates/sharecomponent/tabscomponent/index.jsx
@@ -16,7 +16,6 @@
 
 class TablesComponent extends Component {
   static propTpyes = {
-    type: PropTypes.string,       // 鑿滃崟绫诲瀷
     tabs: PropTypes.array,        // 鏍囩缁�
     config: PropTypes.object,     // 椤甸潰閰嶇疆
     setSubConfig: PropTypes.func, // 瀛愭爣绛鹃厤缃�
@@ -24,10 +23,11 @@
   }
 
   state = {
-    dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
+    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     tabgroups: [],     // 鏍囩缁�
     card: [],          // 缂栬緫鏍囩
     group: [],         // 缂栬緫缁�
+    levels: null,      // 鏍戝舰椤甸潰鐨勬爣绛剧骇鍒叧鑱�
     visible: false     // 妯℃�佹鎺у埗
   }
 
@@ -83,22 +83,28 @@
    * @description 鏍囩缂栬緫锛岀瓫閫夊彲閫夌殑涓嬬骇鏍囩涓庡凡鍏宠仈鐨勪笅绾ф爣绛�
    */
   handleTab = (card, _group) => {
+    const { config } = this.props
     let tabgroups = fromJS(this.state.tabgroups).toJS()
 
     let menus = [
       {value: '', text: '绌�'},
-      {value: 'mainTable', text: this.props.type === 'main' ? '涓昏〃' : '涓绘暟鎹�'}
+      {value: 'mainTable', text: '涓昏〃'}
     ]
     let equalTabs = []
     let supMenu = card.supMenu || ''
     let equalTab = card.equalTab || []
     let isuptab = true
     let equalTabIds = []
+    let levels = {}
 
-    tabgroups.forEach((group, i) => {
+    tabgroups.forEach(group => {
       if (group.uuid === _group.uuid) {
         isuptab = false
         group.sublist.forEach(tab => { // 鍙叧鑱旂殑鍚岀骇鏍囩
+          if (tab.level || tab.level === 0) {
+            levels[tab.uuid] = tab.level
+          }
+
           if (tab.uuid === card.uuid) return
 
           equalTabIds.push(tab.uuid)
@@ -106,6 +112,10 @@
         })
       } else if (isuptab) {
         group.sublist.forEach(tab => {
+          if (tab.level || tab.level === 0) {
+            levels[tab.uuid] = tab.level
+          }
+
           menus.push({
             value: tab.uuid,
             text: tab.label
@@ -122,11 +132,16 @@
       equalTab = equalTab.filter(tabId => equalTabIds.includes(tabId))
     }
 
+    if (config.Template !== 'TreePage') {
+      levels = null
+    }
+
     this.setState({
       visible: true,
       card: card,
+      levels: levels,
       group: _group,
-      formlist: getTabForm(card, supMenu, menus, equalTab, equalTabs, this.props.type)
+      formlist: getTabForm(card, supMenu, menus, equalTab, equalTabs, config.Template)
     })
   }
 
@@ -176,6 +191,20 @@
         return _group
       })
 
+      // 鏇存柊涓庝箣鍏宠仈鐨勬爣绛炬樉绀虹骇鍒�
+      if (config.Template === 'TreePage' && res.level !== card.level) {
+        tabgroups = tabgroups.map(_group => {
+          _group.sublist = _group.sublist.map(item => {
+            if (item.supMenu === res.uuid) {
+              item.level = res.level
+            }
+
+            return item
+          })
+          return _group
+        })
+      }
+
       this.setState({
         card: null,
         group: null,
@@ -197,8 +226,6 @@
 
     confirm({
       content: `纭畾鍒犻櫎<<${card.label}>>鍚楋紵`,
-      okText: this.state.dict['model.confirm'],
-      cancelText: this.state.dict['header.cancel'],
       onOk() {
         tabgroups = tabgroups.map(_group => {
           if (_group.uuid === group.uuid) {
@@ -207,10 +234,21 @@
           return _group
         })
 
+        // 娓呴櫎涓庝箣鍏宠仈鏍囩鐨勪笂绾ф爣绛捐缃�
+        tabgroups = tabgroups.map(_group => {
+          _group.sublist = _group.sublist.map(item => {
+            if (item.supMenu === card.uuid) {
+              item.supMenu = ''
+            }
+            return item
+          })
+          return _group
+        })
+
         _this.setState({
           tabgroups: tabgroups
         }, () => {
-          _this.props.updatetabs({...config, tabgroups: tabgroups}, [card])
+          _this.props.updatetabs({...config, tabgroups: tabgroups})
         })
       },
       onCancel() {}
@@ -227,8 +265,6 @@
 
     confirm({
       content: `纭畾鏂板缓鏍囩缁勫悧锛焋,
-      okText: this.state.dict['model.confirm'],
-      cancelText: this.state.dict['header.cancel'],
       onOk() {
         if (_tabgroups.length === 1) {
           _tabgroups.forEach(group => {
@@ -261,8 +297,6 @@
 
     confirm({
       content: `纭畾鍒犻櫎鏍囩缁勫悧锛焋,
-      okText: this.state.dict['model.confirm'],
-      cancelText: this.state.dict['header.cancel'],
       onOk() {
         _tabgroups = _tabgroups.filter(_group => _group.uuid !== group.uuid)
 
@@ -336,6 +370,10 @@
     }
   }
 
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.state), fromJS(nextState))
+  }
+
   /**
    * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
    */
@@ -368,13 +406,13 @@
                 handleMenu={(card) => this.handleTab(card, group)}
                 deleteMenu={(card) => this.deleteElement(card, group)}
                 doubleClickCard={this.props.setSubConfig}
-                placeholder={this.state.dict['header.form.tab.placeholder']}
+                placeholder={dict['form.required.add'] + dict['model.form.tab']}
               />
             </div>)
         })}
         {/* 鏍囩缂栬緫 */}
         <Modal
-          title={this.state.dict['header.modal.tabs.edit']}
+          title={dict['header.modal.tabs.edit']}
           visible={visible}
           width={750}
           maskClosable={false}
@@ -383,9 +421,10 @@
           destroyOnClose
         >
           <TabForm
-            dict={this.state.dict}
+            dict={dict}
             card={this.state.card}
             tabs={this.props.tabs}
+            levels={this.state.levels}
             formlist={this.state.formlist}
             inputSubmit={this.handleSubmit}
             wrappedComponentRef={(inst) => this.tabsFormRef = inst}

--
Gitblit v1.8.0