From 65e310e342effbb7d98bd5f97b3404a44e3c5233 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 21 十二月 2019 00:29:36 +0800
Subject: [PATCH] 2019-12-21

---
 src/utils/utils.js |  202 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 194 insertions(+), 8 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index 840f7b1..46e4704 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -213,10 +213,70 @@
         item.value = item.value ? [moment().subtract(item.value * 7, 'days').startOf('week').format('YYYY-MM-DD'),
           moment().subtract(item.value * 7, 'days').endOf('week').format('YYYY-MM-DD')] : ''
       } else if (item.type === 'daterange') {
-        item.value = item.value ? [moment().subtract(item.value, 'days').format('YYYY-MM-DD'),
-          moment().subtract(item.value === 1 ? 1 : 0, 'days').format('YYYY-MM-DD')] : ''
+        let _val = item.value
+        if (_val) {
+          try {
+            _val = JSON.parse(_val)
+          } catch {
+            _val = ''
+          }
+        }
+        item.value = _val ? [moment().subtract(_val[0], 'days').format('YYYY-MM-DD'),
+          moment().subtract(_val[1], 'days').format('YYYY-MM-DD')] : ''
       }
       newsearches.push(item)
+    })
+    
+    return newsearches
+  }
+
+  /**
+   * @description 鍒濆鍖栨悳绱㈡潯浠�
+   * @param {Array}   searches     鎼滅储鏉′欢
+   * @return {String}  searches    鏍煎紡鍖栧悗缁撴灉
+   */
+  static formatCustomMainSearch (searches) {
+    if (!searches || searches.length === 0) return {}
+
+    let newsearches = {}
+    searches.forEach(item => {
+      if (item.type === 'date') {
+        let timetail = ''
+
+        if (item.match === '<' || item.match === '<=') {
+          timetail = ' 23:59:59.999'
+        } else if (item.match === '>' || item.match === '>=') {
+          timetail = ' 00:00:00.000'
+        }
+
+        if (newsearches[item.key]) {
+          newsearches[item.key + '1'] = item.value ? item.value + timetail : null
+        } else {
+          newsearches[item.key] = item.value ? item.value + timetail : null
+        }
+      } else if (item.type === 'datemonth') {
+        // 鏈�-杩囨护鏉′欢锛屼粠鏈堝紑濮嬭嚦缁撴潫
+        let _startval = null
+        let _endval = null
+
+        if (item.value) {
+          _startval = moment(item.value, 'YYYY-MM').startOf('month').format('YYYY-MM-DD') + ' 00:00:00.000'
+          _endval = moment(item.value, 'YYYY-MM').endOf('month').format('YYYY-MM-DD') + ' 23:59:59.999'
+        }
+        
+        newsearches[item.key] = _startval
+        newsearches[item.key + '1'] = _endval
+      } else if (item.type === 'dateweek') {
+
+        newsearches[item.key] = item.value ? item.value[0] + ' 00:00:00.000' : null
+        newsearches[item.key + '1'] = item.value ? item.value[1] + ' 23:59:59.999' : null
+      } else if (item.type === 'daterange') {
+
+        newsearches[item.key] = item.value ? item.value[0] + ' 00:00:00.000' : null
+        newsearches[item.key + '1'] = item.value ? item.value[1] + ' 23:59:59.999' : null
+      } else {
+        newsearches[item.key] = item.value
+      }
     })
     
     return newsearches
@@ -361,7 +421,7 @@
     } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'delete') {
       _sql = `insert into snote (remark,createuserid) select '鍒犻櫎琛�:${btn.sql} 鏁版嵁: id='+@id,@userid delete ${btn.sql} where ${setting.primaryKey}=@id`
     }
-    console.log(_sql)
+
     return _sql
   }
 
