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 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 './index.scss'
|
|
const SettingComponent = asyncIconComponent(() => import('../tabsetting'))
|
const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
|
const PasteController = asyncIconComponent(() => import('@/menu/pastecontroller'))
|
const TabComponents = asyncComponent(() => import('../tabcomponents'))
|
|
class NormalGroup extends Component {
|
static propTpyes = {
|
group: PropTypes.object,
|
deletecomponent: PropTypes.func,
|
updateConfig: PropTypes.func,
|
}
|
|
state = {
|
dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
group: null,
|
editab: null,
|
}
|
|
UNSAFE_componentWillMount () {
|
const { group } = this.props
|
|
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,
|
setting: { width: 24, name: group.name },
|
style: { marginLeft: '8px', marginRight: '8px', marginTop: '8px', marginBottom: '8px' },
|
components: []
|
}
|
this.setState({
|
group: _group
|
})
|
this.props.updateConfig(_group)
|
} else {
|
this.setState({
|
group: fromJS(group).toJS()
|
})
|
}
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('tabsChange', this.handleTabsChange)
|
MKEmitter.addListener('submitStyle', this.getStyle)
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
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)
|
}
|
|
getStyle = (comIds, style) => {
|
const { group } = this.state
|
|
if (comIds.length !== 1 || comIds[0] !== group.uuid) return
|
|
let _card = {...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)
|
}
|
|
component.width = component.setting.width
|
component.name = component.setting.name
|
|
this.setState({
|
group: component
|
})
|
this.props.updateConfig(component)
|
}
|
|
insert = (item, cell) => {
|
let group = fromJS(this.state.group).toJS()
|
|
group.components.push(item)
|
|
this.setState({group})
|
this.props.updateConfig(group)
|
}
|
|
render() {
|
const { group } = this.state
|
|
return (
|
<div className="menu-group-edit-box" style={group.style}>
|
<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)} />
|
</div>
|
} trigger="hover">
|
<Icon type="tool" />
|
</Popover>
|
<TabComponents 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)
|