From 9a1416e0b5cdb40f49b3c2061b04b35551d77e99 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 19 九月 2023 18:14:21 +0800
Subject: [PATCH] 2023-09-19

---
 src/utils/utils-custom.js |  226 +++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 183 insertions(+), 43 deletions(-)

diff --git a/src/utils/utils-custom.js b/src/utils/utils-custom.js
index edd4314..9ad1446 100644
--- a/src/utils/utils-custom.js
+++ b/src/utils/utils-custom.js
@@ -932,6 +932,178 @@
 }
 
 /**
+ * @description 鏍煎紡鍖栨悳绱㈡潯浠�
+ */
+export function formatSearch (searches) {
+  if (!searches) return []
+
+  let newsearches = []
+  searches.forEach(item => {
+    if (!item.field) return
+
+    if (item.type === 'group') {
+      newsearches.push({
+        key: item.field,
+        match: '',
+        type: item.type,
+        value: 'customized',
+        forbid: true
+      }, {
+        key: item.datefield,
+        match: 'between',
+        type: 'daterange',
+        value: '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000',
+        forbid: item.query === 'false'
+      })
+    } else {
+      let value = item.initval
+      let type = item.type
+
+      if (item.type === 'date') {
+        value = '1949-10-01 00:00:00.000'
+      } else if (item.type === 'datemonth') {
+        value = '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000'
+      } else if (item.type === 'dateweek') {
+        value = '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000'
+      } else if (item.type === 'daterange') {
+        value = '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000'
+      } else if (item.type === 'range') {
+        value = `${item.minValue},${item.maxValue}`
+      } else if (item.type === 'multiselect' || (item.type === 'checkcard' && item.multiple === 'true')) {
+        type = 'multi'
+        value = '0'
+      } else {
+        value = '0'
+      }
+      newsearches.push({
+        key: item.field,
+        match: item.match,
+        type: type,
+        value: value,
+        precision: item.precision || 'day',
+        forbid: item.query === 'false'
+      })
+    }
+  })
+
+  return newsearches
+}
+
+/**
+ * @description 鎷兼帴where鏉′欢
+ */
+export function joinMainSearchkey (searches) {
+  if (!searches || searches.length === 0) return ''
+
+  let searchText = []
+  searches.forEach(item => {
+    if (item.forbid) return
+    
+    if (item.type === 'text' || item.type === 'select') { // 缁煎悎鎼滅储锛屾枃鏈垨涓嬫媺锛屾墍鏈夊瓧娈垫嫾鎺�
+      let str = item.match === 'like' || item.match === 'not like' ? '%' : ''
+      let fields = item.key.split(',').map(field => {
+        return field + ' ' + item.match + ' \'' + str + item.value + str + '\''
+      })
+
+      searchText.push('(' + fields.join(' OR ') + ')')
+    } else if (item.type === 'checkcard') {
+      let str = item.match === 'like' || item.match === 'not like' ? '%' : ''
+
+      searchText.push('(' + item.key + ' ' + item.match + ' \'' + str + item.value + str + '\')')
+    } else if (item.type === 'multi') {
+      searchText.push(`('${item.value}' ${item.match} '%'+${item.key}+'%')`)
+    } else if (item.type === 'date') {
+      searchText.push('(' + item.key + ' ' + item.match + ' \'' + item.value + '\')')
+    } else if (item.type === 'datemonth' || item.type === 'dateweek' || item.type === 'range') {
+      let val = item.value.split(',')
+      searchText.push('(' + item.key + ' >= \'' + val[0] + '\' AND ' + item.key + ' < \'' + val[1] + '\')')
+    } else if (item.type === 'daterange') {
+      let val = item.value.split(',')
+
+      let _skey = item.key
+      let _ekey = item.key
+
+      if (/,/.test(item.key)) {
+        _skey = item.key.split(',')[0]
+        _ekey = item.key.split(',')[1]
+      }
+
+      searchText.push('(' + _skey + ' >= \'' + val[0] + '\' AND ' + _ekey + ' < \'' + val[1] + '\')')
+    } else {
+      searchText.push('(' + item.key + ' ' + item.match + ' \'' + item.value + '\')')
+    }
+  })
+
+  return searchText.join(' AND ')
+}
+
+/**
+ * @description 鑾峰彇鎼滅储姝e垯鏇挎崲
+ */
+export function getSearchRegs (searches) {
+  if (!searches) return []
+
+  let options = []
+  let fieldmap = new Map()
+  searches.forEach(item => {
+    if (item.type === 'date') {
+      if (fieldmap.has(item.key)) {
+        options.push({
+          reg: new RegExp('@' + item.key + '1@', 'ig'),
+          value: `'${item.value}'`
+        })
+      } else {
+        fieldmap.set(item.key, true)
+        options.push({
+          reg: new RegExp('@' + item.key + '@', 'ig'),
+          value: `'${item.value}'`
+        })
+      }
+    } else if (['dateweek', 'datemonth', 'range'].includes(item.type)) {
+      let val = item.value.split(',')
+      options.push({
+        reg: new RegExp('@' + item.key + '@', 'ig'),
+        value: `'${val[0]}'`
+      }, {
+        reg: new RegExp('@' + item.key + '1@', 'ig'),
+        value: `'${val[1]}'`
+      })
+    } else if (item.type === 'daterange') {
+      let val = item.value.split(',')
+      let _skey = item.key
+      let _ekey = item.key + '1'
+
+      if (/,/.test(item.key)) {
+        _skey = item.key.split(',')[0]
+        _ekey = item.key.split(',')[1]
+      }
+
+      options.push({
+        reg: new RegExp('@' + _skey + '@', 'ig'),
+        value: `'${val[0]}'`
+      }, {
+        reg: new RegExp('@' + _ekey + '@', 'ig'),
+        value: `'${val[1]}'`
+      })
+    } else if (item.type === 'text' || item.type === 'select') {
+      item.key.split(',').forEach(field => {
+        options.push({
+          reg: new RegExp('@' + field + '@', 'ig'),
+          value: `'${item.value}'`
+        })
+      })
+    } else {
+      options.push({
+        reg: new RegExp('@' + item.key + '@', 'ig'),
+        value: `'${item.value}'`
+      })
+    }
+  })
+
+  return options
+}
+
+/**
  * @description 閲嶇疆绉诲姩绔痵tyle
  * @return {Object}  style
  */
