修复没有off带来的问题

This commit is contained in:
xu_yanfeng 2024-12-28 15:05:05 +08:00
parent 8d5b8240cc
commit 1000b60f20
5 changed files with 65 additions and 33 deletions

View File

@ -9,6 +9,7 @@ export enum BusMsg {
* 便 * 便
*/ */
EnableSchedule = "EnableSchedule", EnableSchedule = "EnableSchedule",
SelectNode = "SelectNode",
} }
export const Bus = new TinyEmitter(); export const Bus = new TinyEmitter();

View File

@ -14,7 +14,7 @@
import ccui from "@xuyanfeng/cc-ui"; import ccui from "@xuyanfeng/cc-ui";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
import { defineComponent, nextTick, onMounted, onUnmounted, ref, toRaw, watch } from "vue"; 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 { bridge } from "./bridge";
import { Bus, BusMsg } from "./bus"; import { Bus, BusMsg } from "./bus";
import { EngineData, TreeData } from "./data"; import { EngineData, TreeData } from "./data";
@ -26,24 +26,28 @@ export default defineComponent({
components: { CCButtonGroup, CCInput, CCTree, CCDock }, components: { CCButtonGroup, CCInput, CCTree, CCDock },
setup() { setup() {
onMounted(() => {}); onMounted(() => {});
Bus.on(BusMsg.ShowPlace, (data: EngineData) => { const funcShowPlace = (data: EngineData) => {
console.log(toRaw(data)); console.log(toRaw(data));
_expand(data.engineUUID); _expand(data.engineUUID);
}); };
Bus.on(BusMsg.EnableSchedule, (b: boolean) => { const funcEnableSchedule = (b: boolean) => {
if (b) { if (b) {
timer.create(); timer.create();
} else { } else {
timer.clean(); timer.clean();
} }
}); };
const timer: Timer = new Timer(() => { const timer: Timer = new Timer(() => {
updateTree(); updateTree();
}); });
onMounted(() => { onMounted(() => {
Bus.on(BusMsg.ShowPlace, funcShowPlace);
Bus.on(BusMsg.EnableSchedule, funcEnableSchedule);
timer.create(); timer.create();
}); });
onUnmounted(() => { onUnmounted(() => {
Bus.off(BusMsg.ShowPlace, funcShowPlace);
Bus.off(BusMsg.EnableSchedule, funcEnableSchedule);
timer.clean(); timer.clean();
}); });
function _expand(uuid: string) { function _expand(uuid: string) {
@ -93,11 +97,6 @@ export default defineComponent({
const matchCase = ref<boolean>(false); const matchCase = ref<boolean>(false);
const elTree = ref<typeof CCTree>(); const elTree = ref<typeof CCTree>();
const treeData = ref<TreeData[]>([]); const treeData = ref<TreeData[]>([]);
function updateNodeInfo() {
if (selectedUUID) {
bridge.send(Msg.RequestNodeInfo, { uuid: selectedUUID } as RequestNodeInfoData);
}
}
let selectedUUID: string | null = null; let selectedUUID: string | null = null;
bridge.on(Msg.ResponseTreeInfo, (event: PluginEvent) => { bridge.on(Msg.ResponseTreeInfo, (event: PluginEvent) => {
let data: Array<TreeData> = event.data; let data: Array<TreeData> = event.data;
@ -139,6 +138,10 @@ export default defineComponent({
} }
}); });
const expandedKeys = ref<Array<string>>([]); const expandedKeys = ref<Array<string>>([]);
function updateSelect(uuid: string | null) {
selectedUUID = uuid;
Bus.emit(BusMsg.SelectNode, uuid);
}
return { return {
expandedKeys, expandedKeys,
elTree, elTree,
@ -147,14 +150,13 @@ export default defineComponent({
matchCase, matchCase,
frameID, frameID,
handleNodeUnclick() { handleNodeUnclick() {
selectedUUID = null; updateSelect(null);
}, },
handleNodeClick(data: TreeData | null) { handleNodeClick(data: TreeData | null) {
if (data) { if (data) {
selectedUUID = data.id; updateSelect(data.id);
updateNodeInfo();
} else { } else {
selectedUUID = null; updateSelect(null);
} }
}, },
onNodeExpand(data: TreeData) { onNodeExpand(data: TreeData) {

View File

@ -60,9 +60,11 @@ export default defineComponent({
checkSupport(); checkSupport();
}); });
onMounted(() => { onMounted(() => {
Bus.on(BusMsg.EnableSchedule, funcEnableSchedule);
timer.create(); timer.create();
}); });
onUnmounted(() => { onUnmounted(() => {
Bus.off(BusMsg.EnableSchedule, funcEnableSchedule);
timer.clean(); timer.clean();
}); });
// DOM // DOM
@ -82,13 +84,13 @@ export default defineComponent({
} }
}); });
} }
Bus.on(BusMsg.EnableSchedule, (b: boolean) => { const funcEnableSchedule = (b: boolean) => {
if (b) { if (b) {
timer.create(); timer.create();
} else { } else {
timer.clean(); timer.clean();
} }
}); };
bridge.on(Msg.ResponseTreeInfo, (event: PluginEvent) => { bridge.on(Msg.ResponseTreeInfo, (event: PluginEvent) => {
let data: Array<TreeData> = event.data; let data: Array<TreeData> = event.data;
isShowDebug.value = true; isShowDebug.value = true;

View File

@ -7,17 +7,50 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import ccui from "@xuyanfeng/cc-ui"; import ccui from "@xuyanfeng/cc-ui";
import { defineComponent, ref } from "vue"; import { defineComponent, onMounted, onUnmounted, ref } from "vue";
import { Msg, PluginEvent, RequestObjectData, ResponseObjectData, ResponseSupportData } from "../../core/types"; import { Msg, PluginEvent, RequestNodeInfoData, RequestObjectData, ResponseObjectData, ResponseSupportData } from "../../core/types";
import { bridge } from "./bridge"; import { bridge } from "./bridge";
import { Bus, BusMsg } from "./bus"; import { Bus, BusMsg } from "./bus";
import { NodeInfoData, ObjectData } from "./data"; import { NodeInfoData, ObjectData } from "./data";
import { Timer } from "./timer";
import Properties from "./ui/propertys.vue"; import Properties from "./ui/propertys.vue";
const { CCDock } = ccui.components; const { CCDock } = ccui.components;
export default defineComponent({ export default defineComponent({
components: { Properties, CCDock }, components: { Properties, CCDock },
setup() { setup() {
function updateNodeInfo() {
if (selectedUUID) {
console.log(`update node info: ${selectedUUID}`);
bridge.send(Msg.RequestNodeInfo, { uuid: selectedUUID } as RequestNodeInfoData);
} else {
// TODO:
treeItemData.value = null;
}
}
const timer = new Timer(updateNodeInfo);
const treeItemData = ref<NodeInfoData | null>(null); const treeItemData = ref<NodeInfoData | null>(null);
const funcEnableSchedule = (b: boolean) => {
if (b) {
timer.create();
} else {
timer.clean();
}
};
let selectedUUID: string | null = null;
const funSelectNode = (uuid: string | null) => {
selectedUUID = uuid;
updateNodeInfo();
};
onMounted(() => {
Bus.on(BusMsg.SelectNode, funSelectNode);
Bus.on(BusMsg.EnableSchedule, funcEnableSchedule);
timer.create();
});
onUnmounted(() => {
Bus.off(BusMsg.SelectNode, funSelectNode);
Bus.off(BusMsg.EnableSchedule, funcEnableSchedule);
timer.clean();
});
bridge.on(Msg.ResponseSupport, (event: PluginEvent) => { bridge.on(Msg.ResponseSupport, (event: PluginEvent) => {
let data: ResponseSupportData = event.data; let data: ResponseSupportData = event.data;
const isCocosGame: boolean = data.support; const isCocosGame: boolean = data.support;
@ -41,7 +74,6 @@ export default defineComponent({
* 请求属性的列表如果一个属性请求失败会阻断后续的相同请求因为都已经失败了就没必要再响应请求了 * 请求属性的列表如果一个属性请求失败会阻断后续的相同请求因为都已经失败了就没必要再响应请求了
*/ */
const requestList: Array<{ id: string; cb: Function }> = []; const requestList: Array<{ id: string; cb: Function }> = [];
bridge.on(Msg.ResponseObjectItemData, (event: PluginEvent) => { bridge.on(Msg.ResponseObjectItemData, (event: PluginEvent) => {
const requestData: ResponseObjectData = event.data; const requestData: ResponseObjectData = event.data;
if (requestData.id !== null) { if (requestData.id !== null) {
@ -59,8 +91,6 @@ export default defineComponent({
requestList.push({ id: data.id, cb }); requestList.push({ id: data.id, cb });
bridge.send(Msg.RequestObjectItemData, data as RequestObjectData); bridge.send(Msg.RequestObjectItemData, data as RequestObjectData);
}); });
// TODO:
// treeItemData.value = null;
return { return {
treeItemData, treeItemData,
}; };

View File

@ -14,7 +14,7 @@
<script lang="ts"> <script lang="ts">
import ccui from "@xuyanfeng/cc-ui"; import ccui from "@xuyanfeng/cc-ui";
import { defineComponent, PropType, ref, toRaw, watch } from "vue"; import { defineComponent, onMounted, onUnmounted, PropType, ref, toRaw, watch } from "vue";
import { Msg, RequestLogData } from "../../../core/types"; import { Msg, RequestLogData } from "../../../core/types";
import { bridge } from "../bridge"; import { bridge } from "../bridge";
import { Bus, BusMsg } from "../bus"; import { Bus, BusMsg } from "../bus";
@ -23,16 +23,7 @@ import UiProp from "./ui-prop.vue";
const { CCInput, CCSection, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCColor } = ccui.components; const { CCInput, CCSection, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCColor } = ccui.components;
export default defineComponent({ export default defineComponent({
name: "property-group", name: "property-group",
components: { components: { UiProp, CCSection, CCInput, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCColor },
UiProp,
CCSection,
CCInput,
CCButton,
CCInputNumber,
CCSelect,
CCCheckBox,
CCColor,
},
props: { props: {
group: { group: {
type: Object as PropType<Group>, type: Object as PropType<Group>,
@ -42,8 +33,14 @@ export default defineComponent({
}, },
}, },
setup(props, context) { setup(props, context) {
Bus.on(BusMsg.FoldAllGroup, (b: boolean) => { const funcFoldAllGroup = (b: boolean) => {
fold.value = b; fold.value = b;
};
onMounted(() => {
Bus.on(BusMsg.FoldAllGroup, funcFoldAllGroup);
});
onUnmounted(() => {
Bus.off(BusMsg.FoldAllGroup, funcFoldAllGroup);
}); });
const fold = ref(false); const fold = ref(false);
watch( watch(