From a5bc394eceeaae5923057f1fd919968fd234af23 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 27 五月 2025 17:59:57 +0800
Subject: [PATCH] 2025-05-27

---
 src/utils/utils.js |   94 +++++++++++++++++++++++++++++++++++-----------
 1 files changed, 71 insertions(+), 23 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index 8f21c6f..d9502c6 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -192,8 +192,10 @@
    * @param {Array}   searches     鎼滅储鏉′欢
    */
   static initSearchVal (config) {
-    if (!config.search) {
+    if (!config.search || config.search.length === 0) {
       config.search = []
+      config.$s_keys = []
+      config.$s_req = false
       return
     }
 
@@ -247,9 +249,6 @@
 
               config.checkBid = true
               item.checkShift = true
-              if (config.setting) {
-                config.setting.checkBid = true
-              }
             }
 
             item.initval = ''
@@ -265,7 +264,7 @@
             }
 
             if (d) {
-              item.initval = moment(d).subtract(item.initval, 'month').format('YYYY-MM')
+              item.initval = moment(d).subtract(item.$initval, 'month').format('YYYY-MM')
             }
           }
         }
@@ -294,6 +293,10 @@
               item.initval = [moment().startOf('month').format(format), moment().endOf('month').format(format)].join(',')
             } else if (item.initval === 'lastMonth') {
               item.initval = [moment().subtract(1, 'months').startOf('month').format(format), moment().subtract(1, 'months').endOf('month').format(format)].join(',')
+            } else if (item.initval === 'year') {
+              item.initval = [moment().startOf('year').format(format), moment().endOf('year').format(format)].join(',')
+            } else if (item.initval === 'lastYear') {
+              item.initval = [moment().subtract(1, 'years').startOf('year').format(format), moment().subtract(1, 'years').endOf('year').format(format)].join(',')
             } else if (item.initval) {
               try {
                 let _initval = JSON.parse(item.initval)
@@ -311,9 +314,6 @@
 
               config.checkBid = true
               item.checkShift = true
-              if (config.setting) {
-                config.setting.checkBid = true
-              }
             }
 
             item.initval = ''
@@ -335,6 +335,10 @@
                 item.initval = [moment(d).startOf('month').format(format), moment(d).endOf('month').format(format)].join(',')
               } else if (item.$initval === 'lastMonth') {
                 item.initval = [moment(d).subtract(1, 'months').startOf('month').format(format), moment(d).subtract(1, 'months').endOf('month').format(format)].join(',')
+              } else if (item.$initval === 'year') {
+                item.initval = [moment(d).startOf('year').format(format), moment(d).endOf('year').format(format)].join(',')
+              } else if (item.$initval === 'lastYear') {
+                item.initval = [moment(d).subtract(1, 'years').startOf('year').format(format), moment(d).subtract(1, 'years').endOf('year').format(format)].join(',')
               } else {
                 try {
                   let _initval = JSON.parse(item.$initval)
@@ -408,9 +412,6 @@
         if (/@BID@/ig.test(item.dataSource) && supModule) {
           config.checkBid = true
           item.checkBid = true
-          if (config.setting) {
-            config.setting.checkBid = true
-          }
         }
         if (item.initval === '$first') {
           item.initval = ''
@@ -458,6 +459,15 @@
 
       return item
     })
+
+    if (config.checkBid) {
+      if (config.setting) {
+        config.setting.checkBid = true
+      }
+      if (config.type !== 'search') {
+        config.$checkBid = true
+      }
+    }
 
     config.$s_keys = keys
     config.$s_req = required
@@ -1132,16 +1142,34 @@
     cols.push('A' + cols[i])
   }
 
