From 326aa6b3effaccc71cfe0775d47b0f29eb3695a6 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 25 八月 2024 00:36:40 +0800 Subject: [PATCH] 2024-08-25 --- src/menu/components/group/normal-group/index.jsx | 152 +++++++++++++++++++++++++++++--------------------- 1 files changed, 88 insertions(+), 64 deletions(-) diff --git a/src/menu/components/group/normal-group/index.jsx b/src/menu/components/group/normal-group/index.jsx index 0d19e48..aa41f27 100644 --- a/src/menu/components/group/normal-group/index.jsx +++ b/src/menu/components/group/normal-group/index.jsx @@ -1,45 +1,43 @@ 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, @@ -62,11 +60,6 @@ return !is(fromJS(this.state), fromJS(nextState)) } - componentDidMount () { - MKEmitter.addListener('tabsChange', this.handleTabsChange) - MKEmitter.addListener('submitStyle', this.getStyle) - } - /** * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆 */ @@ -74,22 +67,16 @@ 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 @@ -98,20 +85,16 @@ 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 @@ -123,50 +106,91 @@ 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) \ No newline at end of file +export default NormalGroup \ No newline at end of file -- Gitblit v1.8.0