From ae170a9d58b4f91a225eada1dc83ed4a116b8d50 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 25 八月 2024 00:57:37 +0800
Subject: [PATCH] 2024-08-25

---
 src/menu/components/tabs/antv-tabs/index.jsx |  343 +++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 222 insertions(+), 121 deletions(-)

diff --git a/src/menu/components/tabs/antv-tabs/index.jsx b/src/menu/components/tabs/antv-tabs/index.jsx
index c36136a..145bcdc 100644
--- a/src/menu/components/tabs/antv-tabs/index.jsx
+++ b/src/menu/components/tabs/antv-tabs/index.jsx
@@ -1,35 +1,38 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Tabs, Icon, Popover, Modal } from 'antd'
+import { Tabs, Popover, Modal } from 'antd'
+import { PlusOutlined, CloseOutlined, EditOutlined, DeleteOutlined, FontColorsOutlined, ToolOutlined } from '@ant-design/icons'
 
 import MKEmitter from '@/utils/events.js'
 import asyncComponent from '@/utils/asyncComponent'
-
+import asyncIconComponent from '@/utils/asyncIconComponent'
+import MkIcon from '@/components/mk-icon'
+import DraggableTabs from './dragabletabs'
+import { resetStyle } from '@/utils/utils-custom.js'
 import Utils from '@/utils/utils.js'
-import zhCN from '@/locales/zh-CN/model.js'
-import enUS from '@/locales/en-US/model.js'
+import { getTabForm, getTabsSetForm } from './options'
 import './index.scss'
 
-const SettingComponent = asyncComponent(() => import('../tabsetting'))
-const TabLabelComponent = asyncComponent(() => import('../tablabelform'))
+const NormalForm = asyncIconComponent(() => import('@/components/normalform'))
+const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
+const PasteController = asyncIconComponent(() => import('@/menu/pastecontroller'))
 const TabComponents = asyncComponent(() => import('../tabcomponents'))
 
 const { TabPane } = Tabs
 const { confirm } = Modal
 
-class antvBarLineChart extends Component {
+class antvTabs extends Component {
   static propTpyes = {
-    menu: PropTypes.object,
     tabs: PropTypes.object,
+    deletecomponent: PropTypes.func,
     updateConfig: PropTypes.func,
   }
 
   state = {
-    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     tabs: null,
     editab: null,
-    labelvisible: false
+    defaultActiveKey: ''
   }
 
   UNSAFE_componentWillMount () {
@@ -39,23 +42,25 @@
       let _tabs = {
         uuid: tabs.uuid,
         type: tabs.type,
-        floor: tabs.floor,
-        tabId: tabs.tabId || '',
-        parentId: tabs.parentId || '',
         subtype: tabs.subtype,
-        setting: {span: 12, position: 'top', tabStyle: 'line', name: tabs.name},
+        width: 24,
+        name: tabs.name,
+        setting: {width: 24, position: 'top', tabStyle: 'line', name: tabs.name},
+        style: { marginLeft: '8px', marginRight: '8px', marginTop: '8px', marginBottom: '8px' },
         subtabs: [
-          { uuid: Utils.getuuid(), parentId: tabs.uuid, floor: tabs.floor, label: 'Tab 1', icon: '', components: [] },
-          { uuid: Utils.getuuid(), parentId: tabs.uuid, floor: tabs.floor, label: 'Tab 2', icon: '', components: [] },
-          { uuid: Utils.getuuid(), parentId: tabs.uuid, floor: tabs.floor, label: 'Tab 3', icon: '', components: [] }
+          { uuid: Utils.getuuid(), label: 'Tab 1', icon: '', components: [] },
+          { uuid: Utils.getuuid(), label: 'Tab 2', icon: '', components: [] },
+          { uuid: Utils.getuuid(), label: 'Tab 3', icon: '', components: [] }
         ]
       }
       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()
       })
     }
@@ -65,10 +70,6 @@
     return !is(fromJS(this.state), fromJS(nextState))
   }
 
-  componentDidMount () {
-    MKEmitter.addListener('tabsChange', this.handleTabsChange)
-  }
-
   /**
    * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆
    */
@@ -76,24 +77,52 @@
     this.setState = () => {
       return
     }
-    MKEmitter.removeListener('tabsChange', this.handleTabsChange)
   }
 
