From c0930736f5b5955efecdac4c0ca85957d4f7b574 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 16 十二月 2019 22:55:17 +0800
Subject: [PATCH] 2019-12-16

---
 src/templates/comtableconfig/index.jsx |  181 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 141 insertions(+), 40 deletions(-)

diff --git a/src/templates/comtableconfig/index.jsx b/src/templates/comtableconfig/index.jsx
index 75af4d9..e0fe8b5 100644
--- a/src/templates/comtableconfig/index.jsx
+++ b/src/templates/comtableconfig/index.jsx
@@ -1,5 +1,6 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
+import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
 import { DndProvider } from 'react-dnd'
 import HTML5Backend from 'react-dnd-html5-backend'
@@ -60,7 +61,8 @@
     selectedTables: [],      // 宸查�夎〃鍚�
     originMenu: null,        // 鍘熷鑿滃崟
     originActions: null,
-    delActions: []
+    delActions: [],
+    funcLoading: false
   }
 
   /**
@@ -471,6 +473,7 @@
   }
 
   handleAction = (card) => {
+    let ableField = this.props.permFuncField.join(', ')
     this.setState({
       visible: true,
       formtemp: 'action',
@@ -557,9 +560,10 @@
           label: this.state.dict['header.form.innerFunc'],
           initVal: card.innerFunc,
           tooltip: <div>
-            <p>鍐呴儴鎺ュ彛: 鍙嚜瀹氫箟鏁版嵁澶勭悊鍑芥暟锛屾湭璁剧疆鏃朵細璋冪敤绯荤粺鍑芥暟锛屼娇鐢ㄧ郴缁熷嚱鏁伴渶瀹屽杽鏁版嵁婧愬強鎿嶄綔绫诲瀷;</p>
+            <p>鍐呴儴鎺ュ彛: 鍙嚜瀹氫箟鏁版嵁澶勭悊鍑芥暟锛屽嚱鏁板悕绉伴渶浠ableField}绛夊瓧绗﹀紑濮嬶紱鏈缃椂浼氳皟鐢ㄧ郴缁熷嚱鏁帮紝浣跨敤绯荤粺鍑芥暟闇�瀹屽杽鏁版嵁婧愬強鎿嶄綔绫诲瀷;</p>
             <p>澶栭儴鎺ュ彛: 鍙嚜瀹氫箟鏁版嵁澶勭悊鍑芥暟锛屾彁浜ゆ暟鎹粡杩囧唴閮ㄥ嚱鏁板鐞嗗悗锛屼紶鍏ュ閮ㄦ帴鍙o紝鏈缃椂锛屾暟鎹細鐩存帴浼犲叆澶栭儴鎺ュ彛銆�</p>
           </div>,
+          fields: this.props.permFuncField,
           tooltipClass: 'middle',
           required: false,
           readonly: false
@@ -686,10 +690,13 @@
           type: 'select',
           key: 'sqlType',
           label: this.state.dict['header.form.action.type'],
-          initVal: card.sqlType || 'insert',
+          initVal: card.sqlType || '',
           tooltip: this.state.dict['header.form.actionhelp.sqlType'],
           required: false,
           options: [{
+            MenuID: '',
+            text: this.state.dict['header.form.empty']
+          }, {
             MenuID: 'insert',
             text: this.state.dict['header.form.action.insert']
           }, {
@@ -1039,15 +1046,21 @@
     }
   }
 
+  /**
+   * @description 鍒涘缓鎸夐挳瀛樺偍杩囩▼
+   */
   creatFunc = () => {
     let _config = JSON.parse(JSON.stringify(this.state.config))
 
     this.formRef.handleConfirm().then(res => {
-      let btn = res.values
-      let LText = ''
-      let DelText = ''
-      let isExit = false
+      let btn = res.values  // 鎸夐挳淇℃伅
+      let newLText = ''     // 鍒涘缓瀛樺偍杩囩▼sql
+      let DelText = ''      // 鍒犻櫎瀛樺偍杩囩▼sql
+      let isExit = false    // 瀛樺偍杩囩▼鏄惁瀛樺湪
+      let sysTVPText = ''   // 宸叉湁鐨勫瓨鍌ㄨ繃绋嬭鍙�(浜戠)
+      let localTVPText = '' // 宸叉湁鐨勫瓨鍌ㄨ繃绋嬭鍙�(鏈湴)
 
+      // 鍒涘缓瀛樺偍杩囩▼锛屽繀椤诲~鍐欏唴閮ㄥ嚱鏁板悕
       if (!btn.innerFunc) {
         notification.warning({
           top: 92,
@@ -1057,8 +1070,14 @@
         return
       }
 
+      // 鍒涘缓涓�
+      this.setState({
+        funcLoading: true
+      })
+
       new Promise(resolve => {
-        // 鍐呴儴璇锋眰
+        // 寮圭獥锛堣〃鍗曪級绫绘寜閽紝鍏堣幏鍙栨寜閽厤缃俊鎭紝濡傛灉灏氭湭閰嶇疆鎸夐挳鍒欎細鎶ラ敊骞剁粓姝€��
+        // 鑾峰彇淇℃伅鍚庣敓鎴愬垹闄ゅ拰鍒涘缓瀛樺偍杩囩▼鐨勮鍙�
         if (btn.OpenType === 'pop') {
           Api.getSystemConfig({
             func: 'sPC_Get_LongParam',
@@ -1090,7 +1109,7 @@
                 fields: fields,
                 menuNo: this.props.menu.MenuNo
               }
-              LText = Utils.formatOptions(Utils.getfunc(_param))
+              newLText = Utils.formatOptions(Utils.getfunc(_param))
               DelText = Utils.formatOptions(Utils.dropfunc(_param.funcName))
               resolve(true)
             } else {
@@ -1109,44 +1128,101 @@
             fields: '',
             menuNo: this.props.menu.MenuNo
           }
-          LText = Utils.formatOptions(Utils.getfunc(_param))
+          newLText = Utils.formatOptions(Utils.getfunc(_param))
           DelText = Utils.formatOptions(Utils.dropfunc(_param.funcName))
           resolve(true)
         }
       }).then(res => {
+        // 鑾峰彇浜戠鍙婃湰鍦帮紝鏄惁宸插瓨鍦ㄨ瀛樺偍杩囩▼鐨勪俊鎭�
         console.log(res)
         if (res === false) return res
-        
-        return Api.getSystemConfig({
-          func: 'sPC_Get_TVP',
-          TVPName: btn.innerFunc
-        })
-      }).then(res => {
-        console.log(res)
-        if (res === false) return res
-        if (!res.status) {
-          notification.warning({
-            top: 92,
-            message: res.message,
-            duration: 10
-          })
-          return false
-        }
 
-        if (res.TVPText && LText === res.TVPText) {
-          return 'drop'
-        } else {
-          if (res.TVPText) {
-            isExit = true
+        let sysDefer = new Promise(resolve => {
+          Api.getSystemConfig({
+            func: 'sPC_Get_TVP', // 浜戠鑾峰彇瀛樺偍缁撴灉
+            TVPName: btn.innerFunc
+          }).then(result => {
+            resolve(result)
+          })
+        })
+
+        let localDefer = new Promise(resolve => {
+          let _param = { // 鑾峰彇鏈湴瀛樺偍杩囩▼淇℃伅
+            func: 's_get_userproc',
+            LText: btn.innerFunc
           }
+          _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
+          _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
+          
+          Api.getLocalConfig(_param).then(result => {
+            resolve(result)
+          })
+        })
+        
+        return Promise.all([sysDefer, localDefer])
+      }).then(res => {
+        // 浜戠缁撴灉涓庢柊璇彞涓嶅悓鏃讹紝鏇存柊浜戠淇℃伅
+        console.log(res)
+        if (res === false) return res
+
+        let isError = false
+
+        res.forEach((result, index) => {
+          if (!result.status) {
+            notification.warning({
+              top: 92,
+              message: result.message,
+              duration: 10
+            })
+            isError = true
+          } else if (index === 0) {
+            sysTVPText = result.TVPText
+          } else {
+            console.log(result.Ltext)
+            if (result.Ltext) { // 鏈湴瀛樺偍杩囩▼鏄惁瀛樺湪
+              isExit = true
+            }
+            localTVPText = Utils.formatOptions(result.Ltext)
+          }
+        })
+
+        if (isError) return false
+        
+        if ((newLText === localTVPText) && (newLText === sysTVPText)) {
+          return 'drop'
+        } else if (!localTVPText || (sysTVPText === localTVPText)) {
+          // 鏈湴瀛樺偍杩囩▼涓嶅瓨鍦紝鎴栦簯绔拰鏈湴瀛樺偍杩囩▼涓�鑷存椂锛屽皢鏂扮殑瀛樺偍杩囩▼鏇存柊鑷充簯绔�
           return Api.getSystemConfig({
             func: 'sPC_TVP_InUp',
             TVPName: btn.innerFunc,
-            TVPText: LText,
+            TVPText: newLText,
             TypeName: 'P'
+          })
+        } else {
+          return new Promise(resolve => {
+            Api.getSystemConfig({ // 娣诲姞鐜版湁鐨勬湰鍦板瓨鍌ㄨ繃绋嬭嚦浜戠
+              func: 'sPC_TVP_InUp',
+              TVPName: btn.innerFunc,
+              TVPText: localTVPText,
+              TypeName: 'P'
+            }).then(result => {
+              if (result.status) {
+                Api.getSystemConfig({
+                  func: 'sPC_TVP_InUp', // 娣诲姞鏈�鏂扮殑瀛樺偍杩囩▼鑷充簯绔�
+                  TVPName: btn.innerFunc,
+                  TVPText: newLText,
+                  TypeName: 'P'
+                }).then(response => {
+                  resolve(response)
+                })
+              } else {
+                resolve(result)
+              }
+            })
           })
         }
       }).then(res => {
+        // 浜戠淇℃伅鏇存柊鍚庯紝鍒ゆ柇鏄垹闄ゆ垨鏄洿鎺ユ柊寤哄瓨鍌ㄨ繃绋�
         console.log(res)
         if (res === false || res === 'drop') return res
 
@@ -1163,17 +1239,22 @@
           return 'create'
         }
       }).then(res => {
+        // 鍒犻櫎瀛樺偍杩囩▼
         console.log(res)
         if (res === false || res === 'create') return res
 
         let _param = {
           func: 'sPC_TableData_InUpDe',
-          LText: DelText
+          LText: DelText,
+          TypeCharOne: 'proc' // 鍒犻櫎鎴栧垱寤哄瓨鍌ㄨ繃绋�
         }
+
         _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
         _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
-        return Api.getSystemConfig(_param)
+
+        return Api.getLocalConfig(_param)
       }).then(res => {
+        // 鏍规嵁涓婅堪鎿嶄綔缁撴灉锛屽垽鏂槸鍚︽柊寤哄瓨鍌ㄨ繃绋�
         console.log(res)
         if (res === false || res === 'create') return res
 
@@ -1188,18 +1269,21 @@
           return 'create'
         }
       }).then(res => {
+        // 鏂板缓瀛樺偍杩囩▼
         console.log(res)
         if (res === false) return res
 
         let _param = {
           func: 'sPC_TableData_InUpDe',
-          LText: LText
+          LText: newLText,
+          TypeCharOne: 'proc' // 鍒犻櫎鎴栧垱寤哄瓨鍌ㄨ繃绋�
         }
         _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
         _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
 
-        return Api.getSystemConfig(_param)
+        return Api.getLocalConfig(_param)
       }).then(res => {
+        // 澶勭悊鏂板缓缁撴灉
         console.log(res)
         if (res === false) return res
 
@@ -1219,8 +1303,14 @@
           return true
         }
       }).then(res => {
+        // 鏂板缓鎴愬姛鍚庯紝鏇存柊椤甸潰鎸夐挳淇℃伅
         console.log(res)
-        if (res === false) return res
+        if (res === false) {
+          this.setState({
+            funcLoading: false
+          })
+          return
+        }
 
         let isupdate = false
         _config.action = _config.action.map(item => {
@@ -1263,7 +1353,8 @@
 
         this.setState({
           config: _config,
-          actionloading: true
+          actionloading: true,
+          funcLoading: false
         }, () => {
           this.setState({
             actionloading: false
@@ -2177,7 +2268,7 @@
           onOk={this.handleSubmit}
           footer={[
             this.state.formtemp === 'action' ?
-            <Button key="delete" className="mk-btn mk-purple" onClick={this.creatFunc} loading={this.state.confirmLoading}>{this.state.dict['header.menu.func.create']}</Button> : null,
+            <Button key="delete" className="mk-btn mk-purple" onClick={this.creatFunc} loading={this.state.funcLoading}>{this.state.dict['header.menu.func.create']}</Button> : null,
             <Button key="cancel" onClick={() => { this.setState({ visible: false }) }}>{this.state.dict['header.cancel']}</Button>,
             <Button key="confirm" type="primary" onClick={this.handleSubmit}>{this.state.dict['header.confirm']}</Button>
           ]}
@@ -2287,4 +2378,14 @@
   }
 }
 
-export default ComTableConfig
\ No newline at end of file
+const mapStateToProps = (state) => {
+  return {
+    permFuncField: state.permFuncField
+  }
+}
+
+const mapDispatchToProps = () => {
+  return {}
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(ComTableConfig)

--
Gitblit v1.8.0