From 4c2ef2d3a98d7d9a2592721db2f5858528eb5c86 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 26 十二月 2019 11:33:48 +0800 Subject: [PATCH] 2019-12-26 --- src/utils/utils.js | 255 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 232 insertions(+), 23 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 840f7b1..963039c 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -42,7 +42,11 @@ */ static encrypt (str, timestamp) { let salt = 'mingke' // 鐩愬�� - return md5(str + salt + timestamp) + let _str = str + salt + timestamp + if (_str.length > 8000) { + _str = _str.slice(_str.length - 8000) + } + return md5(_str) } /** @@ -213,10 +217,82 @@ 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 = '' + let _val = item.value + + if (item.match === '<' || item.match === '<=') { + timetail = ' 00:00:00.000' + if (_val) { + _val = moment(_val, 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') + } + } else if (item.match === '>' || item.match === '>=') { + timetail = ' 00:00:00.000' + } + + if (newsearches[item.key]) { + newsearches[item.key + '1'] = _val ? _val + timetail : null + } else { + newsearches[item.key] = _val ? _val + 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').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' + } + + newsearches[item.key] = _startval + newsearches[item.key + '1'] = _endval + } else if (item.type === 'dateweek') { + let _endval = '' + if (item.value) { + _endval = moment(item.value[1], 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') + } + + newsearches[item.key] = item.value ? item.value[0] + ' 00:00:00.000' : null + newsearches[item.key + '1'] = item.value ? _endval + ' 00:00:00.000' : null + } else if (item.type === 'daterange') { + let _endval = '' + if (item.value) { + _endval = moment(item.value[1], 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') + } + + newsearches[item.key] = item.value ? item.value[0] + ' 00:00:00.000' : null + newsearches[item.key + '1'] = item.value ? _endval + ' 00:00:00.000' : null + } else { + newsearches[item.key] = item.value + } }) return newsearches @@ -241,30 +317,37 @@ // eslint-disable-next-line searchText += item.key + ' ' + item.match + ' ' + '\'' + str + item.value + str + '\'' } else if (item.type === 'date') { + let _val = item.value let timetail = ' 00:00:00.000' - if (item.match === '<' || item.match === '<=') { - timetail = ' 23:59:59.999' + let _match = item.match + + if (item.match === '<' || item.match === '<=') { // 鏃堕棿涓�<=鏃讹紝鍖归厤鍚庝竴澶╃殑0鐐癸紝鍖归厤鏂瑰紡涓�< + _match = '<' + _val = moment(_val, 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') } else if (item.match === '=') { timetail = '' } + // eslint-disable-next-line - searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + timetail + '\')' - } else if (item.type === 'datemonth') { - // 鏈�-杩囨护鏉′欢锛屼粠鏈堝紑濮嬭嚦缁撴潫 + searchText += '(' + item.key + ' ' + _match + ' ' + '\'' + _val + timetail + '\')' + } else if (item.type === 'datemonth') { // 鏈�-杩囨护鏉′欢锛屼粠鏈堝紑濮嬭嚦缁撴潫锛岀粨鏉熸椂闂翠负鏈堟湯鍔犱竴澶╃殑0鐐癸紝鏂瑰紡涓�< let _startval = moment(item.value, 'YYYY-MM').startOf('month').format('YYYY-MM-DD') + ' 00:00:00.000' - let _endval = moment(item.value, 'YYYY-MM').endOf('month').format('YYYY-MM-DD') + ' 23:59:59.999' + let _endval = moment(item.value, 'YYYY-MM').endOf('month').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' + // eslint-disable-next-line - searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + _startval + '\' AND \'' + _endval + '\')' - } else if (item.type === 'dateweek') { - let stimetail = ' 00:00:00.000' - let etimetail = ' 23:59:59.999' + searchText += '(' + item.key + ' >= \'' + _startval + '\' AND ' + item.key + ' < \'' + _endval + '\')' + } else if (item.type === 'dateweek') { // 鍛�-杩囨护鏉′欢 + let _startval = item.value[0] + ' 00:00:00.000' + let _endval = moment(item.value[1], 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' + // eslint-disable-next-line - searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + stimetail + '\' AND \'' + item.value[1] + etimetail + '\')' + searchText += '(' + item.key + ' >= \'' + _startval + '\' AND ' + item.key + ' < \'' + _endval + '\')' } else if (item.type === 'daterange') { - let stimetail = ' 00:00:00.000' - let etimetail = ' 23:59:59.999' + let _startval = item.value[0] + ' 00:00:00.000' + let _endval = moment(item.value[1], 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' + // eslint-disable-next-line - searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + stimetail + '\' AND \'' + item.value[1] + etimetail + '\')' + searchText += '(' + item.key + ' >= \'' + _startval + '\' AND ' + item.key + ' < \'' + _endval + '\')' } else { // eslint-disable-next-line searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' @@ -361,7 +444,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 +457,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 +674,7 @@ BEGIN TRAN /*鍏蜂綋涓氬姟鎿嶄綔*/ - /* + /* select top 10 * from sProcExcep order by id desc declare @UserName nvarchar(50),@FullName nvarchar(50) @@ -504,14 +713,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