From b7e71fefa5fc506831882d3fbe2d42aea67b7edf Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 13 五月 2025 16:34:37 +0800
Subject: [PATCH] 2025-05-13

---
 src/tabviews/zshare/topSearch/index.jsx |  259 ++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 200 insertions(+), 59 deletions(-)

diff --git a/src/tabviews/zshare/topSearch/index.jsx b/src/tabviews/zshare/topSearch/index.jsx
index 4929607..06cddd2 100644
--- a/src/tabviews/zshare/topSearch/index.jsx
+++ b/src/tabviews/zshare/topSearch/index.jsx
@@ -48,13 +48,31 @@
     let fieldMap = new Map()
     let mainItems = []  // 浜戠鎴栧崟鐐规暟鎹�
     let localItems = [] // 鏈湴鏁版嵁
+    let backMItems = [] // 浜戠鎴栧崟鐐规暟鎹�
+    let backLItems = [] // 鏈湴鏁版嵁
     let deForms = []    // 娴嬭瘯绯荤粺锛屽崟涓姹�
     let advanceValues = []
     let linkFields = {}
     let record = {}
     let forbid = false // header涓笉璁剧疆楂樼骇鎼滅储
-    let _setting = {showAdv: false, show: false, style: null}
+    let _setting = {showAdv: false, show: false, style: null, $pageId: config.$pageId || ''}
     let BID = this.props.BID
+    let sysvals = {}
+
+    if (window.backend) {
+      sysvals = {
+        mk_departmentcode: sessionStorage.getItem('departmentcode') || '',
+        mk_organization: sessionStorage.getItem('organization') || '',
+        mk_user_type: sessionStorage.getItem('mk_user_type') || '',
+        bid: BID || '',
+        datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+        datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+        datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+      }
+      if (window.GLOB.externalDatabase !== null) {
+        sysvals.db = window.GLOB.externalDatabase
+      }
+    }
     
     if (config.wrap) {
       _setting.show = config.wrap.show !== 'false'
@@ -67,7 +85,7 @@
       _setting.wrapperCol = {style: {width: (100 - _setting.labelwidth) + '%'}}
       _setting.borderRadius = config.wrap.borderRadius
       _setting.resetContrl = config.wrap.resetContrl || 'init'
-      _setting.size = config.wrap.searchSize || ''
+      _setting.order = config.wrap.searchSize || ''
 
       if (config.wrap.searchBtn === 'show') {
         _setting.showBtn = true
@@ -152,6 +170,10 @@
               item.initval = [moment(d).startOf('month').format(item.format), moment(d).endOf('month').format(item.format)].join(',')
             } else if (item.$initval === 'lastMonth') {
               item.initval = [moment(d).subtract(1, 'months').startOf('month').format(item.format), moment(d).subtract(1, 'months').endOf('month').format(item.format)].join(',')
+            } else if (item.$initval === 'year') {
+              item.initval = [moment(d).startOf('year').format(item.format), moment(d).endOf('year').format(item.format)].join(',')
+            } else if (item.$initval === 'lastYear') {
+              item.initval = [moment(d).subtract(1, 'years').startOf('year').format(item.format), moment(d).subtract(1, 'years').endOf('year').format(item.format)].join(',')
             } else {
               try {
                 let _initval = JSON.parse(item.$initval)
@@ -164,6 +186,7 @@
           } else {
             item.initval = moment(d).subtract(item.$initval, 'month').format('YYYY-MM')
           }
+          item.oriInitval = item.initval
         }
       }
 
@@ -188,43 +211,77 @@
 
         // 鏁版嵁婧愭煡璇㈣鍙�
         if (item.resourceType === '1' && item.dataSource) {
-          let _option = Utils.getSelectQueryOptions(item)
-          let _declare = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)  select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n`
+          if (window.backend && window.GLOB.CacheData.has('sql_' + item.uuid)) {
+            let ex = window.GLOB.CacheData.get('sql_' + item.uuid)
+            let exps = []
 
-          let exec = true
-          if (item.checkBid) {
-            item.sql = _declare + _option.sql
-            item.arr_field = _option.field
+            ex.reps.forEach(n => {
+              let key = n.toLowerCase()
+              if (sysvals.hasOwnProperty(key)) {
+                exps.push({
+                  key: n,
+                  value: sysvals[key]
+                })
+              }
+            })
 
-            exec = !!BID
-          }
+            let cell = {
+              id: ex.id,
+              exps: exps,
+              menuname: item.label + '锛堟悳绱級',
+              md5_id: ''
+            }
+            if (item.checkBid) {
+              item.sqlId = ex.id
+              item.exps = exps
+            }
 
-          if (exec) {
-            let _sql = _option.sql.replace(/@BID@/ig, `'${BID || ''}'`)
+            if (item.checkBid && !BID) {
+
+            } else if (item.database === 'sso' && window.GLOB.mainSystemApi) {
+              backMItems.push(cell)
+            } else {
+              backLItems.push(cell)
+            }
+          } else {
+            let _option = Utils.getSelectQueryOptions(item)
+            let _declare = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)  select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n`
   
