From fc8c8d714687a22f711d642d192bd4149f3b7e88 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 22 四月 2024 11:15:14 +0800
Subject: [PATCH] 2024-04-22

---
 src/tabviews/zshare/automatic/index.jsx |  113 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 88 insertions(+), 25 deletions(-)

diff --git a/src/tabviews/zshare/automatic/index.jsx b/src/tabviews/zshare/automatic/index.jsx
index 067bd17..d165c28 100644
--- a/src/tabviews/zshare/automatic/index.jsx
+++ b/src/tabviews/zshare/automatic/index.jsx
@@ -1,27 +1,46 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Button } 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
   }
 
   state = {
     running: false,
     line: 1,
-    init: true
+    gap: 2000
   }
 
   timer = null
 
+  UNSAFE_componentWillMount() {
+    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)
+    }
+  }
+
   componentDidMount () {
+    MKEmitter.addListener('modifyTabs', this.breakOff)
     MKEmitter.addListener('autoGetData', this.autoGetData)
+    MKEmitter.addListener('resetActiveMenu', this.breakOff)
     MKEmitter.addListener('autoExecOver', this.autoExecOver)
     MKEmitter.addListener('autoMaticOver', this.autoMaticOver)
     MKEmitter.addListener('autoMaticError', this.autoMaticError)
@@ -40,29 +59,41 @@
       return
     }
     clearTimeout(this.timer)
+    MKEmitter.removeListener('modifyTabs', this.breakOff)
     MKEmitter.removeListener('autoGetData', this.autoGetData)
+    MKEmitter.removeListener('resetActiveMenu', this.breakOff)
     MKEmitter.removeListener('autoExecOver', this.autoExecOver)
     MKEmitter.removeListener('autoMaticOver', this.autoMaticOver)
     MKEmitter.removeListener('autoMaticError', this.autoMaticError)
     MKEmitter.removeListener('autoTransSelectData', this.autoTransSelectData)
   }
 
+  breakOff = () => {
+    if (this.state.running) {
+      this.setState({running: false})
+      clearTimeout(this.timer)
+    }
+  }
+
   autoExecOver = (btnId, type) => {
     const { autoMatic, config } = this.props
+    const { gap } = this.state
 
     if (!this.state.running || btnId !== autoMatic.action) return
 
-    if (type === 'error') {
+    if (this.state.line >= 1000) {
+      this.breakOff()
+    } else if (type === 'error') {
       if (autoMatic.onFail === 'next') {
         this.setState({line: this.state.line + 1}, () => {
           setTimeout(() => {
             MKEmitter.emit('autoQueryData', config.MenuID, this.state.line)
-          }, 1000)
+          }, gap)
         })
       } else if (autoMatic.onFail === 'stay') {
         setTimeout(() => {
           MKEmitter.emit('autoQueryData', config.MenuID, this.state.line)
-        }, 1000)
+        }, gap)
       } else {
         this.setState({running: false})
       }
@@ -71,12 +102,12 @@
         this.setState({line: this.state.line + 1}, () => {
           setTimeout(() => {
             MKEmitter.emit('autoQueryData', config.MenuID, this.state.line)
-          }, 1000)
+          }, gap)
         })
       } else if (autoMatic.onSuccess === 'stay') {
         setTimeout(() => {
           MKEmitter.emit('autoQueryData', config.MenuID, this.state.line)
-        }, 1000)
+        }, gap)
       } else {
         this.setState({running: false})
       }
@@ -88,17 +119,32 @@
 
     if (!this.state.running || MenuID !== config.MenuID) return
 
+    if (data.$disabled) {
+      this.setState({line: this.state.line + 1}, () => {
+        setTimeout(() => {
+          MKEmitter.emit('autoQueryData', config.MenuID, this.state.line)
+        }, 100)
+      })
+      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
+        let delay = autoMatic.OpenType === 'pop' ? 2000 : 300
 
         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)
+            let node = document.querySelector('.ant-modal-confirm-btns >.ant-btn-primary')
+
+            if (node) {
+              node.click()
+            } else {
+              MKEmitter.emit('triggerBtnPopSubmit', autoMatic.action)
+            }
           }
         }, delay)
       }
@@ -130,10 +176,20 @@
 
     this.setState({running: running, line: 1})
     clearTimeout(this.timer)
+
+    message.info('鎸塃sc閿粓姝㈣繍琛屻��')
+
+    document.onkeydown = (event) => {
+      let e = event || window.event
+
+      if (e.key === 'Escape') {
+        this.breakOff()
+      }
+    }
   }
 
   autoMaticOver = (MenuID) => {
-    const { config, autoMatic } = this.props
+    const { config, autoMatic, tabId } = this.props
 
     if (!this.state.running || MenuID !== config.MenuID) return
 
@@ -142,16 +198,24 @@
     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)
     }
   }
 
@@ -159,12 +223,11 @@
     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>
     )
   }
 }

--
Gitblit v1.8.0