fix 过滤规则删除问题

This commit is contained in:
jxxghp
2023-09-09 09:40:06 +08:00
parent c44c7ed0f0
commit 03d6e46eca
3 changed files with 18 additions and 29 deletions

View File

@@ -50,9 +50,6 @@ const selectFilterOptions = ref<{ [key: string]: string }[]>([
{ title: '排除: 国语配音', value: ' !CNVOI ' },
{ title: '促销: 免费', value: ' FREE ' },
])
// 已选择的过滤规则
const selectedFilters = ref<string[]>(props.rules ?? [])
</script>
<template>
@@ -64,7 +61,7 @@ const selectedFilters = ref<string[]>(props.rules ?? [])
<VCol>
<VSelect
:key="props.pri"
v-model="selectedFilters"
v-model="props.rules"
variant="underlined"
:items="selectFilterOptions"
chips

View File

@@ -5,15 +5,10 @@ import FilterRuleCard from '@/components/cards/FilterRuleCard.vue'
// 规则卡片类型
interface FilterCard {
// 优先级
pri: string
// 已选规则
rules: string[]
// 是否可见
visible: boolean
}
// 提示框
@@ -48,7 +43,6 @@ async function queryCustomFilters(ruleType: string) {
return {
pri: (index + 1).toString(),
rules: group.split('&'),
visible: true,
}
})
}
@@ -138,23 +132,18 @@ function updateFilterCardValue2(pri: string, rules: string[]) {
// 移除卡片
function filterCardClose(ruleType: string, pri: string) {
// 将卡片从列表中删除,并更新剩余卡片的序号
const cards = ruleType === 'FilterRules' ? filterCards : filterCards2
const index = cards.value.findIndex(card => card.pri === pri)
if (index !== -1) {
// 创建新的数组,然后使用 splice 方法来删除元素
const updatedCards = [...cards.value]
updatedCards.splice(index, 1)
// 更新剩余卡片的序号
updatedCards.forEach((card, i) => {
card.pri = (i + 1).toString()
// 将pri对应的卡片从列表中删除,并更新剩余卡片的序号
const updatedCards = (ruleType === 'FilterRules' ? filterCards.value : filterCards2.value)
.filter(card => card.pri !== pri)
.map((card, index) => {
card.pri = (index + 1).toString()
return card
})
// 更新 filterCards.value
cards.value = updatedCards
}
// 更新 filterCards.value
if (ruleType === 'FilterRules')
filterCards.value = updatedCards
else
filterCards2.value = updatedCards
}
// 增加卡片
@@ -164,7 +153,7 @@ function addFilterCard(ruleType: string) {
const pri = (cards.value.length + 1).toString()
// 新卡片
const newCard: FilterCard = { pri, rules: [], visible: true }
const newCard: FilterCard = { pri, rules: [] }
// 添加到列表
cards.value.push(newCard)
@@ -189,7 +178,6 @@ onMounted(() => {
:key="index"
:pri="card.pri"
:rules="card.rules"
:visible="card.visible"
@changed="updateFilterCardValue"
@close="filterCardClose('FilterRules', card.pri)"
/>
@@ -224,7 +212,6 @@ onMounted(() => {
:key="index"
:pri="card.pri"
:rules="card.rules"
:visible="card.visible"
@changed="updateFilterCardValue2"
@close="filterCardClose('FilterRules2', card.pri)"
/>

View File

@@ -1836,6 +1836,11 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==
"@types/lodash@^4.14.197":
version "4.14.198"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.198.tgz#4d27465257011aedc741a809f1269941fa2c5d4c"
integrity sha512-trNJ/vtMZYMLhfN45uLq4ShQSw0/S7xCTLLVM+WM1rmFpba/VS42jVUgaO3w/NOLiWR/09lnYk0yMaA/atdIsg==
"@types/mdast@^3.0.0":
version "3.0.11"
resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.11.tgz#dc130f7e7d9306124286f6d6cee40cf4d14a3dc0"