From e70553694d5ab6869a85a0db60bc14942a06bc15 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 17 七月 2020 11:13:16 +0800
Subject: [PATCH] 2020-07-17

---
 src/utils/utils.js |  106 ++++++++++++++++++++++++++---------------------------
 1 files changed, 52 insertions(+), 54 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index 715db52..c2cc84f 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -766,92 +766,73 @@
           val = val.replace(/(^\s*$)|\t*|\v*/ig, '')
 
           if (!val && col.required === 'true') { // 蹇呭~鏍¢獙
-            let _error =  _position + dict['main.excel.content.emptyerror']
-            errors.push(_error)
+            errors.push(_position + dict['main.excel.content.emptyerror'])
           } else if (val.length > col.limit) {    // 闀垮害鏍¢獙
-            let _error =  _position + dict['main.excel.content.maxlimit']
-            errors.push(_error)
+            errors.push(_position + dict['main.excel.content.maxlimit'])
           } else {                               // 鍏抽敭瀛楁牎楠�
             keys.forEach(key => {
               let _patten = new RegExp('(^' + key + '\\s+)|(\\s+' + key + '\\s+)', 'ig')
               if (_patten.test(val)) {
-                let _error = _position + dict['main.excel.includekey'] + key
-                errors.push(_error)
+                errors.push(_position + dict['main.excel.includekey'] + key)
               }
             })
           }
         } else if (/^int/ig.test(col.type)) {
           if (!val && val !== 0) {
-            let _error =  _position + dict['main.excel.content.emptyerror']
-            errors.push(_error)
+            errors.push(_position + dict['main.excel.content.emptyerror'])
           } else {
             let _val = val + ''
 
             if (!/^(([^0][0-9]+|0)$)|^(([1-9]+)$)/.test(_val)) {               // 妫�楠屾槸鍚︿负鏁存暟
-              let _error = _position + dict['main.excel.content.interror']
-              errors.push(_error)
+              errors.push(_position + dict['main.excel.content.interror'])
             } else if ((col.min || col.min === 0) && val < col.min) {          // 鏈�灏忓�兼楠�
-              let _error = _position + dict['main.excel.content.limitmin']
-              errors.push(_error)
+              errors.push(_position + dict['main.excel.content.limitmin'])
             } else if ((col.max || col.max === 0) && val > col.max) {          // 鏈�澶у�兼楠�
-              let _error = _position + dict['main.excel.content.limitmax']
-              errors.push(_error)
+              errors.push(_position + dict['main.excel.content.limitmax'])
             }
           }
         } else if (/^Decimal/ig.test(col.type)) {
           if (!val && val !== 0) {
-            let _error =  _position + dict['main.excel.content.emptyerror']
-            errors.push(_error)
+            errors.push(_position + dict['main.excel.content.emptyerror'])
           } else {
             let _val = val + ''
             let _vals = _val.split('.')
 
             if (!/^(([^0][0-9]+|0)\.([0-9]+)$)|^(([^0][0-9]+|0)$)|^(([1-9]+)\.([0-9]+)$)|^(([1-9]+)$)/.test(_val)) {                           // 妫�楠屾槸鍚︿负娴偣鏁�
-              let _error = _position + dict['main.excel.content.floaterror']
-              errors.push(_error)
-            } else if (_vals[0].length > 18) {                         // 妫�楠屾暣鏁颁綅
-              let _error = _position + dict['main.excel.content.floatIntover']
-              errors.push(_error)
+              errors.push(_position + dict['main.excel.content.floaterror'])
+            } else if (_vals[0].length > 18) {                          // 妫�楠屾暣鏁颁綅
+              errors.push(_position + dict['main.excel.content.floatIntover'])
             } else if (_vals[1] && _vals[1].length > col.limit) {       // 鏈�灏忓�兼楠�
-              let _error = _position + dict['main.excel.content.floatPointover']
-              errors.push(_error)
-            } else if ((col.min || col.min === 0) && val < col.min) { // 鏈�灏忓�兼楠�
-              let _error = _position + dict['main.excel.content.limitmin']
-              errors.push(_error)
-            } else if ((col.max || col.max === 0) && val > col.max) { // 鏈�澶у�兼楠�
-              let _error = _position + dict['main.excel.content.limitmax']
-              errors.push(_error)
+              errors.push(_position + dict['main.excel.content.floatPointover'])
+            } else if ((col.min || col.min === 0) && val < col.min) {   // 鏈�灏忓�兼楠�
+              errors.push(_position + dict['main.excel.content.limitmin'])
+            } else if ((col.max || col.max === 0) && val > col.max) {   // 鏈�澶у�兼楠�
+              errors.push(_position + dict['main.excel.content.limitmax'])
             }
           }
         } else if (col.type === 'date') {
-          val = val.replace(/(^\s*$)|\t*|\v*/ig, '')
-
-          if (!val && col.required === 'true') { // 蹇呭~鏍¢獙
-            let _error =  _position + dict['main.excel.content.emptyerror']
-            errors.push(_error)
-          } else {                               // 鍏抽敭瀛楁牎楠�
-            keys.forEach(key => {
-              let _patten = new RegExp('(^' + key + '\\s+)|(\\s+' + key + '\\s+)', 'ig')
-              if (_patten.test(val)) {
-                let _error = _position + dict['main.excel.includekey'] + key
-                errors.push(_error)
-              }
-            })
+          if (typeof(val) === 'number') {
+            if (val > 2958465 || val <= 0) {                 // 鏃堕棿杩囧ぇ鎴栧皬浜庣瓑浜�0
+              errors.push(_position + dict['main.excel.content.date.over'])
+            } else {                                         // 鏃堕棿鏍煎紡鍖�
+              val = this.formatExcelDate(val)
+            }
+          } else if (typeof(val) === 'string') {
+            val = val.replace(/(^\s*$)|\t*|\v*/ig, '')
+            if (!val && col.required === 'true') {           // 鏃堕棿蹇呭~鏍¢獙
+              errors.push(_position + dict['main.excel.content.emptyerror'])
+            } else if (val && !/^[1-9][0-9]{3}/.test(val)) { // 鏃堕棿姝e垯鏍¢獙
+              errors.push(_position + dict['main.excel.content.date.formatError'])
+            }
+          } else {                                           // 鏃堕棿鏍煎紡閿欒
+            errors.push(_position + dict['main.excel.content.date.formatError'])
           }
         }
 
-        if (col.type === 'date') {
-          vals.push(`case when '${val}'='' then '1900-01-01' else dateadd(day,cast('${val}' as int)-2,'1900-01-01') end`)
-        } else {
-          vals.push(`'${val}'`)
-        }
+        vals.push(`'${val}'`)
 
         if (lindex < 40) {
-          if (col.type === 'date') {
-            convals.push(`case when '${val}'='' then '1900-01-01' else dateadd(day,cast('${val}' as int)-2,'1900-01-01') end as ${col.Column}`)
-          } else {
-            convals.push(`'${val}' as ${col.Column}`)
-          }
+          convals.push(`'${val}' as ${col.Column}`)
         }
       })
 
