From 76427d51a079a5fd1f45bf7188249e7a4647ae05 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 14 九月 2020 10:37:25 +0800
Subject: [PATCH] 2020-09-14

---
 src/utils/utils.js |  285 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 149 insertions(+), 136 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index 7808f1e..31c3abf 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -2,7 +2,55 @@
 import md5 from 'md5'
 import options from '@/store/options.js'
 
+const formatKeys = [
+  { key: 'select', value: ' msltk ' },
+  { key: 'from', value: ' mfrmk ' },
+  { key: 'where', value: ' mwhrk ' },
+  { key: 'order by', value: ' modbk ' },
+  { key: 'asc', value: ' modack ' },
+  { key: 'desc', value: ' moddesk ' },
+  { key: 'top', value: ' mtpk ' },
+  { key: 'like', value: ' mlkk ' },
+  { key: 'not like', value: ' mnlkk ' },
+  { key: 'between', value: ' mbtnk ' },
+  { key: 'and', value: ' madk ' },
+  { key: 'insert', value: ' mistk ' },
+  { key: 'into', value: ' mitk ' },
+  { key: 'update', value: ' muptk ' },
+  { key: 'delete', value: ' mdelk ' },
+  { key: 'begin', value: ' mbgink ' },
+  { key: 'end', value: ' medk ' },
+  { key: 'if', value: ' mefk ' },
+  { key: 'while', value: ' mwilk ' },
+  { key: 'create', value: ' mcrtk ' },
+  { key: 'alter', value: ' matek ' },
+  { key: 'len', value: ' mlnk ' },
+  { key: 'left', value: ' mlftk ' },
+  { key: 'right', value: ' mritk ' },
+  { key: 'union', value: ' munok ' },
+  { key: 'varchar', value: ' mvcrk ' },
+  { key: 'getdate', value: ' mgtdtk ' },
+  { key: 'TRY', value: ' mtryonek ' },
+  { key: 'TRAN', value: ' mtrnk ' },
+  { key: 'goto', value: ' mgtk ' },
+  { key: 'set', value: ' mstk ' },
+  { key: 'ROLLBACK', value: ' mrlbkk ' }
+]
+
 export default class Utils {
+  /**
+   * @description 鏁版嵁婧愬悕绉帮紝鐢ㄤ簬缁熶竴鏌ヨ
+   * @return {String}  name
+   */
+  static getdataName () {
+    let name = []
+    let _options = 'abcdefghigklmnopqrstuvwxyz'
+    for (let i = 0; i < 6; i++) {
+      name.push(_options.substr(Math.floor(Math.random() * 26), 1))
+    }
+    return name.join('')
+  }
+
   /**
    * @description 鐢熸垚32浣島uid string + 鏃堕棿
    * @return {String}  uuid
@@ -38,22 +86,26 @@
    * @description md5鍔犲瘑
    * @return {String}  str         鍔犲瘑涓�
    * @return {String}  timestamp   鏃堕棿鎴�
-   * @return {Boolean} isopenkey   鏄惁涓轰簯绔瘑閽�
    */
-  static encrypt (str, timestamp, isopenkey) {
-    let salt1 = 'mingke'    // sql璇硶鐩愬��
-    let salt2 = 'open_key'  // 浜戠鏁版嵁鎿嶄綔鐩愬��
-    let _str = ''
-
-    if (isopenkey) {
-      _str = salt2 + timestamp + str
-    } else {
-      _str = str + salt1 + timestamp
-    }
+  static encrypt (str, timestamp) {
+    let salt = 'mingke'    // sql璇硶鐩愬��
+    let _str = str + salt + timestamp
 
     if (_str.length > 8000) {
       _str = _str.slice(_str.length - 8000)
     }
+    return md5(_str)
+  }
+
+  /**
+   * @description md5鍔犲瘑 浜戠openkey鍔犲瘑
+   * @return {String}  secretkey   Ltext瀵嗛挜
+   * @return {String}  timestamp   鏃堕棿鎴�
+   */
+  static encryptOpenKey (secretkey, timestamp) {
+    let salt = 'open_key'  // 浜戠鏁版嵁鎿嶄綔鐩愬��
+    let _str = salt + timestamp + secretkey
+
     return md5(_str)
   }
 
@@ -96,90 +148,69 @@
 
   /**
    * @description sql鍔犲瘑
-   * @return {String}  value
+   * @return {String}   value
    */
-  static formatOptions (value, isUnFormat = false) {
+  static formatOptions (value) {
     if (!value) return ''
 
     let salt = 'minKe' // 鐩愬��
-    // 鍏抽敭瀛楄浆鎹㈣鍒�
-    let format = [
-      { key: 'select', value: ' msltk ' },
-      { key: 'from', value: ' mfrmk ' },
-      { key: 'where', value: ' mwhrk ' },
-      { key: 'order by', value: ' modbk ' },
-      { key: 'asc', value: ' modack ' },
-      { key: 'desc', value: ' moddesk ' },
-      { key: 'top', value: ' mtpk ' },
-      { key: 'like', value: ' mlkk ' },
-      { key: 'not like', value: ' mnlkk ' },
-      { key: 'between', value: ' mbtnk ' },
-      { key: 'and', value: ' madk ' },
-      { key: 'insert', value: ' mistk ' },
-      { key: 'into', value: ' mitk ' },
-      { key: 'update', value: ' muptk ' },
-      { key: 'delete', value: ' mdelk ' },
-      { key: 'begin', value: ' mbgink ' },
-      { key: 'end', value: ' medk ' },
-      { key: 'if', value: ' mefk ' },
-      { key: 'while', value: ' mwilk ' },
-      { key: 'create', value: ' mcrtk ' },
-      { key: 'alter', value: ' matek ' },
-      { key: 'len', value: ' mlnk ' },
-      { key: 'left', value: ' mlftk ' },
-      { key: 'right', value: ' mritk ' },
-      { key: 'union', value: ' munok ' },
-      { key: 'varchar', value: ' mvcrk ' },
-      { key: 'getdate', value: ' mgtdtk ' },
-      { key: 'TRY', value: ' mtryonek ' },
-      { key: 'TRAN', value: ' mtrnk ' },
-      { key: 'goto', value: ' mgtk ' },
-      { key: 'set', value: ' mstk ' },
-      { key: 'ROLLBACK', value: ' mrlbkk ' }
-    ]
 
-    if (!isUnFormat) { // 鍔犲瘑
-      value = value.replace(/\n/ig, ' \n ')
-      // 鏇挎崲鍏抽敭瀛�
-      format.forEach(item => {
-        let reg = new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig')
-        value = value.replace(reg, item.value)
-      })
-  
-      // 1銆佹浛鎹�%绗︼紙鏁版嵁搴撲腑瑙f瀽鍚巗ql鎶ラ敊锛�
-      value = value.replace(/%/ig, ' mpercent ')
-
-      // 1銆乪ncode缂栫爜锛堜腑鏂囧瓧绗﹁秴鍑篵ase64鍔犲瘑鑼冨洿锛夛紝2銆乥ase64鍔犲瘑
-      value = window.btoa(window.encodeURIComponent(value))
-  
-      // 鎻掑叆瀛楃
-      let index = Math.floor(value.length / 2)
-      value = value.slice(0, index) + salt + value.slice(index)
-  
-      // base64鍔犲瘑
-      value = window.btoa(value)
-    } else { // 瑙e瘑
-      try {
-        value = window.atob(value)
-        value = value.replace(salt, '')
-        value = window.decodeURIComponent(window.atob(value))
-
-        value = value.replace(/\smpercent\s/g, '%')
-
-        format.forEach(item => {
-          let reg = new RegExp(item.value, 'g')
-          value = value.replace(reg, ' ' + item.key + ' ')
-        })
-
-        value = value.replace(/\s\n\s/ig, '\n')
-        value = value.replace(/(^\s+|\s+$)/ig, '')
-      } catch {
-        console.warn('UnFormat Failure')
-        value = ''
-      }
-    }
+    value = value.replace(/\n/ig, ' \n ')
+    // 鏇挎崲鍏抽敭瀛�
+    formatKeys.forEach(item => {
+      let reg = new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig')
+      value = value.replace(reg, item.value)
+    })
+    // 1銆佹浛鎹�%绗︼紙鏁版嵁搴撲腑瑙f瀽鍚巗ql鎶ラ敊锛�
+    value = value.replace(/%/ig, ' mpercent ')
+    // 1銆乪ncode缂栫爜锛堜腑鏂囧瓧绗﹁秴鍑篵ase64鍔犲瘑鑼冨洿锛夛紝2銆乥ase64鍔犲瘑
+    value = window.btoa(window.encodeURIComponent(value))
+    // 鎻掑叆瀛楃
+    let index = Math.floor(value.length / 2)
+    value = value.slice(0, index) + salt + value.slice(index)
+    // base64鍔犲瘑
+    value = window.btoa(value)
 
     return value
+  }
+
+  /**
+   * @description 瑙e瘑
+   * @return {String}   value
+   */
+  static UnformatOptions (value) {
+    if (!value) return ''
+    let salt = 'minKe' // 鐩愬��
+    let _value = ''
+
+    try {
+      try {
+        _value = JSON.parse(window.decodeURIComponent(window.atob(value)))
+      } catch {
+        _value = ''
+      }
+
+      if (!_value) {
+        _value = window.atob(value)
+        _value = _value.replace(salt, '')
+        _value = window.decodeURIComponent(window.atob(_value))
+  
+        _value = _value.replace(/\smpercent\s/g, '%')
+  
+        formatKeys.forEach(item => {
+          let reg = new RegExp(item.value, 'g')
+          _value = _value.replace(reg, ' ' + item.key + ' ')
+        })
+  
+        _value = _value.replace(/\s\n\s/ig, '\n')
+        _value = _value.replace(/(^\s+|\s+$)/ig, '')
+      }
+    } catch {
+      console.warn('UnFormat Failure')
+      _value = ''
+    }
+
+    return _value
   }
 
   /**
@@ -188,47 +219,11 @@
    */
   static sPCInUpDeFormatOptions (value) {
     if (!value) return {LText: '', LText1: '', LText2: ''}
-
     let salt = 'minKe' // 鐩愬��
-    // 鍏抽敭瀛楄浆鎹㈣鍒�
-    let format = [
-      { key: 'select', value: ' msltk ' },
-      { key: 'from', value: ' mfrmk ' },
-      { key: 'where', value: ' mwhrk ' },
-      { key: 'order by', value: ' modbk ' },
-      { key: 'asc', value: ' modack ' },
-      { key: 'desc', value: ' moddesk ' },
-      { key: 'top', value: ' mtpk ' },
-      { key: 'like', value: ' mlkk ' },
-      { key: 'not like', value: ' mnlkk ' },
-      { key: 'between', value: ' mbtnk ' },
-      { key: 'and', value: ' madk ' },
-      { key: 'insert', value: ' mistk ' },
-      { key: 'into', value: ' mitk ' },
-      { key: 'update', value: ' muptk ' },
-      { key: 'delete', value: ' mdelk ' },
-      { key: 'begin', value: ' mbgink ' },
-      { key: 'end', value: ' medk ' },
-      { key: 'if', value: ' mefk ' },
-      { key: 'while', value: ' mwilk ' },
-      { key: 'create', value: ' mcrtk ' },
-      { key: 'alter', value: ' matek ' },
-      { key: 'len', value: ' mlnk ' },
-      { key: 'left', value: ' mlftk ' },
-      { key: 'right', value: ' mritk ' },
-      { key: 'union', value: ' munok ' },
-      { key: 'varchar', value: ' mvcrk ' },
-      { key: 'getdate', value: ' mgtdtk ' },
-      { key: 'TRY', value: ' mtryonek ' },
-      { key: 'TRAN', value: ' mtrnk ' },
-      { key: 'goto', value: ' mgtk ' },
-      { key: 'set', value: ' mstk ' },
-      { key: 'ROLLBACK', value: ' mrlbkk ' }
-    ]
 
     value = value.replace(/\n/ig, ' \n ')
     // 鏇挎崲鍏抽敭瀛�
-    format.forEach(item => {
+    formatKeys.forEach(item => {
       let reg = new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig')
       value = value.replace(reg, item.value)
     })
@@ -689,7 +684,7 @@
     arrfield = arrfield.join(',')
 
     if (item.orderBy) {
-      sql = 'select distinct ' + arrfield + ',' + item.orderBy + ' as orderfield from ' + _datasource + ' order by orderfield ' + item.orderType
+      sql = `select ${arrfield} from (select distinct ${arrfield},${item.orderBy} as orderfield from ${_datasource} ) a order by orderfield ${item.orderType}`
     } else {
       sql = 'select distinct ' + arrfield + ' from ' + _datasource
     }
@@ -765,11 +760,11 @@
 
           val = val.replace(/(^\s*$)|\t*|\v*/ig, '')
 
-          if (!val && col.required === 'true') { // 蹇呭~鏍¢獙
+          if (!val && col.required === 'true') {            // 蹇呭~鏍¢獙
             errors.push(_position + dict['main.excel.content.emptyerror'])
-          } else if (val.length > col.limit) {    // 闀垮害鏍¢獙
+          } else if (col.limit && val.length > col.limit) { // 闀垮害鏍¢獙
             errors.push(_position + dict['main.excel.content.maxlimit'])
-          } else {                               // 鍏抽敭瀛楁牎楠�
+          } else {                                          // 鍏抽敭瀛楁牎楠�
             keys.forEach(key => {
               let _patten = new RegExp('(^' + key + '\\s+)|(\\s+' + key + '\\s+)', 'ig')
               if (_patten.test(val)) {
@@ -863,7 +858,7 @@
     let _sqlInsert = ''
     let _sqlBottom = ''
 
-    if (item.intertype === 'inner' && !item.innerFunc) {
+    if (item.intertype === 'system') {
       let _uniquesql = ''
       if (btn.uniques && btn.uniques.length > 0) {
         btn.uniques.forEach(unique => {
@@ -948,8 +943,7 @@
         
         aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
 
-      // if (window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') {
-      if (window.GLOB.systemType !== 'production') {
+      if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
         let fsql = `
         ${_sql}
         ${_sqlInsert}
@@ -1204,8 +1198,15 @@
     // 澶辨晥楠岃瘉锛屾坊鍔犳暟鎹椂涓嶇敤
     if (btn.sqlType !== 'insert' && verify.invalid === 'true' && setting.dataresource) {
       let datasource = setting.dataresource
-      if (/\s/.test(datasource)) { // 鎷兼帴鍒悕
+      if (/\s/.test(datasource) && !/tb$/.test(datasource)) { // 鎷兼帴鍒悕
         datasource = '(' + datasource + ') tb'
+      }
+
+      if (setting.customScript) {
+        _sql += `
+        /* 鏁版嵁婧愯嚜瀹氫箟鑴氭湰锛岃娉ㄦ剰鍙橀噺瀹氫箟鏄惁閲嶅 */
+        ${setting.customScript}
+        `
       }
 
       if (btn.Ot === 'requiredOnce') {
@@ -1374,9 +1375,18 @@
     } else if (verify.uniques && verify.uniques.length > 0 && btn.Ot === 'requiredOnce' && setting.dataresource) {
       let datasource = setting.dataresource
       if (/\s/.test(datasource)) { // 鎷兼帴鍒悕
-        datasource = '(' + datasource + ') tb'
+        if (!/tb$/.test(datasource)) {
+          datasource = '(' + datasource + ') tb'
+        }
       } else {
         datasource = datasource + ' tb'
+      }
+
+      if (setting.customScript) {
+        _sql += `
+        /* 鏁版嵁婧愯嚜瀹氫箟鑴氭湰锛岃娉ㄦ剰鍙橀噺瀹氫箟鏄惁閲嶅 */
+        ${setting.customScript}
+        `
       }
 
       verify.uniques.forEach(item => {
@@ -1430,6 +1440,8 @@
       let values = []
 
       formdata.forEach(item => {
+        if (item.writein === false) return
+
         keys.push(item.key.toLowerCase())
         values.push('@' + item.key)
       })
@@ -1473,6 +1485,8 @@
       let _arr = []
 
       formdata.forEach(item => {
+        if (item.writein === false) return
+        
         _arr.push(item.key.toLowerCase())
         _form.push(item.key + '=@' + item.key)
       })
@@ -1582,8 +1596,7 @@
     _sql += `
         aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
 
-    // if (window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') {
-    if (window.GLOB.systemType !== 'production') {
+    if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
       _sql = _sql.replace(/\n\s{8}/ig, '\n')
       console.log(_sql)
     }

--
Gitblit v1.8.0