From 84a746468a3f7e5b39a3ed53090a19a8dec8cb10 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 06 九月 2021 11:48:25 +0800
Subject: [PATCH] 2021-09-06

---
 src/mob/components/tabs/antv-tabs/index.jsx |  208 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 115 insertions(+), 93 deletions(-)

diff --git a/src/mob/components/tabs/antv-tabs/index.jsx b/src/mob/components/tabs/antv-tabs/index.jsx
index b98c70c..6a26189 100644
--- a/src/mob/components/tabs/antv-tabs/index.jsx
+++ b/src/mob/components/tabs/antv-tabs/index.jsx
@@ -10,14 +10,15 @@
 import { resetStyle } from '@/utils/utils-custom.js'
 import MenuUtils from '@/utils/utils-custom.js'
 import Utils from '@/utils/utils.js'
+import { getTabForm, getTabsSetForm } from './options'
 import zhCN from '@/locales/zh-CN/model.js'
 import enUS from '@/locales/en-US/model.js'
 import './index.scss'
 
-const SettingComponent = asyncIconComponent(() => import('@/menu/components/tabs/tabsetting'))
+const NormalForm = asyncIconComponent(() => import('@/components/normalform'))
 const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
 const PasteController = asyncIconComponent(() => import('@/menu/pastecontroller'))
-const TabLabelComponent = asyncComponent(() => import('@/menu/components/tabs/tablabelform'))
+// const TabLabelComponent = asyncComponent(() => import('@/menu/components/tabs/tablabelform'))
 const TabComponents = asyncComponent(() => import('../tabcomponents'))
 
 const { TabPane } = Tabs
@@ -35,7 +36,7 @@
     appType: sessionStorage.getItem('appType'),
     tabs: null,
     editab: null,
-    labelvisible: false
+    defaultActiveKey: ''
   }
 
   UNSAFE_componentWillMount () {
@@ -59,12 +60,19 @@
           { uuid: Utils.getuuid(), parentId: tabs.uuid, floor: tabs.floor, label: 'Tab 3', icon: '', components: [] }
         ]
       }
+
+      if (this.state.appType === 'mob') {
+        _tabs.setting.display = 'flex'
+      }
+      
       this.setState({
+        defaultActiveKey: _tabs.subtabs[0].uuid,
         tabs: _tabs
       })
       this.props.updateConfig(_tabs)
     } else {
       this.setState({
+        defaultActiveKey: window.GLOB.TabsMap.get(tabs.uuid) || '',
         tabs: fromJS(tabs).toJS()
       })
     }
@@ -133,18 +141,34 @@
     MKEmitter.emit('changeStyle', [tabs.uuid], ['background', 'border', 'padding', 'margin', 'shadow'], tabs.style)
   }
 
+  changeTabStyle = () => {
+    const { tabs } = this.state
+
+    MKEmitter.emit('changeStyle', [tabs.uuid, 'tab'], ['font', 'padding'], tabs.tabStyle || {})
+  }
+
   getStyle = (comIds, style) => {
     const { tabs } = this.state
 
-    if (comIds.length !== 1 || comIds[0] !== tabs.uuid) return
+    if (comIds[0] !== tabs.uuid) return
 
-    let _card = {...tabs, style}
+    if (comIds.length === 1) {
+      let _card = {...tabs, style}
 
-    this.setState({
-      tabs: _card
-    })
-    
-    this.props.updateConfig(_card)
+      this.setState({
+        tabs: _card
+      })
+      
+      this.props.updateConfig(_card)
+    } else if (comIds[1] === 'tab') {
+      let _card = {...tabs, tabStyle: style}
+
+      this.setState({
+        tabs: _card
+      })
+      
+      this.props.updateConfig(_card)
+    }
   }
 
   handleTabsChange = (parentId) => {
@@ -185,63 +209,6 @@
 
     this.setState({tabs})
     this.props.updateConfig(tabs)
-  }
-
-  tabAdd = (e) => {
-    const { tabs } = this.state
-
-    e.stopPropagation()
-
-    this.setState({
-      editab: {
-        uuid: '',
-        parentId: tabs.uuid,
-        floor: tabs.floor,
-        label: '',
-        icon: '',
-        components: []
-      },
-      labelvisible: true
-    })
-  }
-
-  editTab = (tab) => {
-    this.setState({
-      editab: tab,
-      labelvisible: true
-    })
-  }
-
-  tabLabelSubmit = () => {
-    let tabs = fromJS(this.state.tabs).toJS()
-    let editab = fromJS(this.state.editab).toJS()
-
-    this.tabLabelRef.handleConfirm().then(res => {
-      editab.label = res.label
-      editab.icon = res.icon
-      editab.hasSearch = res.hasSearch || ''
-      editab.blacklist = res.blacklist
-
-      if (editab.uuid) {
-        tabs.subtabs = tabs.subtabs.map(t => {
-          if (t.uuid === editab.uuid) {
-            return editab
-          } else {
-            return t
-          }
-        })
-      } else {
-        editab.uuid = Utils.getuuid()
-        tabs.subtabs.push(editab)
-      }
-
-      this.setState({
-        editab: null,
-        labelvisible: false,
-        tabs
-      })
-      this.props.updateConfig(tabs)
-    })
   }
 
   delTab = (tab) => {
@@ -338,6 +305,72 @@
     MKEmitter.emit('changeSearch', card)
   }
 
