| | |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button } from 'antd' |
| | | |
| | | // import MKEmitter from '@/utils/events.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import './index.scss' |
| | | |
| | | class AutoMatic extends Component { |
| | |
| | | |
| | | state = { |
| | | running: false, |
| | | line: 0 |
| | | line: 1, |
| | | init: true |
| | | } |
| | | |
| | | timer = null |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('autoGetData', this.autoGetData) |
| | | MKEmitter.addListener('autoExecOver', this.autoExecOver) |
| | | MKEmitter.addListener('autoMaticOver', this.autoMaticOver) |
| | | MKEmitter.addListener('autoMaticError', this.autoMaticError) |
| | | MKEmitter.addListener('autoTransSelectData', this.autoTransSelectData) |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | MKEmitter.removeListener('autoGetData', this.autoGetData) |
| | | MKEmitter.removeListener('autoExecOver', this.autoExecOver) |
| | | MKEmitter.removeListener('autoMaticOver', this.autoMaticOver) |
| | | MKEmitter.removeListener('autoMaticError', this.autoMaticError) |
| | | MKEmitter.removeListener('autoTransSelectData', this.autoTransSelectData) |
| | | } |
| | | |
| | | autoExecOver = (btnId, type) => { |
| | | const { autoMatic, config } = this.props |
| | | |
| | | if (!this.state.running || btnId !== autoMatic.action) return |
| | | |
| | | if (type === 'error') { |
| | | if (autoMatic.onFail === 'next') { |
| | | this.setState({line: this.state.line + 1}, () => { |
| | | setTimeout(() => { |
| | | MKEmitter.emit('autoQueryData', config.MenuID, this.state.line) |
| | | }, 1000) |
| | | }) |
| | | } else if (autoMatic.onFail === 'stay') { |
| | | setTimeout(() => { |
| | | MKEmitter.emit('autoQueryData', config.MenuID, this.state.line) |
| | | }, 1000) |
| | | } else { |
| | | this.setState({running: false}) |
| | | } |
| | | } else { |
| | | if (autoMatic.onSuccess === 'next') { |
| | | this.setState({line: this.state.line + 1}, () => { |
| | | setTimeout(() => { |
| | | MKEmitter.emit('autoQueryData', config.MenuID, this.state.line) |
| | | }, 1000) |
| | | }) |
| | | } else if (autoMatic.onSuccess === 'stay') { |
| | | setTimeout(() => { |
| | | MKEmitter.emit('autoQueryData', config.MenuID, this.state.line) |
| | | }, 1000) |
| | | } else { |
| | | this.setState({running: false}) |
| | | } |
| | | } |
| | | } |
| | | |
| | | autoTransSelectData = (MenuID, data) => { |
| | | const { config, autoMatic } = this.props |
| | | |
| | | if (!this.state.running || MenuID !== config.MenuID) return |
| | | |
| | | setTimeout(() => { |
| | | MKEmitter.emit('triggerBtnId', autoMatic.action, [data], 'autoMatic') |
| | | if (['prompt', 'pop'].includes(autoMatic.OpenType)) { |
| | | let delay = this.state.init && autoMatic.OpenType === 'pop' ? 2000 : 200 |
| | | |
| | | setTimeout(() => { |
| | | if (autoMatic.OpenType === 'prompt') { |
| | | let node = document.querySelector('.ant-modal-confirm-btns >.ant-btn-primary') |
| | | node && node.click() |
| | | } else if (autoMatic.OpenType === 'pop') { |
| | | MKEmitter.emit('triggerBtnPopSubmit', autoMatic.action) |
| | | } |
| | | }, delay) |
| | | } |
| | | }, 100) |
| | | } |
| | | |
| | | autoMaticError = (MenuID) => { |
| | | const { config } = this.props |
| | | |
| | | if (!this.state.running || MenuID !== config.MenuID) return |
| | | |
| | | this.setState({running: false}) |
| | | } |
| | | |
| | | autoGetData = (MenuID) => { |
| | | const { config } = this.props |
| | | |
| | | if (!this.state.running || MenuID !== config.MenuID) return |
| | | setTimeout(() => { |
| | | MKEmitter.emit('autoSelectData', config.MenuID, this.state.line) |
| | | }, 100) |
| | | } |
| | | |
| | | trigger = () => { |
| | | // const { config } = this.props |
| | | const { config } = this.props |
| | | let running = !this.state.running |
| | | |
| | | // MKEmitter.emit('autoQueryData', config.MenuID, 0) |
| | | MKEmitter.emit('autoQueryData', config.MenuID, 1) |
| | | |
| | | this.setState({running: running}) |
| | | this.setState({running: running, line: 1}) |
| | | clearTimeout(this.timer) |
| | | } |
| | | |
| | | autoMaticOver = (MenuID) => { |
| | | const { config, autoMatic } = this.props |
| | | |
| | | if (!this.state.running || MenuID !== config.MenuID) return |
| | | |
| | | this.setState({running: false}) |
| | | |
| | | if (autoMatic.onFinish !== 'over') { |
| | | let interval = autoMatic.interval * 1000 || 10 |
| | | |
| | | 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) |
| | | } |
| | | } |
| | | |
| | | render() { |