From da11f5b8ca3e96f1c74fc0f7022155de7565364b Mon Sep 17 00:00:00 2001 From: Fine Date: Wed, 12 Oct 2022 16:59:44 +0800 Subject: [PATCH] update --- src/components/Graph.vue | 26 ++++-------------------- src/hooks/useAssociateProcessor.ts | 32 +++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/components/Graph.vue b/src/components/Graph.vue index dbde4827..2ba6b8ad 100644 --- a/src/components/Graph.vue +++ b/src/components/Graph.vue @@ -66,7 +66,6 @@ const visMenus = ref(false); const { setOptions, resize, getInstance } = useECharts( chartRef as Ref ); -const { eventAssociate } = associateProcessor(); const currentParams = ref>(null); const showTrace = ref(false); const traceOptions = ref<{ type: string; filters?: unknown }>({ @@ -154,6 +153,7 @@ function updateOptions() { return; } if (props.filters.isRange) { + const { eventAssociate } = associateProcessor(); const options = eventAssociate(props); setOptions(options || props.option); } else { @@ -166,27 +166,8 @@ function updateOptions() { } function viewTrace() { - if (!currentParams.value) { - return; - } - const start = appStore.intervalUnix[currentParams.value.dataIndex]; - const end = start; - const { step } = appStore.durationRow; - const item = { - duration: { - start: dateFormatStep( - getLocalTime(appStore.utc, new Date(start)), - step, - true - ), - end: dateFormatStep( - getLocalTime(appStore.utc, new Date(end)), - step, - true - ), - step, - }, - }; + const item = associateProcessor().traceFilters(currentParams.value); + traceOptions.value = { ...traceOptions.value, filters: item, @@ -205,6 +186,7 @@ watch( } let options; if (props.filters && props.filters.isRange) { + const { eventAssociate } = associateProcessor(); options = eventAssociate(props); } setOptions(options || props.option); diff --git a/src/hooks/useAssociateProcessor.ts b/src/hooks/useAssociateProcessor.ts index 5e6fba1b..cc3554cb 100644 --- a/src/hooks/useAssociateProcessor.ts +++ b/src/hooks/useAssociateProcessor.ts @@ -14,6 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { useAppStoreWithOut } from "@/store/modules/app"; +import dateFormatStep from "@/utils/dateFormat"; +import getLocalTime from "@/utils/localtime"; + export default function associateProcessor() { function eventAssociate(props: any) { if (!props.filters) { @@ -59,5 +63,31 @@ export default function associateProcessor() { }; return options; } - return { eventAssociate }; + function traceFilters(currentParams: any) { + const appStore = useAppStoreWithOut(); + + if (!currentParams.value) { + return; + } + const start = appStore.intervalUnix[currentParams.value.dataIndex]; + const end = start; + const { step } = appStore.durationRow; + const item = { + duration: { + start: dateFormatStep( + getLocalTime(appStore.utc, new Date(start)), + step, + true + ), + end: dateFormatStep( + getLocalTime(appStore.utc, new Date(end)), + step, + true + ), + step, + }, + }; + return item; + } + return { eventAssociate, traceFilters }; }