+  let columns = JSON.parse(JSON.stringify(btn.columns))
+  columns = columns.filter((col, index) => {
+    col.colIndex = cols[index] || (index + 1)
+    if (col.import !== 'init' && (/^Decimal/ig.test(col.type) || /^int/ig.test(col.type))) {
+      col.declen = 0
+      if (/^Decimal/ig.test(col.type)) {
+        col.declen = +col.type.match(/\d+/g)[1]
+      }
+      col.declen = col.declen || 0
+    }
+    if (col.required === 'false') {
+      delete col.min
+      delete col.max
+    }
+
+    return col.import !== 'false'
+  })
+
   let _Ltext = data.map((item, lindex) => {
     let vals = []
-    btn.columns.forEach((col, cindex) => {
-      if (col.import === 'false') return
-
+    columns.forEach(col => {
       let val = item[col.Column] !== undefined ? item[col.Column] : ''
-      let _colindex = cols[cindex] || (cindex + 1)
-      let _position = (_topline + lindex + 1) + '琛� ' + _colindex + '鍒� '
+      let _position = (_topline + lindex + 1) + '琛� ' + col.colIndex + '鍒� '
+      let eLen = errors.length
 
-      if (col.import === 'init') {
+      if (col.$error) {
+
+      } else if (col.import === 'init') {
         if (/^Nvarchar/ig.test(col.type)) {
           val = ''
         } else if (/^Decimal/ig.test(col.type) || /^int/ig.test(col.type)) {
@@ -1160,6 +1188,10 @@
 
         val = val.replace(/(^\s+$)|\t+|\v+/ig, '')
 
+        if (col.interception !== 'false') {
+          val = val.replace(/^\s+|\s+$/g, '')
+        }
+
         if (!val && col.required === 'true') {            // 蹇呭~鏍¢獙
           errors.push(_position + '鍐呭涓嶅彲涓虹┖')
         } else if (col.limit && val.length > col.limit) { // 闀垮害鏍¢獙
@@ -1177,14 +1209,24 @@
           if (!val || isNaN(val)) {
             val = 0
           }
-        } else if (!val && val !== 0) {
+        }
+        if (!val && val !== 0) {
           errors.push(_position + '鍐呭涓嶅彲涓虹┖')
         } else if (isNaN(val)) {                                  // 妫�楠屾槸鍚︿负鏁板��
           errors.push(_position + '鍐呭搴斾负鏁板��')
-        } else if ((col.min || col.min === 0) && val < col.min) { // 鏈�灏忓�兼楠�
+        } else if (typeof(col.min) === 'number' && val < col.min) { // 鏈�灏忓�兼楠�
           errors.push(_position + '灏忎簬鏈�灏忓��')
-        } else if ((col.max || col.max === 0) && val > col.max) { // 鏈�澶у�兼楠�
+        } else if (typeof(col.max) === 'number' && val > col.max) { // 鏈�澶у�兼楠�
           errors.push(_position + '澶т簬鏈�澶у��')
+        } else {
+          let _float = (val + '').split('.')[1]
+          if (_float && _float.length > col.declen) {
+            if (col.declen) {
+              errors.push(_position + `鏁板�间笉鍙ぇ浜�${col.declen}浣嶅皬鏁癭)
+            } else {
+              errors.push(_position + '鏁板�煎簲涓烘暣鏁�')
+            }
+          }
         }
       } else if (col.type === 'date' || col.type === 'datetime') {
         if (typeof(val) === 'number') {
@@ -1219,6 +1261,10 @@
         } else {                                    // 鏃堕棿鏍煎紡閿欒
           errors.push(_position + '鏃堕棿鏍煎紡閿欒')
         }
+      }
+
+      if (errors.length > eLen) {
+        col.$error = true
       }
 
       vals.push(`'${val}'`)
@@ -1835,6 +1881,7 @@
   let _initColfields = []
   let _declarefields = []
   let verifyValSql = ''
+  let datavars = {}
 
   // 鑾峰彇瀛楁閿�煎
   formdata && formdata.forEach(form => {
@@ -1849,6 +1896,7 @@
     }
 
     let _key = form.key.toLowerCase()
+    datavars[_key] = form.value
 
     if (!_initvars.includes(_key)) {
       _initvars.push(_key)
@@ -1903,6 +1951,8 @@
 
   // 娣诲姞鏁版嵁涓瓧娈碉紝琛ㄥ崟鍊间紭鍏�(鎸夐挳涓嶉�夎鎴栧琛屾嫾鎺ユ椂璺宠繃)
   if (data && btn.Ot !== 'notRequired' && columns && columns.length > 0) {
+    datavars = {..._data, ...datavars}
+
     const setField = (col) => {
       if (!col.field) return
       let _key = col.field.toLowerCase()
@@ -2197,7 +2247,7 @@
       item.field.split(',').forEach((_field, index) => {
         let _key = _field.toLowerCase()
         let _val = ''
-        let _val2 = ''
+        let _val2 = datavars[_key] !== undefined ? datavars[_key] : ''
 
         arr.push(_key)
         if (_key === 'bid') {
@@ -2208,8 +2258,6 @@
         
         if (_key === 'bid') {
           _val2 = BID
-        } else {
-          _val2 = `' + @${_field} + '`
         }
         
         _fieldValue.push(`${_key}=${_val}`)

--
Gitblit v1.8.0