diff --git a/package-lock.json b/package-lock.json index 40152bd4..a388a03a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "echarts": "^5.2.2", "element-plus": "^2.2.5", "lodash": "^4.17.21", + "mitt": "^3.0.1", "monaco-editor": "^0.34.1", "pinia": "^2.0.28", "vis-timeline": "^7.5.1", @@ -9750,9 +9751,9 @@ } }, "node_modules/mitt": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/mitt/-/mitt-2.1.0.tgz", - "integrity": "sha512-ILj2TpLiysu2wkBbWjAmww7TkZb65aiQO+DkVdUTBpBXq+MHYiETENkKFMtsJZX1Lf4pe4QOrTSjIfUwN5lRdg==" + "version": "3.0.1", + "resolved": "https://registry.npmmirror.com/mitt/-/mitt-3.0.1.tgz", + "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==" }, "node_modules/mixin-deep": { "version": "1.3.2", @@ -14819,6 +14820,11 @@ "mitt": "^2.1.0" } }, + "node_modules/vue-grid-layout/node_modules/mitt": { + "version": "2.1.0", + "resolved": "https://registry.npmmirror.com/mitt/-/mitt-2.1.0.tgz", + "integrity": "sha512-ILj2TpLiysu2wkBbWjAmww7TkZb65aiQO+DkVdUTBpBXq+MHYiETENkKFMtsJZX1Lf4pe4QOrTSjIfUwN5lRdg==" + }, "node_modules/vue-i18n": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/vue-i18n/-/vue-i18n-9.2.2.tgz", @@ -22286,9 +22292,9 @@ } }, "mitt": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/mitt/-/mitt-2.1.0.tgz", - "integrity": "sha512-ILj2TpLiysu2wkBbWjAmww7TkZb65aiQO+DkVdUTBpBXq+MHYiETENkKFMtsJZX1Lf4pe4QOrTSjIfUwN5lRdg==" + "version": "3.0.1", + "resolved": "https://registry.npmmirror.com/mitt/-/mitt-3.0.1.tgz", + "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==" }, "mixin-deep": { "version": "1.3.2", @@ -25853,6 +25859,13 @@ "@interactjs/modifiers": "^1.10.2", "element-resize-detector": "^1.2.1", "mitt": "^2.1.0" + }, + "dependencies": { + "mitt": { + "version": "2.1.0", + "resolved": "https://registry.npmmirror.com/mitt/-/mitt-2.1.0.tgz", + "integrity": "sha512-ILj2TpLiysu2wkBbWjAmww7TkZb65aiQO+DkVdUTBpBXq+MHYiETENkKFMtsJZX1Lf4pe4QOrTSjIfUwN5lRdg==" + } } }, "vue-i18n": { diff --git a/package.json b/package.json index beca5ae2..c6b35cbb 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "echarts": "^5.2.2", "element-plus": "^2.2.5", "lodash": "^4.17.21", + "mitt": "^3.0.1", "monaco-editor": "^0.34.1", "pinia": "^2.0.28", "vis-timeline": "^7.5.1", diff --git a/src/main.ts b/src/main.ts index d051bb83..d4dbbf7a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,6 +22,7 @@ import i18n from "./locales"; import { useAppStoreWithOut } from "@/store/modules/app"; import "./styles/index.ts"; import "virtual:svg-icons-register"; +import mitt from "mitt"; const app = createApp(App); const appStore = useAppStoreWithOut(); @@ -29,6 +30,7 @@ const appStore = useAppStoreWithOut(); app.use(components); app.use(i18n); app.use(store); +app.config.globalProperties.$mybus = mitt(); mountApp(); async function mountApp() { diff --git a/src/utils/mitt.ts b/src/utils/mitt.ts new file mode 100644 index 00000000..433de4a3 --- /dev/null +++ b/src/utils/mitt.ts @@ -0,0 +1,22 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mitt from "mitt"; + +const emitter = mitt(); + +export default emitter; diff --git a/src/views/dashboard/controls/Trace.vue b/src/views/dashboard/controls/Trace.vue index d3fddd2a..b988df3a 100644 --- a/src/views/dashboard/controls/Trace.vue +++ b/src/views/dashboard/controls/Trace.vue @@ -25,11 +25,17 @@ limitations under the License. -->
- +
-
+
@@ -47,6 +53,7 @@ limitations under the License. --> import TraceDetail from "../related/trace/Detail.vue"; import { useI18n } from "vue-i18n"; import { useDashboardStore } from "@/store/modules/dashboard"; + import emitter from "@/utils/mitt"; /* global defineProps */ const props = defineProps({ @@ -58,12 +65,14 @@ limitations under the License. --> needQuery: { type: Boolean, default: true }, }); provide("options", props.data); + const defaultWidth = 280, + minArrowLeftWidth = 120; const serviceId = ref(""); const { t } = useI18n(); const dashboardStore = useDashboardStore(); const isLeft = ref(true); const showIcon = ref(false); - const currentWidth = ref(280); + const currentWidth = ref(defaultWidth); const isDrag = ref(false); function removeWidget() { @@ -72,14 +81,22 @@ limitations under the License. --> function getService(id: string) { serviceId.value = id; } - // The width of the trace-list is always determined by the direction of the arrow. + // When click the arrow, the width of the segment list is determined by the direction it points to. function triggerArrow() { - currentWidth.value = isLeft.value ? 0 : 280; + currentWidth.value = isLeft.value ? 0 : defaultWidth; isLeft.value = !isLeft.value; + setTimeout(() => { + emitter.emit("traceResize", "trace-arrow"); + }); + } + function popSegmentList() { + if (currentWidth.value >= defaultWidth) { + return; + } + currentWidth.value = defaultWidth; + isLeft.value = true; + emitter.emit("traceResize", "trace-search"); } - const mousedown = () => { - isDrag.value = true; - }; const mousemove = (event: MouseEvent) => { if (!isDrag.value) { return; @@ -87,11 +104,18 @@ limitations under the License. --> const diffX = event.clientX; let leftWidth = document.querySelector(".trace-list")!.getBoundingClientRect(); currentWidth.value = diffX - leftWidth.left; - isLeft.value = currentWidth.value >= 120; + isLeft.value = currentWidth.value >= minArrowLeftWidth; + emitter.emit("traceResize", "trace-move"); }; const mouseup = () => { + showIcon.value = false; isDrag.value = false; }; + const mousedown = (event: MouseEvent) => { + if ((event.target as HTMLDivElement)?.className === "trace-line") { + isDrag.value = true; + } + }; onMounted(() => { document.addEventListener("mousedown", mousedown); document.addEventListener("mousemove", mousemove); @@ -101,6 +125,7 @@ limitations under the License. --> document.removeEventListener("mousedown", mousedown); document.removeEventListener("mousemove", mousemove); document.removeEventListener("mouseup", mouseup); + emitter.off("traceResize"); });