From af6486b3629d23e426ce85b87dbc20dfa15b1afe Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 07 十一月 2022 18:50:27 +0800 Subject: [PATCH] 2022-11-07 --- src/menu/components/tabs/table-tabs/index.jsx | 288 +++++++++++++++----------------------------------------- 1 files changed, 79 insertions(+), 209 deletions(-) diff --git a/src/menu/components/tabs/table-tabs/index.jsx b/src/menu/components/tabs/table-tabs/index.jsx index a272815..293312c 100644 --- a/src/menu/components/tabs/table-tabs/index.jsx +++ b/src/menu/components/tabs/table-tabs/index.jsx @@ -2,23 +2,19 @@ import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' import { Tabs, Popover, Modal } from 'antd' -import { PlusOutlined, CloseOutlined, EditOutlined, DeleteOutlined, FontColorsOutlined, ToolOutlined } from '@ant-design/icons' +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, getTabsSetForm } from './options' +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 TabComponents = asyncComponent(() => import('../tabcomponents')) +const PasteBaseTable = asyncIconComponent(() => import('@/menu/components/share/pastebasetable')) +const BaseTable = asyncComponent(() => import('@/menu/components/table/base-table')) const { TabPane } = Tabs const { confirm } = Modal @@ -31,10 +27,9 @@ } state = { - appType: sessionStorage.getItem('appType'), tabs: null, editab: null, - defaultActiveKey: '' + sign: 1 } UNSAFE_componentWillMount () { @@ -44,27 +39,19 @@ let _tabs = { uuid: tabs.uuid, type: tabs.type, - tabId: tabs.tabId || '', - parentId: tabs.parentId || '', - subtype: tabs.subtype, - width: 24, - name: tabs.name, - setting: {width: 24, position: 'top', tabStyle: 'line', name: tabs.name}, - style: { marginLeft: '8px', marginRight: '8px', marginTop: '8px', marginBottom: '8px' }, + subtype: 'tabletabs', + setting: {}, + style: {}, subtabs: [ - { uuid: Utils.getuuid(), parentId: tabs.uuid, label: 'Tab 1', icon: '', components: [] }, - { uuid: Utils.getuuid(), parentId: tabs.uuid, label: 'Tab 2', icon: '', components: [] }, - { uuid: Utils.getuuid(), parentId: tabs.uuid, label: 'Tab 3', icon: '', components: [] } + { uuid: Utils.getuuid(), label: '瀛愯〃1', icon: '', components: [{uuid: Utils.getuuid(), name: '瀛愯〃1', type: 'table', subtype: 'basetable', isNew: true}] }, ] } 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() }) } @@ -74,12 +61,6 @@ return !is(fromJS(this.state), fromJS(nextState)) } - componentDidMount () { - MKEmitter.addListener('submitSearch', this.getSearch) - MKEmitter.addListener('tabsChange', this.handleTabsChange) - MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle) - } - /** * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆 */ @@ -87,98 +68,6 @@ this.setState = () => { return } - MKEmitter.removeListener('submitSearch', this.getSearch) - MKEmitter.removeListener('tabsChange', this.handleTabsChange) - MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle) - } - - updateComponentStyle = (parentId, keys, style) => { - const { tabs } = this.state - - if (tabs.subtabs.findIndex(tab => tab.uuid === parentId) === -1) return - - let _tabs = fromJS(tabs).toJS() - let _tabs_ = fromJS(tabs).toJS() - - let components = [] - _tabs.subtabs.forEach(tab => { - if (tab.uuid === parentId) { - components = tab.components.map(item => { - if (keys.includes(item.uuid)) { - item.style = {...item.style, ...style} - } - return item - }) - tab.components = [] - } - }) - - _tabs_.subtabs = _tabs_.subtabs.map(tab => { - if (tab.uuid === parentId) { - tab.components = components - } - return tab - }) - - this.setState({tabs: _tabs}, () => { - this.updateComponent(_tabs_) - }) - } - - 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) - } - - handleTabsChange = (parentId) => { - const { tabs } = this.state - - if (parentId === tabs.parentId) { - MKEmitter.emit('tabsChange', tabs.uuid) - } - } - - updateComponent = (component) => { - const { tabs } = this.state - - if (!is(fromJS(tabs.setting), fromJS(component.setting)) || !is(fromJS(tabs.style), fromJS(component.style))) { - // 娉ㄥ唽浜嬩欢-鏍囩鍙樺寲锛岄�氱煡鏍囩鍐呭厓绱� - MKEmitter.emit('tabsChange', tabs.uuid) - } - - 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) => { @@ -187,18 +76,12 @@ tabs.subtabs = tabs.subtabs.filter(t => t.uuid !== tab.uuid) - let uuids = MenuUtils.getDelButtonIds({...tab, type: 'group'}) - confirm({ title: '纭畾鍒犻櫎鏍囩锛�', content: '', onOk() { _this.setState({tabs}) _this.props.updateConfig(tabs) - - if (uuids.length === 0) return - - MKEmitter.emit('delButtons', uuids) }, onCancel() {} }) @@ -223,63 +106,70 @@ this.props.updateConfig(tabs) } - insert = (item, tab) => { - let tabs = fromJS(this.state.tabs).toJS() + dropTable = (hoverKey, dragKey) => { + 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.forEach(stab => { - if (stab.uuid === tab.uuid) { - stab.components.push(item) + const hoverIndex = tabs.subtabs.findIndex(item => item.uuid === hoverKey) + + if (hoverIndex === -1) { + tabs.subtabs.push(tab) + } else { + tabs.subtabs.splice(hoverIndex + 1, 0, tab) } - }) - this.setState({tabs}) + this.setState({tabs}, () => { + setTimeout(() => { + let node = document.getElementById(tab.uuid) + node && node.click() + }, 200) + }) + this.props.updateConfig(tabs) + } + } + + 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) } - getSearch = (config) => { - const { tabs } = this.state + insert = (item) => { + let tabs = fromJS(this.state.tabs).toJS() - if (tabs.uuid !== config.uuid) return + let name = item.name || ('瀛愯〃' + (tabs.subtabs.length + 1)) + let tab = { uuid: Utils.getuuid(), label: name, icon: '', components: [item]} - let _tabs = fromJS(tabs).toJS() + tabs.subtabs.push(tab) - _tabs.subtabs = _tabs.subtabs.map(t => { - if (t.uuid === config.tabId) { - t.search = config.search - } - return t + this.setState({tabs}, () => { + setTimeout(() => { + let node = document.getElementById(tab.uuid) + node && node.click() + }, 200) }) - - this.setState({ - tabs: _tabs - }) - this.props.updateConfig(_tabs) - } - - setSearch = (tab) => { - const { tabs } = this.state - let card = { - uuid: tabs.uuid, - tabId: tab.uuid, - search: tab.search - } - - if (!card.search) { - card.search = { - floor: 1, - setting: { type: 'title', field: '', title: '', focus: 'true', btn: 'hidden' }, - groups: [], - fields: [] - } - } - MKEmitter.emit('changeSearch', card) - } - - clickComponent = (e) => { - if (sessionStorage.getItem('style-control') === 'true' || sessionStorage.getItem('style-control') === 'component') { - e.stopPropagation() - MKEmitter.emit('clickComponent', this.state.tabs) - } + this.props.updateConfig(tabs) } getTabForms = (tab) => { @@ -288,7 +178,6 @@ if (!tab) { tab = { uuid: '', - parentId: tabs.uuid, label: '', icon: '', components: [] @@ -308,12 +197,9 @@ editab.label = res.label editab.icon = res.icon - // editab.hasSearch = res.hasSearch || '' 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 => { @@ -336,58 +222,42 @@ this.props.updateConfig(tabs) } - getTabsForms = () => { - const { tabs } = this.state + updateConfig = (tb, i) => { + let tabs = fromJS(this.state.tabs).toJS() + tabs.subtabs[i].components = [tb] - return getTabsSetForm(tabs.setting, tabs.uuid) - } + this.setState({ tabs }) - updateTabs = (res) => { - this.updateComponent({...this.state.tabs, setting: res}) - } - - onChange = (key) => { - const { tabs } = this.state - window.GLOB.TabsMap.set(tabs.uuid, key) + this.props.updateConfig(tabs) } render() { - const { tabs, defaultActiveKey } = this.state - let _style = resetStyle(tabs.style) + const { tabs } = this.state return ( - <div className={'menu-tabs-edit-box ' + (tabs.setting.display || '')} style={_style} onClick={this.clickComponent} 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 => ( + <div className="table-tabs-edit-box" style={tabs.style} id={tabs.uuid}> + <DraggableTabs tabsMove={this.moveSwitch} tabsDrop={this.dropTable}> + {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"> <NormalForm title="鏍囩缂栬緫" width={800} update={this.updateTab} getForms={() => this.getTabForms(tab)}> <EditOutlined style={{color: '#1890ff'}} title="缂栬緫"/> </NormalForm> - <PasteComponent Tab={tab} insert={this.insert} /> <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} style={{backgroundColor: tab.backgroundColor || 'transparent'}}> - {/* {appType === 'mob' && tabs.setting.position === 'top' && tabs.setting.display === 'inline-block' && tab.hasSearch === 'icon' ? - <SearchOutlined className="search-icon" onDoubleClick={() => this.setSearch(tab)}/> : null} */} - <TabComponents config={tab} handleList={this.updateTabComponent} deleteCard={this.deleteCard} /> + } key={tab.uuid}> + <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"> - <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}/> + <PlusOutlined className="plus" title="娣诲姞瀛愯〃" onClick={this.plusTable}/> + <PasteBaseTable insert={this.insert} /> <DeleteOutlined className="close" onClick={() => this.props.deletecomponent(tabs.uuid)} /> </div> } trigger="hover"> -- Gitblit v1.8.0