259 lines
6.6 KiB
Vue
Raw Normal View History

2019-03-15 10:08:39 +08:00
<template>
2021-04-03 19:31:47 +08:00
<div id="devtools">
<div v-show="isShowDebug" class="find">
<div v-if="false">
<el-button type="success" @click="onMemoryTest">内存测试</el-button>
2019-03-18 18:03:07 +08:00
</div>
2021-04-03 19:31:47 +08:00
<div v-if="false">
<span>JS堆栈限制: {{ memory.performance.jsHeapSizeLimit }}</span>
<span>JS堆栈大小: {{ memory.performance.totalJSHeapSize }}</span>
<span>JS堆栈使用: {{ memory.performance.usedJSHeapSize }}</span>
2019-03-18 12:05:07 +08:00
</div>
2021-04-03 19:31:47 +08:00
<div class="left">
<div class="tool-btn">
<el-switch active-text="实时监控" v-model="watchEveryTime" @change="onChangeWatchState"></el-switch>
<div class="flex1"></div>
<el-button type="success" class="el-icon-refresh" @click="onBtnClickUpdateTree"></el-button>
</div>
<div class="treeList">
<el-tree :data="treeData"
style="display: inline-block;"
:props="defaultProps"
:highlight-current="true"
:default-expand-all="false"
:expand-on-click-node="true"
@node-click="handleNodeClick"></el-tree>
</div>
</div>
<div class="right">
2021-04-05 18:38:44 +08:00
<NodeBaseProperty :all-group="treeItemData"></NodeBaseProperty>
2021-04-03 19:31:47 +08:00
</div>
2019-03-15 10:08:39 +08:00
</div>
2021-04-03 19:31:47 +08:00
<div v-show="!isShowDebug" class="no-find">
<span>未发现cocos creator的游戏!</span>
<el-button type="success" class="el-icon-refresh" @click="onBtnClickUpdatePage">刷新</el-button>
2019-03-15 10:08:39 +08:00
</div>
</div>
</template>
2021-04-03 19:31:47 +08:00
<script lang="ts">
// import injectScript from '../injectScript.js'
// import EvalCode from "./evalCodeString.js";
import Vue from "vue";
import {Component, Prop} from "vue-property-decorator";
2021-04-03 22:45:51 +08:00
import SceneProperty from "@/devtools/ccType/SceneProperty.vue";
import ComponentsProperty from "@/devtools/ccType/ComponentsProperty.vue";
import NodeBaseProperty from "@/devtools/ccType/NodeBaseProperty.vue";
2021-04-03 19:31:47 +08:00
const PluginMsg = require("../core/plugin-msg");
@Component({
components: {
2021-04-03 22:45:51 +08:00
NodeBaseProperty, ComponentsProperty, SceneProperty,
}
})
2021-04-03 19:31:47 +08:00
export default class Index extends Vue {
2021-04-04 20:48:18 +08:00
private isShowDebug: boolean = false;
2021-04-05 18:38:44 +08:00
treeItemData: Array<Record<string, any>> = [];
2021-04-03 22:45:51 +08:00
treeData: Array<Record<string, any>> = []
bgConn: chrome.runtime.Port | null = null// 与background.js的链接
2021-04-03 19:31:47 +08:00
// el-tree的渲染key
2021-04-03 19:31:47 +08:00
defaultProps = {
children: "children",
label: "name"
};
private watchEveryTime: boolean = false;// 实时监控节点树
2021-04-03 19:31:47 +08:00
memory = {
performance: {},
console: {},
}
2021-04-03 22:45:51 +08:00
timerID: number = 0;
2019-03-18 12:05:07 +08:00
2021-04-03 19:31:47 +08:00
created() {
this.onTestData();
if (chrome && chrome.runtime) {
this._initChromeRuntimeConnect();
}
2019-03-15 10:08:39 +08:00
2021-04-03 19:31:47 +08:00
window.addEventListener("message", function (event) {
console.log("on vue:" + JSON.stringify(event.data));
console.log("on vue:" + JSON.stringify(event));
}, false);
}
2019-03-18 12:05:07 +08:00
2021-04-03 19:31:47 +08:00
_initChromeRuntimeConnect() {
// chrome.devtools.inspectedWindow.tabId
// 接收来自background.js的消息数据
this.bgConn = chrome.runtime.connect({name: PluginMsg.Page.Devtools});
this.bgConn.onMessage.addListener((data, sender) => {
if (!data) {
return;
2019-03-15 10:08:39 +08:00
}
2021-04-03 19:31:47 +08:00
let eventData = data.data;
let eventMsg = data.msg;
if (eventMsg === PluginMsg.Msg.ListInfo) {
this.isShowDebug = true;
2021-04-05 18:38:44 +08:00
if (!Array.isArray(eventData)) {
eventData = [eventData]
}
this.treeData = eventData;
2021-04-03 19:31:47 +08:00
} else if (eventMsg === PluginMsg.Msg.Support) {
this.isShowDebug = eventData.support;
} else if (eventMsg === PluginMsg.Msg.NodeInfo) {
this.isShowDebug = true;
2021-04-05 18:38:44 +08:00
if (!Array.isArray(eventData)) {
eventData = [eventData]
}
2021-04-03 19:31:47 +08:00
this.treeItemData = eventData;
} else if (eventMsg === PluginMsg.Msg.MemoryInfo) {
this.memory = eventData;
}
});
}
2019-04-16 10:34:34 +08:00
2021-04-03 19:31:47 +08:00
onTestData() {
for (let i = 0; i < 40; i++) {
this.treeData.push({name: `node${i}`, children: [{name: `children11111111111111111111111111111111111111${i}`}]})
}
}
2019-04-16 10:34:34 +08:00
2021-04-03 22:45:51 +08:00
handleNodeClick(data: any) {
2021-04-03 19:31:47 +08:00
// todo 去获取节点信息
// console.log(data);
let uuid = data.uuid;
if (uuid !== undefined) {
this.evalInspectorFunction("getNodeInfo", `"${uuid}"`);
}
}
2019-04-16 10:34:34 +08:00
2021-04-03 19:31:47 +08:00
onChangeWatchState() {
if (this.watchEveryTime) {
2021-04-03 22:45:51 +08:00
this.timerID = setInterval(() => {
2021-04-03 19:31:47 +08:00
this.onBtnClickUpdateTree();
2021-04-03 22:45:51 +08:00
}, 100);
2021-04-03 19:31:47 +08:00
} else {
clearInterval(this.timerID);
}
2019-04-16 10:34:34 +08:00
2021-04-03 19:31:47 +08:00
}
2021-04-05 18:38:44 +08:00
evalInspectorFunction(func: string, para?: string = '') {
if (!func || func.length < 0) {
console.log("缺失执行函数名!");
return;
2021-04-03 19:31:47 +08:00
}
2021-04-05 18:38:44 +08:00
if (!chrome || !chrome.devtools) {
console.log("环境异常,无法执行函数");
return;
2021-04-03 19:31:47 +08:00
}
2021-04-05 18:38:44 +08:00
let injectCode =
`if(window.ccinspector){
let func = window.ccinspector.${func};
2019-03-18 12:05:07 +08:00
if(func){
2021-04-05 18:38:44 +08:00
console.log("执行${func}成功");
func.apply(window.ccinspector,[${para}]);
2019-03-18 12:05:07 +08:00
}else{
2021-04-05 18:38:44 +08:00
console.log("未发现${func}函数");
2019-03-18 12:05:07 +08:00
}
2021-04-05 18:38:44 +08:00
}else{
console.log("脚本inject.js未注入");
}`;
chrome.devtools.inspectedWindow.eval(injectCode, (result, isException) => {
if (isException) {
console.error(isException);
} else {
console.log(`执行结果:${result}`)
2021-04-03 19:31:47 +08:00
}
2021-04-05 18:38:44 +08:00
});
2021-04-03 19:31:47 +08:00
}
onBtnClickUpdateTree() {
this.evalInspectorFunction("updateTreeInfo");
}
onBtnClickUpdatePage() {
this.evalInspectorFunction("checkIsGamePage", "true");
2019-03-15 10:08:39 +08:00
}
2021-04-03 19:31:47 +08:00
onMemoryTest() {
this.evalInspectorFunction("onMemoryInfo");
2019-03-15 10:08:39 +08:00
}
2021-04-03 19:31:47 +08:00
}
</script>
2019-03-15 10:08:39 +08:00
2021-04-03 19:31:47 +08:00
<style scoped lang="less">
@import "../index.less";
2019-03-15 10:08:39 +08:00
2021-04-03 19:31:47 +08:00
#devtools {
display: flex;
width: 100%;
height: 100%;
2019-03-15 10:08:39 +08:00
2021-04-03 19:31:47 +08:00
.no-find {
display: flex;
flex: 1;
flex-direction: row;
align-items: center;
justify-content: center;
2019-03-18 12:05:07 +08:00
2021-04-03 19:31:47 +08:00
span {
margin-right: 20px;
}
2019-03-18 12:05:07 +08:00
}
2021-04-03 19:31:47 +08:00
.find {
display: flex;
flex: 1;
2019-03-18 12:05:07 +08:00
flex-direction: row;
2021-04-03 19:31:47 +08:00
.left {
display: flex;
flex: 1;
flex-direction: column;
2019-03-18 12:05:07 +08:00
2021-04-03 19:31:47 +08:00
.tool-btn {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.treeList {
margin-top: 3px;
flex: 1;
height: 100%;
border-radius: 4px;
min-height: 20px;
overflow: scroll;
width: 300px;
&::-webkit-scrollbar {
width: 6px;
height: 6px;
background: #999;
border-radius: 2px;
}
&::-webkit-scrollbar-thumb {
background-color: #333;
border-radius: 2px;
}
}
}
.right {
flex: 2;
2021-04-04 19:21:17 +08:00
background: #e5e9f2;
overflow: scroll;
2021-04-03 19:31:47 +08:00
}
2019-03-18 12:05:07 +08:00
}
2021-04-03 19:31:47 +08:00
}
2019-03-15 10:08:39 +08:00
</style>