-            if (window.GLOB.debugger === true) {
-              console.info(_declare + _sql)
+            let exec = true
+            if (item.checkBid) {
+              item.sql = _declare + _option.sql
+              item.arr_field = _option.field
+  
+              exec = !!BID
             }
   
-            // 娴嬭瘯绯荤粺鍗曚釜璇锋眰
-            if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && !window.GLOB.systemType) {
-              deForms.push({
-                ...item,
-                arr_field: _option.field,
-                data_sql: Utils.formatOptions(_declare + _sql, window.GLOB.execType)
-              })
-            } else { // 鍚堝苟璇锋眰锛屽尯鍒嗘湰鍦板強绯荤粺
-              _sql = _sql.replace(/%/ig, ' mpercent ')
-              if (item.database === 'sso' && (window.GLOB.mkHS || window.GLOB.systemType === 'production')) {
-                if (mainItems.length === 0) {
-                  _sql = _declare + _sql
+            if (exec) {
+              let _sql = _option.sql.replace(/@BID@/ig, `'${BID || ''}'`)
+    
+              if (window.GLOB.debugger === true) {
+                window.mkInfo(_declare + _sql)
+              }
+    
+              // 娴嬭瘯绯荤粺鍗曚釜璇锋眰
+              if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && !window.GLOB.systemType) {
+                deForms.push({
+                  ...item,
+                  arr_field: _option.field,
+                  data_sql: Utils.formatOptions(_declare + _sql, window.GLOB.execType)
+                })
+              } else { // 鍚堝苟璇锋眰锛屽尯鍒嗘湰鍦板強绯荤粺
+                _sql = _sql.replace(/%/ig, ' mpercent ')
+                if (item.database === 'sso') {
+                  if (mainItems.length === 0) {
+                    _sql = _declare + _sql
+                  }
+                  mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
+                } else {
+                  if (localItems.length === 0) {
+                    _sql = _declare + _sql
+                  }
+                  localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
                 }
-                mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
-              } else {
-                if (localItems.length === 0) {
-                  _sql = _declare + _sql
-                }
-                localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
               }
             }
           }
@@ -296,7 +353,9 @@
       advanceValues,
       searchlist: _list
     }, () => {
-      if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') {
+      if (window.backend && (backMItems.length > 0 || backLItems.length > 0)) {
+        this.improveBackSearch(backMItems, backLItems, false)
+      } else if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') {
         this.improveSimpleSearch(deForms, false, null, BID)
       } else if (mainItems.length > 0 || localItems.length > 0) {
         this.improveSearch(mainItems, localItems, BID)
@@ -322,7 +381,7 @@
   UNSAFE_componentWillReceiveProps(nextProps) {
     const { config, BID } = this.props
 
-    if (config.checkBid && config.type !== 'search' && nextProps.BID !== BID) {
+    if (config.$checkBid && nextProps.BID !== BID) {
       this.resetOptions(nextProps.BID)
     }
   }
@@ -337,19 +396,41 @@
 
   resetOptions = (BID) => {
     let deForms = []
+    let backMItems = [] // 浜戠鎴栧崟鐐规暟鎹�
+    let backLItems = [] // 鏈湴鏁版嵁
     let searchlist = fromJS(this.state.searchlist).toJS().map(item => {
       if (item.checkBid) {
-        let sql = item.sql.replace(/@BID@/ig, `'${BID || ''}'`)
-  
-        if (window.GLOB.debugger === true) {
-          console.info(sql)
-        }
+        if (window.backend && item.sqlId) {
+          let cell = {
+            id: item.sqlId,
+            menuname: item.label + '锛堟悳绱級',
+            md5_id: '',
+            exps: item.exps.map(n => {
+              if (n.key === 'BID') {
+                n.value = BID
+              }
+              return n
+            })
+          }
 
-        deForms.push({
-          ...item,
-          arr_field: item.arr_field,
-          data_sql: Utils.formatOptions(sql, window.GLOB.execType)
-        })
+          if (item.database === 'sso' && window.GLOB.mainSystemApi) {
+            backMItems.push(cell)
+          } else {
+            backLItems.push(cell)
+          }
+        } else {
+          let sql = item.sql.replace(/@BID@/ig, `'${BID || ''}'`)
+    
+          if (window.GLOB.debugger === true) {
+            window.mkInfo(sql)
+          }
+  
+          deForms.push({
+            ...item,
+            arr_field: item.arr_field,
+            data_sql: Utils.formatOptions(sql, window.GLOB.execType)
+          })
+        }
       } else if (item.checkShift) {
         let d = ''
         if (window.GLOB.CacheData.has(item.$supId)) {
@@ -369,6 +450,10 @@
               item.initval = [moment(d).startOf('month').format(item.format), moment(d).endOf('month').format(item.format)].join(',')
             } else if (item.$initval === 'lastMonth') {
               item.initval = [moment(d).subtract(1, 'months').startOf('month').format(item.format), moment(d).subtract(1, 'months').endOf('month').format(item.format)].join(',')
+            } else if (item.$initval === 'year') {
+              item.initval = [moment(d).startOf('year').format(item.format), moment(d).endOf('year').format(item.format)].join(',')
+            } else if (item.$initval === 'lastYear') {
+              item.initval = [moment(d).subtract(1, 'years').startOf('year').format(item.format), moment(d).subtract(1, 'years').endOf('year').format(item.format)].join(',')
             } else {
               try {
                 let _initval = JSON.parse(item.$initval)
@@ -381,13 +466,16 @@
           } else {
             item.initval = moment(d).subtract(item.$initval, 'month').format('YYYY-MM')
           }
+          item.oriInitval = item.initval
         }
       }
 
       return item
     })
 
-    if (deForms.length > 0) {
+    if (window.backend && (backMItems.length > 0 || backLItems.length > 0)) {
+      this.improveBackSearch(backMItems, backLItems, true, searchlist)
+    } else if (deForms.length > 0) {
       this.improveSimpleSearch(deForms, true, searchlist, BID)
     } else {
       this.setState({
@@ -465,7 +553,7 @@
       deffers.push(
         new Promise(resolve => {
           Api.getSystemCacheConfig(param).then(res => {
-            if (!res.status) {
+            if (!res.status && res.ErrCode !== '-2') {
               notification.warning({
                 top: 92,
                 message: res.message,
@@ -510,7 +598,7 @@
       deffers.push(
         new Promise(resolve => {
           Api.getSystemCacheConfig(mainparam).then(res => {
-            if (!res.status) {
+            if (!res.status && res.ErrCode !== '-2') {
               notification.warning({
                 top: 92,
                 message: res.message,
@@ -532,6 +620,54 @@
       delete result.status
 
       this.resetSearch(result, false)
+    })
+  }
+
+  // 鏌ヨ涓嬫媺鑿滃崟
+  improveBackSearch = (mainItems, localItems, trigger, searchlist) => {
+    let deffers = []
+    
+    if (localItems.length) {
+      deffers.push({
+        $backend: true,
+        $type: 's_Get_SelectedList',
+        data: localItems
+      })
+    }
+
+    if (mainItems.length) {
+      deffers.push({
+        $backend: true,
+        $type: 's_Get_SelectedList',
+        data: mainItems,
+        rduri: window.GLOB.mainSystemApi
+      })
+    }
+
+    deffers = deffers.map(item => {
+      return new Promise(resolve => {
+        Api.getSystemCacheConfig(item).then(res => {
+          if (!res.status && res.ErrCode !== '-2') {
+            notification.warning({
+              top: 92,
+              message: res.message,
+              duration: 5
+            })
+          }
+          resolve(res)
+        })
+      })
+    })
+
+    Promise.all(deffers).then(response => {
+      let result = {...response[0], ...(response[1] || {})}
+
+      delete result.ErrCode
+      delete result.ErrMesg
+      delete result.message
+      delete result.status
+
+      this.resetSearch(result, trigger, searchlist)
     })
   }
 
@@ -558,7 +694,7 @@
       param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
       param.secretkey = Utils.encrypt(window.GLOB.execType === 'x' ? '' : param.LText, param.timestamp)
 
-      if (item.database === 'sso' && window.GLOB.mainSystemApi && (window.GLOB.mkHS || window.GLOB.systemType === 'production')) {
+      if (item.database === 'sso' && window.GLOB.mainSystemApi) {
         param.rduri = window.GLOB.mainSystemApi
       }
 
@@ -566,7 +702,7 @@
         new Promise(resolve => {
           setTimeout(() => {
             Api.getSystemCacheConfig(param).then(res => {
-              if (!res.status) {
+              if (!res.status && res.ErrCode !== '-2') {
                 notification.warning({
                   top: 92,
                   message: res.message,
@@ -730,7 +866,7 @@
       const _rules = [
         {
           required: item.required,
-          message: item.label + '涓嶅彲涓虹┖!'
+          message: item.label + (window.GLOB.dict['not_empty'] || '涓嶅彲涓虹┖锛�')
         }
       ]
 
@@ -791,13 +927,13 @@
             wrapperCol={setting.wrapperCol}
           >
             {setting.show ? <Button style={style} type="primary" onClick={this.handleSubmit}>
-              鎼滅储
+              {window.GLOB.dict['search'] || '鎼滅储'}
             </Button> : null}
             {setting.show ? <Button style={{ marginLeft: 8, ...style }} onClick={this.handleReset}>
-              閲嶇疆
+              {window.GLOB.dict['reset'] || '閲嶇疆'}
             </Button> : null}
             {setting.showAdv ? <Button className={visible ? 'visible' : ''} type="link" onClick={this.handleAdvance}>
-              楂樼骇{setting.advanceType === 'pulldown' ? <DownOutlined /> : null}
+              {window.GLOB.dict['senior'] || '楂樼骇'}{setting.advanceType === 'pulldown' ? <DownOutlined /> : null}
             </Button> : null}
           </Form.Item>
         </Col>
@@ -807,7 +943,7 @@
         <Col className="mk-search-col search-button" key="actions">
           <Form.Item>
             <Button type="primary" onClick={this.handleSubmit}>
-              鎼滅储
+              {window.GLOB.dict['search'] || '鎼滅储'}
             </Button>
           </Form.Item>
         </Col>
@@ -893,7 +1029,7 @@
       
             notification.warning({
               top: 92,
-              message: '璇疯緭鍏�' + labels.join('銆�') + ' !',
+              message: (window.GLOB.dict['input_tip'] || '璇疯緭鍏�') + labels.join('銆�') + ' !',
               duration: 3
             })
             return
@@ -933,6 +1069,11 @@
    */
   handleReset = () => {
     const { setting } = this.state
+
+    if (setting.resetContrl === 'refresh') {
+      MKEmitter.emit('reloadMenuView', setting.$pageId, true)
+      return
+    }
 
     let record = {}
     let advanceValues = []
@@ -1049,7 +1190,7 @@
         }
 
         if (typeof(val) === 'string') {
-          val = val.replace(/(^\s*|\s*$)/ig, '')
+          val = val.replace(/(^\s+|\s+$)/ig, '').replace(/\t+|\v+/g, '')
         }
 
         search.push({
@@ -1125,7 +1266,7 @@
 
     return (
       <>
-        <Form {...formItemLayout} className={`mk-search-wrap mk-float-${setting.float} mk-size-${setting.size}`} style={setting.style}>
+        <Form {...formItemLayout} className={`mk-search-wrap mk-float-${setting.float} mk-order-${setting.order || 'none'}`} style={setting.style}>
           <Row gutter={24}>{this.getFields()}</Row>
           {advanceValues.length && (setting.advanceType !== 'pulldown' || (setting.advanceType === 'pulldown' && !visible)) ? <Row gutter={24}>
             <div className="advanced-list">
@@ -1141,7 +1282,7 @@
           </Row> : null}
         </Form>
         {setting.advanceType === 'modal' ? <Modal
-          title="楂樼骇鎼滅储"
+          title={window.GLOB.dict['adv_search'] || '楂樼骇鎼滅储'}
           maskClosable={false}
           visible={visible}
           width={setting.advWidth}
@@ -1157,7 +1298,7 @@
           />
         </Modal> : null}
         {setting.advanceType === 'drawer' ? <Drawer
-          title="楂樼骇鎼滅储"
+          title={window.GLOB.dict['adv_search'] || '楂樼骇鎼滅储'}
           className="mk-search-drawer"
           width={setting.advWidth}
           height={setting.advHeight}

--
Gitblit v1.8.0