diff --git a/cc-inspector/src/views/devtools/bus.ts b/cc-inspector/src/views/devtools/bus.ts index 3da3ef4..4481b4d 100644 --- a/cc-inspector/src/views/devtools/bus.ts +++ b/cc-inspector/src/views/devtools/bus.ts @@ -9,6 +9,7 @@ export enum BusMsg { * 开关定时器,方便测试 */ EnableSchedule = "EnableSchedule", + SelectNode = "SelectNode", } export const Bus = new TinyEmitter(); diff --git a/cc-inspector/src/views/devtools/hierarchy.vue b/cc-inspector/src/views/devtools/hierarchy.vue index 42d5c21..06a4a94 100644 --- a/cc-inspector/src/views/devtools/hierarchy.vue +++ b/cc-inspector/src/views/devtools/hierarchy.vue @@ -14,7 +14,7 @@ import ccui from "@xuyanfeng/cc-ui"; import { storeToRefs } from "pinia"; import { defineComponent, nextTick, onMounted, onUnmounted, ref, toRaw, watch } from "vue"; -import { Msg, PluginEvent, RequestNodeInfoData, RequestTreeInfoData, ResponseSetPropertyData } from "../../core/types"; +import { Msg, PluginEvent, RequestTreeInfoData, ResponseSetPropertyData } from "../../core/types"; import { bridge } from "./bridge"; import { Bus, BusMsg } from "./bus"; import { EngineData, TreeData } from "./data"; @@ -26,24 +26,28 @@ export default defineComponent({ components: { CCButtonGroup, CCInput, CCTree, CCDock }, setup() { onMounted(() => {}); - Bus.on(BusMsg.ShowPlace, (data: EngineData) => { + const funcShowPlace = (data: EngineData) => { console.log(toRaw(data)); _expand(data.engineUUID); - }); - Bus.on(BusMsg.EnableSchedule, (b: boolean) => { + }; + const funcEnableSchedule = (b: boolean) => { if (b) { timer.create(); } else { timer.clean(); } - }); + }; const timer: Timer = new Timer(() => { updateTree(); }); onMounted(() => { + Bus.on(BusMsg.ShowPlace, funcShowPlace); + Bus.on(BusMsg.EnableSchedule, funcEnableSchedule); timer.create(); }); onUnmounted(() => { + Bus.off(BusMsg.ShowPlace, funcShowPlace); + Bus.off(BusMsg.EnableSchedule, funcEnableSchedule); timer.clean(); }); function _expand(uuid: string) { @@ -93,11 +97,6 @@ export default defineComponent({ const matchCase = ref(false); const elTree = ref(); const treeData = ref([]); - function updateNodeInfo() { - if (selectedUUID) { - bridge.send(Msg.RequestNodeInfo, { uuid: selectedUUID } as RequestNodeInfoData); - } - } let selectedUUID: string | null = null; bridge.on(Msg.ResponseTreeInfo, (event: PluginEvent) => { let data: Array = event.data; @@ -139,6 +138,10 @@ export default defineComponent({ } }); const expandedKeys = ref>([]); + function updateSelect(uuid: string | null) { + selectedUUID = uuid; + Bus.emit(BusMsg.SelectNode, uuid); + } return { expandedKeys, elTree, @@ -147,14 +150,13 @@ export default defineComponent({ matchCase, frameID, handleNodeUnclick() { - selectedUUID = null; + updateSelect(null); }, handleNodeClick(data: TreeData | null) { if (data) { - selectedUUID = data.id; - updateNodeInfo(); + updateSelect(data.id); } else { - selectedUUID = null; + updateSelect(null); } }, onNodeExpand(data: TreeData) { diff --git a/cc-inspector/src/views/devtools/index.vue b/cc-inspector/src/views/devtools/index.vue index 96f3e28..8bb0bc0 100644 --- a/cc-inspector/src/views/devtools/index.vue +++ b/cc-inspector/src/views/devtools/index.vue @@ -60,9 +60,11 @@ export default defineComponent({ checkSupport(); }); onMounted(() => { + Bus.on(BusMsg.EnableSchedule, funcEnableSchedule); timer.create(); }); onUnmounted(() => { + Bus.off(BusMsg.EnableSchedule, funcEnableSchedule); timer.clean(); }); // 问题:没有上下文的权限,只能操作DOM @@ -82,13 +84,13 @@ export default defineComponent({ } }); } - Bus.on(BusMsg.EnableSchedule, (b: boolean) => { + const funcEnableSchedule = (b: boolean) => { if (b) { timer.create(); } else { timer.clean(); } - }); + }; bridge.on(Msg.ResponseTreeInfo, (event: PluginEvent) => { let data: Array = event.data; isShowDebug.value = true; diff --git a/cc-inspector/src/views/devtools/inspector.vue b/cc-inspector/src/views/devtools/inspector.vue index f094244..1ffccf6 100644 --- a/cc-inspector/src/views/devtools/inspector.vue +++ b/cc-inspector/src/views/devtools/inspector.vue @@ -7,17 +7,50 @@