From 5cfe6db94c1449810a44660b299dba8e7e98e5c5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 10 六月 2021 14:43:39 +0800
Subject: [PATCH] 2021-06-10

---
 src/utils/utils.js |  100 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 90 insertions(+), 10 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index d0a9b07..891d2fd 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -1057,13 +1057,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
@@ -1290,14 +1291,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 +1475,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 +1598,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 +1754,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