@@ -997,6 +978,20 @@
       bottom: _sqlBottom,
       errors: errors.join('; ')
     }
+  }
+
+  /**
+   * @description 鏍煎紡鍖杄xcel涓殑date鍊�
+   * @param {Number} number 鏃堕棿鍊� 
+   */
+  static formatExcelDate(number) {
+    const time = new Date((number - 1) * 24 * 3600000 + 1)
+    time.setYear(time.getFullYear() - 70)
+    const year = time.getFullYear()
+    const month = time.getMonth() + 1
+    const date = time.getDate() - 1
+
+    return `${year}-${(month < 10 ? '0' + month : month)}-${(date < 10 ? '0' + date : date)}`
   }
 
   /**
@@ -1167,7 +1162,9 @@
     // 鍙橀噺璧嬪��
     _initfields = _initfields.join(',')
     if (_initfields) {
-      _sql += `select ${_initfields}
+      _sql += `
+        
+        select ${_initfields}
         `
     }
 
@@ -1568,7 +1565,8 @@
 
       _sql += `
         /* 榛樿sql */
-        insert into snote (remark,createuserid,CreateUser,CreateStaff) select left('鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@ID@,200),@userid@,@username,@fullname delete ${btn.sql} where ${primaryKey}${_ID};`
+        insert into snote (remark,createuserid,CreateUser,CreateStaff) select left('鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@ID@,200),@userid@,@username,@fullname
+        delete ${btn.sql} where ${primaryKey}${_ID};`
     } else if (_actionType === 'insertOrUpdate') {
       _sql += `
         /* 榛樿sql */

--
Gitblit v1.8.0