@@ -1227,50 +1399,16 @@
  * @description 鑾峰彇鎺ュ彛鍙婂嚱鏁�
  */
 export function getFuncsAndInters (config) {
-  let inters = []
-  // let funcs = []
+  let inters = 'false'
 
   let filterBtn = (cell) => {
-    if (cell.intertype === 'inner') {
-      // funcs.push(cell.innerFunc)
-    } else if (cell.intertype === 'outer' || cell.intertype === 'custom') {
-      // if (cell.innerFunc) {
-      //   funcs.push(cell.innerFunc)
-      // }
-      // if (cell.outerFunc) {
-      //   funcs.push(cell.outerFunc)
-      // }
-      if (cell.interface && cell.sysInterface !== 'true') {
-        inters.push(cell.interface)
-      }
-      if (cell.proInterface) {
-        inters.push(cell.proInterface)
-      }
-      // if (cell.callbackFunc) {
-      //   funcs.push(cell.callbackFunc)
-      // }
-    }
-  }
-
-  let filterSetting = (item) => {
-    if (!item.setting) return
-    if (item.setting.interType === 'inner') {
-      // funcs.push(item.setting.innerFunc)
-    } else if (item.setting.interType === 'outer') {
-      // if (item.setting.outerFunc) {
-      //   funcs.push(item.setting.outerFunc)
-      // }
-      if (item.setting.interface && item.setting.sysInterface !== 'true') {
-        inters.push(item.setting.interface)
-      }
-      if (item.setting.proInterface) {
-        inters.push(item.setting.proInterface)
-      }
+    if ((cell.intertype === 'outer' && cell.sysInterface !== 'true') || cell.intertype === 'custom') {
+      inters = 'true'
     }
   }
 
   let traversal = (components) => {
-    if (!components) return
+    if (!components || inters === 'true') return
 
     components.forEach(item => {
       if (item.type === 'tabs') {
@@ -1280,7 +1418,9 @@
       } else if (item.type === 'group') {
         traversal(item.components)
       } else {
-        filterSetting(item)
+        if (item.setting && item.setting.interType === 'outer' && item.setting.sysInterface !== 'true') {
+          inters = 'true'
+        }
 
         if (item.action) {
           item.action.forEach(cell => {
@@ -1363,15 +1503,15 @@
 
   if (config.interfaces) {
     config.interfaces.forEach(item => {
-      filterSetting(item)
+      if (item.setting && item.setting.interType === 'outer' && item.setting.sysInterface !== 'true') {
+        inters = 'true'
+      }
     })
   }
 
   traversal(config.components)
 
-  // inters = Array.from(new Set(inters))
-
-  return inters.length > 0 ? 'true' : 'false'
+  return inters
 }
 
 /**

--
Gitblit v1.8.0