From 2b84af9bed8f4b7da94a4bb85e7223d3b18e4fcb Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 14 十二月 2019 23:03:26 +0800 Subject: [PATCH] 2019-12-14 --- src/utils/utils.js | 102 +++++++++++++++++++++++++++++++++------------------ 1 files changed, 66 insertions(+), 36 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 1102b7c..d76bdcd 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -189,37 +189,45 @@ } /** + * @description 鍒濆鍖栨悳绱㈡潯浠� + * @param {Array} searches 鎼滅储鏉′欢 + * @return {String} searches 鏍煎紡鍖栧悗缁撴灉 + */ + static initMainSearch (searches) { + if (!searches || searches.length === 0) return [] + + let newsearches = [] + searches.forEach(search => { + let item = { + key: search.field, + match: search.match, + type: search.type, + value: search.initval + } + if (item.type === 'date') { + item.value = item.value ? moment().subtract(item.value, 'days').format('YYYY-MM-DD') : '' + } else if (item.type === 'datemonth') { + item.value = item.value ? moment().subtract(item.value, 'month').format('YYYY-MM') : '' + } else if (item.type === 'dateweek') { + 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')] : '' + } + newsearches.push(item) + }) + + return newsearches + } + + /** * @description 鎷兼帴鎼滅储鏉′欢 * @param {Array} searches 鎼滅储鏉′欢 * @return {String} searchText 鎷兼帴缁撴灉 */ - static mainjointsearchkey (searches) { + static joinMainSearchkey (searches) { if (!searches || searches.length === 0) return '' - - if (searches[0].hasOwnProperty('initval')) { - let newsearches = [] - searches.forEach(search => { - let item = { - key: search.field, - match: search.match, - type: search.type, - value: search.initval - } - if (item.type === 'date') { - item.value = item.value ? moment().subtract(item.value, 'days').format('YYYY-MM-DD') : '' - } else if (item.type === 'datemonth') { - item.value = item.value ? moment().subtract(item.value, 'month').format('YYYY-MM') : '' - } else if (item.type === 'dateweek') { - 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')] : '' - } - newsearches.push(item) - }) - searches = newsearches - } let searchText = '' searches.forEach(item => { @@ -231,15 +239,26 @@ let str = item.match === '=' ? '' : '%' // eslint-disable-next-line searchText += item.key + ' ' + item.match + ' ' + '\'' + str + item.value + str + '\'' - } else if (item.type === 'date' || item.type === 'datemonth') { + } else if (item.type === 'date') { + let timetail = ' 00:00:00.000' + if (item.match === '<' || item.match === '<=') { + timetail = ' 23:59:59.999' + } + // eslint-disable-next-line + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + timetail + '\')' + } else if (item.type === 'datemonth') { // eslint-disable-next-line searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' } else if (item.type === 'dateweek') { + let stimetail = ' 00:00:00.000' + let etimetail = ' 23:59:59.999' // eslint-disable-next-line - searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')' + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + stimetail + '\' AND \'' + item.value[1] + etimetail + '\')' } else if (item.type === 'daterange') { + let stimetail = ' 00:00:00.000' + let etimetail = ' 23:59:59.999' // eslint-disable-next-line - searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')' + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + stimetail + '\' AND \'' + item.value[1] + etimetail + '\')' } else { // eslint-disable-next-line searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' @@ -311,10 +330,22 @@ */ static getfunc (param) { let form = '' + let formParam = '' + if (param.fields && param.fields.length > 0) { let _fields = [] param.fields.forEach(item => { if (item.field) { + let type = '' + if (item.type.match(/date/ig)) { + type = 'datetime is null' + } else if (item.type === 'number') { + type = `decimal(18,${item.decimal})=0` + } else { + type = 'nvarchar(50)=\'\'' + } + formParam = formParam + `mchr13k@${item.field} ${type},` + _fields.push(item.field) } }) @@ -329,18 +360,17 @@ field3 = field3.join(',') form = ` - insert into ${param.name} (${field1}) select ${field2},@UserID + insert into ${param.name} (${field1},createuserid) select ${field2},@UserID update ${param.name} set ${field3},modifydate=getdate(),modifyuserid=@UserID ` } - let Ltext = `create proc ${param.name} + let Ltext = `create proc ${param.funcName} ( @BID nvarchar(50)='', - @ID nvarchar(50)='', - 琛ㄥ崟浼犲��,鏂囨湰鐢╪varchar(50)='',鏃ユ湡鐢╠atetime is null ,鏁板�肩敤decimal(18,灏忔暟鐐逛綅鏁�)=0, - @sEPTMenuNo='', --浼犺彍鍗曞弬鏁� + @ID nvarchar(50)='',${formParam} + @sEPTMenuNo nvarchar(50)='${param.menuNo}', @lang nvarchar(50)='', @debug nvarchar(50)='', @LoginUID nvarchar(50)='', @@ -363,7 +393,7 @@ /* select top 10 * from sProcExcep order by id desc - declare @UserName nvarchar(50),@FullName nvarchar(50) + declare @UserName nvarchar(50),@FullName nvarchar(50) select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID ${form} @@ -406,8 +436,8 @@ ROLLBACK TRAN END` - Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k') console.log(Ltext) + Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k') return Ltext } } \ No newline at end of file -- Gitblit v1.8.0