king
2024-03-26 7da23c8a73681703f42c4c5a4c907dc17acf8b8f
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
  }
@@ -171,59 +187,6 @@
  // }
  /**
   * @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 初始化搜索条件初始值
   * @param {Array}   searches     搜索条件
   */
@@ -239,6 +202,13 @@
    let values = null
    if (config.wrap && config.wrap.cacheSearch === 'true') {
      values = window.GLOB.SearchBox.get(config.$searchId + 'cache')
    }
    let supModule = ''
    if (config.setting && config.setting.supModule) {
      supModule = config.setting.supModule
    } else if (config.wrap && config.wrap.supModule) {
      supModule = config.wrap.supModule
    }
    config.search = config.search.map(item => {
@@ -271,12 +241,14 @@
          } else {
            item.$initval = item.initval
            item.$supId = config.$pageId
            if (config.setting && config.setting.supModule) {
              item.$supId = config.setting.supModule
            if (supModule) {
              item.$supId = supModule
              config.checkBid = true
              config.setting.checkBid = true
              item.checkShift = true
              if (config.setting) {
                config.setting.checkBid = true
              }
            }
            item.initval = ''
@@ -333,12 +305,14 @@
          } else {
            item.$initval = item.initval
            item.$supId = config.$pageId
            if (config.setting && config.setting.supModule) {
              item.$supId = config.setting.supModule
            if (supModule) {
              item.$supId = supModule
              config.checkBid = true
              config.setting.checkBid = true
              item.checkShift = true
              if (config.setting) {
                config.setting.checkBid = true
              }
            }
            item.initval = ''
@@ -430,10 +404,12 @@
          item.initType = ''
        }
      } else if ((item.type === 'select' || item.type === 'link') && item.resourceType === '1') {
        if (/@BID@/ig.test(item.dataSource) && config.setting && config.setting.supModule) {
        if (/@BID@/ig.test(item.dataSource) && supModule) {
          config.checkBid = true
          config.setting.checkBid = true
          item.checkBid = true
          if (config.setting) {
            config.setting.checkBid = true
          }
        }
        if (item.initval === '$first') {
          item.initval = ''
@@ -575,6 +551,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 = ''
@@ -722,7 +703,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 + '\')')
      }
@@ -758,9 +739,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)) {
@@ -781,8 +762,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'
@@ -793,9 +774,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'
@@ -806,8 +798,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(',')
@@ -1177,7 +1169,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
@@ -1397,7 +1389,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
@@ -1657,6 +1649,14 @@
  _sql = `/* 系统生成 */
      Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50),@ModularDetailCode nvarchar(50), @UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20),@mk_nation nvarchar(50),@mk_province nvarchar(50),@mk_city nvarchar(50),@mk_district nvarchar(50),@mk_address nvarchar(100),@mk_deleted int,@bid nvarchar(50)${_declarefields}
    `
  if (btn.$process && verify.workFlow === 'true' && window.GLOB.UserCacheMap.has(btn.$flowId)) {
    _sql += `
      /* 工作流变量定义与赋值 */
      Declare @works_flow_code nvarchar(50),@works_flow_name nvarchar(50),@works_flow_param nvarchar(4000),@works_flow_detail_id nvarchar(50),@status int,@statusname nvarchar(50), @work_group nvarchar(50),@work_grade int, @start_type nvarchar(50),@check_type nvarchar(50),@notice_type nvarchar(50),@check_userids nvarchar(512),@notice_userids nvarchar(512)
      select @works_flow_code=@works_flow_code@,@works_flow_name=@works_flow_name@,@works_flow_param=@works_flow_param@,@works_flow_detail_id=@works_flow_detail_id@,@status=@status@,@statusname=@statusname@,@work_group=@work_group@,@work_grade=@work_grade@, @start_type=@start_type@,@check_type=@check_type@,@notice_type=@notice_type@,@check_userids=@check_userids@,@notice_userids=@notice_userids@
      `
  }
  let userName = sessionStorage.getItem('User_Name') || '' 
  let fullName = sessionStorage.getItem('Full_Name') || ''
@@ -2334,6 +2334,9 @@
        _sql = _sql.replace(/@check_userids@/ig, `''`)
        _sql = _sql.replace(/@notice_userids@/ig, `''`)
      }
    } else {
      _sql = _sql.replace(/@check_userids@/ig, `''`)
      _sql = _sql.replace(/@notice_userids@/ig, `''`)
    }
    _sql = _sql.replace(/@start_type@/ig, `'开始'`)