| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, message } from 'antd' |
| | | import { Button, message, Tooltip } from 'antd' |
| | | |
| | | import MKEmitter from '@/utils/events.js' |
| | | import './index.scss' |
| | | // import './index.scss' |
| | | |
| | | class AutoMatic extends Component { |
| | | static propTpyes = { |
| | | autoMatic: PropTypes.object, |
| | | tabId: PropTypes.string, |
| | | config: PropTypes.object |
| | | } |
| | | |
| | |
| | | timer = null |
| | | |
| | | UNSAFE_componentWillMount() { |
| | | const { autoMatic } = this.props |
| | | const { autoMatic, tabId } = this.props |
| | | |
| | | if (autoMatic.gap && autoMatic.gap >= 1) { |
| | | this.setState({gap: autoMatic.gap * 1000}) |
| | | } |
| | | |
| | | if (tabId && tabId === sessionStorage.getItem('autoExecId')) { |
| | | sessionStorage.removeItem('autoExecId') |
| | | |
| | | setTimeout(() => { |
| | | this.trigger() |
| | | }, 10000) |
| | | } |
| | | } |
| | | |
| | |
| | | let node = document.querySelector('.ant-modal-confirm-btns >.ant-btn-primary') |
| | | node && node.click() |
| | | } else if (autoMatic.OpenType === 'pop') { |
| | | MKEmitter.emit('triggerBtnPopSubmit', autoMatic.action) |
| | | let node = document.querySelector('.ant-modal-confirm-btns >.ant-btn-primary') |
| | | |
| | | if (node) { |
| | | node.click() |
| | | } else { |
| | | MKEmitter.emit('triggerBtnPopSubmit', autoMatic.action) |
| | | } |
| | | } |
| | | }, delay) |
| | | } |
| | |
| | | } |
| | | |
| | | autoMaticOver = (MenuID) => { |
| | | const { config, autoMatic } = this.props |
| | | const { config, autoMatic, tabId } = this.props |
| | | |
| | | if (!this.state.running || MenuID !== config.MenuID) return |
| | | |
| | |
| | | if (autoMatic.onFinish !== 'over') { |
| | | let interval = autoMatic.interval * 1000 || 10 |
| | | |
| | | if (autoMatic.restart === 'first') { |
| | | this.setState({line: 1}) |
| | | if (autoMatic.restart === 'refresh') { |
| | | this.timer = setTimeout(() => { |
| | | sessionStorage.setItem('ThirdMenu', tabId) |
| | | sessionStorage.setItem('autoExecId', tabId) |
| | | window.location.reload() |
| | | }, interval) |
| | | } else { |
| | | this.setState({line: this.state.line + 1}) |
| | | if (autoMatic.restart === 'first') { |
| | | this.setState({line: 1}) |
| | | } else { |
| | | this.setState({line: this.state.line + 1}) |
| | | } |
| | | |
| | | this.timer = setTimeout(() => { |
| | | this.setState({running: true}) |
| | | MKEmitter.emit('autoQueryData', config.MenuID, this.state.line) |
| | | }, interval) |
| | | } |
| | | |
| | | this.timer = setTimeout(() => { |
| | | this.setState({running: true}) |
| | | MKEmitter.emit('autoQueryData', config.MenuID, this.state.line) |
| | | }, interval) |
| | | } |
| | | } |
| | | |
| | |
| | | const { running } = this.state |
| | | |
| | | return ( |
| | | <Button |
| | | icon={running ? 'pause' : 'forward'} |
| | | shape="circle" |
| | | className={'auto-matic ' + (window.GLOB.systemType === 'production' ? 'low' : '')} |
| | | onClick={this.trigger} |
| | | /> |
| | | <div className="tool-wrap"> |
| | | <Tooltip placement="left" title="无人值守"> |
| | | <Button icon={running ? 'pause' : 'forward'} shape="circle" onClick={this.trigger}/> |
| | | </Tooltip> |
| | | </div> |
| | | ) |
| | | } |
| | | } |