-  handleTabsChange = (parentId) => {
+  changeStyle = () => {
     const { tabs } = this.state
 
-    if (parentId === tabs.parentId) {
-      MKEmitter.emit('tabsChange', tabs.uuid)
-    }
+    MKEmitter.emit('changeStyle', ['background', 'border', 'padding', 'margin', 'shadow', 'clear'], tabs.style, this.getStyle)
+  }
+
+  getStyle = (style) => {
+    let _card = {...this.state.tabs, style}
+
+    this.setState({
+      tabs: _card
+    })
+    
+    this.props.updateConfig(_card)
+  }
+
+  getSubIds = (components, ids) => {
+    components.forEach(item => {
+      if (item.type === 'tabs') {
+        item.subtabs.forEach(tab => {
+          this.getSubIds(tab.components, ids)
+        })
+      } else if (item.type === 'group') {
+        this.getSubIds(item.components, ids)
+      } else {
+        ids.push(item.uuid)
+      }
+    })
   }
 
   updateComponent = (component) => {
     const { tabs } = this.state
 
-    if (!is(fromJS(tabs.setting), fromJS(component.setting))) {
+    if (!is(fromJS(tabs.setting), fromJS(component.setting)) || !is(fromJS(tabs.style), fromJS(component.style))) {
       // 娉ㄥ唽浜嬩欢-鏍囩鍙樺寲锛岄�氱煡鏍囩鍐呭厓绱�
-      MKEmitter.emit('tabsChange', tabs.uuid)
+      let ids = []
+      tabs.subtabs.forEach(tab => {
+        this.getSubIds(tab.components, ids)
+      })
+      MKEmitter.emit('tabsChange', ids.join(','))
     }
+
+    component.width = component.setting.width
+    component.name = component.setting.name
 
     this.setState({
       tabs: component
@@ -116,64 +145,9 @@
     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
-
-      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) => {
     let tabs = fromJS(this.state.tabs).toJS()
-    const _this = this
+    const that = this
 
     tabs.subtabs = tabs.subtabs.filter(t => t.uuid !== tab.uuid)
 
@@ -181,67 +155,194 @@
       title: '纭畾鍒犻櫎鏍囩锛�',
       content: '',
       onOk() {
-        _this.setState({tabs})
-        _this.props.updateConfig(tabs)
+        that.setState({tabs})
+        that.props.updateConfig(tabs)
       },
       onCancel() {}
     })
   }
 
-  moveSwitch = (index, index1) => {
+  moveSwitch = (order) => {
     let tabs = fromJS(this.state.tabs).toJS()
-    tabs.subtabs[index] = tabs.subtabs.splice(index1, 1, tabs.subtabs[index])[0]
+    let subtab = {}
+    tabs.subtabs.forEach(item => {
+      subtab[item.uuid] = item
+    })
+
+    tabs.subtabs = []
+
+    order.forEach(item => {
+      if (subtab[item]) {
+        tabs.subtabs.push(subtab[item])
+      }
+    })
 
     this.setState({tabs})
     this.props.updateConfig(tabs)
   }
 
+  insert = (item, tabId) => {
+    let tabs = fromJS(this.state.tabs).toJS()
+
+    tabs.subtabs.forEach(stab => {
+      if (stab.uuid === tabId) {
+        stab.components.push(item)
+      }
+    })
+
+    this.setState({tabs})
+    this.props.updateConfig(tabs)
+  }
+
+  getTabForms = (tab) => {
+    if (!tab) {
+      tab = {
+        uuid: '',
+        label: '',
+        icon: '',
+        components: []
+      }
+    }
+
+    this.setState({
+      editab: tab
+    })
+
+    return getTabForm(tab)
+  }
+
+  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.hide = res.hide || 'false'
+    editab.backgroundColor = res.backgroundColor
+    // editab.controlVal = res.controlVal || ''
+    // editab.selectVal = res.selectVal || ''
+    editab.blacklist = res.blacklist
+
+    if (/^\s+$/.test(editab.label) && editab.icon) {
+      editab.taType = 'only-icon'
+    } else {
+      delete editab.taType
+    }
+
+    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, tabs.uuid, tabs.subtabs)
+  }
+
+  updateTabs = (res) => {
+    let tabs = fromJS(this.state.tabs).toJS()
+
+    if (res.controlVals) {
+      let values = {}
+      res.controlVals.forEach(item => {
+        values[item.uuid] = item.value
+      })
+      tabs.subtabs.forEach(tab => {
+        tab.controlVal = values[tab.uuid]
+      })
+
+      delete res.controlVals
+    }
+    if (res.selectVals) {
+      let values = {}
+      res.selectVals.forEach(item => {
+        values[item.uuid] = item.value
+      })
+      tabs.subtabs.forEach(tab => {
+        tab.selectVal = values[tab.uuid]
+      })
+
+      delete res.selectVals
+    }
+
+    res.tabStyle = res.tabStyle || 'line'
+    res.cusClass = ''
+
+    if (!['line', 'card'].includes(res.tabStyle)) {
+      res.cusClass = res.tabStyle
+      res.tabStyle = 'line'
+    }
+
+    tabs.setting = res
+
+    this.updateComponent(tabs)
+  }
+
+  onChange = (key) => {
+    const { tabs } = this.state
+    window.GLOB.TabsMap.set(tabs.uuid, key)
+  }
+
   render() {
-    const { menu } = this.props
-    const { tabs, dict, labelvisible, editab } = this.state
+    const { tabs, defaultActiveKey } = this.state
+    let _style = resetStyle(tabs.style)
 
     return (
-      <div className="menu-tabs-edit-box">
-        <SettingComponent config={tabs} updateConfig={this.updateComponent} />
-        <Tabs defaultActiveKey="1" tabPosition={tabs.setting.position} type={tabs.setting.tabStyle}>
-          {tabs.subtabs.map((tab, index) => (
+      <div className="menu-tabs-edit-box" style={_style} id={tabs.uuid}>
+        <DraggableTabs defaultActiveKey={defaultActiveKey} tabBarStyle={{background: tabs.setting.backgroundColor || 'transparent'}} 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)} />
-                  {index !== 0 ? <Icon className="edit" type="arrow-left" onClick={() => this.moveSwitch(index, index - 1)} /> : null}
-                  {(index + 1) !== tabs.subtabs.length ? <Icon className="edit" type="arrow-right" onClick={() => this.moveSwitch(index, index + 1)} /> : null}
-                  <Icon className="close" title="delete" type="close" onClick={() => this.delTab(tab)} />
+                  <NormalForm title="鏍囩缂栬緫" width={800} update={this.updateTab} getForms={() => this.getTabForms(tab)}>
+                    <EditOutlined style={{color: '#1890ff'}} title="缂栬緫"/>
+                  </NormalForm>
+                  <PasteController type="tabs" tab={tab} insert={(item) => this.insert(item, tab.uuid)} />
+                  <CloseOutlined className="close" onClick={() => this.delTab(tab)} />
                 </div>
               } trigger="hover">
-                <span>{tab.icon ? <Icon type={tab.icon} /> : null}{tab.label}</span>
+                <span style={{textDecoration: tab.hide === 'true' ? 'line-through' : 'none'}}>{tab.icon ? <MkIcon type={tab.icon} /> : null}{tab.label}</span>
               </Popover>
-            } key={tab.uuid}>
-              <TabComponents menu={menu} config={tab} handleList={this.updateTabComponent} deleteCard={this.deleteCard} />
+            } key={tab.uuid} style={{backgroundColor: tab.backgroundColor || 'transparent'}}>
+              <TabComponents config={tab} handleList={this.updateTabComponent} deleteCard={this.deleteCard} />
             </TabPane>
           ))}
