From 34e7681fd12b1c4e4994d3bea1a553870e10bc50 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 11 三月 2023 17:58:54 +0800
Subject: [PATCH] 2023-03-11

---
 src/tabviews/zshare/actionList/normalbutton/index.jsx |  319 +++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 227 insertions(+), 92 deletions(-)

diff --git a/src/tabviews/zshare/actionList/normalbutton/index.jsx b/src/tabviews/zshare/actionList/normalbutton/index.jsx
index 0654d5f..4b9f777 100644
--- a/src/tabviews/zshare/actionList/normalbutton/index.jsx
+++ b/src/tabviews/zshare/actionList/normalbutton/index.jsx
@@ -13,6 +13,7 @@
 import { updateForm } from '@/utils/utils-update.js'
 import MKEmitter from '@/utils/events.js'
 import MkIcon from '@/components/mk-icon'
+import MkCounter from './mkcounter'
 // import './index.scss'
 
 const MutilForm = asyncSpinComponent(() => import('@/tabviews/zshare/mutilform'))
@@ -43,42 +44,35 @@
     disabled: false,
     hidden: false,
     autoMatic: false,
-    check: false
+    check: false,
+    count: 0
   }
 
   moduleParams = null
 
   UNSAFE_componentWillMount () {
-    const { btn, selectedData, BData } = this.props
-    let disabled = false
+    const { btn, selectedData, BData, disabled } = this.props
 
-    if (btn.controlField && selectedData && selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒�
-      selectedData.forEach(item => {
-        let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
-        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
-          disabled = true
-        }
-      })
-      this.setState({hidden: disabled && btn.control === 'hidden'})
-    } else if (btn.control === 'parent') {
-      if (!BData || !BData.hasOwnProperty(btn.controlField)) {
-        this.setState({hidden: true})
-      } else {
-        let s = BData[btn.controlField] + ''
-        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
-          this.setState({hidden: true})
-        } else {
-          this.setState({hidden: false})
-        }
-      }
-    }
-    if (this.props.disabled || disabled) {
+    if (btn.controlField) {
+      this.setStatus(btn, selectedData || [], BData, disabled)
+    } else if (disabled) {
       this.setState({disabled: true})
     }
     
     if (btn.OpenType === 'form') {
       let data = selectedData && selectedData[0] ? selectedData[0] : null
-      this.setState({check: data && data[btn.field] === btn.openVal})
+      if (btn.formType === 'counter') {
+        let count = 0
+        if (data && data[btn.field]) {
+          count = +data[btn.field]
+          if (isNaN(count)) {
+            count = 0
+          }
+        }
+        this.setState({count: count })
+      } else {
+        this.setState({check: data && data[btn.field] === btn.openVal})
+      }
     } else if (btn.OpenType === 'formSubmit') {
       this.setState({
         selines: selectedData || []
@@ -104,41 +98,28 @@
   }
 
   UNSAFE_componentWillReceiveProps (nextProps) {
-    const { btn, selectedData, BData } = this.props
+    const { btn } = this.props
 
-    let disabled = false
-    if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) {
-      if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒�
-        nextProps.selectedData.forEach(item => {
-          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
-          if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
-            disabled = true
-          }
-        })
-      }
-      this.setState({hidden: disabled && btn.control === 'hidden'})
-    } else if (btn.control === 'parent' && !is(fromJS(nextProps.BData || {}), fromJS(BData || {}))) {
-      if (!nextProps.BData || !nextProps.BData.hasOwnProperty(btn.controlField)) {
-        this.setState({hidden: true})
-      } else {
-        let s = nextProps.BData[btn.controlField] + ''
-        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
-          this.setState({hidden: true})
-        } else {
-          this.setState({hidden: false})
-        }
-      }
-    }
-
-    if (nextProps.disabled || disabled) {
-      this.setState({disabled: true})
+    if (btn.controlField) {
+      this.setStatus(btn, nextProps.selectedData || [], nextProps.BData, nextProps.disabled)
     } else {
-      this.setState({disabled: false})
+      this.setState({disabled: nextProps.disabled === true})
     }
 
     if (btn.OpenType === 'form') {
       let data = nextProps.selectedData && nextProps.selectedData[0] ? nextProps.selectedData[0] : null
-      this.setState({check: data && data[btn.field] === btn.openVal})
+      if (btn.formType === 'counter') {
+        let count = 0
+        if (data && data[btn.field]) {
+          count = +data[btn.field]
+          if (isNaN(count)) {
+            count = 0
+          }
+        }
+        this.setState({count: count })
+      } else {
+        this.setState({check: data && data[btn.field] === btn.openVal})
+      }
     } else if (btn.OpenType === 'formSubmit') {
       this.setState({
         selines: nextProps.selectedData || []
@@ -153,6 +134,43 @@
     MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
     MKEmitter.removeListener('triggerFormSubmit', this.actionSubmit)
     MKEmitter.removeListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit)
+  }
+
+  setStatus = (btn, data, BData, disprop) => {
+    let disabled = false
+    let hidden = false
+
+    if (btn.control !== 'parent') {
+      if (data.length > 0) {
+        data.forEach(item => {
+          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
+          if (btn.controlVals.includes(s)) {
+            disabled = true
+          }
+        })
+      } else if (btn.controlVals.includes('')) {
+        disabled = true
+      }
+    } else {
+      if (!BData || !BData.hasOwnProperty(btn.controlField)) {
+        hidden = true
+      } else {
+        let s = BData[btn.controlField] + ''
+        if (btn.controlVals.includes(s)) {
+          hidden = true
+        }
+      }
+    }
+
+    if (disabled && btn.control === 'hidden') {
+      hidden = true
+    }
+
+    if (disprop) {
+      disabled = true
+    }
+
+    this.setState({hidden, disabled})
   }
 
   triggerBtnPopSubmit = (id) => {
@@ -358,29 +376,41 @@
         this.improveAction()
       })
     } else if (btn.OpenType === 'form') {
-      this.setState({
-        loading: true,
-        check: !this.state.check
-      }, () => {
-        let type = 'text'
-        let fieldlen = 50
-        let value = this.state.check ? btn.openVal : btn.closeVal
-
-        if (typeof(value) === 'number') {
-          type = 'number'
-          fieldlen = 0
-        }
-        
+      if (btn.formType === 'counter') {
         let item = {
-          type: type,
+          type: 'number',
           readin: true,
           writein: true,
-          fieldlen: fieldlen,
+          fieldlen: btn.decimal || 0,
           key: btn.field,
-          value: value
+          value: this.state.count
         }
-        this.execSubmit(data, () => { this.setState({loading: false})}, [item])
-      })
+        this.execSubmit(data, () => {}, [item])
+      } else {
+        this.setState({
+          loading: true,
+          check: !this.state.check
+        }, () => {
+          let type = 'text'
+          let fieldlen = 50
+          let value = this.state.check ? btn.openVal : btn.closeVal
+  
+          if (typeof(value) === 'number') {
+            type = 'number'
+            fieldlen = 0
+          }
+          
+          let item = {
+            type: type,
+            readin: true,
+            writein: true,
+            fieldlen: fieldlen,
+            key: btn.field,
+            value: value
+          }
+          this.execSubmit(data, () => { this.setState({loading: false})}, [item])
+        })
+      }
     }
 
     if (window.GLOB.systemType === 'production') {
@@ -973,6 +1003,7 @@
     _sql = _sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
     _sql = _sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
     _sql = _sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+    _sql = _sql.replace(/@typename@/ig, `'admin'`)
 
     return _sql
   }
