mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-11-26 02:07:37 +00:00
追加测试server的逻辑
This commit is contained in:
46
cc-inspector/src/views/devtools/test/server.ts
Normal file
46
cc-inspector/src/views/devtools/test/server.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Msg, Page, PluginEvent } from "../../../core/types";
|
||||
import { NodeInfoData, TreeData } from "../data";
|
||||
export class TestClient {
|
||||
recv(event: PluginEvent) {
|
||||
|
||||
}
|
||||
}
|
||||
export class TestServer {
|
||||
private clients: TestClient[] = [];
|
||||
add(client: TestClient) {
|
||||
this.clients.push(client);
|
||||
}
|
||||
recv(msg: string, data: any) {
|
||||
switch (msg) {
|
||||
case Msg.NodeInfo: {
|
||||
console.log(data);
|
||||
const ret: NodeInfoData = {
|
||||
uuid: "1",
|
||||
group: []
|
||||
};
|
||||
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.NodeInfo, ret);
|
||||
this.send(event);
|
||||
break;
|
||||
}
|
||||
case Msg.TreeInfo: {
|
||||
const data: TreeData = {
|
||||
id: "1",
|
||||
text: "root",
|
||||
active: true,
|
||||
children: [],
|
||||
};
|
||||
const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.TreeInfo, data);
|
||||
this.send(event);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
send(event: PluginEvent) {
|
||||
this.clients.forEach((client) => {
|
||||
client.recv(event)
|
||||
});
|
||||
}
|
||||
}
|
||||
export const testServer = new TestServer();
|
||||
55
cc-inspector/src/views/devtools/test/test.vue
Normal file
55
cc-inspector/src/views/devtools/test/test.vue
Normal file
@@ -0,0 +1,55 @@
|
||||
<template>
|
||||
<div v-if="show" class="test">
|
||||
<CCSection name="功能测试">
|
||||
<CCButton @click="onClickHasCocosGame">Has CocosGame</CCButton>
|
||||
<CCButton @click="onClickNoCocosGame">No CocosGame</CCButton>
|
||||
<CCButton @click="onTestTree">init tree data</CCButton>
|
||||
</CCSection>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import ccui from "@xuyanfeng/cc-ui";
|
||||
import { ITreeData } from "@xuyanfeng/cc-ui/types/cc-tree/const";
|
||||
import { defineComponent, ref } from "vue";
|
||||
import { Msg, Page, PluginEvent } from "../../../core/types";
|
||||
import { connectBackground } from "../connectBackground";
|
||||
import { TreeData } from "../data";
|
||||
import { TestServer } from "./server";
|
||||
const { CCButton, CCSection } = ccui.components;
|
||||
export default defineComponent({
|
||||
name: "test",
|
||||
components: { CCButton, CCSection },
|
||||
emits: ["validGame"],
|
||||
props: {
|
||||
isCocosGame: { type: Boolean, default: false },
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
const show = ref(__DEV__);
|
||||
return {
|
||||
show,
|
||||
onClickHasCocosGame() {
|
||||
emit("validGame", true);
|
||||
},
|
||||
onClickNoCocosGame() {
|
||||
emit("validGame", false);
|
||||
},
|
||||
onTestTree() {
|
||||
const data: TreeData = {
|
||||
id: "1",
|
||||
text: "root",
|
||||
active: true,
|
||||
children: [],
|
||||
};
|
||||
const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.TreeInfo, data);
|
||||
connectBackground.doCallback(event);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style scoped lang="less">
|
||||
.test {
|
||||
color: rgb(192, 56, 56);
|
||||
font-size: 11%;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user