king
2021-06-24 95afd40fc2741ac0ce59c2091f6cfce1f98877d4
src/utils/utils.js
@@ -702,7 +702,10 @@
      arrfield.push(...item.linkSubField)
    } else if (item.type === 'checkcard') {
      arrfield = item.fields.map(f => f.field)
      arrfield.push(item.valueField)
      arrfield.push(item.cardValField)
      if (item.urlField) {
        arrfield.push(item.urlField)
      }
    }
    arrfield = Array.from(new Set(arrfield))
@@ -1057,13 +1060,14 @@
 * @return {Object}  tab       标签信息
 * @return {Boolean} retmsg    是否需要数据返回
 */
export function getSysDefaultSql (btn, setting, formdata, param, data, columns, tab, retmsg = false) {
export function getSysDefaultSql (btn, setting, formdata, param, data, columns, tab, retmsg = false, moduleParams, getOptions) {
  let primaryId = param.ID
  let BID = param.BID
  let verify = btn.verify || {}
  let datavars = {}                 // 声明的变量,表单及显示列
  let _actionType = null
  let _callbacksql = ''
  let foreignKey = tab && tab.foreignKey ? tab.foreignKey.toLowerCase() : ''
  if (verify.default !== 'false') { // 判断是否使用默认sql
    _actionType = btn.sqlType
@@ -1156,7 +1160,7 @@
  }
  // 添加数据中字段,表单值优先(按钮不选行或多行拼接时跳过)
  if (data && btn.Ot !== 'notRequired' && btn.Ot !== 'requiredOnce') {
  if (data && !btn.$forbid && btn.Ot !== 'notRequired' && btn.Ot !== 'requiredOnce') {
    datavars = {...data, ...datavars}
    const setField = (col) => {
@@ -1290,14 +1294,53 @@
  // 失效验证,添加数据时不用
  if (btn.sqlType !== 'insert' && btn.Ot !== 'notRequired' && verify.invalid === 'true' && setting.dataresource) {
    let datasource = setting.dataresource
    let customScript = setting.customScript || ''
    let search = moduleParams ? moduleParams.search : null
    let orderBy = moduleParams ? moduleParams.orderBy : setting.order
    if (/\s/.test(datasource) && !/tb$/.test(datasource)) { // 拼接别名
      datasource = '(' + datasource + ') tb'
    }
    if (setting.customScript) {
    if (getOptions && (setting.queryType === 'statistics' || customScript)) {
      let allSearch = getOptions(search)
      let regoptions = allSearch.map(item => {
        return {
          reg: new RegExp('@' + item.key + '@', 'ig'),
          value: `'${item.value}'`
        }
      })
      regoptions.push({
        reg: new RegExp('@login_city@', 'ig'),
        value: `'${city}'`
      }, {
        reg: new RegExp('@userName@', 'ig'),
        value: `'${userName}'`
      }, {
        reg: new RegExp('@fullName@', 'ig'),
        value: `'${fullName}'`
      }, {
        reg: new RegExp('@orderBy@', 'ig'),
        value: orderBy
      }, {
        reg: new RegExp('@pageSize@', 'ig'),
        value: 999999
      }, {
        reg: new RegExp('@pageIndex@', 'ig'),
        value: 1
      })
      regoptions.forEach(item => {
        datasource = datasource.replace(item.reg, item.value)
        customScript = customScript.replace(item.reg, item.value)
      })
    }
    if (customScript) {
      _sql += `
      /* 数据源自定义脚本,请注意变量定义是否重复 */
      ${setting.customScript}
      ${customScript}
      `
    }
@@ -1435,9 +1478,9 @@
        if (_key === 'bid' && !datavars.bid) { // 表单中没有bid则使用系统bid变量
          _fval = '@BID@'
        }
        if (_key === 'bid' && tab && tab.foreignKey) {
          arr.push(tab.foreignKey.toLowerCase())
          _fieldValue.push(`${tab.foreignKey}=${_fval}`)
        if (_key === 'bid' && foreignKey) {
          arr.push(foreignKey)
          _fieldValue.push(`${foreignKey}=${_fval}`)
        } else {
          arr.push(_key)
          _fieldValue.push(`${_key}=${_fval}`)
@@ -1558,14 +1601,14 @@
      values.push('@fullname')
    }
    if (!keys.includes('bid')) {
      if (tab && tab.foreignKey && !keys.includes(tab.foreignKey.toLowerCase())) {
        keys.push(tab.foreignKey.toLowerCase())
      if (foreignKey && !keys.includes(foreignKey)) {
        keys.push(foreignKey)
      } else {
        keys.push('bid')
      }
      values.push('@BID@')
    } else if (tab && tab.foreignKey && !keys.includes(tab.foreignKey.toLowerCase())) {
      keys.push(tab.foreignKey.toLowerCase())
    } else if (foreignKey && !keys.includes(foreignKey)) {
      keys.push(foreignKey)
      values.push('@BID@')
    }
@@ -1714,6 +1757,46 @@
}
/**
 * @description 生成替换函数列表
 */
export function setGLOBFuncs () {
  window.GLOB.funcs = []
  if (!window.GLOB.WebSql && !window.GLOB.IndexDB) {
    return
  }
  if (window.GLOB.WebSql) {
    window.GLOB.WebSql.transaction(tx => {
      tx.executeSql("SELECT * FROM FUNCS", [], (tx, results) => {
        let rows = results.rows
        if (!rows || rows.length === 0) return
        for (let i = 0; i < rows.length; i++) {
          window.GLOB.funcs.push({
            func_code: rows[i].func_code,
            key_sql: window.decodeURIComponent(window.atob(rows[i].key_sql))
          })
        }
      })
    })
  } else {
    let objectStore = window.GLOB.IndexDB.transaction('funcs').objectStore('funcs')
    objectStore.openCursor().onsuccess = (event) => {
      let cursor = event.target.result
      if (cursor) {
        window.GLOB.funcs.push({
          func_code: cursor.value.func_code,
          key_sql: window.decodeURIComponent(window.atob(cursor.value.key_sql))
        })
        cursor.continue()
      }
    }
  }
}
/**
 * @description 创建存储过程类
 */
export class FuncUtils {