From 72419e2f826031a158173f46d723a672064e37cd Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 31 八月 2021 22:42:51 +0800 Subject: [PATCH] 2021-08-31 --- src/tabviews/zshare/actionList/tabbutton/index.jsx | 189 +++++++++++++++++++++++++++++++--------------- 1 files changed, 127 insertions(+), 62 deletions(-) diff --git a/src/tabviews/zshare/actionList/tabbutton/index.jsx b/src/tabviews/zshare/actionList/tabbutton/index.jsx index ccd4e50..db9b04b 100644 --- a/src/tabviews/zshare/actionList/tabbutton/index.jsx +++ b/src/tabviews/zshare/actionList/tabbutton/index.jsx @@ -2,54 +2,91 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { Button, notification } from 'antd' +import { Button, notification, Icon } 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' class TabButton extends Component { static propTpyes = { show: PropTypes.any, // 鎸夐挳鏄剧ず鏍峰紡鎺у埗 + position: PropTypes.any, // 鎸夐挳浣嶇疆锛屽伐鍏锋爮涓簍oolbar MenuID: PropTypes.string, // 鑿滃崟ID btn: PropTypes.object, // 鎸夐挳 selectedData: PropTypes.any, // 瀛愯〃涓�夋嫨鏁版嵁 setting: PropTypes.any, // 椤甸潰閫氱敤璁剧疆 - triggerBtn: PropTypes.any, - updateStatus: PropTypes.any } state = { dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, + disabled: false, primaryId: '' } - /** - * @description 澶栭儴瑙﹀彂鎸夐挳鐐瑰嚮 - */ - UNSAFE_componentWillReceiveProps(nextProps) { - if (nextProps.triggerBtn && !is(fromJS(this.props.triggerBtn), fromJS(nextProps.triggerBtn)) && nextProps.triggerBtn.button.uuid === this.props.btn.uuid) { - this.actionTrigger(nextProps.triggerBtn.data) + UNSAFE_componentWillMount () { + const { btn, selectedData } = this.props + let disabled = false + + if (btn.controlField && selectedData && selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒� + selectedData.forEach(item => { + let s = item[btn.controlField] + '' + if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { + disabled = true + } + }) + this.setState({disabled}) } } shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) } + + componentDidMount () { + const { position } = this.props + + if (position === 'toolbar') { + MKEmitter.addListener('triggerBtnId', this.actionTrigger) + } + } + + UNSAFE_componentWillReceiveProps (nextProps) { + const { btn, selectedData } = this.props + + 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] + '' + if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { + disabled = true + } + }) + } + this.setState({disabled}) + } + } + + componentWillUnmount () { + this.setState = () => { + return + } + MKEmitter.removeListener('triggerBtnId', this.actionTrigger) + } /** * @description 瑙﹀彂鎸夐挳鎿嶄綔 */ - actionTrigger = (record) => { + actionTrigger = (triggerId, record) => { const { setting, btn, tabviews, MenuID, selectedData } = this.props - let data = [] - if (record) { // 琛ㄦ牸涓Е鍙戞寜閽� - data = [record] - } else { - data = selectedData || [] - } + if (triggerId && btn.uuid !== triggerId) return + + let data = record || selectedData || [] if (btn.Ot === 'requiredSgl' && data.length !== 1) { // 闇�瑕侀�夋嫨鍗曡鏃讹紝鏍¢獙鏁版嵁 @@ -59,22 +96,12 @@ duration: 5 }) return - } else if (!setting.primaryKey) { - // 闇�瑕侀�夋嫨琛屾椂锛屾牎楠屾槸鍚﹁缃富閿� - notification.warning({ - top: 92, - message: '鏈缃富閿紒', - duration: 5 - }) - return } let primaryId = '' - let _data = null - if (btn.Ot === 'requiredSgl') { + if (btn.Ot === 'requiredSgl' && setting.primaryKey) { primaryId = data[0][setting.primaryKey] || '' - _data = data[0] } let newtab = {} @@ -94,75 +121,113 @@ } } } else if (btn.tabTemplate === 'ThdMenu') { - let _type = 'CommonTable' - if (btn.linkThdMenu && btn.linkThdMenu.PageParam) { - try { - _type = JSON.parse(btn.linkThdMenu.PageParam).Template - } catch { - _type = 'CommonTable' - } + let menu = null + + 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) { + notification.warning({ + top: 92, + message: '鑿滃崟宸插垹闄ゆ垨娌℃湁璁块棶鏉冮檺锛�', + duration: 5 + }) + return } newtab = { - MenuNo: btn.linkThdMenu.MenuNo, - MenuID: btn.linkThdMenu.MenuID, - MenuName: btn.linkThdMenu.MenuName, - type: _type, + ...menu, selected: true, param: { - BID: primaryId, - data: _data + $BID: primaryId } } } let index = 0 - let isexit = false - let tabs = tabviews.map((tab, i) => { + let tabs = tabviews.filter((tab, i) => { tab.selected = false if (tab.MenuID === MenuID) { index = i - } else if (tab.MenuID === btn.uuid) { - tab.selected = true - isexit = true } - return tab + return tab.MenuID !== newtab.MenuID }) - if (!isexit) { - tabs.splice(index + 1, 0, newtab) + if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) { + this.props.modifyTabview([newtab]) + } 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) + }) } - if (this.props.updateStatus) { - this.props.updateStatus('trigger') + MKEmitter.emit('openNewTab') + if (window.GLOB.systemType === 'production') { + MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '鏍囩椤�'}) } - - this.props.modifyTabview(tabs) } render() { const { btn, show } = this.props + const { disabled } = this.state - return ( - <div className="mk-btn-wrap"> - {!show ? <Button + if (show === 'actionList') { + return ( + <Button className={'mk-btn mk-' + btn.class} icon={btn.icon} - onClick={() => {this.actionTrigger()}} - >{btn.label}</Button> : null} - {show === 'icon' ? <Button className="action-cell" icon={btn.icon || 'dash'} onClick={() => {this.actionTrigger()}}></Button> : null} - {show === 'text' ? <Button className="action-cell" onClick={() => {this.actionTrigger()}}>{btn.label}</Button> : null} - {show === 'all' ? <Button className="action-cell" icon={btn.icon || ''} onClick={() => {this.actionTrigger()}}>{btn.label}</Button> : null} - </div> - ) + disabled={disabled} + onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} + >{btn.label}</Button> + ) + } else { // icon銆乼ext銆� all 鍗$墖 + let label = '' + let icon = '' + + if (show === 'button') { + label = btn.label + icon = btn.icon || '' + } else if (show === 'link') { + label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> + icon = '' + } else if (show === 'icon') { + icon = btn.icon || '' + // } else if (show === 'text') { + } else { + label = btn.label + } + + return ( + <Button + type="link" + title={show === 'icon' ? btn.label : ''} + style={btn.style} + disabled={disabled} + icon={icon} + onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} + >{label}</Button> + ) + } } } const mapStateToProps = (state) => { return { tabviews: state.tabviews, + permMenus: state.permMenus, } } -- Gitblit v1.8.0