From cf8e332b14ca79859fcd89f2ac097ed7c6aa66c5 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 01 十二月 2019 18:15:45 +0800 Subject: [PATCH] 2019-12-01 --- src/utils/utils.js | 67 ++++++++++++++++++++++++++++++++- 1 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 1717dc4..a312464 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -1,3 +1,5 @@ +import moment from 'moment' + export default class Utils { /** * @description 鐢熸垚32浣島uid string + 鏃堕棿 @@ -138,9 +140,8 @@ }) value = value.replace(/(^\s|\s$)/ig, '') value = window.btoa(window.encodeURIComponent(value)) - // let index = Math.floor(Math.random() * value.length) - // value = value.slice(0, index) + 'minKe' + value.slice(index) - value = 'minKe' + value + let index = Math.floor(Math.random() * value.length) + value = value.slice(0, index) + 'minKe' + value.slice(index) value = window.btoa(value) // value = value.replace(/%/ig, 'mpercent') // .replace(/>/ig, 'greateror') @@ -164,6 +165,66 @@ * @param {Array} searches 鎼滅储鏉′欢 * @return {String} searchText 鎷兼帴缁撴灉 */ + static mainjointsearchkey (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 => { + if (!item.value) return + // eslint-disable-next-line + searchText += (searchText !== '' ? ' ' + 'AND' + ' ' : '') + if (item.type === 'text' || item.type === 'select') { + // eslint-disable-next-line + 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') { + // eslint-disable-next-line + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' + } else if (item.type === 'dateweek') { + // eslint-disable-next-line + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')' + } else if (item.type === 'daterange') { + // eslint-disable-next-line + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')' + } else { + // eslint-disable-next-line + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' + } + }) + return searchText + } + + /** + * @description 鎷兼帴鎼滅储鏉′欢 + * @param {Array} searches 鎼滅储鏉′欢 + * @return {String} searchText 鎷兼帴缁撴灉 + */ static jointsearchkey (searches) { if (!searches || searches.length === 0) return '' let searchText = '' -- Gitblit v1.8.0