-          <TabPane className="tab-add" disabled tab={<Icon onClick={this.tabAdd} type="plus" />} key="add"></TabPane>
-        </Tabs>
-        <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}
-            wrappedComponentRef={(inst) => this.tabLabelRef = inst}
-          />
-        </Modal>
+        </DraggableTabs>
+        <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
+          <div className="mk-popover-control">
+            <NormalForm title="娣诲姞鏍囩" width={800} update={this.updateTab} getForms={() => this.getTabForms()}>
+              <PlusOutlined className="plus" title="娣诲姞鏍囩"/>
+            </NormalForm>
+            <NormalForm title="鏍囩椤佃缃�" width={800} update={this.updateTabs} getForms={this.getTabsForms}>
+              <EditOutlined style={{color: '#1890ff'}} title="缂栬緫"/>
+            </NormalForm>
+            <CopyComponent type="tabs" card={tabs}/>
+            <FontColorsOutlined className="style" title="璋冩暣鏍峰紡" onClick={this.changeStyle}/>
+            <DeleteOutlined className="close" onClick={() => this.props.deletecomponent(tabs.uuid)} />
+          </div>
+        } trigger="hover">
+          <ToolOutlined />
+        </Popover>
       </div>
     )
   }
 }
 
-export default antvBarLineChart
\ No newline at end of file
+export default antvTabs
\ No newline at end of file

--
Gitblit v1.8.0