From a70940450c021a47e69abdf8fa8f7f98594601cc Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 13 十二月 2019 17:36:54 +0800 Subject: [PATCH] 2019-12-13 --- src/utils/utils.js | 79 ++++++++++++++++++++++++--------------- 1 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 1102b7c..d561d04 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 + '\')' @@ -363,7 +382,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} -- Gitblit v1.8.0