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 | 231 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 215 insertions(+), 16 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 62df4d8..8b0a88f 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -223,7 +223,59 @@ } /** - * @description 鎷兼帴鎼滅储鏉′欢 + * @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 鎷兼帴缁撴灉 */ @@ -244,12 +296,17 @@ let timetail = ' 00:00:00.000' if (item.match === '<' || item.match === '<=') { timetail = ' 23:59:59.999' + } else if (item.match === '=') { + timetail = '' } // eslint-disable-next-line searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + timetail + '\')' } else if (item.type === 'datemonth') { + // 鏈�-杩囨护鏉′欢锛屼粠鏈堝紑濮嬭嚦缁撴潫 + 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' // eslint-disable-next-line - searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' + 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' @@ -269,7 +326,7 @@ } /** - * @description 鎷兼帴鎼滅储鏉′欢 + * @description 鎷兼帴鎼滅储鏉′欢datamanage * @param {Array} searches 鎼滅储鏉′欢 * @return {String} searchText 鎷兼帴缁撴灉 */ @@ -323,8 +380,6 @@ * @return {String} table 琛ㄥ悕 */ static getSysDefaultSql (btn, setting, formdata) { - console.log(btn) - console.log(formdata) let _sql = '' if (btn.OpenType === 'pop' && btn.sqlType === 'insert') { let keys = [] @@ -358,15 +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` } - //insert into 琛ㄥ悕 (琛ㄥ崟瀛楁锛岄�楀彿鍒嗛殧锛屽鏋滀富閿负鍙紪杈戝垯浼犲~鍐欏唴瀹癸紝鍙鎴栨病鏈夐厤缃〃鍗曪紝鍒欎紶鍓嶇鐢熸垚id,+createuserid) - // +select 琛ㄥ崟瀛楁鍊�+@userid - // 淇敼锛歶pdate 琛ㄥ悕 set 琛ㄥ崟闈炲彧璇诲瓧娈�=琛ㄥ崟鍊硷紝modifydate=getdate(),modifyuserid=@userid where 涓婚敭=@id琛宨d - - // 閫昏緫鍒犻櫎:update 琛ㄥ悕 set deleted=1锛宮odifydate=getdate(),modifyuserid=@userid where 涓婚敭=@id琛宨d - - // 鐗╃悊鍒犻櫎锛歩nsert into snote (remark,createuserid) select '鍒犻櫎琛� '+琛ㄥ悕+'鏁版嵁 '+id=@id delete 琛ㄥ悕 where 涓婚敭=@id琛宨d - console.log(_sql) return _sql } @@ -379,10 +426,136 @@ } /** + * @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) { + static getfunc (param, btn, menu, columns) { let form = '' let formParam = '' @@ -420,8 +593,33 @@ ` } + if (columns) { + let _col = [] + let _field = [] + columns.forEach(col => { + if (col.field) { + if (col.type === 'number') { + _col.push(col.field + ' decimal(18,2)') + } else { + _col.push(col.field + ' nvarchar(50)') + } + _field.push(col.field) + } + }) + _col = _col.join(',') + _field = _field.join(',') + + form = form + ` + declare @dc table (${_col}) + + insert into @dc (${_field}) + + @tableid ='${menu.MenuID}' + ` + } + let Ltext = `create proc ${param.funcName} - ( + ( /*${menu.MenuName} ${btn.label}*/ @BID nvarchar(50)='', @ID nvarchar(50)='',${formParam} @sEPTMenuNo nvarchar(50)='${param.menuNo}', @@ -490,8 +688,9 @@ ROLLBACK TRAN END` + Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k') - console.log(Ltext) + return Ltext } } \ No newline at end of file -- Gitblit v1.8.0