From 95afd40fc2741ac0ce59c2091f6cfce1f98877d4 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 24 六月 2021 09:15:45 +0800
Subject: [PATCH] 2021-06-24

---
 src/utils/utils.js |  107 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 95 insertions(+), 12 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index d0a9b07..2687da4 100644
--- a/src/utils/utils.js
+++ b/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) { // 琛ㄥ崟涓病鏈塨id鍒欎娇鐢ㄧ郴缁焍id鍙橀噺
           _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 {

--
Gitblit v1.8.0