+  getTabForms = (tab) => {
+    const { tabs } = this.state
+
+    if (!tab) {
+      tab = {
+        uuid: '',
+        parentId: tabs.uuid,
+        floor: tabs.floor,
+        label: '',
+        icon: '',
+        components: []
+      }
+    }
+
+    this.setState({
+      editab: tab
+    })
+
+    return getTabForm(tab, tabs.setting)
+  }
+
+  updateTab = (res) => {
+    let tabs = fromJS(this.state.tabs).toJS()
+    let editab = fromJS(this.state.editab).toJS()
+
+    editab.label = res.label
+    editab.icon = res.icon
+    editab.hasSearch = res.hasSearch || ''
+    editab.blacklist = res.blacklist
+
+    if (editab.uuid) {
+      tabs.subtabs = tabs.subtabs.map(t => {
+        if (t.uuid === editab.uuid) {
+          return editab
+        } else {
+          return t
+        }
+      })
+    } else {
+      editab.uuid = Utils.getuuid()
+      tabs.subtabs.push(editab)
+    }
+
+    this.setState({
+      editab: null,
+      tabs
+    })
+
+    this.props.updateConfig(tabs)
+  }
+
+  getTabsForms = () => {
+    const { tabs } = this.state
+
+    return getTabsSetForm(tabs.setting)
+  }
+
+  updateTabs = (res) => {
+    this.updateComponent({...this.state.tabs, setting: res})
+  }
+
+  onChange = (key) => {
+    const { tabs } = this.state
+    window.GLOB.TabsMap.set(tabs.uuid, key)
+  }
+
   clickComponent = (e) => {
     if (sessionStorage.getItem('style-control') === 'true' || sessionStorage.getItem('style-control') === 'component') {
       e.stopPropagation()
@@ -346,22 +379,26 @@
   }
 
   render() {
-    const { tabs, dict, labelvisible, editab, appType } = this.state
+    const { tabs, appType, defaultActiveKey } = this.state
     let _style = resetStyle(tabs.style)
+    let _tabStyle = resetStyle(tabs.tabStyle)
 
     return (
-      <div className={'menu-tabs-edit-box ' + tabs.setting.display} style={_style} onClick={this.clickComponent} id={tabs.uuid}>
-        <DraggableTabs tabPosition={tabs.setting.position} type={tabs.setting.tabStyle} tabsMove={this.moveSwitch}>
+      <div className={'mob-tabs-edit-box ' + tabs.setting.display} style={_style} onClick={this.clickComponent} id={tabs.uuid}>
+        <DraggableTabs defaultActiveKey={defaultActiveKey} tabPosition={tabs.setting.position} type={tabs.setting.tabStyle} tabsMove={this.moveSwitch} onChange={this.onChange}>
           {tabs.subtabs.map(tab => (
             <TabPane tab={
               <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
                 <div className="mk-popover-control">
-                  <Icon className="edit" title="edit" type="edit" onClick={() => this.editTab(tab)} />
+                  <NormalForm title="鏍囩缂栬緫" width={600} update={this.updateTab} getForms={() => this.getTabForms(tab)}>
+                    <Icon type="edit" style={{color: '#1890ff'}} title="缂栬緫"/>
+                  </NormalForm>
                   <PasteController type="tab" Tab={tab} insert={this.insert} />
+                  <Icon className="style" title="璋冩暣鏍峰紡" onClick={this.changeTabStyle} type="font-colors" />
                   <Icon className="close" title="delete" type="close" onClick={() => this.delTab(tab)} />
                 </div>
               } trigger="hover">
-                <span>{tab.icon ? <Icon type={tab.icon} /> : null}{tab.label}</span>
+                <span style={_tabStyle}>{tab.icon ? <Icon type={tab.icon} /> : null}{tab.label}</span>
               </Popover>
             } key={tab.uuid}>
               {appType === 'mob' && tabs.setting.position === 'top' && tabs.setting.display === 'inline-block' && tab.hasSearch === 'icon' ?
@@ -372,8 +409,12 @@
         </DraggableTabs>
         <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
           <div className="mk-popover-control">
-            <Icon className="plus" title="娣诲姞鏍囩" type="plus" onClick={this.tabAdd} />
-            <SettingComponent config={tabs} updateConfig={this.updateComponent} />
+            <NormalForm title="娣诲姞鏍囩" width={600} update={this.updateTab} getForms={() => this.getTabForms()}>
+              <Icon type="plus" className="plus" title="娣诲姞鏍囩"/>
+            </NormalForm>
+            <NormalForm title="鏍囩椤佃缃�" width={700} update={this.updateTabs} getForms={this.getTabsForms}>
+              <Icon type="edit" style={{color: '#1890ff'}} title="缂栬緫"/>
+            </NormalForm>
             <CopyComponent type="tabs" card={tabs}/>
             <Icon className="style" title="璋冩暣鏍峰紡" onClick={this.changeStyle} type="font-colors" />
             <Icon className="close" title="delete" type="delete" onClick={() => this.props.deletecomponent(tabs.uuid)} />
@@ -381,25 +422,6 @@
         } trigger="hover">
           <Icon type="tool" />
         </Popover>
-        <Modal
-          wrapClassName="popview-modal"
-          title={'鏍囩缂栬緫'}
-          visible={labelvisible}
-          width={600}
-          maskClosable={false}
-          okText={dict['model.submit']}
-          onOk={this.tabLabelSubmit}
-          onCancel={() => { this.setState({ labelvisible: false }) }}
-          destroyOnClose
-        >
-          <TabLabelComponent
-            dict={dict}
-            tab={editab}
-            setting={tabs.setting}
-            inputSubmit={this.tabLabelSubmit}
-            wrappedComponentRef={(inst) => this.tabLabelRef = inst}
-          />
-        </Modal>
       </div>
     )
   }

--
Gitblit v1.8.0