From 9c6795fd3c44e46cf3955fbfd8f8eeca23acb7a9 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 08 十月 2022 00:31:51 +0800 Subject: [PATCH] 2022-10-08 --- src/tabviews/zshare/actionList/tabbutton/index.jsx | 207 ++++++++++++++++++++++++++------------------------- 1 files changed, 104 insertions(+), 103 deletions(-) diff --git a/src/tabviews/zshare/actionList/tabbutton/index.jsx b/src/tabviews/zshare/actionList/tabbutton/index.jsx index f7f654e..6158165 100644 --- a/src/tabviews/zshare/actionList/tabbutton/index.jsx +++ b/src/tabviews/zshare/actionList/tabbutton/index.jsx @@ -1,43 +1,58 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { Button, notification, Icon } from 'antd' +import { Button, notification } from 'antd' -import { modifyTabview } from '@/store/action' import zhCN from '@/locales/zh-CN/main.js' import enUS from '@/locales/en-US/main.js' import MKEmitter from '@/utils/events.js' -import './index.scss' +import MkIcon from '@/components/mk-icon' +// import './index.scss' class TabButton extends Component { static propTpyes = { - show: PropTypes.any, // 鎸夐挳鏄剧ず鏍峰紡鎺у埗 - position: PropTypes.any, // 鎸夐挳浣嶇疆锛屽伐鍏锋爮涓簍oolbar + BData: PropTypes.any, // 涓昏〃鏁版嵁 MenuID: PropTypes.string, // 鑿滃崟ID btn: PropTypes.object, // 鎸夐挳 selectedData: PropTypes.any, // 瀛愯〃涓�夋嫨鏁版嵁 setting: PropTypes.any, // 椤甸潰閫氱敤璁剧疆 + disabled: PropTypes.any, // 琛屾寜閽鐢� } state = { dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, disabled: false, + hidden: false, primaryId: '' } UNSAFE_componentWillMount () { - const { btn, selectedData } = this.props + const { btn, selectedData, BData } = this.props let disabled = false if (btn.controlField && selectedData && selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒� selectedData.forEach(item => { - let s = item[btn.controlField] + '' + let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { disabled = true } }) - this.setState({disabled}) + this.setState({hidden: disabled && btn.control === 'hidden'}) + } else if (btn.control === 'parent') { + if (!BData || !BData.hasOwnProperty(btn.controlField)) { + this.setState({hidden: true}) + } else { + let s = BData[btn.controlField] + '' + if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { + this.setState({hidden: true}) + } else { + this.setState({hidden: false}) + } + } + } + + if (this.props.disabled || disabled) { + this.setState({disabled: true}) } } @@ -46,28 +61,40 @@ } componentDidMount () { - const { position } = this.props - - if (position === 'toolbar') { - MKEmitter.addListener('triggerBtnId', this.actionTrigger) - } + MKEmitter.addListener('triggerBtnId', this.actionTrigger) } UNSAFE_componentWillReceiveProps (nextProps) { - const { btn, selectedData } = this.props + const { btn, selectedData, BData } = this.props + let disabled = false if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) { - let disabled = false - if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒� nextProps.selectedData.forEach(item => { - let s = item[btn.controlField] + '' + let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { disabled = true } }) } - this.setState({disabled}) + this.setState({hidden: disabled && btn.control === 'hidden'}) + } else if (btn.control === 'parent' && !is(fromJS(nextProps.BData || {}), fromJS(BData || {}))) { + if (!nextProps.BData || !nextProps.BData.hasOwnProperty(btn.controlField)) { + this.setState({hidden: true}) + } else { + let s = nextProps.BData[btn.controlField] + '' + if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { + this.setState({hidden: true}) + } else { + this.setState({hidden: false}) + } + } + } + + if (nextProps.disabled || disabled) { + this.setState({disabled: true}) + } else { + this.setState({disabled: false}) } } @@ -81,10 +108,16 @@ /** * @description 瑙﹀彂鎸夐挳鎿嶄綔 */ - actionTrigger = (triggerId, record) => { - const { setting, btn, tabviews, MenuID, selectedData } = this.props + actionTrigger = (triggerId, record, type) => { + const { setting, btn, selectedData } = this.props + const { disabled } = this.state + if (disabled) return if (triggerId && btn.uuid !== triggerId) return + + if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) { + return + } let data = record || selectedData || [] @@ -112,7 +145,6 @@ MenuID: btn.uuid, MenuName: btn.label, type: btn.tabTemplate, - selected: true, param: { parentId: this.props.MenuID, btn: btn, @@ -120,12 +152,17 @@ primaryId: primaryId } } - } else if (btn.tabTemplate === 'ThdMenu') { - let menu = null + } else if (btn.MenuID || btn.linkmenu) { + let menuId = btn.MenuID || btn.linkmenu.slice(-1)[0] + let menu = window.GLOB.mkThdMenus.filter(m => m.MenuID === menuId)[0] - if (btn.linkmenu && btn.linkmenu.length > 0) { - let menu_id = btn.linkmenu.slice(-1)[0] - menu = this.props.permMenus.filter(m => m.MenuID === menu_id)[0] || '' + if (!menu && btn.MenuName && btn.tabType) { + menu = { + MenuID: btn.MenuID, + MenuName: btn.MenuName, + MenuNo: btn.MenuNo, + type: btn.tabType + } } if (!menu) { @@ -139,39 +176,16 @@ newtab = { ...menu, - selected: true, param: { $BID: primaryId } } } - let index = 0 - let tabs = tabviews.filter((tab, i) => { - tab.selected = false - - if (tab.MenuID === MenuID) { - index = i - } - - return tab.MenuID !== newtab.MenuID - }) - - if (['linkage_navigation', 'linkage'].includes(window.GLOB.navBar)) { - this.props.modifyTabview([newtab]) + if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) { + MKEmitter.emit('modifyTabs', newtab, 'replace') } else { - if (tabviews.length !== tabs.length) { - this.props.modifyTabview(fromJS(tabs).toJS()) - } - - this.setState({}, () => { - if (MenuID) { - tabs.splice(index + 1, 0, newtab) - } else { - tabs.push(newtab) - } - this.props.modifyTabview(tabs) - }) + MKEmitter.emit('modifyTabs', newtab, 'plus', true) } MKEmitter.emit('openNewTab') @@ -181,60 +195,47 @@ } render() { - const { btn, show } = this.props - const { disabled } = this.state + const { btn } = this.props + const { disabled, hidden } = this.state - if (show === 'actionList') { - return ( - <Button - className={'mk-btn mk-' + btn.class} - icon={btn.icon} - disabled={disabled} - onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} - >{btn.label}</Button> - ) - } else { // icon銆乼ext銆� all 鍗$墖 - let label = '' - let icon = '' + if (hidden) return null - if (show === 'button') { - label = btn.label - icon = btn.icon || '' - } else if (show === 'link') { - label = <span>{btn.label}{btn.icon ? <Icon type={btn.icon}/> : ''}</span> - icon = '' - } else if (show === 'icon') { - icon = btn.icon || '' - // } else if (show === 'text') { - } else { - label = btn.label - } + let label = '' + let icon = '' + let type = 'link' + let className = '' - return ( - <Button - type="link" - title={show === 'icon' ? btn.label : ''} - style={btn.style} - disabled={disabled} - icon={icon} - onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} - >{label}</Button> - ) + if (btn.show === 'button') { + label = btn.label + icon = btn.icon || '' + } else if (btn.show === 'link') { + label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> + icon = '' + } else if (btn.show === 'icon') { + icon = btn.icon || '' + } else if (!btn.$toolbtn) { + icon = btn.icon || '' + label = btn.label + className = 'mk-btn mk-' + btn.class + } else { + type = '' + icon = btn.icon || '' + label = btn.label + className = 'mk-btn mk-' + btn.class } + + return ( + <Button + type={type} + title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')} + style={btn.style || null} + disabled={disabled} + icon={icon} + className={className} + onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} + >{label}</Button> + ) } } -const mapStateToProps = (state) => { - return { - tabviews: state.tabviews, - permMenus: state.permMenus, - } -} - -const mapDispatchToProps = (dispatch) => { - return { - modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)) - } -} - -export default connect(mapStateToProps, mapDispatchToProps)(TabButton) \ No newline at end of file +export default TabButton \ No newline at end of file -- Gitblit v1.8.0