From d1f19b794216b37417e114b71c1cd7a2ac3d7748 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 02 三月 2023 01:14:29 +0800
Subject: [PATCH] 2023-03-02

---
 src/utils/utils.js |  214 +++++++++++++++++++++++++++++++++++------------------
 1 files changed, 141 insertions(+), 73 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index 06f55ca..09aede5 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -59,17 +59,22 @@
   }
 
   /**
-   * @description 鏁版嵁婧愬悕绉帮紝鐢ㄤ簬缁熶竴鏌ヨ
-   * @return {String}  name
+   * @description 鑾峰彇鍥捐〃楂樺害
    */
-  static getdataName () {
-    let name = []
-    let _options = 'abcdefghigklmnopqrstuvwxyz'
-    for (let i = 0; i < 6; i++) {
-      name.push(_options.substr(Math.floor(Math.random() * 26), 1))
+  static getHeight (val) {
+    if (typeof(val) === 'string') {
+      if (val.indexOf('px') > -1) {
+        val = parseFloat(val)
+      } else if (val.indexOf('vw') > -1) {
+        val = parseFloat(val)
+        val = document.body.clientWidth * val / 100
+      } else if (val.indexOf('vh') > -1) {
+        val = parseFloat(val)
+        val = document.body.clientHeight * val / 100
+      }
     }
-    name.splice(3, 0, new Date().getTime())
-    return name.join('')
+  
+    return parseInt(val || 400) - 30
   }
 
   /**
@@ -158,7 +163,7 @@
 
     let error = ''
     
-    sql = sql.replace(/sys\.fn_sqlvarbasetostr\(HashBytes\('MD5'/ig, '') // 璺宠繃MD5鍔犲瘑
+    sql = sql.replace(/sys\.fn_/ig, '') // 璺宠繃sys.fn_楠岃瘉
 
     chars.forEach(char => {
       if (!error && char.reg.test(sql)) {
@@ -200,6 +205,35 @@
 
     return value
   }
+
+  // /**
+  //  * @description sql瑙e瘑
+  //  * @return {String}   value
+  //  */
+  // static unFormatOptions (value) {
+  //   if (!value) return ''
+
+  //   value = window.atob(value)
+  //   value = value.replace('minKe', '')
+  //   value = window.decodeURIComponent(window.atob(value))
+
+  //   // 澶栬仈鏁版嵁搴撴浛鎹�
+  //   if (window.GLOB.externalDatabase !== null && window.GLOB.externalDatabase) {
+  //     value = value.replace(window.GLOB.externalDatabase, '@db@')
+  //   }
+
+  //   value = value.replace(/ mpercent /ig, '%')
+    
+  //   // 鏇挎崲鍏抽敭瀛�
+  //   formatKeys.forEach(item => {
+  //     let reg = new RegExp('(\\s)?' + item.value.replace(/\s/g, '') + '(\\s)?', 'ig')
+  //     value = value.replace(reg, ' ' + item.key + ' ')
+  //   })
+
+  //   // value = value.replace(/\n/ig, ' \n ')
+
+  //   return value
+  // }
 
   /**
    * @description sPC_TableData_InUpDe sql鍔犲瘑
@@ -730,14 +764,7 @@
   static getrealurl (url) {
     if (!url) return ''
 
-    let baseurl = ''
-    if (process.env.NODE_ENV === 'production') {
-      baseurl = document.location.origin + '/' + window.GLOB.service
-    } else {
-      baseurl = window.GLOB.location + '/' + window.GLOB.service
-    }
-
-    let realurl = url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url
+    let realurl = url.match(/^http/) || url.match(/^\/\//) ? url : window.GLOB.baseurl + url
     return realurl
   }
 
@@ -753,7 +780,7 @@
     if (options.cloudServiceApi) {
       baseurl = options.cloudServiceApi.replace(/webapi(.*)$/, '')
     } else {
-      baseurl = document.location.origin + '/' + window.GLOB.service
+      baseurl = window.GLOB.baseurl
     }
 
     return url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url
@@ -771,6 +798,8 @@
       arrfield.push(item.cardValField)
       if (item.urlField) {
         arrfield.push(item.urlField)
+      } else if (item.colorField) {
+        arrfield.push(item.colorField)
       }
     }
 
@@ -796,10 +825,8 @@
     arrfield = arrfield.join(',')
 
     if (item.orderBy) {
-      // sql = `select ${item.type === 'checkcard' ? 'top 20' : ''} ${arrfield} from (select distinct ${arrfield},${item.orderBy} as orderfield from ${_datasource} ) a order by orderfield ${item.orderType}`
       sql = `select distinct ${arrfield},${item.orderBy} as orderfield from ${_datasource} order by orderfield ${item.orderType}`
     } else {
-      // sql = `select ${item.type === 'checkcard' ? 'top 20' : ''} ${arrfield} from (select distinct ${arrfield} from ${_datasource}) a`
       sql = `select distinct ${arrfield} from ${_datasource}`
     }
 
@@ -818,10 +845,6 @@
     sql = sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
     sql = sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
 
-    if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
-      console.info(sql)
-    }
-
     return {
       sql: sql,
       field: arrfield
@@ -836,7 +859,7 @@
  * @return {Object} dict   瀛楀吀椤�
  * @return {String} BID    涓婄骇Id
  */
-export function getExcelInSql (item, data, dict, BID) {
+export function getExcelInSql (item, data, dict, BID, primaryId) {
   let btn = item.verify
   let keys = ['delete', 'drop', 'insert', 'truncate', 'update']
   let userName = sessionStorage.getItem('User_Name') || ''
@@ -889,20 +912,30 @@
     btn.scripts.forEach(script => {
       if (script.status === 'false') return
 
+      let _sql = script.sql
+
+      _sql = _sql.replace(/@ID@/ig, `'${primaryId || ''}'`)
+      _sql = _sql.replace(/@BID@/ig, `'${BID}'`)
+      _sql = _sql.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
+      _sql = _sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
+      _sql = _sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
+      _sql = _sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+      _sql = _sql.replace(/@typename@/ig, `'admin'`)
+
       if (script.position === 'init') {
         _initCustomScript += `
       /* 鑷畾涔夎剼鏈� */
-      ${script.sql}
+      ${_sql}
       `
       } else if (script.position === 'front') {
         _prevCustomScript += `
       /* 鑷畾涔夎剼鏈� */
-      ${script.sql}
+      ${_sql}
       `
       } else {
         _backCustomScript += `
       /* 鑷畾涔夎剼鏈� */
-      ${script.sql}
+      ${_sql}
       `
       }
     })
@@ -1376,17 +1409,16 @@
  * @return {Object}  param     璇锋眰鍙傛暟
  * @return {Array}   data      鍒楄〃琛屾暟鎹�
  * @return {Array}   columns   鏄剧ず鍒�
- * @return {Object}  tab       鏍囩淇℃伅
  * @return {Boolean} retmsg    鏄惁闇�瑕佹暟鎹繑鍥�
  */
-export function getSysDefaultSql (btn, setting, formdata, param, data, columns, tab, retmsg = false, moduleParams, getOptions) {
+export function getSysDefaultSql (btn, setting, formdata, param, data, columns, retmsg = false, moduleParams, getOptions) {
   let primaryId = param.ID
-  let BID = param.BID
+  let BID = param.BID || ''
   let verify = btn.verify || {}
   let datavars = {}                 // 澹版槑鐨勫彉閲忥紝琛ㄥ崟鍙婃樉绀哄垪
   let _actionType = null
   let _callbacksql = ''
-  let foreignKey = tab && tab.foreignKey ? tab.foreignKey.toLowerCase() : ''
+  let foreignKey = setting.foreignKey ? setting.foreignKey.toLowerCase() : ''
 
   if (verify.default !== 'false') { // 鍒ゆ柇鏄惁浣跨敤榛樿sql
     _actionType = btn.sqlType
@@ -1441,14 +1473,11 @@
 
       if (form.type === 'number' || form.type === 'rate') {
         let val = form.value
-        if (typeof(val) !== 'number') {
-          val = parseFloat(val)
-          if (isNaN(val)) {
-            val = 0
-          }
+        if (isNaN(val)) {
+          val = 0
         }
         _initFormfields.push(`@${_key}=${val}`)
-      } else if (['date', 'datemonth', 'datetime'].includes(form.type)) {
+      } else if (['date', 'datemonth'].includes(form.type)) {
         _initFormfields.push(`@${_key}='${form.value || '1949-10-01'}'`)
       } else {
         _initFormfields.push(`@${_key}='${form.value}'`)
@@ -1483,7 +1512,7 @@
   }
 
   // 娣诲姞鏁版嵁涓瓧娈碉紝琛ㄥ崟鍊间紭鍏�(鎸夐挳涓嶉�夎鎴栧琛屾嫾鎺ユ椂璺宠繃)
-  if (data && btn.Ot !== 'notRequired' && btn.Ot !== 'requiredOnce') {
+  if (data && btn.Ot !== 'notRequired' && columns && columns.length > 0) {
     datavars = {...data, ...datavars}
 
     const setField = (col) => {
@@ -1525,17 +1554,15 @@
       }
     }
 
-    if (columns && columns.length > 0) {
-      columns.forEach(col => {
-        if (col.type === 'colspan' || col.type === 'old_colspan') {
-          col.subcols.forEach(cell => {
-            setField(cell)
-          })
-        } else {
-          setField(col)
-        }
-      })
-    }
+    columns.forEach(col => {
+      if (col.type === 'colspan' || col.type === 'old_colspan') {
+        col.subcols.forEach(cell => {
+          setField(cell)
+        })
+      } else {
+        setField(col)
+      }
+    })
   }
 
   // 鍙橀噺澹版槑
@@ -1567,7 +1594,7 @@
   // 鍒濆鍖栧嚟璇佸強鐢ㄦ埛淇℃伅瀛楁
   _sql += `
       /* 鍑瘉鍙婄敤鎴蜂俊鎭垵濮嬪寲璧嬪�� */
-      select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}', @mk_nation='${nation}', @mk_province='${province}', @mk_city='${city}', @mk_district='${district}', @mk_address='${address}', @BillCode='', @ModularDetailCode=''
+      select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}', @mk_nation='${nation}', @mk_province='${province}', @mk_city='${city}', @mk_district='${district}', @mk_address='${address}', @bid='${BID}', @BillCode='', @ModularDetailCode=''
       `
 
   // 琛ㄥ崟鍙橀噺璧嬪��
@@ -1944,6 +1971,11 @@
       values.push('@BID@')
     }
 
+    if (!keys.includes('typename')) {
+      keys.push('typename')
+      values.push('@typename@')
+    }
+
     keys = keys.join(',')
     values = values.join(',')
     _insertsql = `insert into ${btn.sql} (${keys}) select ${values};`
@@ -1966,11 +1998,14 @@
       if (!_arr.includes('submitdate')) {
         _form.push('submitdate=getdate()')
       }
-      if (!_arr.includes('submituserid')) {
-        _form.push('submituserid=@userid@')
-      }
       if (!_arr.includes('submituser')) {
         _form.push('submituser=@username')
+      }
+      if (!_arr.includes('submitstaff')) {
+        _form.push('submitstaff=@fullname')
+      }
+      if (!_arr.includes('submituserid')) {
+        _form.push('submituserid=@userid@')
       }
     } else {
       if (!_arr.includes('modifydate')) {
@@ -1978,6 +2013,9 @@
       }
       if (!_arr.includes('modifyuser')) {
         _form.push('modifyuser=@username')
+      }
+      if (!_arr.includes('modifystaff')) {
+        _form.push('modifystaff=@fullname')
       }
       if (!_arr.includes('modifyuserid')) {
         _form.push('modifyuserid=@userid@')
@@ -1994,6 +2032,9 @@
       if (!_arr.includes('fiyear')) {
         _form.push('FiYear=@FiYear')
       }
+    }
+    if (!_arr.includes('typename')) {
+      _form.push('typename=@typename@')
     }
     _form = _form.join(',')
 
@@ -2026,17 +2067,16 @@
 
     _sql += `
       /* 榛樿sql */
-      update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuser=@username,modifyuserid=@userid@ where ${primaryKey}${_ID};`
+      update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuser=@username,modifystaff=@fullname,modifyuserid=@userid@ where ${primaryKey}${_ID};`
   
   } else if (_actionType === 'delete') {      // 鐗╃悊鍒犻櫎
     let _msg = ''
-    if (data && columns && columns.length > 0) {
+    if (data && columns && columns.length > 0 && btn.Ot !== 'notRequired') {
       let _index = 0
       columns.forEach(col => {
-        if (col.Hide !== 'true' && col.type !== 'colspan' && col.type !== 'old_colspan' && _index < 4) {
-          _msg += col.label + '=' + data[col.field] + ','
-          _index++
-        }
+        if (!col.field || col.Hide === 'true' || _index >= 4) return
+        _msg += col.label + '=' + data[col.field] + ','
+        _index++
       })
     }
 
@@ -2047,7 +2087,7 @@
 
     _sql += `
       /* 榛樿sql */
-      insert into snote (remark,createuserid,CreateUser,CreateStaff) select left('鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@ID@,200),@userid@,@username,@fullname
+      insert into snote (remark,createuserid,CreateUser,CreateStaff,typename) select left('鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@ID@,200),@userid@,@username,@fullname,@typename@
       delete ${btn.sql} where ${primaryKey}${_ID};`
   } else if (_actionType === 'insertOrUpdate') {
     _sql += `
@@ -2070,6 +2110,20 @@
     _sql += _backCustomScript
   }
 
+  if (window.GLOB.breakpoint) {
+    let start = new RegExp('\\/\\*\\$breakpoint_begin_' + window.GLOB.breakpoint + '@', 'ig')
+    let end = new RegExp('@breakpoint_end_' + window.GLOB.breakpoint + '\\$\\*\\/', 'ig')
+
+    if (window.GLOB.breakpoint === 'all') {
+      start = /\/\*\$breakpoint_begin_[0-9a-z_]+@/ig
+      end = /@breakpoint_end_[0-9a-z_]+\$\*\//ig
+    }
+    
+    _sql = _sql.replace(start, '').replace(end, '').replace(/\$breakpoint_proc@/ig, window.GLOB.breakpoint)
+    _sql += `
+      z_debug_end: select @ErrorCode='E',@retmsg='debug_end' goto aaa`
+  }
+
   if (retmsg) {
     _sql += `
       aaa: if @ErrorCode!=''
@@ -2083,11 +2137,12 @@
   }
 
   _sql = _sql.replace(/@ID@/ig, `'${primaryId || ''}'`)
-  _sql = _sql.replace(/@BID@/ig, `'${BID || ''}'`)
+  _sql = _sql.replace(/@BID@/ig, `'${BID}'`)
   _sql = _sql.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
   _sql = _sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
   _sql = _sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
   _sql = _sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+  _sql = _sql.replace(/@typename@/ig, `'admin'`)
 
   if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
     // _sql = _sql.replace(/\n\s{8}/ig, '\n')
@@ -2095,6 +2150,14 @@
   }
 
   if (retmsg) {
+    _callbacksql = _callbacksql.replace(/@ID@/ig, `'${primaryId || ''}'`)
+    _callbacksql = _callbacksql.replace(/@BID@/ig, `'${BID}'`)
+    _callbacksql = _callbacksql.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
+    _callbacksql = _callbacksql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
+    _callbacksql = _callbacksql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
+    _callbacksql = _callbacksql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+    _callbacksql = _callbacksql.replace(/@typename@/ig, `'admin'`)
+    
     return {
       sql: _sql,
       callbacksql: _callbacksql
@@ -2111,6 +2174,7 @@
   let icon = null
   let innerStyle = null
   let position = null
+  let signType = ''
   style = JSON.parse(JSON.stringify(style))
 
   marks.some(mark => {
@@ -2120,6 +2184,7 @@
 
     if (mark.field[1] === 'static') {
       contrastVal = mark.contrastValue
+      originVal = originVal + ''
     } else {
       contrastVal = record[mark.field[2]]
     }
@@ -2147,8 +2212,9 @@
     if (type === 'font') {
       style.color = mark.color
       innerStyle = {color: mark.color}
+      signType = ' sign-font'
     } else if (type === 'background') {
-      style.background = mark.color
+      style.backgroundColor = mark.color
       if (mark.fontColor) {
         style.color = mark.fontColor
         innerStyle = {color: mark.fontColor}
@@ -2178,7 +2244,8 @@
     style,
     icon,
     innerStyle,
-    position
+    position,
+    signType
   }
 }
 
@@ -2237,7 +2304,7 @@
    * @description 鍒涘缓椤甸潰瀛樺偍杩囩▼
    * @return {String}
    */
-  static getTableFunc (param, menu, config) {
+  static getTableFunc (func = 'func', menu, config) {
     let form = ''
     let formParam = ''
     let _vars = ['bid', 'pageindex', 'pagesize', 'ordercol', 'ordertype', 'exceltype', 'septmenuno', 'lang', 'debug', 'loginuid', 'sessionuid', 'userid', 'errorcode', 'retmsg']
@@ -2292,7 +2359,7 @@
       `
     }
 
-    let Ltext = `create proc ${param.innerFunc}
+    let Ltext = `create proc ${func}
     ( /*${menu.MenuName}*/
     @appkey nvarchar(50)='',
     @BID nvarchar(50)='',${formParam}
@@ -2307,6 +2374,7 @@
     @LoginUID nvarchar(50)='',
     @SessionUid nvarchar(50)='',
     @UserID nvarchar(50),
+    @dataM nvarchar(50),
     @ErrorCode nvarchar(50) out,
     @retmsg nvarchar(4000) out
     )
@@ -2528,9 +2596,9 @@
         @ErrorSeverity=ERROR_SEVERITY(),
         @ErrorState=ERROR_STATE();
         
-      RAISERROR(@ErrorMessage, /*-- Message text.*/
-        @ErrorSeverity, /*-- Severity.*/
-        @ErrorState  /*-- State.*/
+      RAISERROR(@ErrorMessage, /* Message text.*/
+        @ErrorSeverity, /* Severity.*/
+        @ErrorState  /* State.*/
       );
     END CATCH
     
@@ -2669,9 +2737,9 @@
         @ErrorSeverity=ERROR_SEVERITY(),
         @ErrorState=ERROR_STATE();
         
-      RAISERROR(@ErrorMessage, /*-- Message text.*/
-        @ErrorSeverity, /*-- Severity.*/
-        @ErrorState  /*-- State.*/
+      RAISERROR(@ErrorMessage, /* Message text.*/
+        @ErrorSeverity, /* Severity.*/
+        @ErrorState  /* State.*/
       );
     END CATCH
     

--
Gitblit v1.8.0