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 |  130 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 112 insertions(+), 18 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index 8d35665..2687da4 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -598,6 +598,10 @@
           key: search.datefield,
           value: '0'
         })
+        options.push({
+          key: search.datefield + '1',
+          value: '0'
+        })
         if (search.transfer === 'true') {
           options.push(item)
         }
@@ -698,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))
@@ -725,6 +732,11 @@
       sql = sql.replace(/@\$|\$@/ig, '')
     }
 
+    // 澶栬仈鏁版嵁搴撴浛鎹�
+    if (window.GLOB.externalDatabase !== null) {
+      sql = sql.replace(/@db@/ig, window.GLOB.externalDatabase)
+    }
+
     if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
       console.info(sql)
     }
@@ -748,6 +760,7 @@
   let keys = ['delete', 'drop', 'insert', 'truncate', 'update']
   let userName = sessionStorage.getItem('User_Name') || ''
   let fullName = sessionStorage.getItem('Full_Name') || ''
+  let city = sessionStorage.getItem('city') || ''
 
   if (sessionStorage.getItem('isEditState') === 'true') {
     userName = sessionStorage.getItem('CloudUserName') || ''
@@ -981,9 +994,9 @@
     _sql = `
       /* 绯荤粺鐢熸垚 */
       declare @${sheet} table (${declarefields.join(',')},jskey nvarchar(50),BID nvarchar(50) )
-      Declare @UserName nvarchar(50),@FullName nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@tbid Nvarchar(512)
+      Declare @UserName nvarchar(50),@FullName nvarchar(50),@login_city nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@tbid Nvarchar(512)
       
-      Select  @ErrorCode='', @retmsg='', @UserName='${userName}', @FullName='${fullName}'
+      Select  @ErrorCode='', @retmsg='', @UserName='${userName}', @FullName='${fullName}', @login_city='${city}'
       ${_initCustomScript}
       `
     _sqlInsert = `Insert into @${sheet} (${fields},jskey,BID)`
@@ -1016,9 +1029,9 @@
     _sql = `
       /* 绯荤粺鐢熸垚 */
       declare @${sheet} table (jskey nvarchar(50))
-      Declare @UserName nvarchar(50),@FullName nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@tbid Nvarchar(512)
+      Declare @UserName nvarchar(50),@FullName nvarchar(50),@login_city nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@tbid Nvarchar(512)
       
-      Select  @ErrorCode='', @retmsg='', @UserName='${userName}', @FullName='${fullName}'
+      Select  @ErrorCode='', @retmsg='', @UserName='${userName}', @FullName='${fullName}', @login_city='${city}'
       `
   }
 
@@ -1047,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
@@ -1146,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) => {
@@ -1203,7 +1217,7 @@
     _declarefields = ',' + _declarefields
   }
   _sql = `/* 绯荤粺鐢熸垚 */
-      Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50), @UserName nvarchar(50),@FullName nvarchar(50),@ModularDetailCode nvarchar(50)${_declarefields}
+      Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50), @UserName nvarchar(50),@FullName nvarchar(50),@login_city nvarchar(50),@ModularDetailCode nvarchar(50)${_declarefields}
     `
 
   // 琛ㄥ崟鍙橀噺璧嬪��
@@ -1237,6 +1251,7 @@
 
   let userName = sessionStorage.getItem('User_Name') || ''
   let fullName = sessionStorage.getItem('Full_Name') || ''
+  let city = sessionStorage.getItem('city') || ''
 
   if (sessionStorage.getItem('isEditState') === 'true') {
     userName = sessionStorage.getItem('CloudUserName') || ''
@@ -1246,7 +1261,7 @@
   // 鍒濆鍖栧嚟璇佸強鐢ㄦ埛淇℃伅瀛楁
   _sql += `
       /* 鍑瘉鍙婄敤鎴蜂俊鎭垵濮嬪寲璧嬪�� */
-      select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}', @BillCode='', @ModularDetailCode=''
+      select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}', @login_city='${city}', @BillCode='', @ModularDetailCode=''
       `
 
   if (retmsg) {
@@ -1279,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}
       `
     }
 
@@ -1424,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}`)
@@ -1547,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@')
     }
 
@@ -1703,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