更新前端src/views/hooks目录文件

This commit is contained in:
limengnan 2025-06-24 10:11:25 +08:00
parent 092b51445a
commit 1820065d63

View File

@ -1,5 +1,7 @@
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain' import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import type { ManipulateType } from 'dayjs'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import dayjs from 'dayjs'
import { getDynamicRange, getCustomTime } from '@/custom-component/v-query/time-format' import { getDynamicRange, getCustomTime } from '@/custom-component/v-query/time-format'
import { getCustomRange } from '@/custom-component/v-query/time-format-dayjs' import { getCustomRange } from '@/custom-component/v-query/time-format-dayjs'
const dvMainStore = dvMainStoreWithOut() const dvMainStore = dvMainStoreWithOut()
@ -8,23 +10,37 @@ const { componentData, canvasStyleData } = storeToRefs(dvMainStore)
const getDynamicRangeTime = (type: number, selectValue: any, timeGranularityMultiple: string) => { const getDynamicRangeTime = (type: number, selectValue: any, timeGranularityMultiple: string) => {
const timeType = (timeGranularityMultiple || '').split('range')[0] 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)) 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 [ return [
+new Date(start), +new Date(start),
+getCustomTime( +getCustomTime(
1, 1,
timeType, timeType as ManipulateType,
timeType, timeType,
'b', 'b',
null, null,
timeGranularityMultiple, timeGranularityMultiple,
'start-config', 'start-config'
new Date(end)
) - 1000 ) - 1000
] ]
} }
@ -58,32 +74,42 @@ export const getRange = (selectValue, timeGranularity) => {
} }
} }
const getYearEnd = timestamp => { const getYearEnd = timestamp => {
const time = new Date(timestamp)
return [ return [
+new Date(time.getFullYear(), 0, 1), +new Date(dayjs(timestamp).startOf('year').format('YYYY/MM/DD HH:mm:ss')),
+new Date(time.getFullYear(), 11, 31) + 60 * 1000 * 60 * 24 - 1000 +new Date(dayjs(timestamp).endOf('year').format('YYYY/MM/DD HH:mm:ss'))
] ]
} }
const getMonthEnd = timestamp => { const getMonthEnd = timestamp => {
const time = new Date(timestamp) return [
const date = new Date(time.getFullYear(), time.getMonth(), 1) +new Date(dayjs(timestamp).startOf('month').format('YYYY/MM/DD HH:mm:ss')),
date.setDate(1) +new Date(dayjs(timestamp).endOf('month').format('YYYY/MM/DD HH:mm:ss'))
date.setMonth(date.getMonth() + 1) ]
return [+new Date(time.getFullYear(), time.getMonth(), 1), +new Date(date.getTime() - 1000)]
} }
const getDayEnd = timestamp => { 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 getFieldId = (arr, result, relationshipChartIndex, ids) => {
const [obj] = result const [obj] = [...result].reverse()
const idArr = obj.split(',') const valArr = obj.split(',')
return arr const idArr = arr.map(ele => ele.id)
.map(ele => ele.id) const indexArr = relationshipChartIndex.filter(ele => valArr[ele])
.slice(0, idArr.length) if (!relationshipChartIndex.length) {
.join(',') 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 = ( const getValueByDefaultValueCheckOrFirstLoad = (
@ -123,10 +149,10 @@ const getValueByDefaultValueCheckOrFirstLoad = (
return (selectValue?.length ? mapValue : selectValue) || '' return (selectValue?.length ? mapValue : selectValue) || ''
} }
if (firstLoad && !selectValue?.length) { if (firstLoad) {
return defaultValueCheck ? defaultValue : multiple ? [] : '' return defaultValueCheck ? defaultValue : multiple ? [] : ''
} }
return selectValue ? selectValue : '' return selectValue ? selectValue : multiple ? [] : ''
} }
export const useFilter = (curComponentId: string, firstLoad = false) => { 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') { if (ele.innerType === 'DeTabs') {
@ -276,7 +315,25 @@ export const searchQuery = (queryComponentList, filter, curComponentId, firstLoa
queryComponentList.forEach(ele => { queryComponentList.forEach(ele => {
if (!!ele.propValue?.length) { if (!!ele.propValue?.length) {
ele.propValue.forEach(item => { 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 let selectValue
const { const {
id, id,
@ -422,9 +479,12 @@ export const searchQuery = (queryComponentList, filter, curComponentId, firstLoa
firstLoad firstLoad
) )
if (result?.length) { if (result?.length) {
const fieldId = isTree let fieldId = item.checkedFieldsMap[curComponentId]
? getFieldId(treeFieldList, result) if (isTree) {
: item.checkedFieldsMap[curComponentId] const [i, r] = getFieldId(treeFieldList, result, relationshipChartIndex, ids)
fieldId = i
result = r
}
let parametersFilter = duplicateRemoval( let parametersFilter = duplicateRemoval(
parameters.reduce((pre, next) => { parameters.reduce((pre, next) => {
if (next.id === fieldId && !pre.length) { if (next.id === fieldId && !pre.length) {