From 5ba94ec7b5ad34098ff9c5d21b4139b1b91c2865 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 29 五月 2020 18:24:11 +0800
Subject: [PATCH] 2020-05-29

---
 src/tabviews/zshare/mutilform/index.jsx |   74 +++++++++++++++++++++++++++++--------
 1 files changed, 58 insertions(+), 16 deletions(-)

diff --git a/src/tabviews/zshare/mutilform/index.jsx b/src/tabviews/zshare/mutilform/index.jsx
index 6e9cfa0..5e8fa89 100644
--- a/src/tabviews/zshare/mutilform/index.jsx
+++ b/src/tabviews/zshare/mutilform/index.jsx
@@ -27,6 +27,8 @@
     readin: null,
     fieldlen: null,
     formlist: [],
+    encrypts: [],    // 鍔犲瘑瀛楁
+    intercepts: [],  // 鎴彇瀛楁
     record: {}
   }
 
@@ -53,6 +55,8 @@
     let readin = {}
     let fieldlen = {}
     let formlist = []
+    let encrypts = []
+    let intercepts = []
 
     if (action.groups.length > 0) {
       action.groups.forEach(group => {
@@ -75,6 +79,15 @@
     let _inputfields = formlist.filter(item => item.type === 'text' || item.type === 'number') // 鐢ㄤ簬杩囨护涓嬫媺鑿滃崟鍏宠仈琛ㄥ崟
 
     formlist = formlist.map(item => {
+      if (item.type === 'title') return item
+
+      if (item.type === 'textarea' && item.encryption === 'true') {
+        encrypts.push(item.field)
+      }
+      if (item.interception === 'true') {
+        intercepts.push(item.field)
+      }
+
       let _readin = item.readin !== 'false'
       if (item.type === 'linkMain' || item.type === 'funcvar') {
         _readin = false
@@ -115,10 +128,23 @@
         }
       }
 
+      let newval = '$$initval$$'
       if (item.type === 'linkMain' && BData && BData.hasOwnProperty(item.field)) {
-        item.initval = BData[item.field]
+        newval = BData[item.field]
       } else if (item.type !== 'linkMain' && _readin && !/^date/.test(item.type) && this.props.data && this.props.data.hasOwnProperty(item.field)) {
-        item.initval = this.props.data[item.field]
+        newval = this.props.data[item.field]
+      }
+
+      if (encrypts.includes(item.field) && newval !== '$$initval$$') {
+        try {
+          newval = window.decodeURIComponent(window.atob(newval))
+        } catch (e) {
+          console.warn(e)
+        }
+      }
+
+      if (newval !== '$$initval$$') {
+        item.initval = newval
       }
 
       if (item.supvalue) {
@@ -163,6 +189,8 @@
       datatype: datatype,
       readin: readin,
       fieldlen: fieldlen,
+      encrypts: encrypts,
+      intercepts: intercepts,
       formlist: formlist
     }, () => {
       if (action.setting && action.setting.focus) {
@@ -290,7 +318,6 @@
 
     formlist.forEach((item, index) => {
       // if ((!item.field && item.type !== 'title') || item.hidden === 'true') return
-
       // if (item.supField && !item.supvalue.includes(this.props.form.getFieldValue(item.supField))) return
 
       if (item.type === 'title') {
@@ -558,15 +585,7 @@
           </Col>
         )
       } else if (item.type === 'funcvar') {
-        // fields.push(
-        //   <Col span={24 / cols} key={index}>
-        //     <Form.Item label={item.label}>
-        //       {getFieldDecorator(item.field, {
-        //         initialValue: item.linkfield,
-        //       })(<Input placeholder="" autoComplete="off" disabled={item.readonly === 'true'} />)}
-        //     </Form.Item>
-        //   </Col>
-        // )
+        // 鍑芥暟鍙橀噺瀛楁锛岄粯璁や笉鏄剧ず
       } else if (item.type === 'textarea') {
         let _max = item.fieldlength || 512
         let _labelcol = cols !== 3 ? 8 / cols : 3
@@ -601,7 +620,9 @@
   }
 
   handleConfirm = () => {
-    const { record } = this.state
+    const { record, encrypts, intercepts } = this.state
+
+    let _encrypts = JSON.parse(JSON.stringify(encrypts))
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     return new Promise((resolve, reject) => {
       this.props.form.validateFieldsAndScroll((err, values) => {
@@ -624,7 +645,9 @@
               let _val = item.initval
               if (record.hasOwnProperty(item.field)) {
                 _val = record[item.field]
+                _encrypts = _encrypts.filter(_field => _field !== item.field)
               }
+              
               search.push({
                 type: this.state.datatype[item.field],
                 readonly: this.state.readtype[item.field],
@@ -640,7 +663,7 @@
                 readin: this.state.readin[item.field],
                 fieldlen: this.state.fieldlen[item.field],
                 key: item.field,
-                value: item.initVal
+                value: item.initval
               })
             }
           })
@@ -679,9 +702,12 @@
               }
 
               _value = vals.join(',')
-            } else if (this.state.datatype[key] === 'text') {
-              _value = values[key].replace(/(^\s*|\s*$) | \t* | \v*/ig, '')
+            } else if (this.state.datatype[key] === 'text' || this.state.datatype[key] === 'textarea') {
+              _value = values[key].replace(/\t*|\v*/g, '') // 鍘婚櫎鍒惰〃绗�
 
+              if (intercepts.includes(key)) {              // 鍘婚櫎棣栧熬绌烘牸
+                _value = _value.replace(/(^\s*|\s*$)/g, '')
+              }
             } else {
               _value = values[key]
               
@@ -697,6 +723,22 @@
             })
           })
 
+          if (_encrypts && _encrypts.length > 0) {
+            search = search.map(item => {
+              let _value = item.value
+              if (_encrypts.includes(item.key)) {
+                try {
+                  _value = window.btoa(window.encodeURIComponent(_value))
+                } catch (e) {
+                  console.warn(e)
+                }
+              }
+              item.value = _value
+
+              return item
+            })
+          }
+
           resolve(search)
         } else {
           reject(err)

--
Gitblit v1.8.0