适配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 {
data: Array<Property> = [];
constructor() {
super();
this.type = DataType.Array;
}
add(info: Property) {
this.data.push(info);
return this;
}
}
export class ObjectData extends Info {

View File

@ -255,7 +255,7 @@ class CCInspector {
return null;
}
_genInfoData(node: any, key: string, path: any) {
_genInfoData(node: any, key: string, path: Array<string>) {
let propertyValue = node[key];
let info = null;
switch (typeof propertyValue) {
@ -277,6 +277,13 @@ class CCInspector {
info = new ColorData(`#${hex}`);
} else if (Array.isArray(propertyValue)) {
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) {
!info && (info = this._buildVecData({
// @ts-ignore

View File

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