From ab60d53b67f802878662aaa5a5b52580cca421b8 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 26 九月 2020 08:52:46 +0800 Subject: [PATCH] 2020-09-26 --- src/menu/actioncomponent/index.jsx | 118 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 85 insertions(+), 33 deletions(-) diff --git a/src/menu/actioncomponent/index.jsx b/src/menu/actioncomponent/index.jsx index c95adb2..ea88b06 100644 --- a/src/menu/actioncomponent/index.jsx +++ b/src/menu/actioncomponent/index.jsx @@ -13,6 +13,7 @@ import enUS from '@/locales/en-US/model.js' import { getActionForm } from './formconfig' +import MKEmitter from '@/utils/events.js' import ActionForm from './actionform' import VerifyCard from '@/templates/zshare/verifycard' import CreateFunc from '@/templates/zshare/createfunc' @@ -27,6 +28,7 @@ class ActionComponent extends Component { static propTpyes = { type: PropTypes.string, // 鑿滃崟绫诲瀷锛屼富琛ㄦ垨瀛愯〃 + plus: PropTypes.any, // 鏄惁瀛樺湪娣诲姞鎸夐挳锛屽�间负false鏃堕殣钘� config: PropTypes.object, // 鑿滃崟閰嶇疆淇℃伅 setSubConfig: PropTypes.func, // 璁剧疆瀛愰厤缃俊鎭� updateaction: PropTypes.func // 鑿滃崟閰嶇疆鏇存柊 @@ -51,6 +53,10 @@ }) } + componentDidMount () { + MKEmitter.addListener('addButton', this.addButton) + } + /** * @description 鐩戝惉鍒版寜閽鍒舵椂锛岃Е鍙戞寜閽紪杈� */ @@ -60,6 +66,29 @@ if (!is(fromJS(nextProps.config.action), fromJS(this.props.config.action)) && !is(fromJS(nextProps.config.action), fromJS(actionlist))) { this.setState({actionlist: fromJS(nextProps.config.action).toJS()}) } + } + + shouldComponentUpdate (nextProps, nextState) { + return !is(fromJS(this.props.config), fromJS(nextProps.config)) || !is(fromJS(this.state), fromJS(nextState)) + } + + /** + * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆 + */ + componentWillUnmount () { + this.setState = () => { + return + } + MKEmitter.removeListener('addButton', this.addButton) + } + + addButton = (cardId, element) => { + if (cardId !== this.props.config.uuid) return + + const { actionlist } = this.state + + this.setState({actionlist: [...actionlist, element]}) + this.handleAction(element) } /** @@ -76,6 +105,57 @@ this.props.updateaction({...config, action: list}) }) } + } + + getModules = (components, selfId) => { + let modules = components.map(item => { + if (item.uuid === selfId) { + return { + children: null + } + } else if (item.format) { + return { + value: item.uuid, + label: item.name + } + } else if (item.type === 'tabs') { + let _item = { + value: item.uuid, + label: item.name, + children: item.subtabs.map(f_tab => { + let subItem = { + value: f_tab.uuid, + label: f_tab.label, + children: this.getModules(f_tab.components, selfId) + } + + if (!subItem.children || subItem.children.length === 0) { + return {children: null} + } + return subItem + }) + } + + _item.children = _item.children.filter(t => t.children !== null) + + if (_item.children.length === 0) { + return {children: null} + } + + return _item + } else { + return { + children: null + } + } + }) + + modules = modules.filter(mod => mod.children !== null) + + if (modules.length === 0) { + return null + } + return modules } /** @@ -101,22 +181,7 @@ }) } - // let modules = [] - - // menu.components.forEach(item => { - // if (item.uuid === config.uuid) return - - // modules.push({ - // value: item.uuid, - // text: item.setting.name - // }) - // }) - - // if (supModule && supModule !== 'empty') { - // if (modules.filter(item => item.value === supModule).length === 0) { - // supModule = '' - // } - // } + let modules = this.getModules(menu.components, config.uuid) if (menu.fstMenuList && card.linkmenu && card.linkmenu.length > 0) { let _param = { @@ -165,14 +230,14 @@ this.setState({ visible: true, card: card, - formlist: getActionForm(card, functip, config.setting, menu.permFuncField, this.props.type, menulist) + formlist: getActionForm(card, functip, config.setting, menu.permFuncField, this.props.type, menulist, modules) }) }) } else { this.setState({ visible: true, card: card, - formlist: getActionForm(card, functip, config.setting, menu.permFuncField, this.props.type, menulist) + formlist: getActionForm(card, functip, config.setting, menu.permFuncField, this.props.type, menulist, modules) }) } } @@ -875,27 +940,14 @@ } } - shouldComponentUpdate (nextProps, nextState) { - return !is(fromJS(this.props.config), fromJS(nextProps.config)) || !is(fromJS(this.state), fromJS(nextState)) - } - - /** - * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊 - */ - componentWillUnmount () { - this.setState = () => { - return - } - } - render() { - const { config, type } = this.props + const { config, plus } = this.props const { actionlist, visible, card, dict, copying, profVisible } = this.state return ( <div className="model-menu-action-list"> <DragElement - type={type} + plus={plus} list={actionlist} handleList={this.handleList} handleMenu={this.handleAction} -- Gitblit v1.8.0