From 67036fb0ed31d77ca33b660ce5f9f47c29ae65c0 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 03 三月 2024 11:47:46 +0800
Subject: [PATCH] 2024-03-03

---
 src/utils/utils.js |  183 ++++++++++++++++++++++++---------------------
 1 files changed, 97 insertions(+), 86 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index f4dc5e3..a904374 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -1,6 +1,7 @@
 import React from 'react'
 import moment from 'moment'
 import md5 from 'md5'
+import CryptoJS from 'crypto-js'
 
 const formatKeys = [
   { key: 'select', value: ' msltk ' },
@@ -119,30 +120,45 @@
    * @description sql鍔犲瘑
    * @return {String}   value
    */
-  static formatOptions (value) {
+  static formatOptions (value, exec_type = '') {
     if (!value) return ''
 
-    let salt = 'minKe' // 鐩愬��
-
     value = value.replace(/\n/ig, ' \n ')
-    // 鏇挎崲鍏抽敭瀛�
-    formatKeys.forEach(item => {
-      let reg = new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig')
-      value = value.replace(reg, item.value)
-    })
-    // 鏇挎崲%绗︼紙鏁版嵁搴撲腑瑙f瀽鍚巗ql鎶ラ敊锛�
-    value = value.replace(/%/ig, ' mpercent ')
+
     // 澶栬仈鏁版嵁搴撴浛鎹�
     if (window.GLOB.externalDatabase !== null) {
       value = value.replace(/@db@/ig, window.GLOB.externalDatabase)
     }
-    // encode缂栫爜锛堜腑鏂囧瓧绗﹁秴鍑篵ase64鍔犲瘑鑼冨洿锛�
-    value = window.btoa(window.encodeURIComponent(value))
-    // 鎻掑叆瀛楃
-    let index = Math.floor(value.length / 2)
-    value = value.slice(0, index) + salt + value.slice(index)
-    // base64鍔犲瘑
-    value = window.btoa(value)
+
+    // 鏇挎崲%绗︼紙鏁版嵁搴撲腑瑙f瀽鍚巗ql鎶ラ敊锛�
+    value = value.replace(/%/ig, ' mpercent ')
+
+    if (exec_type === 'x') {
+      let key = CryptoJS.enc.Utf8.parse('D1185ED7B32568C9')
+      let iv = CryptoJS.enc.Utf8.parse('')
+      let srcs = CryptoJS.enc.Utf8.parse(value)
+
+      let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
+      value = encrypted.toString()
+
+      // let wordArray = CryptoJS.enc.Base64.parse(value)
+      // let decryptedWordArray = CryptoJS.AES.decrypt({ ciphertext: wordArray }, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
+      // let decryptedText = CryptoJS.enc.Utf8.stringify(decryptedWordArray)
+    } else {
+      // 鏇挎崲鍏抽敭瀛�
+      formatKeys.forEach(item => {
+        let reg = new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig')
+        value = value.replace(reg, item.value)
+      })
+      // encode缂栫爜锛堜腑鏂囧瓧绗﹁秴鍑篵ase64鍔犲瘑鑼冨洿锛�
+      value = window.btoa(window.encodeURIComponent(value))
+      // 鎻掑叆瀛楃
+      let salt = 'minKe' // 鐩愬��
+      let index = Math.floor(value.length / 2)
+      value = value.slice(0, index) + salt + value.slice(index)
+      // base64鍔犲瘑
+      value = window.btoa(value)
+    }
 
     return value
   }
@@ -169,59 +185,6 @@
 
   //   return value
   // }
-
-  /**
-   * @description sPC_TableData_InUpDe sql鍔犲瘑
-   * @return {String}  value
-   */
-  static sPCInUpDeFormatOptions (value) {
-    if (!value) return {LText: '', LText1: '', LText2: ''}
-    let salt = 'minKe' // 鐩愬��
-
-    value = value.replace(/\n/ig, ' \n ')
-    // 鏇挎崲鍏抽敭瀛�
-    formatKeys.forEach(item => {
-      let reg = new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig')
-      value = value.replace(reg, item.value)
-    })
-
-    // 1銆佹浛鎹�%绗︼紙鏁版嵁搴撲腑瑙f瀽鍚巗ql鎶ラ敊锛�
-    value = value.replace(/%/ig, ' mpercent ')
-    // 澶栬仈鏁版嵁搴撴浛鎹�
-    if (window.GLOB.externalDatabase !== null) {
-      value = value.replace(/@db@/ig, window.GLOB.externalDatabase)
-    }
-
-    let encodesql = (val) => {
-      if (!val) return ''
-
-      let _value = window.btoa(window.encodeURIComponent(val))
-
-      // 鎻掑叆瀛楃
-      let index = Math.floor(_value.length / 2)
-      _value = _value.slice(0, index) + salt + _value.slice(index)
-
-      // base64鍔犲瘑
-      return window.btoa(_value)
-    }
-
-    let len = value.length
-    // 娉細LText 涓� LText1 椤哄簭棰犲��
-    if (len > 1000) {
-      let limit = Math.floor(len / 3)
-      return {
-        LText1: encodesql(value.substring(0, limit)),
-        LText: encodesql(value.substring(limit, limit * 2)),
-        LText2: encodesql(value.substring(limit * 2))
-      }
-    } else {
-      return {
-        LText1: '',
-        LText: encodesql(value),
-        LText2: ''
-      }
-    }
-  }
 
   /**
    * @description 鍒濆鍖栨悳绱㈡潯浠跺垵濮嬪��
@@ -264,7 +227,38 @@
         item.initval = item.initval ? moment().subtract(item.initval, 'days').format(format) : ''
       } else if (item.type === 'datemonth') {
         item.format = 'YYYY-MM'
-        item.initval = item.initval ? moment().subtract(item.initval, 'month').format('YYYY-MM') : ''
+
+        if (item.initval) {
+          if (!item.dateShift) {
+            item.initval = moment().subtract(item.initval, 'month').format('YYYY-MM')
+          } else {
+            item.$initval = item.initval
+            item.$supId = config.$pageId
+            if (config.setting && config.setting.supModule) {
+              item.$supId = config.setting.supModule
+
+              config.checkBid = true
+              config.setting.checkBid = true
+              item.checkShift = true
+            }
+
+            item.initval = ''
+
+            let d = ''
+            if (window.GLOB.CacheData.has(item.$supId)) {
+              d = window.GLOB.CacheData.get(item.$supId)
+              d = d[item.dateShift] || ''
+              if (d) {
+                d = moment(d).format('YYYY-MM-DD')
+                d = d === 'Invalid date' ? '' : d
+              }
+            }
+
+            if (d) {
+              item.initval = moment(d).subtract(item.initval, 'month').format('YYYY-MM')
+            }
+          }
+        }
       } else if (item.type === 'dateweek') {
         item.format = 'YYYY-MM-DD'
         item.initval = item.initval ? moment().subtract(item.initval * 7, 'days').format('YYYY-MM-DD') : ''
@@ -304,11 +298,12 @@
             item.$supId = config.$pageId
             if (config.setting && config.setting.supModule) {
               item.$supId = config.setting.supModule
+
+              config.checkBid = true
+              config.setting.checkBid = true
+              item.checkShift = true
             }
 
-            config.checkBid = true
-            config.setting.checkBid = true
-            item.checkShift = true
             item.initval = ''
 
             let d = ''
@@ -543,6 +538,11 @@
           newsearches[item.key] = _startval
           newsearches[item.key + '1'] = _endval
         }
+      } else if (item.type === 'range') {
+        let val = item.value.split(',')
+
+        newsearches[item.key] = val[0] || -999999
+        newsearches[item.key + '1'] = val[1] || 999999
       } else if (item.type === 'dateweek') {
         let _startval = ''
         let _endval = ''
@@ -690,7 +690,7 @@
       } else if (item.type === 'range') {
         let val = item.value.split(',')
 
-        searchText.push('(' + item.key + ' >= \'' + val[0] + '\' AND ' + item.key + ' < \'' + val[1] + '\')')
+        searchText.push('(' + item.key + ' >= ' + (val[0] || -999999) + ' AND ' + item.key + ' < ' + (val[1] || 999999) + ')')
       } else {
         searchText.push('(' + item.key + ' ' + item.match + ' \'' + item.value + '\')')
       }
@@ -726,9 +726,9 @@
       if (item.type === 'date') {
         if (!item.value) {
           if (['>=', '>'].includes(item.match)) {
-            item.value = '1970-01-01 00:00:00.000'
+            item.value = '1900-01-01 00:00:00.000'
           } else if (['<=', '<'].includes(item.match)) {
-            item.value = '2050-01-01 00:00:00.000'
+            item.value = '3000-01-01 00:00:00.000'
           }
         } else if (search.precision === 'day') {
           if (['>=', '>'].includes(item.match)) {
@@ -749,8 +749,8 @@
         if (item.match === '=') {
           options.push(item)
         } else {
-          let _startval = item.value ? moment(item.value, 'YYYY-MM').startOf('month').format('YYYY-MM-DD') + ' 00:00:00.000' : '1970-01-01 00:00:00.000'
-          let _endval = item.value ? moment(item.value, 'YYYY-MM').endOf('month').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' : '2050-01-01 00:00:00.000'
+          let _startval = item.value ? moment(item.value, 'YYYY-MM').startOf('month').format('YYYY-MM-DD') + ' 00:00:00.000' : '1900-01-01 00:00:00.000'
+          let _endval = item.value ? moment(item.value, 'YYYY-MM').endOf('month').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' : '3000-01-01 00:00:00.000'
   
           let copy = JSON.parse(JSON.stringify(item))
           copy.key = copy.key + '1'
@@ -761,9 +761,20 @@
           options.push(item)
           options.push(copy)
         }
+      } else if (item.type === 'range') {
+        let val = item.value.split(',')
+
+        let copy = JSON.parse(JSON.stringify(item))
+        copy.key = copy.key + '1'
+        copy.value = val[1] || 999999
+        
+        item.value = val[0] || -999999
+
+        options.push(item)
+        options.push(copy)
       } else if (item.type === 'dateweek') {
-        let _startval = item.value ? moment(item.value, 'YYYY-MM-DD').startOf('week').format('YYYY-MM-DD') + ' 00:00:00.000' : '1970-01-01 00:00:00.000'
-        let _endval = item.value ? moment(item.value, 'YYYY-MM-DD').endOf('week').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' : '2050-01-01 00:00:00.000'
+        let _startval = item.value ? moment(item.value, 'YYYY-MM-DD').startOf('week').format('YYYY-MM-DD') + ' 00:00:00.000' : '1900-01-01 00:00:00.000'
+        let _endval = item.value ? moment(item.value, 'YYYY-MM-DD').endOf('week').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' : '3000-01-01 00:00:00.000'
 
         let copy = JSON.parse(JSON.stringify(item))
         copy.key = copy.key + '1'
@@ -774,8 +785,8 @@
         options.push(item)
         options.push(copy)
       } else if (item.type === 'daterange') {
-        let _startval = '1970-01-01 00:00:00.000'
-        let _endval = '2050-01-01 00:00:00.000'
+        let _startval = '1900-01-01 00:00:00.000'
+        let _endval = '3000-01-01 00:00:00.000'
 
         if (item.value) {
           let val = item.value.split(',')
@@ -1145,7 +1156,7 @@
       end
       
       ${unique.verifyType.indexOf('temp') === -1 ? `Set @tbid=''
-      Select top 1 @tbid=${_afields.join('+\' \'+')} from  #${sheet} a Inner join ${sheet} b on ${_fields_}
+      Select top 1 @tbid=${_afields.join('+\' \'+')} from  #${sheet} a Inner join ${database}${sheet} b on ${_fields_}
       
       If @tbid!=''
       Begin
@@ -1365,7 +1376,7 @@
       end
       
       ${unique.verifyType.indexOf('temp') === -1 ? `Set @tbid=''
-      Select top 1 @tbid=${_afields.join('+\' \'+')} from  #${sheet} a Inner join ${sheet} b on ${_fields_}
+      Select top 1 @tbid=${_afields.join('+\' \'+')} from  #${sheet} a Inner join ${database}${sheet} b on ${_fields_}
       
       If @tbid!=''
       Begin
@@ -2342,7 +2353,7 @@
       z_debug_end: select @ErrorCode='E',@retmsg='debug_end' goto aaa`
   }
 
-  if (retmsg) {
+  if (retmsg || btn.returnValue === 'true') {
     _sql += `
       aaa: if @ErrorCode!=''
       insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@`

--
Gitblit v1.8.0