From ff045a6a19e2e0bd5c2433aae71145401627c22d Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 19 十二月 2019 19:08:32 +0800 Subject: [PATCH] 2019-12-19 --- src/utils/utils.js | 185 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 181 insertions(+), 4 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 840f7b1..8b0a88f 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -223,6 +223,58 @@ } /** + * @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 + } + + /** * @description 鎷兼帴鎼滅储鏉′欢main * @param {Array} searches 鎼滅储鏉′欢 * @return {String} searchText 鎷兼帴缁撴灉 @@ -361,7 +413,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 +426,139 @@ } /** + * @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)='', + @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 => { @@ -511,7 +688,7 @@ ROLLBACK TRAN END` - console.log(Ltext) + Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k') return Ltext -- Gitblit v1.8.0