king
2024-02-05 130afe2d26891f9d4c2edbe980603c93f6fd0d5c
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)
    })
    // 替换%符(数据库中解析后sql报错)
    value = value.replace(/%/ig, ' mpercent ')
    // 外联数据库替换
    if (window.GLOB.externalDatabase !== null) {
      value = value.replace(/@db@/ig, window.GLOB.externalDatabase)
    }
    // encode编码(中文字符超出base64加密范围)
    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)
    // 替换%符(数据库中解析后sql报错)
    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编码(中文字符超出base64加密范围)
      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、替换%符(数据库中解析后sql报错)
    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 初始化搜索条件初始值
@@ -260,10 +223,44 @@
          format = 'YYYY-MM-DD HH:mm:ss'
        }
        item.format = format
        item.initval = item.initval ? moment().subtract(item.initval, 'days').format(format) : ''
      } else if (item.type === 'datemonth') {
        item.initval = item.initval ? moment().subtract(item.initval, 'month').format('YYYY-MM') : ''
        item.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') : ''
      } else if (item.type === 'daterange') {
        let format = 'YYYY-MM-DD'
@@ -276,19 +273,66 @@
        } else if (item.precision === 'second') {
          format = 'YYYY-MM-DD HH:mm:ss'
        }
        if (item.initval === 'week') {
          item.initval = [moment().startOf('week').format(format), moment().endOf('week').format(format)].join(',')
        } else if (item.initval === 'month') {
          item.initval = [moment().startOf('month').format(format), moment().endOf('month').format(format)].join(',')
        } else if (item.initval === 'lastMonth') {
          item.initval = [moment().subtract(1, 'months').startOf('month').format(format), moment().subtract(1, 'months').endOf('month').format(format)].join(',')
        } else if (item.initval) {
          try {
            let _initval = JSON.parse(item.initval)
            let _vals = [moment().subtract(_initval[0], 'days').format(format), moment().subtract(_initval[1], 'days').format(format)]
            item.initval = _vals.join(',')
          } catch (e) {
        item.format = format
        if (item.initval) {
          if (!item.dateShift) {
            if (item.initval === 'week') {
              item.initval = [moment().startOf('week').format(format), moment().endOf('week').format(format)].join(',')
            } else if (item.initval === 'month') {
              item.initval = [moment().startOf('month').format(format), moment().endOf('month').format(format)].join(',')
            } else if (item.initval === 'lastMonth') {
              item.initval = [moment().subtract(1, 'months').startOf('month').format(format), moment().subtract(1, 'months').endOf('month').format(format)].join(',')
            } else if (item.initval) {
              try {
                let _initval = JSON.parse(item.initval)
                let _vals = [moment().subtract(_initval[0], 'days').format(format), moment().subtract(_initval[1], 'days').format(format)]
                item.initval = _vals.join(',')
              } catch (e) {
                item.initval = ''
              }
            }
          } 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) {
              if (item.$initval === 'week') {
                item.initval = [moment(d).startOf('week').format(format), moment(d).endOf('week').format(format)].join(',')
              } else if (item.$initval === 'month') {
                item.initval = [moment(d).startOf('month').format(format), moment(d).endOf('month').format(format)].join(',')
              } else if (item.$initval === 'lastMonth') {
                item.initval = [moment(d).subtract(1, 'months').startOf('month').format(format), moment(d).subtract(1, 'months').endOf('month').format(format)].join(',')
              } else {
                try {
                  let _initval = JSON.parse(item.$initval)
                  let _vals = [moment(d).subtract(_initval[0], 'days').format(format), moment(d).subtract(_initval[1], 'days').format(format)]
                  item.initval = _vals.join(',')
                } catch (e) {
                  item.initval = ''
                }
              }
            }
          }
        }
      } else if (item.type === 'group') {
@@ -348,9 +392,16 @@
          item.initval = ''
          item.initType = ''
        }
      } else if ((item.type === 'select' || item.type === 'link') && item.initval === '$first' && item.resourceType === '1') {
        item.initval = ''
        item.$first = true
      } else if ((item.type === 'select' || item.type === 'link') && item.resourceType === '1') {
        if (/@BID@/ig.test(item.dataSource) && config.setting && config.setting.supModule) {
          config.checkBid = true
          config.setting.checkBid = true
          item.checkBid = true
        }
        if (item.initval === '$first') {
          item.initval = ''
          item.$first = true
        }
      }
      
      item.oriInitval = item.initval
@@ -2286,7 +2337,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@`