mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-19 16:38:41 +00:00
处理无效的数据
This commit is contained in:
parent
d5bce1c75d
commit
ddfc17a08b
@ -10,7 +10,7 @@ export enum DataType {
|
|||||||
Enum,
|
Enum,
|
||||||
Bool,
|
Bool,
|
||||||
Color,
|
Color,
|
||||||
NullOrUndefined,
|
Invalid,
|
||||||
Array, // 暂时在控制台打印下
|
Array, // 暂时在控制台打印下
|
||||||
Object,
|
Object,
|
||||||
ObjectItem,
|
ObjectItem,
|
||||||
@ -78,11 +78,13 @@ export class ObjectData extends Info {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NullOrUndefinedData extends Info {
|
export class InvalidData extends Info {
|
||||||
constructor() {
|
data: any;
|
||||||
super();
|
|
||||||
this.type = DataType.NullOrUndefined;
|
|
||||||
|
|
||||||
|
constructor(data: any) {
|
||||||
|
super();
|
||||||
|
this.data = data;
|
||||||
|
this.type = DataType.Invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ export default class Index extends Vue {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.target === Page.Devtools) {
|
if (data.target === Page.Devtools) {
|
||||||
console.log(`[Devtools] ${JSON.stringify(data)}`);
|
console.log("[Devtools]", data);
|
||||||
PluginEvent.finish(data);
|
PluginEvent.finish(data);
|
||||||
let eventData: any = data.data;
|
let eventData: any = data.data;
|
||||||
switch (data.msg) {
|
switch (data.msg) {
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="value">
|
<div class="value">
|
||||||
|
<div v-if="isInvalid()" class="invalid">
|
||||||
|
{{ getInvalidDisplayText() }}
|
||||||
|
</div>
|
||||||
<el-input v-if="isString()" v-model="value.data"
|
<el-input v-if="isString()" v-model="value.data"
|
||||||
:disabled="value.readonly"
|
:disabled="value.readonly"
|
||||||
@change="onChangeValue">
|
@change="onChangeValue">
|
||||||
@ -155,6 +158,30 @@ export default class UiProp extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isInvalid() {
|
||||||
|
return this.value && (this.value.type === DataType.Invalid);
|
||||||
|
}
|
||||||
|
|
||||||
|
getInvalidDisplayText() {
|
||||||
|
if (this.isInvalid()) {
|
||||||
|
const data = this.value.data;
|
||||||
|
switch (data) {
|
||||||
|
case undefined: {
|
||||||
|
return "undefined"
|
||||||
|
}
|
||||||
|
case null: {
|
||||||
|
return "null"
|
||||||
|
}
|
||||||
|
case Infinity: {
|
||||||
|
return "Infinity"
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return `未知的无效数据:${data}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isString() {
|
isString() {
|
||||||
return this.value && (this.value.type === DataType.String);
|
return this.value && (this.value.type === DataType.String);
|
||||||
}
|
}
|
||||||
@ -403,6 +430,10 @@ export default class UiProp extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.invalid {
|
||||||
|
color: grey;
|
||||||
|
}
|
||||||
|
|
||||||
.objectDesc {
|
.objectDesc {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
Group,
|
Group,
|
||||||
ImageData,
|
ImageData,
|
||||||
Info,
|
Info,
|
||||||
NullOrUndefinedData,
|
InvalidData,
|
||||||
NumberData,
|
NumberData,
|
||||||
ObjectData, ObjectItemRequestData,
|
ObjectData, ObjectItemRequestData,
|
||||||
Property,
|
Property,
|
||||||
@ -282,8 +282,8 @@ class CCInspector {
|
|||||||
info = new StringData(propertyValue);
|
info = new StringData(propertyValue);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (propertyValue == null || typeof propertyValue === "undefined") {
|
if (this._isInvalidValue(propertyValue)) {
|
||||||
info = new NullOrUndefinedData();
|
info = new InvalidData(propertyValue);
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
} else if (propertyValue instanceof cc.Color) {
|
} else if (propertyValue instanceof cc.Color) {
|
||||||
let hex = propertyValue.toHEX();
|
let hex = propertyValue.toHEX();
|
||||||
@ -388,6 +388,10 @@ class CCInspector {
|
|||||||
return keys.filter(key => !key.toString().startsWith("_"));
|
return keys.filter(key => !key.toString().startsWith("_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_isInvalidValue(value: any) {
|
||||||
|
return value === null || value === Infinity || value === undefined;
|
||||||
|
}
|
||||||
|
|
||||||
_buildObjectData({value, path, data, filterKey}: BuildObjectOptions) {
|
_buildObjectData({value, path, data, filterKey}: BuildObjectOptions) {
|
||||||
let keys = Object.keys(value);
|
let keys = Object.keys(value);
|
||||||
if (filterKey) {
|
if (filterKey) {
|
||||||
@ -406,6 +410,8 @@ class CCInspector {
|
|||||||
|
|
||||||
})
|
})
|
||||||
keyDesc = `(${propValue.length}) [...]`
|
keyDesc = `(${propValue.length}) [...]`
|
||||||
|
} else if (this._isInvalidValue(propValue)) { // 不能改变顺序
|
||||||
|
keyDesc = propValue;
|
||||||
} else if (typeof propValue === "object") {
|
} else if (typeof propValue === "object") {
|
||||||
keyDesc = `${propValue.constructor.name} {...}`;
|
keyDesc = `${propValue.constructor.name} {...}`;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user