king
2022-11-21 f6626b05f1275cc2f8ca77f773d4f6a6af1b0a89
src/menu/components/tabs/table-tabs/index.jsx
@@ -4,20 +4,16 @@
import { Tabs, Popover, Modal } from 'antd'
import { PlusOutlined, CloseOutlined, EditOutlined, DeleteOutlined, 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 MenuUtils from '@/utils/utils-custom.js'
import Utils from '@/utils/utils.js'
import { getTabForm } from './options'
import './index.scss'
const NormalForm = asyncIconComponent(() => import('@/components/normalform'))
// const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
const PasteComponent = asyncIconComponent(() => import('../paste'))
const PasteBaseTable = asyncIconComponent(() => import('@/menu/components/share/pastebasetable'))
const BaseTable = asyncComponent(() => import('@/menu/components/table/base-table'))
const { TabPane } = Tabs
@@ -32,7 +28,8 @@
  state = {
    tabs: null,
    editab: null
    editab: null,
    sign: 1
  }
  UNSAFE_componentWillMount () {
@@ -42,13 +39,11 @@
      let _tabs = {
        uuid: tabs.uuid,
        type: tabs.type,
        subtype: tabs.subtype,
        width: 24,
        name: tabs.name,
        subtype: 'tabletabs',
        setting: {},
        style: { marginLeft: '8px', marginRight: '8px', marginTop: '8px', marginBottom: '8px' },
        style: {},
        subtabs: [
          { uuid: Utils.getuuid(), label: '子表1', icon: '', components: [{uuid: Utils.getuuid(), type: 'table', subtype: 'basetable', isNew: true}] },
          { uuid: Utils.getuuid(), label: '子表1', icon: '', components: [{uuid: Utils.getuuid(), name: '子表1', type: 'table', subtype: 'basetable', isNew: true}] },
        ]
      }
      this.setState({
@@ -66,8 +61,6 @@
    return !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount () {}
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
@@ -77,54 +70,11 @@
    }
  }
  changeStyle = () => {
    const { tabs } = this.state
    MKEmitter.emit('changeStyle', ['background', 'border', 'padding', 'margin', 'shadow'], tabs.style, this.getStyle)
  }
  getStyle = (style) => {
    let _card = {...this.state.tabs, style}
    this.setState({
      tabs: _card
    })
    this.props.updateConfig(_card)
  }
  updateComponent = (component) => {
    component.width = component.setting.width
    component.name = component.setting.name
    this.setState({
      tabs: component
    })
    this.props.updateConfig(component)
  }
  updateTabComponent = (tab) => {
    let tabs = fromJS(this.state.tabs).toJS()
    tabs.subtabs = tabs.subtabs.map(t => {
      if (t.uuid === tab.uuid) {
        return tab
      } else {
        return t
      }
    })
    this.setState({tabs})
    this.props.updateConfig(tabs)
  }
  delTab = (tab) => {
    let tabs = fromJS(this.state.tabs).toJS()
    const _this = this
    tabs.subtabs = tabs.subtabs.filter(t => t.uuid !== tab.uuid)
    let uuids = MenuUtils.getDelButtonIds({...tab, type: 'group'})
    confirm({
      title: '确定删除标签?',
@@ -132,10 +82,6 @@
      onOk() {
        _this.setState({tabs})
        _this.props.updateConfig(tabs)
        if (uuids.length === 0) return
        MKEmitter.emit('delButtons', uuids)
      },
      onCancel() {}
    })
@@ -161,34 +107,68 @@
  }
  dropTable = (hoverKey, dragKey) => {
    // let tabs = fromJS(this.state.tabs).toJS()
    // let subtab = {}
    // tabs.subtabs.forEach(item => {
    //   subtab[item.uuid] = item
    // })
    if (dragKey) {
      this.props.switchConfig(dragKey, hoverKey, () => {
        this.setState({sign: this.state.sign + 1}, () => {
          setTimeout(() => {
            let node = document.getElementById(dragKey)
            node && node.click()
          }, 200)
        })
      })
    } else {
      let tabs = fromJS(this.state.tabs).toJS()
      let name = '子表' + (tabs.subtabs.length + 1)
      let tab = { uuid: Utils.getuuid(), label: name, icon: '', components: [{uuid: Utils.getuuid(), type: 'table', name: name, subtype: 'basetable', isNew: true}]}
    // tabs.subtabs = []
      const hoverIndex = tabs.subtabs.findIndex(item => item.uuid === hoverKey)
    // order.forEach(item => {
    //   if (subtab[item]) {
    //     tabs.subtabs.push(subtab[item])
    //   }
    // })
      if (hoverIndex === -1) {
        tabs.subtabs.push(tab)
      } else {
        tabs.subtabs.splice(hoverIndex + 1, 0, tab)
      }
    // this.setState({tabs})
    // this.props.updateConfig(tabs)
      this.setState({tabs}, () => {
        setTimeout(() => {
          let node = document.getElementById(tab.uuid)
          node && node.click()
        }, 200)
      })
      this.props.updateConfig(tabs)
    }
  }
  insert = (item, tab) => {
  plusTable = () => {
    let tabs = fromJS(this.state.tabs).toJS()
    let name = '子表' + (tabs.subtabs.length + 1)
    let tab = { uuid: Utils.getuuid(), label: name, icon: '', components: [{uuid: Utils.getuuid(), type: 'table', name: name, subtype: 'basetable', isNew: true}]}
    tabs.subtabs.push(tab)
    this.setState({tabs}, () => {
      setTimeout(() => {
        let node = document.getElementById(tab.uuid)
        node && node.click()
      }, 200)
    })
    this.props.updateConfig(tabs)
  }
  insert = (item) => {
    let tabs = fromJS(this.state.tabs).toJS()
    tabs.subtabs.forEach(stab => {
      if (stab.uuid === tab.uuid) {
        stab.components.push(item)
      }
    })
    let name = item.name || ('子表' + (tabs.subtabs.length + 1))
    let tab = { uuid: Utils.getuuid(), label: name, icon: '', components: [item]}
    this.setState({tabs})
    tabs.subtabs.push(tab)
    this.setState({tabs}, () => {
      setTimeout(() => {
        let node = document.getElementById(tab.uuid)
        node && node.click()
      }, 200)
    })
    this.props.updateConfig(tabs)
  }
@@ -218,10 +198,8 @@
    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
    editab.permission = res.permission || 'false'
    editab.components[0].name = res.label
    if (editab.uuid) {
      tabs.subtabs = tabs.subtabs.map(t => {
@@ -244,18 +222,22 @@
    this.props.updateConfig(tabs)
  }
  updateConfig = () => {
  updateConfig = (tb, i) => {
    let tabs = fromJS(this.state.tabs).toJS()
    tabs.subtabs[i].components = [tb]
    this.setState({ tabs })
    this.props.updateConfig(tabs)
  }
  render() {
    const { tabs } = this.state
    let _style = resetStyle(tabs.style)
    return (
      <div className={'menu-tabs-edit-box ' + (tabs.setting.display || '')} style={_style} id={tabs.uuid}>
      <div className="table-tabs-edit-box" style={tabs.style} id={tabs.uuid}>
        <DraggableTabs tabsMove={this.moveSwitch} tabsDrop={this.dropTable}>
          {tabs.subtabs.map(tab => (
          {tabs.subtabs.map((tab, i) => (
            <TabPane tab={
              <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
                <div className="mk-popover-control">
@@ -265,17 +247,17 @@
                  <CloseOutlined className="close" onClick={() => this.delTab(tab)} />
                </div>
              } trigger="hover">
                <span style={{textDecoration: tab.hide === 'true' ? 'line-through' : 'none'}}>{tab.icon ? <MkIcon type={tab.icon} /> : null}{tab.label}</span>
                <span id={tab.uuid} style={{textDecoration: tab.hide === 'true' ? 'line-through' : 'none'}}>{tab.icon ? <MkIcon type={tab.icon} /> : null}{tab.label}</span>
              </Popover>
            } key={tab.uuid}>
              <BaseTable card={tab.components[0]} updateConfig={this.updateConfig} />
              <BaseTable card={tab.components[0]} updateConfig={(tb) => this.updateConfig(tb, i)} />
            </TabPane>
          ))}
        </DraggableTabs>
        <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
          <div className="mk-popover-control">
            <PlusOutlined className="plus" title="添加子表"/>
            <PasteComponent insert={this.insert} />
            <PlusOutlined className="plus" title="添加子表" onClick={this.plusTable}/>
            <PasteBaseTable insert={this.insert} />
            <DeleteOutlined className="close" onClick={() => this.props.deletecomponent(tabs.uuid)} />
          </div>
        } trigger="hover">