适配array

This commit is contained in:
xuyanfeng 2021-06-15 22:19:47 +08:00
parent 9540b78e90
commit 5558c6fe71
3 changed files with 221 additions and 150 deletions

View File

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

View File

@ -255,7 +255,7 @@ class CCInspector {
return null; return null;
} }
_genInfoData(node: any, key: string, path: any) { _genInfoData(node: any, key: string, path: Array<string>) {
let propertyValue = node[key]; let propertyValue = node[key];
let info = null; let info = null;
switch (typeof propertyValue) { switch (typeof propertyValue) {
@ -277,6 +277,13 @@ class CCInspector {
info = new ColorData(`#${hex}`); info = new ColorData(`#${hex}`);
} else if (Array.isArray(propertyValue)) { } else if (Array.isArray(propertyValue)) {
info = new ArrayData(); info = new ArrayData();
for (let i = 0; i < propertyValue.length; i++) {
let propPath = path.concat(i.toString());
let itemData = this._genInfoData(propertyValue, i.toString(), propPath);
if (itemData) {
info.add(new Property(i.toString(), itemData));
}
}
} else if (propertyValue instanceof Object) { } else if (propertyValue instanceof Object) {
!info && (info = this._buildVecData({ !info && (info = this._buildVecData({
// @ts-ignore // @ts-ignore

View File

@ -1,6 +1,13 @@
<template> <template>
<div id="ui-prop"> <div id="ui-prop">
<div @mousedown="onPropNameMouseDown" class="key"> <div class="normal-data" style="display: flex;flex-direction: row;align-items: center;min-height: 30px;margin: 0;">
<div @mousedown="onPropNameMouseDown" class="key"
:style="{'margin-left':indent*10+'px'}">
<i class=" data-arrow"
v-if="arrow"
:class="fold?'el-icon-caret-right':'el-icon-caret-bottom'"
:style="{'visibility':isArray()?'visible':'hidden'}"
@click="onClickFold"></i>
<div class="text">{{ name }}</div> <div class="text">{{ name }}</div>
</div> </div>
<div class="value"> <div class="value">
@ -28,6 +35,7 @@
<div v-if="isVec2()||isVec3()" class="vec"> <div v-if="isVec2()||isVec3()" class="vec">
<ui-prop v-for="(vec, index) in value.data" <ui-prop v-for="(vec, index) in value.data"
:key="index" :key="index"
:arrow="false"
:value="vec.value" :value="vec.value"
:name="vec.name"> :name="vec.name">
@ -55,12 +63,15 @@
</el-color-picker> </el-color-picker>
<div class="hex" :style="{color:colorReverse(value.data)}">{{ value.data }}</div> <div class="hex" :style="{color:colorReverse(value.data)}">{{ value.data }}</div>
</div> </div>
<div v-if="isArrayOrObject()" class="array-object"> <div v-if="isArray()" style="display: flex;flex-direction: column;">
<div class="text"> {{ value.data.length }}
{{ valueString() }}
</div>
<el-button @click="onShowValueInConsole">log</el-button>
</div> </div>
<!-- <div v-if="isArrayOrObject()" class="array-object">-->
<!-- <div class="text">-->
<!-- {{ valueString() }}-->
<!-- </div>-->
<!-- <el-button @click="onShowValueInConsole">log</el-button>-->
<!-- </div>-->
<div v-if="isImage()" class="image-property"> <div v-if="isImage()" class="image-property">
<el-popover v-if="isImage()" placement="top" trigger="hover"> <el-popover v-if="isImage()" placement="top" trigger="hover">
<div <div
@ -78,6 +89,17 @@
</div> </div>
</div> </div>
</div> </div>
<div v-if="isArray()">
<div v-show="!fold" style="display: flex;flex-direction: column;">
<ui-prop v-for="(arr,index) in value.data"
:key="index"
:indent="indent+1"
:value="arr.value"
:name="'['+arr.name+']'">
</ui-prop>
</div>
</div>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -96,6 +118,11 @@ export default class UiProp extends Vue {
@Prop({default: ""}) @Prop({default: ""})
name: string | undefined; name: string | undefined;
@Prop({default: 0})
indent!: number;
@Prop({default: true})
arrow!: boolean;
@Prop() @Prop()
value!: Info; value!: Info;
@ -136,6 +163,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)
} }
isArray() {
return this.value && (this.value.type === DataType.Array)
}
isImage() { isImage() {
return this.value && (this.value.type === DataType.Image) return this.value && (this.value.type === DataType.Image)
} }
@ -143,6 +174,12 @@ export default class UiProp extends Vue {
created() { created() {
} }
private fold = false;
onClickFold() {
this.fold = !this.fold;
}
valueString() { valueString() {
try { try {
return JSON.stringify(this.value.data) return JSON.stringify(this.value.data)
@ -213,6 +250,13 @@ export default class UiProp extends Vue {
<style scoped lang="less"> <style scoped lang="less">
#ui-prop { #ui-prop {
min-height: 30px;
margin: 0;
display: flex;
flex-direction: column;
justify-content: center;
.normal-data {
margin: 0; margin: 0;
min-height: 30px; min-height: 30px;
overflow: hidden; overflow: hidden;
@ -231,6 +275,13 @@ export default class UiProp extends Vue {
align-items: center; align-items: center;
min-width: 90px; min-width: 90px;
.data-arrow {
width: 20px;
height: 16px;
font-size: 16px;
cursor: pointer;
}
.text { .text {
user-select: none; user-select: none;
line-height: 30px; line-height: 30px;
@ -268,8 +319,8 @@ export default class UiProp extends Vue {
#ui-prop { #ui-prop {
margin-top: 0; margin-top: 0;
margin-bottom: 0; margin-bottom: 0;
margin-right: 20px;
.normal-data {
.value { .value {
min-width: 100px; min-width: 100px;
} }
@ -277,12 +328,16 @@ export default class UiProp extends Vue {
.key { .key {
min-width: 20px; min-width: 20px;
} }
#ui-prop:first-child {
margin-right: 20px;
} }
#ui-prop:last-child { #ui-prop:last-child {
margin-right: 0; margin-right: 0;
} }
} }
}
.array-object { .array-object {
flex: 1; flex: 1;
@ -314,4 +369,6 @@ export default class UiProp extends Vue {
} }
} }
} }
}
}
</style> </style>