king
2020-04-17 4f8ffec8fc4aa9918264a3b3b4952421d896f5eb
src/utils/utils.js
@@ -96,103 +96,40 @@
    let salt = 'minKe' // 盐值
    // 关键字转换规则
    let format = [{
      key: 'select',
      value: ' msltk '
    }, {
      key: 'from',
      value: ' mfrmk '
    }, {
      key: 'where',
      value: ' mwhrk '
    }, {
      key: 'order by',
      value: ' modbk '
    }, {
      key: 'asc',
      value: ' modack '
    }, {
      key: 'desc',
      value: ' moddesk '
    }, {
      key: 'top',
      value: ' mtpk '
    }, {
      key: 'like',
      value: ' mlkk '
    }, {
      key: 'not like',
      value: ' mnlkk '
    }, {
      key: 'between',
      value: ' mbtnk '
    }, {
      key: 'and',
      value: ' madk '
    }, {
      key: 'insert',
      value: ' mistk '
    }, {
      key: 'into',
      value: ' mitk '
    }, {
      key: 'update',
      value: ' muptk '
    }, {
      key: 'delete',
      value: ' mdelk '
    }, {
      key: 'begin',
      value: ' mbgink '
    }, {
      key: 'end',
      value: ' medk '
    }, {
      key: 'if',
      value: ' mefk '
    }, {
      key: 'while',
      value: ' mwilk '
    }, {
      key: 'create',
      value: ' mcrtk '
    }, {
      key: 'alter',
      value: ' matek '
    }, {
      key: 'len',
      value: ' mlnk '
    }, {
      key: 'left',
      value: ' mlftk '
    }, {
      key: 'right',
      value: ' mritk '
    }, {
      key: 'union',
      value: ' munok '
    }, {
      key: 'varchar',
      value: ' mvcrk '
    }, {
      key: 'getdate',
      value: ' mgtdtk '
    }, {
      key: 'TRY',
      value: ' mtryonek '
    }, {
      key: 'TRAN',
      value: ' mtrnk '
    }, {
      key: 'goto',
      value: ' mgtk '
    }, {
      key: 'set',
      value: ' mstk '
    }, {
      key: 'ROLLBACK',
      value: ' mrlbkk '
    }]
    let format = [
      { key: 'select', value: ' msltk ' },
      { key: 'from', value: ' mfrmk ' },
      { key: 'where', value: ' mwhrk ' },
      { key: 'order by', value: ' modbk ' },
      { key: 'asc', value: ' modack ' },
      { key: 'desc', value: ' moddesk ' },
      { key: 'top', value: ' mtpk ' },
      { key: 'like', value: ' mlkk ' },
      { key: 'not like', value: ' mnlkk ' },
      { key: 'between', value: ' mbtnk ' },
      { key: 'and', value: ' madk ' },
      { key: 'insert', value: ' mistk ' },
      { key: 'into', value: ' mitk ' },
      { key: 'update', value: ' muptk ' },
      { key: 'delete', value: ' mdelk ' },
      { key: 'begin', value: ' mbgink ' },
      { key: 'end', value: ' medk ' },
      { key: 'if', value: ' mefk ' },
      { key: 'while', value: ' mwilk ' },
      { key: 'create', value: ' mcrtk ' },
      { key: 'alter', value: ' matek ' },
      { key: 'len', value: ' mlnk ' },
      { key: 'left', value: ' mlftk ' },
      { key: 'right', value: ' mritk ' },
      { key: 'union', value: ' munok ' },
      { key: 'varchar', value: ' mvcrk ' },
      { key: 'getdate', value: ' mgtdtk ' },
      { key: 'TRY', value: ' mtryonek ' },
      { key: 'TRAN', value: ' mtrnk ' },
      { key: 'goto', value: ' mgtk ' },
      { key: 'set', value: ' mstk ' },
      { key: 'ROLLBACK', value: ' mrlbkk ' }
    ]
    if (!isUnFormat) { // 加密
      value = value.replace(/\n/ig, ' \n ')
@@ -536,8 +473,28 @@
    let _topline = btn.range || 0
    let upId = this.getuuid()
    if (btn.scripts && btn.scripts.length > 0) {
      btn.scripts = btn.scripts.filter(item => item.status !== 'false')
    let _initCustomScript = '' // 初始化脚本
    let _prevCustomScript = '' // 默认sql前执行脚本
    let _backCustomScript = '' // 默认sql后执行脚本
    if (btn.scripts) {
      btn.scripts.forEach(script => {
        if (script.status === 'false') return
        if (script.position === 'init') {
          _initCustomScript += `
          ${script.sql}
          `
        } else if (script.position === 'front') {
          _prevCustomScript += `
          ${script.sql}
          `
        } else {
          _backCustomScript += `
          ${script.sql}
          `
        }
      })
    }
    let _Ltext = data.map((item, lindex) => {
@@ -682,31 +639,19 @@
      let _insert = ''
      if (btn.scripts && btn.scripts.length > 0) {
        btn.scripts.forEach(script => {
          if (script.position !== 'front') return
          _insert += `
          ${script.sql}
          `
        })
      if (_prevCustomScript) {
        _insert += _prevCustomScript
      }
      if (btn.default !== 'false') {
        _insert = `
        _insert += `
        Insert into ${item.sheet} (${fields},createuserid,createuser,createstaff,bid) 
        Select ${fields},@userid@,@username,@fullname,@BID@ From @${item.sheet}
        `
      }
      if (btn.scripts && btn.scripts.length > 0) {
        btn.scripts.forEach(script => {
          if (script.position === 'front') return
          _insert += `
          ${script.sql}
          `
        })
      if (_backCustomScript) {
        _insert += _backCustomScript
      }
      _sql = `declare @${item.sheet} table (${declarefields.join(',')},jskey nvarchar(50) )
@@ -715,7 +660,7 @@
      Select  @ErrorCode='', @retmsg=''
      
      select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID@
      ${_initCustomScript}
      Insert into  @${item.sheet} (${fields},jskey)
      ${_Ltext}
      ${_uniquesql}
@@ -749,6 +694,30 @@
    if (verify.default !== 'false') { // 判断是否使用默认sql
      _actionType = btn.sqlType
    }
    let _initCustomScript = '' // 初始化脚本
    let _prevCustomScript = '' // 默认sql前执行脚本
    let _backCustomScript = '' // 默认sql后执行脚本
    if (verify.scripts) {
      verify.scripts.forEach(item => {
        if (item.status === 'false') return
        if (item.position === 'init') {
          _initCustomScript += `
          ${item.sql}
          `
        } else if (item.position === 'front') {
          _prevCustomScript += `
          ${item.sql}
          `
        } else {
          _backCustomScript += `
          ${item.sql}
          `
        }
      })
    }
    // 需要声明的变量集
@@ -872,9 +841,6 @@
    if (verify.billcodes) {
      verify.billcodes = verify.billcodes.filter(item => item.status !== 'false')
    }
    if (verify.scripts) {
      verify.scripts = verify.scripts.filter(item => item.status !== 'false')
    }
    let userName = sessionStorage.getItem('User_Name') || ''
    let fullName = sessionStorage.getItem('Full_Name') || ''
@@ -887,6 +853,10 @@
    // 初始化凭证及用户信息字段
    _sql += `select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}'
      `
    if (_initCustomScript) {
      _sql += _initCustomScript
    }
    // 启用账期验证
    if (verify.accountdate === 'true') {
@@ -1077,16 +1047,8 @@
      let values = []
      formdata.forEach(item => {
        if (item.type === 'funcvar') {
          keys.push(item.key.toLowerCase())
          values.push('@' + item.key)
        } else if (item.type === 'number') {
          keys.push(item.key.toLowerCase())
          values.push(item.value)
        } else {
          keys.push(item.key.toLowerCase())
          values.push('\'' + item.value + '\'')
        }
        keys.push(item.key.toLowerCase())
        values.push('@' + item.key)
      })
      if (!keys.includes(primaryKey.toLowerCase())) {
@@ -1129,18 +1091,7 @@
      formdata.forEach(item => {
        _arr.push(item.key.toLowerCase())
        if (item.type === 'funcvar') {
          if (_actionType === 'update') {
            _form.push(item.key + '=@' + item.key)
          } else if (_actionType === 'insertOrUpdate') { // 添加或修改时,函数变量添加表单数值
            _form.push(item.key + '=\'' + item.value + '\'')
          }
        } else if (item.type === 'number') {
          _form.push(item.key + '=' + item.value)
        } else {
          _form.push(item.key + '=\'' + item.value + '\'')
        }
        _form.push(item.key + '=@' + item.key)
      })
      if (!_arr.includes('modifydate')) {
@@ -1164,16 +1115,8 @@
      _updatesql = `update ${btn.sql} set ${_form} where ${primaryKey}=@${primaryKeyName};`
    }
    // 拼接自定义脚本
    if (verify.scripts && verify.scripts.length > 0) {
      let _scripts = ''
      verify.scripts.forEach(item => {
        if (item.position !== 'front') return
        _scripts += `
        ${item.sql}`
      })
      _sql += `${_scripts}`
    if (_prevCustomScript) {
      _sql += _prevCustomScript
    }
    // 添加、修改、逻辑删除、物理删除
@@ -1211,16 +1154,8 @@
      `
    }
    // 拼接自定义脚本
    if (verify.scripts && verify.scripts.length > 0) {
      let _scripts = ''
      verify.scripts.forEach(item => {
        if (item.position === 'front') return
        _scripts += `
        ${item.sql}`
      })
      _sql += `${_scripts}`
    if (_backCustomScript) {
      _sql += _backCustomScript
    }
    _sql += `