From c39ea1f23d21b070188abcf5f4dd5bdd7b47c1f9 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 10 三月 2020 10:32:13 +0800
Subject: [PATCH] 2020-03-10

---
 src/utils/utils.js |  192 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 131 insertions(+), 61 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index 70f0abd..9edfb85 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -1,5 +1,6 @@
 import moment from 'moment'
 import md5 from 'md5'
+import options from '@/store/options.js'
 
 const service = window.GLOB.service ? (/\/$/.test(window.GLOB.service) ? window.GLOB.service : window.GLOB.service + '/') : ''
 
@@ -391,6 +392,7 @@
    */
   static getrealurl (url) {
     if (!url) return ''
+
     let baseurl = ''
     if (process.env.NODE_ENV === 'production') {
       baseurl = document.location.origin + '/' + service
@@ -402,6 +404,24 @@
     // }
     let realurl = url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url
     return realurl
+  }
+
+  /**
+   * @description 鑾峰彇浜戠鍥剧墖鐪熷疄璺緞
+   * @return {String}    url 鍥剧墖璺緞
+   */
+  static getcloudurl (url) {
+    if (!url) return ''
+    
+    let baseurl = ''
+    
+    if (options.cloudServiceApi) {
+      baseurl = options.cloudServiceApi.replace(/webapi(.*)$/, '')
+    } else {
+      baseurl = document.location.origin + '/' + service
+    }
+
+    return url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url
   }
 
   /**
@@ -464,12 +484,10 @@
 
           val = val.replace(/(^\s*$)|\t*|\v*/ig, '')
 
-          let limitlen = col.type.match(/\d+/)[0]
-
           if (!val && col.required === 'true') { // 蹇呭~鏍¢獙
             let _error =  _position + dict['main.excel.content.emptyerror']
             errors.push(_error)
-          } else if (val.length > limitlen) {    // 闀垮害鏍¢獙
+          } else if (val.length > col.limit) {    // 闀垮害鏍¢獙
             let _error =  _position + dict['main.excel.content.maxlimit']
             errors.push(_error)
           } else {                               // 鍏抽敭瀛楁牎楠�
@@ -482,36 +500,47 @@
             })
           }
         } else if (/^int/ig.test(col.type)) {
-          if (typeof(val) !== 'number' || parseInt(val) < parseFloat(val)) { // 妫�楠屾槸鍚︿负鏁存暟
-            let _error = _position + dict['main.excel.content.interror']
+          if (!val) {
+            let _error =  _position + dict['main.excel.content.emptyerror']
             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)
+          } else {
+            let _val = val + ''
+
+            if (!/^(([^0][0-9]+|0)$)|^(([1-9]+)$)/.test(_val)) {               // 妫�楠屾槸鍚︿负鏁存暟
+              let _error = _position + dict['main.excel.content.interror']
+              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)
+            }
           }
         } else if (/^Decimal/ig.test(col.type)) {
-          let _val = val + ''
-          _val = _val.split('.')
-          let limitlen = col.type.match(/\d+/ig)[1]
+          if (!val) {
+            let _error =  _position + dict['main.excel.content.emptyerror']
+            errors.push(_error)
+          } else {
+            let _val = val + ''
+            let _vals = _val.split('.')
 
-          if (typeof(val) !== 'number') {                           // 妫�楠屾槸鍚︿负娴偣鏁�
-            let _error = _position + dict['main.excel.content.floaterror']
-            errors.push(_error)
-          } else if (_val[0].length > 18) {                         // 妫�楠屾暣鏁颁綅
-            let _error = _position + dict['main.excel.content.floatIntover']
-            errors.push(_error)
-          } else if (_val[1] && _val[1].length > limitlen) {        // 鏈�灏忓�兼楠�
-            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)
+            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)
+            } 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)
+            }
           }
         }
         
@@ -541,6 +570,25 @@
 
       fields = fields.join(',')
 