@@ -1022,7 +1053,7 @@
 
       if (params[0].$unCheckParam) {
         this.checkLoopRequest(params, _resolve)
-      } else if (params.length <= 20) {
+      } else if (params.length <= 20 && btn.execType !== 'single') {
         let deffers = params.map((param, i) => {
           return new Promise(resolve => {
             setTimeout(() => {
@@ -1068,6 +1099,7 @@
           let iserror = false
           let errorMsg = ''
           result.forEach(res => {
+            if (iserror) return
             if (res.status) {
               errorMsg = res
             } else {
@@ -1083,7 +1115,7 @@
           _resolve()
         })
       } else { // 瓒呭嚭20涓姹傛椂寰幆鎵ц
-        if (btn.progress === 'progressbar' && btn.$toolbtn) {
+        if (btn.progress === 'progressbar' && btn.$toolbtn && params.length > 1) {
           this.setState({
             loadingTotal: params.length
           })
@@ -1456,6 +1488,14 @@
       sql = sql.join('')
       sql = _prevCustomScript + sql
       sql = sql + _backCustomScript
+
+      sql = sql.replace(/@ID@/ig, `'${record.ID || ''}'`)
+      sql = sql.replace(/@BID@/ig, `'${this.props.BID || ''}'`)
+      sql = sql.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
+      sql = sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
+      sql = sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
+      sql = sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+      sql = sql.replace(/@typename@/ig, `'admin'`)
 
       if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
         console.info(sql.replace(/\n\s{8}/ig, '\n'))
@@ -1918,21 +1958,40 @@
    * 4銆佹ā鎬佹鎵ц鎴愬姛鍚庢槸鍚﹀叧闂�
    * 5銆侀�氱煡涓诲垪琛ㄥ埛鏂�
    */
-  execSuccess = (res) => {
+  execSuccess = (res = {}) => {
     const { btn } = this.props
     const { btnconfig, autoMatic } = this.state
 
-    if ((res && (res.ErrCode === 'S' || !res.ErrCode)) || autoMatic) { // 鎵ц鎴愬姛
-      notification.success({
-        top: 92,
-        message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
-        duration: btn.verify && btn.verify.stime ? btn.verify.stime : 2
-      })
-    } else if (res && res.ErrCode === 'Y') { // 鎵ц鎴愬姛
+    if (res.message && /^@speak@/.test(res.message)) {
+      res.message = res.message.replace('@speak@', '')
+      let val = res.message.match(/<<.*>>/)
+      res.message = res.message.replace(/\s*<<.*>>\s*/g, '')
+      val = val ? val[0].replace(/<<|>>/g, '') : ''
+
+      if (/^http/.test(val)) {
+        let audio = document.createElement('audio')
+        audio.src = val
+        audio.play()
+      }
+
+      if (!res.message) {
+        res.ErrCode = '-1'
+      }
+    }
+
+    if ((res.ErrCode === 'S' || !res.ErrCode) || autoMatic) { // 鎵ц鎴愬姛
+      if (btn.formType !== 'counter' || res.message) {
+        notification.success({
+          top: 92,
+          message: res.message || '鎵ц鎴愬姛锛�',
+          duration: btn.verify && btn.verify.stime ? btn.verify.stime : 2
+        })
+      }
+    } else if (res.ErrCode === 'Y') { // 鎵ц鎴愬姛
       Modal.success({
-        title: res.ErrMesg || this.state.dict['main.action.confirm.success']
+        title: res.message || '鎵ц鎴愬姛锛�'
       })
-    } else if (res && res.ErrCode === '-1') { // 瀹屾垚鍚庝笉鎻愮ず
+    } else if (res.ErrCode === '-1') { // 瀹屾垚鍚庝笉鎻愮ず
 
     }
 
@@ -2295,25 +2354,42 @@
     const { btn } = this.props
     const { btnconfig, autoMatic } = this.state
 
+    if (res.message && /^@speak@/.test(res.message)) {
+      res.message = res.message.replace('@speak@', '')
+      let val = res.message.match(/<<.*>>/)
+      res.message = res.message.replace(/\s*<<.*>>\s*/g, '')
+      val = val ? val[0].replace(/<<|>>/g, '') : ''
+
+      if (/^http/.test(val)) {
+        let audio = document.createElement('audio')
+        audio.src = val
+        audio.play()
+      }
+
+      if (!res.message) {
+        res.ErrCode = '-1'
+      }
+    }
+
     if (res.ErrCode === 'E' && !autoMatic) {
       Modal.error({
-        title: res.message || res.ErrMesg,
+        title: res.message || '鎵ц澶辫触锛�',
       })
     } else if (res.ErrCode === 'N' || autoMatic) {
       notification.error({
         top: 92,
-        message: res.message || res.ErrMesg,
+        message: res.message || '鎵ц澶辫触锛�',
         duration: btn.verify && btn.verify.ntime ? btn.verify.ntime : 10
       })
     } else if (res.ErrCode === 'F') {
       notification.error({
         className: 'notification-custom-error',
         top: 92,
-        message: res.message || res.ErrMesg,
+        message: res.message || '鎵ц澶辫触锛�',
         duration: btn.verify && btn.verify.ftime ? btn.verify.ftime : 10
       })
     } else if (res.ErrCode === 'NM') {
-      message.error(res.message || res.ErrMesg)
+      message.error(res.message || '鎵ц澶辫触锛�')
     }
 
     if (autoMatic) {
@@ -2344,7 +2420,7 @@
       MKEmitter.emit('popclose')
     } else if (btn.execError !== 'never') {
       MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines)
-    } else if (btn.OpenType === 'form') {
+    } else if (btn.OpenType === 'form' && btn.formType !== 'counter') {
       let data = this.props.selectedData && this.props.selectedData[0] ? this.props.selectedData[0] : null
       this.setState({check: data && data[btn.field] === btn.openVal})
     }
@@ -2390,7 +2466,20 @@
         this.setState({
           visible: true
         })
+
+        if (btnconfig.setting.display === 'modal' && btnconfig.setting.moveable === 'true') {
+          setTimeout(() => {
+            this.setMove()
+          }, 100)
+        }
       }
+    } else if (!btn.$old) {
+      notification.warning({
+        top: 92,
+        message: '鏈幏鍙栧埌鎸夐挳閰嶇疆淇℃伅锛�',
+        duration: 5
+      })
+      this.setState({ loading: false })
     } else {
       Api.getCacheConfig({
         func: 'sPC_Get_LongParam',
@@ -2643,15 +2732,17 @@
         width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + '%'
         container = () => document.getElementById(btn.ContainerId)
       }
+
       return (
         <Modal
           title={title}
           maskClosable={clickouter}
           getContainer={container}
-          wrapClassName='action-modal'
+          wrapClassName={'action-modal' + (btnconfig.setting.moveable === 'true' ? ' moveable-modal modal-' + btn.uuid : '')}
           visible={visible}
           width={width}
           onOk={this.handleOk}
+          maskStyle={btnconfig.setting.moveable === 'true' ?  {backgroundColor: 'rgba(0, 0, 0, 0.15)'} : null}
           confirmLoading={this.state.confirmLoading}
           onCancel={this.handleCancel}
           destroyOnClose
@@ -2670,15 +2761,59 @@
     }
   }
 
+  setMove = () => {
+    const { btn } = this.props
+    let wrap = document.getElementsByClassName('modal-' + btn.uuid)[0]
+
+    if (!wrap) return
+
+    let node = wrap.getElementsByClassName('ant-modal-header')[0]
+
+    if (!node) return
+
+    node.onmousedown = function(e) {
+      let orileft = 0
+      let oritop = 0
+      let oleft = e.clientX
+      let otop = e.clientY
+
+      if (node.parentNode.style.left) {
+        orileft = parseFloat(node.parentNode.style.left)
+      }
+      if (node.parentNode.style.top) {
+        oritop = parseFloat(node.parentNode.style.top)
+      }
+
+      document.onmousemove = function(e) {
+        let left = e.clientX - oleft
+        let top = e.clientY - otop
+
+        node.parentNode.style.left = (orileft + left) + 'px'
+        node.parentNode.style.top = (oritop + top) + 'px'
+      }
+    }
+
+    document.onmouseup = function() {
+      document.onmousemove = null
+    }
+  }
+
+  changeCount = (count) => {
+    this.setState({count}, () => {
+      this.actionTrigger()
+    })
+  }
+
   render() {
     const { btn } = this.props
-    const { loadingNumber, loadingTotal, loading, disabled, hidden, check } = this.state
+    const { loadingNumber, loadingTotal, loading, disabled, hidden, check, count } = this.state
 
     if (hidden) return null
-
     if (btn.OpenType === 'form') {
       if (btn.formType === 'switch') { 
         return <Switch loading={loading} checked={check} disabled={disabled || loading} title={disabled ? (btn.reason || '') : ''} onChange={(val,e) => {e.stopPropagation();this.actionTrigger()}} style={btn.style} className={btn.size === 'large' ? 'ant-switch-large' : ''} size={btn.size} checkedChildren={btn.openText || ''} unCheckedChildren={btn.closeText || ''}/>
+      } else if (btn.formType === 'counter') {
+        return <MkCounter count={count} disabled={disabled} btn={btn} onChange={this.changeCount}/>
       } else if (btn.formType === 'radio') {
         return <Checkbox className={btn.checkType || ''} disabled={disabled || loading} title={disabled ? (btn.reason || '') : ''} checked={check} onChange={(e) => {e.stopPropagation();this.actionTrigger()}} style={btn.style}></Checkbox>
       } else {

--
Gitblit v1.8.0