| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Icon, Card, Dropdown, Menu, Spin, Empty, Tabs } from 'antd' |
| | | import { Icon, Card, Spin, Empty, Tabs } from 'antd' |
| | | |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import './index.scss' |
| | | |
| | | const NormalButton = asyncComponent(() => import('@/tabviews/zshare/actionList/normalbutton')) |
| | | const PopupButton = asyncComponent(() => import('@/tabviews/zshare/actionList/popupbutton')) |
| | | const TabButton = asyncComponent(() => import('@/tabviews/zshare/actionList/tabbutton')) |
| | | const NewPageButton = asyncComponent(() => import('@/tabviews/zshare/actionList/newpagebutton')) |
| | | const ChangeUserButton = asyncComponent(() => import('@/tabviews/zshare/actionList/changeuserbutton')) |
| | | const PrintButton = asyncComponent(() => import('@/tabviews/zshare/actionList/printbutton')) |
| | | |
| | | const { TabPane } = Tabs |
| | | |
| | | class CardCell extends Component { |
| | | static propTpyes = { |
| | | card: PropTypes.object, |
| | | data: PropTypes.object, |
| | | selectKey: PropTypes.string, |
| | | colMap: PropTypes.any, |
| | | triggerBtn: PropTypes.func, |
| | | switchCard: PropTypes.func |
| | | BID: PropTypes.any, // 主表ID |
| | | BData: PropTypes.any, // 主表数据 |
| | | Tab: PropTypes.any, // 如果当前元素为标签时,tab为标签信息 |
| | | MenuID: PropTypes.string, // 菜单ID |
| | | setting: PropTypes.object, // 页面设定 |
| | | logcolumns: PropTypes.array, // 字段列 |
| | | card: PropTypes.object, // 卡片设置信息 |
| | | data: PropTypes.object, // 卡片数据 |
| | | selectKey: PropTypes.string, // 选择卡片的序号 |
| | | colMap: PropTypes.any, // 显示列信息,用于设置标记 |
| | | refreshdata: PropTypes.func, // 按钮操作后数据刷新 |
| | | switchCard: PropTypes.func // 卡片切换 |
| | | } |
| | | |
| | | state = { |
| | | card: null, |
| | | extra: null, |
| | | actions: null |
| | | extra: null, // 顶部按钮信息 |
| | | actions: null // 底部按钮行 |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | this.getCardActions() |
| | | } |
| | | |
| | | /** |
| | | * @description 数据切换,重新绑定按钮数据 |
| | | */ |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (!is(fromJS(this.props.data), fromJS(nextProps.data))) { |
| | | this.setState({}, () => { |
| | | this.getCardActions() |
| | | }) |
| | | } |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | | return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | /** |
| | | * @description 获取顶部及按钮行的按钮集 |
| | | */ |
| | | getCardActions = () => { |
| | | const { card } = this.props |
| | | |
| | | let extra = null |
| | | if (card.header && card.header.actions) { |
| | | let actions = card.header.actions.map(item => { |
| | | let _action = null |
| | | if (card.header.show === 'icon') { |
| | | _action = <span className="action-cell" onClick={() => this.triggerAction(item)} key={item.uuid}><Icon type={item.icon || 'dash'} /></span> |
| | | } else if (card.bottom.show === 'text') { |
| | | _action = <span className="action-cell" onClick={() => this.triggerAction(item)} key={item.uuid}>{item.label}</span> |
| | | } else { |
| | | _action = <span className="action-cell" onClick={() => this.triggerAction(item)} key={item.uuid}><Icon type={item.icon || 'dash'} /> {item.label}</span> |
| | | } |
| | | |
| | | return _action |
| | | }) |
| | | if (actions.length === 1) { |
| | | extra = actions[0] |
| | | } else { |
| | | extra = <Dropdown overlay={ |
| | | <Menu>{actions.map((item, i) => <Menu.Item key={i}> {item} </Menu.Item>)}</Menu> |
| | | } placement="bottomRight"> |
| | | Action |
| | | </Dropdown> |
| | | } |
| | | let actions = this.getActionList(card.header.actions, card.header.show) |
| | | extra = actions[0] |
| | | } |
| | | |
| | | let _actions = null |
| | | if (card.bottom && card.bottom.actions) { |
| | | _actions = card.bottom.actions.map(item => { |
| | | let _action = null |
| | | if (card.bottom.show === 'icon') { |
| | | _action = <span className="action-cell" onClick={() => this.triggerAction(item)} key={item.uuid}><Icon type={item.icon || 'dash'} /></span> |
| | | } else if (card.bottom.show === 'text') { |
| | | _action = <span className="action-cell" onClick={() => this.triggerAction(item)} key={item.uuid}>{item.label}</span> |
| | | } else { |
| | | _action = <span className="action-cell" onClick={() => this.triggerAction(item)} key={item.uuid}><Icon type={item.icon || 'dash'} /> {item.label}</span> |
| | | } |
| | | |
| | | return _action |
| | | }) |
| | | _actions = this.getActionList(card.bottom.actions, card.bottom.show) |
| | | } |
| | | |
| | | this.setState({ |
| | |
| | | extra: extra |
| | | }) |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | | return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | |
| | | /** |
| | | * @description 获取按钮元素 |
| | | */ |
| | | getActionList = (actions, show) => { |
| | | const { BID, BData, Tab, setting, logcolumns, ContainerId, data, MenuID } = this.props |
| | | |
| | | return actions.map(item => { |
| | | if (['exec', 'prompt', 'pop'].includes(item.OpenType)) { |
| | | return ( |
| | | <NormalButton |
| | | key={item.uuid} |
| | | BID={BID} |
| | | Tab={Tab} |
| | | btn={item} |
| | | show={show} |
| | | BData={BData} |
| | | setting={setting} |
| | | columns={logcolumns} |
| | | selectedData={[data]} |
| | | ContainerId={ContainerId} |
| | | updateStatus={this.updateStatus} |
| | | /> |
| | | ) |
| | | } else if (item.OpenType === 'popview') { |
| | | return ( |
| | | <PopupButton |
| | | key={item.uuid} |
| | | BID={BID} |
| | | Tab={Tab} |
| | | btn={item} |
| | | show={show} |
| | | BData={BData} |
| | | setting={setting} |
| | | selectedData={[data]} |
| | | updateStatus={this.updateStatus} |
| | | /> |
| | | ) |
| | | } else if (item.OpenType === 'tab' || item.OpenType === 'blank') { |
| | | return ( |
| | | <TabButton |
| | | key={item.uuid} |
| | | btn={item} |
| | | show={show} |
| | | MenuID={MenuID} |
| | | setting={setting} |
| | | selectedData={[data]} |
| | | updateStatus={this.updateStatus} |
| | | /> |
| | | ) |
| | | } else if (item.OpenType === 'innerpage' || item.OpenType === 'outerpage') { |
| | | return ( |
| | | <NewPageButton |
| | | key={item.uuid} |
| | | btn={item} |
| | | show={show} |
| | | setting={setting} |
| | | selectedData={[data]} |
| | | /> |
| | | ) |
| | | } else if (item.OpenType === 'funcbutton') { |
| | | if (item.funcType === 'changeuser') { |
| | | return ( |
| | | <ChangeUserButton |
| | | key={item.uuid} |
| | | BID={BID} |
| | | btn={item} |
| | | show={show} |
| | | setting={setting} |
| | | selectedData={[data]} |
| | | updateStatus={this.updateStatus} |
| | | /> |
| | | ) |
| | | } else if (item.funcType === 'print') { |
| | | return ( |
| | | <PrintButton |
| | | key={item.uuid} |
| | | BID={BID} |
| | | Tab={Tab} |
| | | btn={item} |
| | | show={show} |
| | | BData={BData} |
| | | setting={setting} |
| | | selectedData={[data]} |
| | | ContainerId={ContainerId} |
| | | updateStatus={this.updateStatus} |
| | | /> |
| | | ) |
| | | } |
| | | } |
| | | |
| | | return null |
| | | }) |
| | | } |
| | | |
| | | triggerAction = (btn) => { |
| | | this.props.triggerBtn(btn, [this.props.data]) |
| | | /** |
| | | * @description 操作完成后,数据刷新 |
| | | */ |
| | | updateStatus = (type, positon) => { |
| | | if (type === 'refresh') { |
| | | this.props.refreshdata(positon) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 卡片中元素标记设置 |
| | | */ |
| | | getMark = (record, marks) => { |
| | | const { colMap } = this.props |
| | | let className = '' |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 获取卡片内容 |
| | | */ |
| | | getContent = (col) => { |
| | | const { data } = this.props |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 获取卡片中图片或图标设置 |
| | | */ |
| | | getAvatar = () => { |
| | | const { card, data } = this.props |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 卡片点击切换事件 |
| | | */ |
| | | switchCard = () => { |
| | | const { card, data } = this.props |
| | | |
| | |
| | | |
| | | class CardChart extends Component { |
| | | static propTpyes = { |
| | | BID: PropTypes.any, // 主表ID |
| | | BData: PropTypes.any, // 主表数据 |
| | | Tab: PropTypes.any, // 如果当前元素为标签时,tab为标签信息 |
| | | MenuID: PropTypes.string, // 菜单ID |
| | | config: PropTypes.object, // 页面配置信息 |
| | | logcolumns: PropTypes.array, // 显示列 |
| | | ContainerId: PropTypes.any, // tab页面ID,用于弹窗控制 |
| | | plot: PropTypes.object, |
| | | config: PropTypes.object, |
| | | tableId: PropTypes.string, |
| | | loading: PropTypes.bool, |
| | | data: PropTypes.array, |
| | | buttonTrigger: PropTypes.func, |
| | | refreshdata: PropTypes.func, |
| | | handleTableId: PropTypes.func |
| | | } |
| | | |
| | |
| | | selectKey: '' |
| | | } |
| | | |
| | | /** |
| | | * @description 卡片初始化,设置卡片的配置信息 |
| | | */ |
| | | UNSAFE_componentWillMount () { |
| | | const { plot, config } = this.props |
| | | let card = {} |
| | |
| | | }) |
| | | |
| | | actions.forEach(item => { |
| | | if (item.Ot && item.Ot !== 'notRequired' && !['excelIn', 'excelOut'].includes(item.OpenType)) { |
| | | if ((item.Ot && item.Ot !== 'notRequired' && !['excelIn', 'excelOut'].includes(item.OpenType)) || item.funcType === 'changeuser') { |
| | | actionMap.set(item.uuid, item) |
| | | } |
| | | }) |
| | |
| | | if (!actionMap.get(item.value)) return |
| | | card.header.actions.push(actionMap.get(item.value)) |
| | | }) |
| | | card.header.actions.length = 1 |
| | | } |
| | | if (card.header.actions.length === 0) { |
| | | card.header.actions = null |
| | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | | return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | triggerBtn = (btn, data) => { |
| | | this.props.buttonTrigger(btn, data) |
| | | } |
| | | |
| | | /** |
| | | * @description 卡片切换 |
| | | */ |
| | | switchCard = (data) => { |
| | | const { config } = this.props |
| | | |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { plot, data, loading } = this.props |
| | | const { plot, data, loading, BID, BData, Tab, MenuID, config, logcolumns, ContainerId } = this.props |
| | | const { card, colMap, selectKey } = this.state |
| | | |
| | | return ( |
| | |
| | | data.map((item, i) => ( |
| | | <CardCell |
| | | key={i} |
| | | BID={BID} |
| | | Tab={Tab} |
| | | card={card} |
| | | data={item} |
| | | BData={BData} |
| | | MenuID={MenuID} |
| | | colMap={colMap} |
| | | selectKey={selectKey} |
| | | triggerBtn={this.triggerBtn} |
| | | logcolumns={logcolumns} |
| | | setting={config.setting} |
| | | ContainerId={ContainerId} |
| | | switchCard={this.switchCard} |
| | | refreshdata={this.props.refreshdata} |
| | | /> |
| | | )) |
| | | } |
| | |
| | | <Tabs activeKey=""> |
| | | {data.map((item, i) => ( |
| | | <TabPane tab={<CardCell |
| | | BID={BID} |
| | | Tab={Tab} |
| | | card={card} |
| | | data={item} |
| | | BData={BData} |
| | | MenuID={MenuID} |
| | | colMap={colMap} |
| | | selectKey={selectKey} |
| | | triggerBtn={this.triggerBtn} |
| | | logcolumns={logcolumns} |
| | | setting={config.setting} |
| | | ContainerId={ContainerId} |
| | | switchCard={this.switchCard} |
| | | refreshdata={this.props.refreshdata} |
| | | />} key={i}></TabPane> |
| | | |
| | | ))} |