处理无效的数据

This commit is contained in:
xyf-mac 2021-11-07 00:09:02 +08:00
parent ddfc17a08b
commit a911869066
5 changed files with 100 additions and 96 deletions

View File

@ -9,20 +9,21 @@
"build-watch": "vue-cli-service build --watch" "build-watch": "vue-cli-service build --watch"
}, },
"dependencies": { "dependencies": {
"@types/fs-extra": "^9.0.9", "@types/kind-of": "^6.0.0",
"@types/node": "^14.14.37",
"babel-eslint": "^10.1.0", "babel-eslint": "^10.1.0",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"uuid": "^8.3.2",
"element-ui": "^2.15.1", "element-ui": "^2.15.1",
"fs-extra": "^9.1.0", "fs-extra": "^9.1.0",
"less": "^4.1.1", "less": "^4.1.1",
"less-loader": "^7.3.0", "less-loader": "^7.3.0",
"uuid": "^8.3.2",
"vue": "^2.6.11", "vue": "^2.6.11",
"vue-class-component": "^7.2.3", "vue-class-component": "^7.2.3",
"vue-property-decorator": "^9.1.2" "vue-property-decorator": "^9.1.2"
}, },
"devDependencies": { "devDependencies": {
"@types/fs-extra": "^9.0.9",
"@types/node": "^14.14.37",
"@types/uuid": "^8.3.1", "@types/uuid": "^8.3.1",
"@types/chrome": "0.0.133", "@types/chrome": "0.0.133",
"@typescript-eslint/eslint-plugin": "^4.18.0", "@typescript-eslint/eslint-plugin": "^4.18.0",

View File

@ -79,7 +79,7 @@ export class ObjectData extends Info {
} }
export class InvalidData extends Info { export class InvalidData extends Info {
data: any; data: "undefined" | "null" | "Infinity" | "NaN"|string;
constructor(data: any) { constructor(data: any) {
super(); super();

View File

@ -98,7 +98,7 @@ export default class Index extends Vue {
this._expand(data.engineUUID); this._expand(data.engineUUID);
}) })
Bus.$on(BusMsg.RequestObjectData, (data: ObjectData, cb: Function) => { Bus.$on(BusMsg.RequestObjectData, (data: ObjectData, cb: Function) => {
if (this.requestList.find(el => el.id === data.id)) { if (!data.id || this.requestList.find(el => el.id === data.id)) {
return return
} }
this.requestList.push({id: data.id, cb}); this.requestList.push({id: data.id, cb});

View File

@ -20,7 +20,7 @@
</div> </div>
<div class="value"> <div class="value">
<div v-if="isInvalid()" class="invalid"> <div v-if="isInvalid()" class="invalid">
{{ getInvalidDisplayText() }} {{ value.data }}
</div> </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"
@ -162,26 +162,6 @@ export default class UiProp extends Vue {
return this.value && (this.value.type === DataType.Invalid); 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);
} }
@ -244,10 +224,14 @@ export default class UiProp extends Vue {
mounted() { mounted() {
this.watchValue(); this.watchValue();
if(this.isInvalid()){
this.value.data;
debugger
}
} }
isShowTooltip() { isShowTooltip() {
const el: HTMLDivElement = this.$refs.propText; const el: HTMLDivElement = this.$refs.propText as HTMLDivElement;
if (el) { if (el) {
if (el.scrollWidth > el.offsetWidth) { if (el.scrollWidth > el.offsetWidth) {
// //

View File

@ -271,6 +271,10 @@ class CCInspector {
_genInfoData(node: any, key: string | number, path: Array<string>, filterKey = true) { _genInfoData(node: any, key: string | number, path: Array<string>, filterKey = true) {
let propertyValue = node[key]; let propertyValue = node[key];
let info = null; let info = null;
let invalidType = this._isInvalidValue(propertyValue);
if (invalidType) {
info = new InvalidData(invalidType);
} else {
switch (typeof propertyValue) { switch (typeof propertyValue) {
case "boolean": case "boolean":
info = new BoolData(propertyValue); info = new BoolData(propertyValue);
@ -282,10 +286,8 @@ class CCInspector {
info = new StringData(propertyValue); info = new StringData(propertyValue);
break; break;
default: default:
if (this._isInvalidValue(propertyValue)) {
info = new InvalidData(propertyValue);
//@ts-ignore //@ts-ignore
} else if (propertyValue instanceof cc.Color) { if (propertyValue instanceof cc.Color) {
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)) {
@ -344,6 +346,7 @@ class CCInspector {
} }
break; break;
} }
}
if (info) { if (info) {
info.readonly = this._isReadonly(node, key) info.readonly = this._isReadonly(node, key)
info.path = path; info.path = path;
@ -389,7 +392,23 @@ class CCInspector {
} }
_isInvalidValue(value: any) { _isInvalidValue(value: any) {
return value === null || value === Infinity || value === undefined; // !!Infinity=true
if ((value && value !== Infinity) || value === 0 || value === false) {
return false;
}
if (value === null) {
return "null"
} else if (value === Infinity) {
return "Infinity"
} else if (value === undefined) {
return "undefined"
} else if (Number.isNaN(value)) {
return "NaN";
} else {
debugger
return false;
}
} }
_buildObjectData({value, path, data, filterKey}: BuildObjectOptions) { _buildObjectData({value, path, data, filterKey}: BuildObjectOptions) {