+      let _insert = ''
+
+      if (btn.default !== 'false') {
+        _insert = `
+        Insert into ${item.sheet} (${fields},createuserid,createuser,createstaff,bid) 
+        Select ${fields},@userid@,@username,@fullname,@BID@ From @${item.sheet}
+        `
+      }
+
+      if (btn.scripts && btn.scripts.length > 0) {
+        btn.scripts.forEach(script => {
+          if (script.status === 'false') return
+
+          _insert += `
+          ${script.sql}
+          `
+        })
+      }
+
       _sql = `declare @${item.sheet} table (${declarefields.join(',')},jskey nvarchar(50) )
       Declare @UserName nvarchar(50),@FullName nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000)
 
@@ -550,10 +598,7 @@
       
       Insert into  @${item.sheet} (${fields},jskey)
       ${_Ltext}
-
-      Insert into ${item.sheet} (${fields},createuserid,createuser,createstaff,bid) 
-      Select ${fields},@userid@,@username,@fullname,@BID@ From @${item.sheet}
-
+      ${_insert}
       Delete @${item.sheet}
 
       aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
@@ -582,13 +627,13 @@
     // 闇�瑕佸0鏄庣殑鍙橀噺闆�
     // let _vars = ['tbid', 'ErrorCode', 'retmsg', 'BillCode', 'BVoucher', 'FIBVoucherDate', 'FiYear', 'UserName', 'FullName', 'ID', 'BID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey']
     // let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname', 'id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey']
-    let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname']
+    let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname', 'modulardetailcode']
 
     // 涓婚敭瀛楁
     let primaryKey = setting.primaryKey || 'id'
 
     // 绯荤粺鍙橀噺澹版槑涓庤缃垵濮嬪��
-    let _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)
+    let _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)
       `
 
     // let _initvars = ['ID', 'BID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey'] // 宸茶祴鍊煎瓧娈甸泦
