king
2019-12-11 a426c23b9bc90df787bc4d66718872f7c95c255a
src/utils/utils.js
@@ -1,4 +1,5 @@
import moment from 'moment'
import md5 from 'md5'
const service = window.GLOB.service ? (/\/$/.test(window.GLOB.service) ? window.GLOB.service : window.GLOB.service + '/') : ''
@@ -34,11 +35,24 @@
  }
  /**
   * @description md5加密
   * @return {String}  str         加密串
   * @return {String}  timestamp   时间戳
   */
  static encrypt (str, timestamp) {
    let salt = 'mingke' // 盐值
    return md5(str + salt + timestamp)
  }
  /**
   * @description sql加密
   * @return {String}  value
   */
  static formatOptions (value) {
    // 产生一个新的GUID值
    if (!value) return ''
    let salt = 'minKe' // 盐值
    // 关键字转换规则
    let format = [{
      key: 'select',
      value: ' msltk '
@@ -136,18 +150,18 @@
      key: 'ROLLBACK',
      value: ' mrlbkk '
    }]
    // 替换关键字
    format.forEach(item => {
      let reg  =  new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig')
      value = value.replace(reg, item.value)
    })
    // 1、替换%符(数据库中解析后sql报错),2、去除收尾多余空格
    value = value.replace(/%/ig, 'mpercent')
    value = value.replace(/(^\s|\s$)/ig, '')
    value = window.btoa(window.encodeURIComponent(value))
    let index = Math.floor(Math.random() * value.length)
    value = value.slice(0, index) + 'minKe' + value.slice(index)
    value = window.btoa(value)
    // value = value.replace(/%/ig, 'mpercent')
    //   .replace(/>/ig, 'greateror')
    // value = value.replace(/>/ig, 'greateror')
    //   .replace(/</ig, 'lessor')
    //   .replace(/!=/ig, 'noequal')
    //   .replace(/=/ig, 'equal')
@@ -160,6 +174,17 @@
    //   .replace(/\*/ig, 'mastrsk')
    //   .replace(/'/ig, 'mqotek')
    //   .replace(/\s/ig, 'mspace')
    // 1、encode编码(中文字符超出base64加密范围),2、base64加密
    value = window.btoa(window.encodeURIComponent(value))
    // 随机插入字符
    let index = Math.floor(Math.random() * value.length)
    value = value.slice(0, index) + salt + value.slice(index)
    // base64加密
    value = window.btoa(value)
    return value
  }