mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 23:56:42 +08:00
Update AccountSettingRule.vue
This commit is contained in:
@@ -188,15 +188,11 @@ function saveCodeString(type: string, codeString: any) {
|
|||||||
// 更新数据
|
// 更新数据
|
||||||
try {
|
try {
|
||||||
if (type === 'custom') {
|
if (type === 'custom') {
|
||||||
for (const value of parsedCode) {
|
if (!checkValueValidity(parsedCode, type)) return false
|
||||||
if (!checkValueValidity(value, type)) return false
|
|
||||||
}
|
|
||||||
const newCustomRules = extractCustomRules(parsedCode) || []
|
const newCustomRules = extractCustomRules(parsedCode) || []
|
||||||
customRules.value = [...customRules.value, ...newCustomRules]
|
customRules.value = [...customRules.value, ...newCustomRules]
|
||||||
} else if (type === 'group') {
|
} else if (type === 'group') {
|
||||||
for (const value of parsedCode) {
|
if (!checkValueValidity(parsedCode, type)) return false
|
||||||
if (!checkValueValidity(value, type)) return false
|
|
||||||
}
|
|
||||||
const newFilterRuleGroups = extractFilterRuleGroups(parsedCode) || []
|
const newFilterRuleGroups = extractFilterRuleGroups(parsedCode) || []
|
||||||
filterRuleGroups.value = [...filterRuleGroups.value, ...newFilterRuleGroups]
|
filterRuleGroups.value = [...filterRuleGroups.value, ...newFilterRuleGroups]
|
||||||
} else {
|
} else {
|
||||||
@@ -241,33 +237,40 @@ function extractFilterRuleGroups(value: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 根据ID简单区分规则与规则组
|
// 根据ID简单区分规则与规则组
|
||||||
function checkValueValidity(value: any, type: string): boolean {
|
function checkValueValidity(values: any, type: string): boolean {
|
||||||
// 允许空值存在,不影响最终的导入
|
try {
|
||||||
if (!value) return true
|
// 允许空值存在,不影响最终的导入
|
||||||
if (!type) return false
|
if (!values) return true
|
||||||
const keys = Object.keys(value)
|
if (!type) return false
|
||||||
const uniqueKeys = new Set(keys)
|
for (const value of values) {
|
||||||
|
const keys = Object.keys(value)
|
||||||
|
const uniqueKeys = new Set(keys)
|
||||||
|
|
||||||
const hasName = keys.includes('name')
|
const hasName = keys.includes('name')
|
||||||
const hasId = keys.includes('id')
|
const hasId = keys.includes('id')
|
||||||
const noDuplicates = keys.length === uniqueKeys.size
|
const noDuplicates = keys.length === uniqueKeys.size
|
||||||
if (type == 'custom') {
|
if (type == 'custom') {
|
||||||
if (!hasName || !hasId || !noDuplicates) {
|
if (!hasName || !hasId || !noDuplicates) {
|
||||||
if (!noDuplicates) $toast.warning(`存在重名值`)
|
if (!noDuplicates) $toast.warning(`存在重名值`)
|
||||||
if (!hasId) $toast.error(`导入失败!发现有规则不存在ID,可能属于优先级规则组!`)
|
if (!hasId) $toast.error(`导入失败!发现有规则不存在ID,可能属于优先级规则组!`)
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
} else if (type == 'group') {
|
||||||
|
if (!hasName || hasId || !noDuplicates) {
|
||||||
|
if (!noDuplicates) $toast.warning(`存在重名值`)
|
||||||
|
if (hasId) $toast.error(`导入失败!发现有规则存在ID,可能属于自定义规则!`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error(`传入了不合法类型`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (type == 'group') {
|
return true
|
||||||
if (!hasName || hasId || !noDuplicates) {
|
} catch (e) {
|
||||||
if (!noDuplicates) $toast.warning(`存在重名值`)
|
console.error(e)
|
||||||
if (hasId) $toast.error(`导入失败!发现有规则存在ID,可能属于自定义规则!`)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.error(`传入了不合法类型`)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 规则变化时赋值
|
// 规则变化时赋值
|
||||||
|
|||||||
Reference in New Issue
Block a user