diff --git a/core/core-frontend/src/hooks/web/useFilter.ts b/core/core-frontend/src/hooks/web/useFilter.ts index ce465de..4175eb4 100644 --- a/core/core-frontend/src/hooks/web/useFilter.ts +++ b/core/core-frontend/src/hooks/web/useFilter.ts @@ -1,5 +1,7 @@ import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain' +import type { ManipulateType } from 'dayjs' import { storeToRefs } from 'pinia' +import dayjs from 'dayjs' import { getDynamicRange, getCustomTime } from '@/custom-component/v-query/time-format' import { getCustomRange } from '@/custom-component/v-query/time-format-dayjs' const dvMainStore = dvMainStoreWithOut() @@ -8,23 +10,37 @@ const { componentData, canvasStyleData } = storeToRefs(dvMainStore) const getDynamicRangeTime = (type: number, selectValue: any, timeGranularityMultiple: string) => { const timeType = (timeGranularityMultiple || '').split('range')[0] - if (timeGranularityMultiple === 'datetimerange' || type === 1 || !timeType) { + if ('datetimerange' === timeGranularityMultiple || type === 1 || !timeType) { return selectValue.map(ele => +new Date(ele)) } - const [start, end] = selectValue + if (timeGranularityMultiple.includes('range') && type === 7) { + return [ + +new Date( + dayjs(selectValue[0]) + .startOf(timeType as 'month' | 'year' | 'date') + .format('YYYY-MM-DD HH:mm:ss') + ), + +new Date( + dayjs(selectValue[1]) + .endOf(timeType as 'month' | 'year' | 'date') + .format('YYYY-MM-DD HH:mm:ss') + ) + ] + } + + const [start] = selectValue return [ +new Date(start), +getCustomTime( 1, - timeType, + timeType as ManipulateType, timeType, 'b', null, timeGranularityMultiple, - 'start-config', - new Date(end) + 'start-config' ) - 1000 ] } @@ -58,32 +74,42 @@ export const getRange = (selectValue, timeGranularity) => { } } const getYearEnd = timestamp => { - const time = new Date(timestamp) return [ - +new Date(time.getFullYear(), 0, 1), - +new Date(time.getFullYear(), 11, 31) + 60 * 1000 * 60 * 24 - 1000 + +new Date(dayjs(timestamp).startOf('year').format('YYYY/MM/DD HH:mm:ss')), + +new Date(dayjs(timestamp).endOf('year').format('YYYY/MM/DD HH:mm:ss')) ] } const getMonthEnd = timestamp => { - const time = new Date(timestamp) - const date = new Date(time.getFullYear(), time.getMonth(), 1) - date.setDate(1) - date.setMonth(date.getMonth() + 1) - return [+new Date(time.getFullYear(), time.getMonth(), 1), +new Date(date.getTime() - 1000)] + return [ + +new Date(dayjs(timestamp).startOf('month').format('YYYY/MM/DD HH:mm:ss')), + +new Date(dayjs(timestamp).endOf('month').format('YYYY/MM/DD HH:mm:ss')) + ] } const getDayEnd = timestamp => { - return [+new Date(timestamp), +new Date(timestamp) + 60 * 1000 * 60 * 24 - 1000] + return [ + +new Date(dayjs(timestamp).startOf('day').format('YYYY/MM/DD HH:mm:ss')), + +new Date(dayjs(timestamp).endOf('day').format('YYYY/MM/DD HH:mm:ss')) + ] } -const getFieldId = (arr, result) => { - const [obj] = result - const idArr = obj.split(',') - return arr - .map(ele => ele.id) - .slice(0, idArr.length) - .join(',') +const getFieldId = (arr, result, relationshipChartIndex, ids) => { + const [obj] = [...result].reverse() + const valArr = obj.split(',') + const idArr = arr.map(ele => ele.id) + const indexArr = relationshipChartIndex.filter(ele => valArr[ele]) + if (!relationshipChartIndex.length) { + return [idArr.slice(0, valArr.length).join(','), [...new Set(result)]] + } else { + for (const key in result) { + result[key] = indexArr.map(ele => result[key].split(',')[ele]).join(',') + } + return [ + indexArr.map(ele => ids[ele]).join(','), + result.filter(ele => !ele.endsWith(',') && !!ele) + ] + } } const getValueByDefaultValueCheckOrFirstLoad = ( @@ -123,10 +149,10 @@ const getValueByDefaultValueCheckOrFirstLoad = ( return (selectValue?.length ? mapValue : selectValue) || '' } - if (firstLoad && !selectValue?.length) { + if (firstLoad) { return defaultValueCheck ? defaultValue : multiple ? [] : '' } - return selectValue ? selectValue : '' + return selectValue ? selectValue : multiple ? [] : '' } export const useFilter = (curComponentId: string, firstLoad = false) => { @@ -160,6 +186,19 @@ export const useFilter = (curComponentId: string, firstLoad = false) => { }) } }) + + ele.propValue.forEach(element => { + if (element.innerType === 'DeTabs') { + element.propValue.forEach(itx => { + const elementArr = itx.componentData.filter( + item => + item.innerType === 'VQuery' && + (popupAvailable || (!popupAvailable && ele.category !== 'hidden')) + ) + searchQuery(elementArr, filter, curComponentId, firstLoad) + }) + } + }) } if (ele.innerType === 'DeTabs') { @@ -276,7 +315,25 @@ export const searchQuery = (queryComponentList, filter, curComponentId, firstLoa queryComponentList.forEach(ele => { if (!!ele.propValue?.length) { ele.propValue.forEach(item => { - if (item.checkedFields.includes(curComponentId) && item.checkedFieldsMap[curComponentId]) { + let shouldSearch = false + const relationshipChartIndex = [] + const ids = Array(5).fill(1) + if (item.displayType === '9' && item.treeCheckedList?.length) { + item.treeCheckedList.forEach((itx, idx) => { + if ( + itx.checkedFields.includes(curComponentId) && + itx.checkedFieldsMap[curComponentId] && + idx < item.treeFieldList.length + ) { + relationshipChartIndex.push(idx) + ids[idx] = itx.checkedFieldsMap[curComponentId] + } + }) + } else { + shouldSearch = + item.checkedFields.includes(curComponentId) && item.checkedFieldsMap[curComponentId] + } + if (shouldSearch || relationshipChartIndex.length) { let selectValue const { id, @@ -422,9 +479,12 @@ export const searchQuery = (queryComponentList, filter, curComponentId, firstLoa firstLoad ) if (result?.length) { - const fieldId = isTree - ? getFieldId(treeFieldList, result) - : item.checkedFieldsMap[curComponentId] + let fieldId = item.checkedFieldsMap[curComponentId] + if (isTree) { + const [i, r] = getFieldId(treeFieldList, result, relationshipChartIndex, ids) + fieldId = i + result = r + } let parametersFilter = duplicateRemoval( parameters.reduce((pre, next) => { if (next.id === fieldId && !pre.length) {