@@ -374,14 +434,140 @@
   }
 
   /**
+   * @description 鍒涘缓椤甸潰瀛樺偍杩囩▼
+   * @return {String}
+   */
+  static getTableFunc (param, menu, config) {
+    let form = ''
+    let formParam = ''
+    let _columns = []
+
+    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'
+          } else {
+            type = 'nvarchar(50)=\'\''
+          }
+
+          if (_fields.has(item.field)) {
+            _f = _f + '1'
+          }
+
+          _fields.set(item.field, true)
+          formParam = formParam + `mchr13k@${_f} ${type},`
+        }
+      })
+    }
+
+    if (config.columns && config.columns.length > 0) {
+      config.columns.forEach(item => {
+        if (item.field) {
+          _columns.push(`${item.field} as ${item.label}`)
+        }
+      })
+
+      form = `
+        declare @dc table (${_columns.join(',')})
+        
+        @tableid ='${menu.MenuID}'
+      `
+    }
+
+    let Ltext = `create proc ${param.innerFunc}
+    ( /*${menu.MenuName}*/
+    @BID nvarchar(50)='',
+    @ID nvarchar(50)='',${formParam}
+    @PageIndex nvarchar(50)='',
+    @PageSize nvarchar(50)='',
+    @OrderCol nvarchar(50)='',
+    @OrderType nvarchar(50)='',
+    @exceltype nvarchar(50)='',
+    @sEPTMenuNo nvarchar(50)='${menu.MenuNo}',
+    @lang nvarchar(50)='',
+    @debug nvarchar(50)='',
+    @LoginUID nvarchar(50)='',
+    @SessionUid nvarchar(50)='',
+    @UserID nvarchar(50),
+    @ErrorCode nvarchar(50) out,
+    @retmsg nvarchar(4000) out
+    )
+    as
+    begin
+    declare  @BegindateTest datetime,@EnddateTest datetime
+    select  @BegindateTest=getdate()
+    set @ErrorCode=''
+    set @retmsg=''
+    BEGIN TRY
+      /*浜嬪姟鎿嶄綔*/
+      BEGIN TRAN
+        /*鍏蜂綋涓氬姟鎿嶄綔*/
+        
+        /* 
+        select top 10 * from sProcExcep order by id desc
+        
+        declare @UserName  nvarchar(50),@FullName nvarchar(50)
+        
+        select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID
+        ${form}
+        if 1=2
+        begin
+          set @ErrorCode='E'
+          set @retmsg='鍦ㄦ鍐欐姤閿�'
+          goto GOTO_RETURN
+        end
+        
+        insert into sNote (remark,createuserid,CreateUser,CreateStaff)
+        select '鍦ㄦ鍐欐棩蹇�',@UserID,@UserName,@FullName
+        */
+        
+      COMMIT TRAN
+      SET NOCOUNT ON
+      RETURN
+    END TRY
+    BEGIN CATCH
+      /*閿欒澶勭悊*/
+      ROLLBACK TRAN
+      DECLARE @ErrorMessage NVARCHAR(4000);
+      DECLARE @ErrorSeverity INT;
+      DECLARE @ErrorState INT;
+      
+      /*鎶婅嚜瀹氫箟鐨勫弸濂界殑閿欒淇℃伅鎻愮ず鍔犱笂*/
+      set @ErrorCode=cast(ERROR_NUMBER() as nvarchar(50))
+      SET @retmsg=ERROR_MESSAGE();
+      SELECT @ErrorMessage=ERROR_MESSAGE(),
+        @ErrorSeverity=ERROR_SEVERITY(),
+        @ErrorState=ERROR_STATE();
+        
+      RAISERROR(@ErrorMessage, /*-- Message text.*/
+        @ErrorSeverity, /*-- Severity.*/
+        @ErrorState  /*-- State.*/
+      );
+    END CATCH
+    
+    GOTO_RETURN:
+      ROLLBACK TRAN
+      
+    END`
+    console.log(Ltext)
+    Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k')
+
+    return Ltext
+  }
+
+  /**
    * @description 鍒涘缓瀛樺偍杩囩▼
    * @return {String}
    */
   static getfunc (param, btn, menu, columns) {
     let form = ''
     let formParam = ''
-    console.log(menu)
-    console.log(columns)
+
     if (param.fields && param.fields.length > 0) {
       let _fields = []
       param.fields.forEach(item => {
@@ -465,7 +651,7 @@
       BEGIN TRAN
         /*鍏蜂綋涓氬姟鎿嶄綔*/
         
-         /* 
+        /* 
         select top 10 * from sProcExcep order by id desc
         
         declare @UserName  nvarchar(50),@FullName nvarchar(50)
@@ -504,14 +690,14 @@
       RAISERROR(@ErrorMessage, /*-- Message text.*/
         @ErrorSeverity, /*-- Severity.*/
         @ErrorState  /*-- State.*/
-        );
+      );
     END CATCH
     
     GOTO_RETURN:
       ROLLBACK TRAN
       
     END`
-    console.log(Ltext)
+
     Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k')
 
     return Ltext

--
Gitblit v1.8.0