@@ -803,16 +848,24 @@
     if (verify.billcodes && verify.billcodes.length > 0) {
       verify.billcodes.forEach(item => {
         let _ModularDetailCode = ''
-        if (item.TypeCharOne === 'Lp' || item.TypeCharOne === 'BN') {
+        let _lpline = ''
+        if (item.TypeCharOne === 'Lp') {
+          if (item.linkField === 'BID' && BID) { // 鏇挎崲bid
+            _lpline = `set @ModularDetailCode= 'Lp'+ right('${btn.uuid}'+@BID@,48)`
+          } else {
+            _lpline = `set @ModularDetailCode= 'Lp'+ right('${btn.uuid}'+@${item.linkField},48)`
+          }
+          _ModularDetailCode = '@ModularDetailCode'
+        } else if (item.TypeCharOne === 'BN') {
           let _val = ''
           if (item.linkField === 'BID' && BID) { // 鏇挎崲bid
             _val = BID
           } else if (data && data.hasOwnProperty(item.linkField)) {
             _val = data[item.linkField]
           }
-          _ModularDetailCode = item.TypeCharOne + _val
+          _ModularDetailCode = `'${item.TypeCharOne + _val}'`
         } else {
-          _ModularDetailCode = item.ModularDetailCode
+          _ModularDetailCode = `'${item.ModularDetailCode}'`
         }
 
         let _declare = ''
@@ -824,9 +877,10 @@
         }
 
         _sql += `${_declare}
-          select @BillCode='', @${_key}=''
+          select @BillCode='', @${_key}='', @ModularDetailCode=''
+          ${_lpline}
           exec s_get_BillCode
-            @ModularDetailCode='${_ModularDetailCode}',
+            @ModularDetailCode=${_ModularDetailCode},
             @Type=${item.Type},
             @TypeCharOne='${item.TypeCharOne}',
             @TypeCharTwo ='${item.TypeCharTwo}',
@@ -1004,15 +1058,20 @@
   static getTableFunc (param, menu, config) {
     let form = ''
     let formParam = ''
+    let _vars = ['bid', 'pageindex', 'pagesize', 'ordercol', 'ordertype', 'exceltype', 'septmenuno', 'lang', 'debug', 'loginuid', 'sessionuid', 'userid', 'errorcode', 'retmsg']
     let _columns = []
     let primaryKey = config.setting.primaryKey || 'ID'
+
+    if (!_vars.includes(primaryKey.toLowerCase())) {
+      _vars.push(primaryKey.toLowerCase())
+      formParam = `mchr13k@${primaryKey} nvarchar(50)='',`
+    }
 
     if (config.search && config.search.length > 0) {
       let _fields = new Map()
       config.search.forEach(item => {
         if (item.field) {
           let type = ''
-          let _f = item.field
 
           if (item.type.match(/date/ig)) {
             type = 'datetime=null'
@@ -1020,12 +1079,19 @@
             type = 'nvarchar(50)=\'\''
           }
 
-          if (_fields.has(item.field)) {
-            _f = _f + '1'
-          }
+          item.field.split(',').forEach(cell => {
+            let _f = cell
+            if (_fields.has(cell)) {
+              _f = _f + '1'
+            }
+  
+            _fields.set(cell, true)
 
-          _fields.set(item.field, true)
-          formParam = formParam + `mchr13k@${_f} ${type},`
+            if (!_vars.includes(_f.toLowerCase())) {
+              _vars.push(_f.toLowerCase())
+              formParam = formParam + `mchr13k@${_f} ${type},`
+            }
+          })
         }
       })
     }
@@ -1046,8 +1112,7 @@
 
     let Ltext = `create proc ${param.innerFunc}
     ( /*${menu.MenuName}*/
-    @BID nvarchar(50)='',
-    @${primaryKey} nvarchar(50)='',${formParam}
+    @BID nvarchar(50)='',${formParam}
     @PageIndex nvarchar(50)='',
     @PageSize nvarchar(50)='',
     @OrderCol nvarchar(50)='',
@@ -1132,8 +1197,14 @@
   static getfunc (param, btn, menu, config) {
     let form = ''
     let formParam = ''
+    let _vars = ['bid', 'septmenuno', 'lang', 'debug', 'loginuid', 'sessionuid', 'userid', 'errorcode', 'retmsg']
     let columns = config.columns
     let primaryKey = config.setting.primaryKey || 'ID'
+
+    if (!_vars.includes(primaryKey.toLowerCase())) {
+      _vars.push(primaryKey.toLowerCase())
+      formParam = `mchr13k@${primaryKey} nvarchar(50)='',`
+    }
 
     if (param.fields && param.fields.length > 0) {
       let _fields = []
@@ -1147,7 +1218,11 @@
           } else {
             type = 'nvarchar(50)=\'\''
           }
-          formParam = formParam + `mchr13k@${item.field} ${type},`
+
+          if (!_vars.includes(item.field.toLowerCase())) {
+            _vars.push(item.field.toLowerCase())
+            formParam = formParam + `mchr13k@${item.field} ${type},`
+          }
 
           _fields.push(item.field)
         }
@@ -1196,8 +1271,7 @@
 
     let Ltext = `create proc ${param.funcName}
     ( /*${menu.MenuName}  ${btn.label}*/
-    @BID nvarchar(50)='',
-    @${primaryKey} nvarchar(50)='',${formParam}
+    @BID nvarchar(50)='',${formParam}
     @sEPTMenuNo nvarchar(50)='${param.menuNo}',
     @lang nvarchar(50)='',
     @debug nvarchar(50)='',
@@ -1287,24 +1361,20 @@
 
     fields = fields.join(',')
 
-    let _sql = `declare @${btn.sheet} table (${declarefields.join(',')},jskey nvarchar(50) )
-      Declare @UserName nvarchar(50),@FullName nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000)
+    let _sql = `declare @${btn.sheet} table (${declarefields.join(',')},jskey nvarchar(50))
+      Declare @UserName nvarchar(50),@FullName nvarchar(50)
       
-      Select @ErrorCode='',@retmsg=''
-
-      select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID@
+      select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID
       
       Insert into @${btn.sheet} (${fields},jskey)
 
-      exec s_KeyWords_Replace 
+      exec s_KeyWords_Replace
       @LText=@LText, @BID=@BID,@LoginUID=@LoginUID,@SessionUid=@SessionUid,@UserID=@UserID,@ID=@ID
 
       Insert into ${btn.sheet} (${fields},createuserid,createuser,createstaff,bid) 
-      Select ${fields},@userid@,@username,@fullname,@BID@ From @${btn.sheet}
+      Select ${fields},@userid,@username,@fullname,@BID From @${btn.sheet}
 
-      Delete @${btn.sheet}
-      
-      aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
+      Delete @${btn.sheet}`
 
     let Ltext = `create proc ${param.funcName}
     ( /*${menu.MenuName}  ${btn.label}*/

--
Gitblit v1.8.0