对象校验调整&&客户端初始化调整

This commit is contained in:
joylink_fanyuhong 2024-03-12 10:31:16 +08:00
parent b57ea909b4
commit 21e5b5b659
3 changed files with 50 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import { objectIsEqual } from '@/utils/date';
import { objectIsEqualSp } from '@/utils/date';
import Handler from './newHandler.js';
import { ScriptMode } from '@/scripts/ConstDic';
import store from '@/store/index';
@ -50,9 +50,9 @@ class ValidateHandler {
}
}
if (linkDataFlag) {
return objectIsEqual(param1, param2) || objectIsEqual(linkParam, param2);
return objectIsEqualSp(param1, param2) || objectIsEqualSp(linkParam, param2);
} else {
return objectIsEqual(param1, param2);
return objectIsEqualSp(param1, param2);
}
}
// 判断实训操作正确性

View File

@ -121,3 +121,44 @@ export function objectIsEqual(obj1, obj2) {
}
return true;
}
export function checkUndefinedOrNull(key) {
if (key === '' || key === undefined || key === null) {
return false;
}
return true;
}
export function checkTwo(k1, k2) {
console.log(checkUndefinedOrNull(k1), checkUndefinedOrNull(k2), '----', k1, k2);
return checkUndefinedOrNull(k1) || checkUndefinedOrNull(k2);
}
/* 对象是否相等(undefined和空字符串空对象空数组认为相同) */
export function objectIsEqualSp(obj1, obj2) {
if (!(obj1 instanceof Object)) {
return false;
} else if (!(obj2 instanceof Object)) {
return false;
}
// 仅过滤值为null的项
const arr1 = Object.keys(obj1).filter(key => { return obj1[key] != null; });
const arr2 = Object.keys(obj2).filter(key => { return obj2[key] != null; });
// if (arr1.length !== arr2.length) {
// return false;
// }
for (const key of arr1) {
const index = arr2.findIndex(item => item === key);
arr2.splice(index, 1);
if (obj1[key] instanceof Object && obj2[key] instanceof Object) {
if (!objectIsEqualSp(obj1[key], obj2[key])) {
return false;
}
} else if (obj1[key] !== obj2[key] && checkTwo(obj1[key], obj2[key])) {
return false;
}
}
for (const key of arr2) {
if (obj1[key] !== obj2[key] && checkTwo(obj1[key], obj2[key])) {
return false;
}
}
return true;
}

View File

@ -69,7 +69,7 @@ export default {
} else {
this.initPictureShow();
}
} else if (clientIdList.length) {
} else if (clientIdList && clientIdList.length) {
this.initTerminalList(clientIdList);
if (this.$store.state.trainingNew.trainingDetail && this.$store.state.trainingNew.trainingDetail.client) {
const client = this.findTerminalFromMap(this.$store.state.trainingNew.trainingDetail.client);
@ -83,7 +83,11 @@ export default {
}
} else if (!this.terminalList.length) {
this.initTerminalList([]);
if (this.$route.query.client && !this.nowTerminal.id) {
this.changeQueryClient();
} else {
this.initPictureShow();
}
}
}
},