显示Object

This commit is contained in:
xuyanfeng 2021-06-17 22:35:37 +08:00
parent 23e7cc7cb4
commit 459bd643e6
4 changed files with 68 additions and 19 deletions

View File

@ -42,10 +42,17 @@ export class ArrayData extends Info {
} }
export class ObjectData extends Info { export class ObjectData extends Info {
data: Array<Property> = [];
constructor() { constructor() {
super(); super();
this.type = DataType.Object; this.type = DataType.Object;
} }
add(info: Property) {
this.data.push(info);
return this;
}
} }
export class NullOrUndefinedData extends Info { export class NullOrUndefinedData extends Info {

View File

@ -276,15 +276,17 @@ class CCInspector {
let hex = propertyValue.toHEX(); let hex = propertyValue.toHEX();
info = new ColorData(`#${hex}`); info = new ColorData(`#${hex}`);
} else if (Array.isArray(propertyValue)) { } else if (Array.isArray(propertyValue)) {
info = new ArrayData(); let keys = [];
for (let i = 0; i < propertyValue.length; i++) { for (let i = 0; i < propertyValue.length; i++) {
let propPath = path.concat(i.toString()); keys.push(i);
let itemData = this._genInfoData(propertyValue, i.toString(), propPath);
if (itemData) {
info.add(new Property(i.toString(), itemData));
} }
} info = this._buildObjectOrArrayData({
} else if (propertyValue instanceof Object) { data: new ArrayData(),
path: path,
value: propertyValue,
keys: keys,
})
} else {
!info && (info = this._buildVecData({ !info && (info = this._buildVecData({
// @ts-ignore // @ts-ignore
ctor: cc.Vec3, ctor: cc.Vec3,
@ -308,8 +310,12 @@ class CCInspector {
path: path, path: path,
value: propertyValue, value: propertyValue,
})) }))
!info && (info = new ObjectData()); !info && (info = this._buildObjectOrArrayData({
} else { data: new ObjectData(),
path: path,
value: propertyValue,
keys: Object.keys(propertyValue),
}));
} }
break; break;
} }
@ -322,6 +328,22 @@ class CCInspector {
return info; return info;
} }
_buildObjectOrArrayData(options: any) {
let propertyValue: Object = options.value;
let path: Array<string> = options.path;
let data: ObjectData | ArrayData = options.data;
let keys: Array<string> = options.keys;
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
let propPath = path.concat(key.toString());
let itemData = this._genInfoData(propertyValue, key, propPath);
if (itemData) {
data.add(new Property(key.toString(), itemData))
}
}
return data;
}
_getGroupData(node: any) { _getGroupData(node: any) {
let nodeGroup = new Group(node.constructor.name); let nodeGroup = new Group(node.constructor.name);
let keys = this._getNodeKeys(node); let keys = this._getNodeKeys(node);

View File

@ -2,8 +2,10 @@
<div id="prop"> <div id="prop">
<div v-for="(group, index) in allGroup" :key="index" class="group"> <div v-for="(group, index) in allGroup" :key="index" class="group">
<div class="header" @click="onClickHeader(group)"> <div class="header" @click="onClickHeader(group)">
<div style="margin: 0 5px;">
<i v-if="group.fold" class="el-icon-caret-right"></i> <i v-if="group.fold" class="el-icon-caret-right"></i>
<i v-if="!group.fold" class="el-icon-caret-bottom"></i> <i v-if="!group.fold" class="el-icon-caret-bottom"></i>
</div>
{{ group.name }} {{ group.name }}
</div> </div>
<div class="content" v-show="!group.fold"> <div class="content" v-show="!group.fold">
@ -59,6 +61,7 @@ export default class properties extends Vue {
}) })
} }
} }
_evalCode(code: string) { _evalCode(code: string) {
if (chrome && chrome.devtools) { if (chrome && chrome.devtools) {
chrome.devtools.inspectedWindow.eval(code); chrome.devtools.inspectedWindow.eval(code);

View File

@ -1,11 +1,14 @@
<template> <template>
<div id="ui-prop"> <div id="ui-prop">
<div class="normal-data" style="display: flex;flex-direction: row;align-items: center;min-height: 30px;margin: 0;"> <div class="normal-data" style="display: flex;flex-direction: row;align-items: center;min-height: 30px;margin: 0;">
<div @mousedown="onPropNameMouseDown" class="key" @click="onClickFold"> <div @mousedown="onPropNameMouseDown" class="key"
@click="onClickFold"
:style="{'cursor':isArrayOrObject()?'pointer':''}"
>
<i class="data-arrow" <i class="data-arrow"
v-if="arrow" v-if="arrow"
:class="fold?'el-icon-caret-right':'el-icon-caret-bottom'" :class="fold?'el-icon-caret-right':'el-icon-caret-bottom'"
:style="{'visibility':isArray()?'visible':'hidden','margin-left':indent*10+'px'}"> :style="{'visibility':isArrayOrObject()?'visible':'hidden','margin-left':indent*10+'px'}">
</i> </i>
<div class="text">{{ name }}</div> <div class="text">{{ name }}</div>
</div> </div>
@ -88,13 +91,14 @@
</div> </div>
</div> </div>
</div> </div>
<div v-if="isArray()"> <div v-if="isArrayOrObject()">
<div v-show="!fold" style="display: flex;flex-direction: column;"> <div v-show="!fold" style="display: flex;flex-direction: column;">
<ui-prop v-for="(arr,index) in value.data" <ui-prop v-for="(arr,index) in value.data"
:key="index" :key="index"
:indent="indent+1" :indent="indent+1"
:value="arr.value" :value="arr.value"
:name="'['+arr.name+']'"> :name="getName(isArray(),arr)"
>
</ui-prop> </ui-prop>
</div> </div>
</div> </div>
@ -105,9 +109,9 @@
import Vue from "vue" import Vue from "vue"
import {Component, Prop} from "vue-property-decorator" import {Component, Prop} from "vue-property-decorator"
import {DataType, Info, NullOrUndefinedData, Vec2Data, Vec3Data} from './data' import {DataType, Info} from './data'
import {connectBackground} from "@/devtools/connectBackground"; import {connectBackground} from "@/devtools/connectBackground";
import {Msg, Page, PluginEvent} from "@/core/types"; import {Msg} from "@/core/types";
@Component({ @Component({
components: {} components: {}
@ -162,6 +166,10 @@ export default class UiProp extends Vue {
return this.value && (this.value.type === DataType.Array || this.value.type === DataType.Object) return this.value && (this.value.type === DataType.Array || this.value.type === DataType.Object)
} }
isObject() {
return this.value && (this.value.type === DataType.Object)
}
isArray() { isArray() {
return this.value && (this.value.type === DataType.Array) return this.value && (this.value.type === DataType.Array)
} }
@ -173,6 +181,15 @@ export default class UiProp extends Vue {
created() { created() {
} }
getName(isArray: boolean, arr: UiProp) {
const type = arr.value.type;
if (isArray) {
return `[${arr.name}]`
} else {
return arr.name;
}
}
private fold = false; private fold = false;
onClickFold() { onClickFold() {
@ -250,7 +267,7 @@ export default class UiProp extends Vue {
<style scoped lang="less"> <style scoped lang="less">
#ui-prop { #ui-prop {
min-height: 30px; min-height: 30px;
margin: 0; margin: 1px 0;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;