修复没有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",
SelectNode = "SelectNode",
}
export const Bus = new TinyEmitter();

View File

@ -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<boolean>(false);
const elTree = ref<typeof CCTree>();
const treeData = ref<TreeData[]>([]);
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<TreeData> = event.data;
@ -139,6 +138,10 @@ export default defineComponent({
}
});
const expandedKeys = ref<Array<string>>([]);
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) {

View File

@ -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<TreeData> = event.data;
isShowDebug.value = true;

View File

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

View File

@ -14,7 +14,7 @@
<script lang="ts">
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 { bridge } from "../bridge";
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;
export default defineComponent({
name: "property-group",
components: {
UiProp,
CCSection,
CCInput,
CCButton,
CCInputNumber,
CCSelect,
CCCheckBox,
CCColor,
},
components: { UiProp, CCSection, CCInput, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCColor },
props: {
group: {
type: Object as PropType<Group>,
@ -42,8 +33,14 @@ export default defineComponent({
},
},
setup(props, context) {
Bus.on(BusMsg.FoldAllGroup, (b: boolean) => {
const funcFoldAllGroup = (b: boolean) => {
fold.value = b;
};
onMounted(() => {
Bus.on(BusMsg.FoldAllGroup, funcFoldAllGroup);
});
onUnmounted(() => {
Bus.off(BusMsg.FoldAllGroup, funcFoldAllGroup);
});
const fold = ref(false);
watch(