| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { connect } from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Icon, Popover } from 'antd' |
| | | import { Popover, Modal } from 'antd' |
| | | import { EditOutlined, ToolOutlined, DeleteOutlined, FontColorsOutlined, UngroupOutlined } from '@ant-design/icons' |
| | | |
| | | import MKEmitter from '@/utils/events.js' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import asyncIconComponent from '@/utils/asyncIconComponent' |
| | | |
| | | import zhCN from '@/locales/zh-CN/model.js' |
| | | import enUS from '@/locales/en-US/model.js' |
| | | import { resetStyle } from '@/utils/utils-custom.js' |
| | | import getSettingForm from './options' |
| | | import './index.scss' |
| | | |
| | | const SettingComponent = asyncIconComponent(() => import('../tabsetting')) |
| | | const { confirm } = Modal |
| | | const NormalForm = asyncIconComponent(() => import('@/components/normalform')) |
| | | const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent')) |
| | | const NormalHeader = asyncComponent(() => import('@/menu/components/share/normalheader')) |
| | | const PasteController = asyncIconComponent(() => import('@/menu/pastecontroller')) |
| | | const TabComponents = asyncComponent(() => import('../tabcomponents')) |
| | | const GroupComponents = asyncComponent(() => import('../groupcomponents')) |
| | | |
| | | class NormalGroup extends Component { |
| | | static propTpyes = { |
| | | group: PropTypes.object, |
| | | deletecomponent: PropTypes.func, |
| | | unGroup: PropTypes.func, |
| | | updateConfig: PropTypes.func, |
| | | } |
| | | |
| | | state = { |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | group: null, |
| | | editab: null, |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { group } = this.props |
| | | console.log(group) |
| | | |
| | | if (group.isNew) { |
| | | let _group = { |
| | | uuid: group.uuid, |
| | | type: group.type, |
| | | floor: group.floor, |
| | | tabId: group.tabId || '', |
| | | parentId: group.parentId || '', |
| | | subtype: group.subtype, |
| | | width: 24, |
| | | name: group.name, |
| | |
| | | return !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('tabsChange', this.handleTabsChange) |
| | | MKEmitter.addListener('submitStyle', this.getStyle) |
| | | } |
| | | |
| | | /** |
| | | * @description 组件销毁,清除state更新,清除快捷键设置 |
| | | */ |
| | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | MKEmitter.removeListener('tabsChange', this.handleTabsChange) |
| | | MKEmitter.addListener('submitStyle', this.getStyle) |
| | | } |
| | | |
| | | changeStyle = () => { |
| | | const { group } = this.state |
| | | |
| | | MKEmitter.emit('changeStyle', [group.uuid], ['background', 'border', 'padding', 'margin'], group.style) |
| | | MKEmitter.emit('changeStyle', ['background', 'border', 'padding', 'margin', 'shadow', 'clear', 'minHeight'], group.style, this.getStyle) |
| | | } |
| | | |
| | | getStyle = (comIds, style) => { |
| | | const { group } = this.state |
| | | |
| | | if (comIds.length !== 1 || comIds[0] !== group.uuid) return |
| | | |
| | | let _card = {...group, style} |
| | | getStyle = (style) => { |
| | | let _card = {...this.state.group, style} |
| | | |
| | | this.setState({ |
| | | group: _card |
| | |
| | | this.props.updateConfig(_card) |
| | | } |
| | | |
| | | handleTabsChange = (parentId) => { |
| | | const { group } = this.state |
| | | |
| | | if (parentId === group.parentId) { |
| | | MKEmitter.emit('tabsChange', group.uuid) |
| | | } |
| | | } |
| | | |
| | | updateComponent = (component) => { |
| | | const { group } = this.state |
| | | |
| | | if (!is(fromJS(group.setting), fromJS(component.setting))) { |
| | | // 注册事件-标签变化,通知标签内元素 |
| | | MKEmitter.emit('tabsChange', group.uuid) |
| | | if (!is(fromJS(group.setting), fromJS(component.setting)) || !is(fromJS(group.style), fromJS(component.style))) { |
| | | // 注册事件-标签变化,通知组内元素 |
| | | let ids = [] |
| | | group.components.forEach(item => { |
| | | ids.push(item.uuid) |
| | | }) |
| | | MKEmitter.emit('tabsChange', ids.join(',')) |
| | | } |
| | | |
| | | component.width = component.setting.width |
| | |
| | | this.props.updateConfig(component) |
| | | } |
| | | |
| | | insert = (item, cell) => { |
| | | insert = (item) => { |
| | | let group = fromJS(this.state.group).toJS() |
| | | |
| | | group.components.forEach(stab => { |
| | | if (stab.uuid === cell.uuid) { |
| | | stab.components.push(item) |
| | | } |
| | | }) |
| | | group.components.push(item) |
| | | |
| | | this.setState({group}) |
| | | this.props.updateConfig(group) |
| | | } |
| | | |
| | | render() { |
| | | getWrapForms = () => { |
| | | const { setting } = this.state.group |
| | | |
| | | return getSettingForm(setting) |
| | | } |
| | | |
| | | updateWrap = (res) => { |
| | | let group = {...this.state.group, setting: res} |
| | | |
| | | if (res.title && !group.headerStyle) { |
| | | group.headerStyle = { fontSize: '16px', borderBottomWidth: '1px', borderBottomColor: '#e8e8e8' } |
| | | } |
| | | |
| | | this.updateComponent(group) |
| | | } |
| | | |
| | | unGroup = () => { |
| | | const { group } = this.state |
| | | |
| | | if (group.components.length === 0) return |
| | | |
| | | const that = this |
| | | confirm({ |
| | | title: '确定释放分组元素吗?', |
| | | content: '', |
| | | onOk() { |
| | | that.props.unGroup(group.uuid) |
| | | |
| | | setTimeout(() => { |
| | | that.updataGroup() |
| | | }, 10) |
| | | }, |
| | | onCancel() {} |
| | | }) |
| | | } |
| | | |
| | | updataGroup = () => { |
| | | const { group } = this.props |
| | | |
| | | if (group.components.length === 0) { |
| | | this.setState({ |
| | | group: fromJS(group).toJS() |
| | | }) |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { group } = this.state |
| | | let _style = resetStyle(group.style) |
| | | |
| | | let paddingTop = true |
| | | if (group.style.paddingTop && parseInt(group.style.paddingTop) >= 28) { |
| | | paddingTop = false |
| | | } |
| | | |
| | | return ( |
| | | <div className="menu-group-edit-box" style={group.style}> |
| | | <div className={'menu-group-edit-box ' + (paddingTop ? 'padding ' : '') + (group.setting.layout || '')} style={_style} id={group.uuid}> |
| | | <NormalHeader hideSearch="true" config={group} updateComponent={this.updateComponent}/> |
| | | <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <SettingComponent config={group} updateConfig={this.updateComponent} /> |
| | | <CopyComponent type="tabs" card={group}/> |
| | | <PasteController type="tab" Tab={group} insert={this.insert} /> |
| | | <Icon className="style" title="调整样式" onClick={this.changeStyle} type="font-colors" /> |
| | | <Icon className="close" title="delete" type="delete" onClick={() => this.props.deletecomponent(group.uuid)} /> |
| | | <NormalForm title="分组设置" width={700} update={this.updateWrap} getForms={this.getWrapForms}> |
| | | <EditOutlined style={{color: '#1890ff'}} title="编辑"/> |
| | | </NormalForm> |
| | | <CopyComponent type="group" card={group}/> |
| | | <UngroupOutlined title="释放" style={group.components.length > 0 ? {color: '#32c5d2'} : {color: '#eeeeee', cursor: 'not-allowed'}} onClick={this.unGroup}/> |
| | | <PasteController type="group" tab={group} insert={this.insert} /> |
| | | <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/> |
| | | <DeleteOutlined className="close" title="delete" onClick={() => this.props.deletecomponent(group.uuid)} /> |
| | | </div> |
| | | } trigger="hover"> |
| | | <Icon type="tool" /> |
| | | <ToolOutlined /> |
| | | </Popover> |
| | | <TabComponents config={group} handleList={this.updateComponent} deleteCard={this.deleteCard} /> |
| | | |
| | | <GroupComponents config={group} handleList={this.updateComponent} deleteCard={this.deleteCard} /> |
| | | </div> |
| | | ) |
| | | } |
| | | } |
| | | |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | menu: state.customMenu |
| | | } |
| | | } |
| | | |
| | | const mapDispatchToProps = () => { |
| | | return {} |
| | | } |
| | | |
| | | export default connect(mapStateToProps, mapDispatchToProps)(NormalGroup) |
| | | export default NormalGroup |