From e0f1f05b7567a7bfd29fd5ad54e4b2222ddfcb94 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 26 三月 2020 20:19:06 +0800
Subject: [PATCH] 2020-03-26

---
 src/utils/utils.js |  247 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 164 insertions(+), 83 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index 70f0abd..6a5c97a 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 + '/') : ''
 
@@ -193,7 +194,9 @@
         key: search.field,
         match: search.match,
         type: search.type,
-        value: search.initval
+        label: search.label,
+        value: search.initval,
+        required: search.required === 'true'
       }
       if (item.type === 'date') {
         item.value = item.value ? moment().subtract(item.value, 'days').format('YYYY-MM-DD') : ''
@@ -288,6 +291,12 @@
         newsearches[item.key] = item.value
       }
     })
+
+    Object.keys(newsearches).forEach(key => {
+      if (!newsearches[key]) {
+        delete newsearches[key]
+      }
+    })
     
     return newsearches
   }
@@ -317,12 +326,8 @@
 
         searchText += item.key + ' ' + item.match + ' \'' + str + item.value + str + '\''
       } else if (item.type === 'multiselect') {
-        let str = item.match === '=' ? '' : '%'
-        let options = item.value.map(val => {
-          return item.key + ' ' + item.match + ' \'' + str + val + str + '\''
-        })
 
-        searchText += '(' + options.join(' OR ') + ')'
+        searchText += `'${item.value}' ` + item.match + ' \'%\'+' + item.key + '+\'%\''
       } else if (item.type === 'date') {
         let _val = item.value
         let timetail = ' 00:00:00.000'
@@ -355,6 +360,7 @@
         searchText += '(' + item.key + ' ' + item.match + ' \'' + item.value + '\')'
       }
     })
+
     return searchText
   }
 
@@ -391,6 +397,7 @@
    */
   static getrealurl (url) {
     if (!url) return ''
+
     let baseurl = ''
     if (process.env.NODE_ENV === 'production') {
       baseurl = document.location.origin + '/' + service
@@ -402,6 +409,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 +489,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 +505,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 +575,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 +603,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`
@@ -581,18 +631,16 @@
     let _formFieldValue = {}
     // 闇�瑕佸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'] // 宸茶祴鍊煎瓧娈甸泦
-    // let _initvars = ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'] // 宸茶祴鍊煎瓧娈甸泦
     let _initvars = [] // 宸茶祴鍊煎瓧娈甸泦
     let _initfields = []
     let _declarefields = []
@@ -681,11 +729,6 @@
         `
     }
 
-    // 娣诲姞鏃朵富閿负绌� 鏀逛负鍓嶅彴鐢熸垚
-    // if (btn.sqlType === 'insert') {
-    //   primaryId = ''
-    // }
-
     // 鍘婚櫎绂佺敤鐨勯獙璇�
     if (verify.contrasts) {
       verify.contrasts = verify.contrasts.filter(item => item.status !== 'false')
@@ -703,8 +746,16 @@
       verify.scripts = verify.scripts.filter(item => item.status !== 'false')
     }
 
-    // 鍒濆鍖栧嚟璇佸瓧娈�
-    _sql += `select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg=''
+    let userName = sessionStorage.getItem('User_Name') || ''
+    let fullName = sessionStorage.getItem('Full_Name') || ''
+
+    if (sessionStorage.getItem('isEditState') === 'true') {
+      userName = sessionStorage.getItem('CloudUserName') || ''
+      fullName = sessionStorage.getItem('CloudFullName') || ''
+    }
+
+    // 鍒濆鍖栧嚟璇佸強鐢ㄦ埛淇℃伅瀛楁
+    _sql += `select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}'
       `
 
     // 鍚敤璐︽湡楠岃瘉
@@ -803,16 +854,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 +883,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}',
@@ -863,10 +923,6 @@
           GOTO aaa
         `
     }
-
-    // 鐢ㄤ簬鍙栫敤鎴蜂俊鎭�
-    let _user = `select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID@
-      `
 
     let primaryKeyName = ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'].includes(primaryKey.toLowerCase()) ? primaryKey + '@' : primaryKey
 
@@ -917,7 +973,6 @@
 
       keys = keys.join(',')
       values = values.join(',')
-      _sql += _user
       _sql += `insert into ${btn.sql} (${keys}) select ${values};`
     } else if (_actionType === 'update') {
       let _form = []
@@ -969,7 +1024,6 @@
           }
         })
       }
-      _sql += _user
       _sql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select '鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@${primaryKeyName},@userid@,@username,@fullname delete ${btn.sql} where ${primaryKey}=@${primaryKeyName};`
     }
 
@@ -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,8 @@
 
     let Ltext = `create proc ${param.innerFunc}
     ( /*${menu.MenuName}*/
-    @BID nvarchar(50)='',
-    @${primaryKey} nvarchar(50)='',${formParam}
+    @appkey nvarchar(50)='',
+    @BID nvarchar(50)='',${formParam}
     @PageIndex nvarchar(50)='',
     @PageSize nvarchar(50)='',
     @OrderCol nvarchar(50)='',
@@ -1132,8 +1198,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 +1219,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)
         }
@@ -1194,10 +1270,16 @@
       `
     }
 
+    // 鎵撳嵃鑷畾涔夋ā鏉垮瓧娈垫彁绀�
+    let _printRemark = ''
+    if (btn.funcType === 'print') {
+      _printRemark = '/* 鑷畾涔夋暟鎹墦鍗版ā鏉挎椂锛岃浣跨敤TemplateID瀛楁 */'
+    }
+
     let Ltext = `create proc ${param.funcName}
     ( /*${menu.MenuName}  ${btn.label}*/
-    @BID nvarchar(50)='',
-    @${primaryKey} nvarchar(50)='',${formParam}
+    @appkey nvarchar(50)='',
+    @BID nvarchar(50)='',${formParam}
     @sEPTMenuNo nvarchar(50)='${param.menuNo}',
     @lang nvarchar(50)='',
     @debug nvarchar(50)='',
@@ -1217,7 +1299,7 @@
       /*浜嬪姟鎿嶄綔*/
       BEGIN TRAN
         /*鍏蜂綋涓氬姟鎿嶄綔*/
-        
+        ${_printRemark}
         /* 
         select top 10 * from sProcExcep order by id desc
         
@@ -1287,31 +1369,30 @@
 
     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}*/
+      @appkey nvarchar(50)='',
       @ID nvarchar(50)='',
       @BID nvarchar(50)='',
       @Ltext nvarchar(max)='',
       @sEPTMenuNo nvarchar(50)='${param.menuNo}', 
+      @secretkey nvarchar(50)='',
+      @timestamp nvarchar(50)='',
       @lang nvarchar(50)='',
       @LoginUID nvarchar(50)='',
       @SessionUid nvarchar(50)='',

--
Gitblit v1.8.0