Update AccountSettingRule.vue

This commit is contained in:
Aqr-K
2024-12-07 05:28:09 +08:00
committed by GitHub
parent 6dca0c157f
commit 59a7607c07
+11 -8
View File
@@ -188,15 +188,11 @@ function saveCodeString(type: string, codeString: any) {
// 更新数据
try {
if (type === 'custom') {
for (const value of parsedCode) {
if (!checkValueValidity(value, type)) return false
}
if (!checkValueValidity(parsedCode, type)) return false
const newCustomRules = extractCustomRules(parsedCode) || []
customRules.value = [...customRules.value, ...newCustomRules]
} else if (type === 'group') {
for (const value of parsedCode) {
if (!checkValueValidity(value, type)) return false
}
if (!checkValueValidity(parsedCode, type)) return false
const newFilterRuleGroups = extractFilterRuleGroups(parsedCode) || []
filterRuleGroups.value = [...filterRuleGroups.value, ...newFilterRuleGroups]
} else {
@@ -241,10 +237,12 @@ function extractFilterRuleGroups(value: any) {
}
// 根据ID简单区分规则与规则组
function checkValueValidity(value: any, type: string): boolean {
function checkValueValidity(values: any, type: string): boolean {
try {
// 允许空值存在,不影响最终的导入
if (!value) return true
if (!values) return true
if (!type) return false
for (const value of values) {
const keys = Object.keys(value)
const uniqueKeys = new Set(keys)
@@ -267,7 +265,12 @@ function checkValueValidity(value: any, type: string): boolean {
console.error(`传入了不合法类型`)
return false
}
}
return true
} catch (e) {
console.error(e)
return false
}
}
// 规则变化时赋值