mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 15:36:49 +08:00
feat 自定义规则 && 优先级规则组 整体导入导出
This commit is contained in:
@@ -1,15 +1,17 @@
|
|||||||
<!-- eslint-disable sonarjs/no-duplicate-string -->
|
<!-- eslint-disable sonarjs/no-duplicate-string -->
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useToast } from 'vue-toast-notification'
|
import {useToast} from 'vue-toast-notification'
|
||||||
|
import {copyToClipboard} from '@/@core/utils/navigator'
|
||||||
import draggable from 'vuedraggable'
|
import draggable from 'vuedraggable'
|
||||||
import { VRow } from 'vuetify/lib/components/index.mjs'
|
import {VRow} from 'vuetify/lib/components/index.mjs'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { CustomRule, FilterRuleGroup } from '@/api/types'
|
import {CustomRule, FilterRuleGroup} from '@/api/types'
|
||||||
import CustomerRuleCard from '@/components/cards/CustomRuleCard.vue'
|
import CustomerRuleCard from '@/components/cards/CustomRuleCard.vue'
|
||||||
import FilterRuleGroupCard from '@/components/cards/FilterRuleGroupCard.vue'
|
import FilterRuleGroupCard from '@/components/cards/FilterRuleGroupCard.vue'
|
||||||
|
import ImportCodeDialog from '@/components/dialog/ImportCodeDialog.vue'
|
||||||
|
|
||||||
// 自定义规则列表
|
// 自定义规则列表
|
||||||
const customRules = ref<CustomRule[]>([])
|
let customRules = ref<CustomRule[]>([])
|
||||||
|
|
||||||
// 所有规则组列表
|
// 所有规则组列表
|
||||||
const filterRuleGroups = ref<FilterRuleGroup[]>([])
|
const filterRuleGroups = ref<FilterRuleGroup[]>([])
|
||||||
@@ -20,15 +22,24 @@ const selectedTorrentPriority = ref<string>('seeder')
|
|||||||
// 二级分类策略
|
// 二级分类策略
|
||||||
const mediaCategories = ref<{ [key: string]: any }>({})
|
const mediaCategories = ref<{ [key: string]: any }>({})
|
||||||
|
|
||||||
|
// 导入代码弹窗
|
||||||
|
const importCodeDialog = ref(false)
|
||||||
|
|
||||||
|
// 导入的代码
|
||||||
|
const importCodeString = ref('')
|
||||||
|
|
||||||
|
// 导入代码类型
|
||||||
|
const importCodeType = ref('')
|
||||||
|
|
||||||
// 提示框
|
// 提示框
|
||||||
const $toast = useToast()
|
const $toast = useToast()
|
||||||
|
|
||||||
// 种子优先规则下拉框
|
// 种子优先规则下拉框
|
||||||
const TorrentPriorityItems = [
|
const TorrentPriorityItems = [
|
||||||
{ title: '资源优先级', value: 'torrent' },
|
{title: '资源优先级', value: 'torrent'},
|
||||||
{ title: '站点优先级', value: 'site' },
|
{title: '站点优先级', value: 'site'},
|
||||||
{ title: '站点上传量', value: 'upload' },
|
{title: '站点上传量', value: 'upload'},
|
||||||
{ title: '资源做种数', value: 'seeder' },
|
{title: '资源做种数', value: 'seeder'},
|
||||||
]
|
]
|
||||||
|
|
||||||
// 调用API查询自动分类配置
|
// 调用API查询自动分类配置
|
||||||
@@ -110,6 +121,63 @@ function addFilterRuleGroup() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分享规则
|
||||||
|
function shareRules(rules: CustomRule[] | FilterRuleGroup[]) {
|
||||||
|
if (!rules || rules.length === 0) return
|
||||||
|
|
||||||
|
// 将卡片规则接装为字符串
|
||||||
|
const value = JSON.stringify(rules)
|
||||||
|
|
||||||
|
console.log(rules)
|
||||||
|
// 复制到剪贴板
|
||||||
|
try {
|
||||||
|
copyToClipboard(value)
|
||||||
|
$toast.success('优先级规则已复制到剪贴板')
|
||||||
|
} catch (error) {
|
||||||
|
$toast.error('优先级规则复制失败!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导入规则
|
||||||
|
async function importRules(ruleType: string) {
|
||||||
|
importCodeType.value = ruleType
|
||||||
|
importCodeString.value = ''
|
||||||
|
importCodeDialog.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监听导入代码变化
|
||||||
|
watchEffect(() => {
|
||||||
|
if (!importCodeString.value) return
|
||||||
|
// 导入代码需要json格式
|
||||||
|
try {
|
||||||
|
if (importCodeType.value === 'custom') {
|
||||||
|
// 将导入的代码转换为规则卡片
|
||||||
|
customRules.value = JSON.parse(importCodeString.value).map((item: any) => {
|
||||||
|
return {
|
||||||
|
id: item.id,
|
||||||
|
name: item.name,
|
||||||
|
include: item.include,
|
||||||
|
exclude: item.exclude,
|
||||||
|
publish_time: item.publish_time,
|
||||||
|
seeders: item.seeders,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (importCodeType.value === 'group') {
|
||||||
|
// 将导入的代码转换为规则卡片
|
||||||
|
filterRuleGroups.value = JSON.parse(importCodeString.value).map((item: any) => {
|
||||||
|
return {
|
||||||
|
name: item.name,
|
||||||
|
rule_string: item.rule_string,
|
||||||
|
media_type: item.media_type,
|
||||||
|
category: item.category,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
$toast.error('规则导入失败!')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// 规则变化时赋值
|
// 规则变化时赋值
|
||||||
function onRuleChange(rule: CustomRule) {
|
function onRuleChange(rule: CustomRule) {
|
||||||
const index = customRules.value.findIndex(item => item.id === rule.id)
|
const index = customRules.value.findIndex(item => item.id === rule.id)
|
||||||
@@ -201,9 +269,15 @@ onMounted(() => {
|
|||||||
</draggable>
|
</draggable>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
<VCardText>
|
<VCardText>
|
||||||
<VBtn type="submit" class="me-2" @click="saveCustomRules"> 保存 </VBtn>
|
<VBtn type="submit" class="me-2" @click="saveCustomRules"> 保存</VBtn>
|
||||||
<VBtn color="success" variant="tonal" @click="addCustomRule">
|
<VBtn color="success" variant="tonal" @click="addCustomRule">
|
||||||
<VIcon icon="mdi-plus" />
|
<VIcon icon="mdi-plus"/>
|
||||||
|
</VBtn>
|
||||||
|
<VBtn color="success" variant="tonal" @click="importRules('custom')">
|
||||||
|
<VIcon icon="mdi-import"/>
|
||||||
|
</VBtn>
|
||||||
|
<VBtn color="info" variant="tonal" @click="shareRules(customRules)">
|
||||||
|
<VIcon icon="mdi-share"/>
|
||||||
</VBtn>
|
</VBtn>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
</VCard>
|
</VCard>
|
||||||
@@ -235,11 +309,20 @@ onMounted(() => {
|
|||||||
</draggable>
|
</draggable>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
<VCardText>
|
<VCardText>
|
||||||
<VBtn type="submit" class="me-2" @click="saveFilterRuleGroups"> 保存 </VBtn>
|
<VBtn type="submit" class="me-2" @click="saveFilterRuleGroups"> 保存</VBtn>
|
||||||
<VBtn color="success" variant="tonal" @click="addFilterRuleGroup">
|
<VBtn color="success" variant="tonal" @click="addFilterRuleGroup">
|
||||||
<VIcon icon="mdi-plus" />
|
<VIcon icon="mdi-plus"/>
|
||||||
|
</VBtn>
|
||||||
|
<VBtn color="success" variant="tonal" @click="importRules('group')">
|
||||||
|
<VIcon icon="mdi-import"/>
|
||||||
|
</VBtn>
|
||||||
|
<VBtn color="info" variant="tonal" @click="shareRules(filterRuleGroups)">
|
||||||
|
<VIcon icon="mdi-share"/>
|
||||||
</VBtn>
|
</VBtn>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
|
<VDialog v-model="importCodeDialog" width="60rem" scrollable>
|
||||||
|
<ImportCodeDialog v-model="importCodeString" title="导入优先级规则" @close="importCodeDialog = false"/>
|
||||||
|
</VDialog>
|
||||||
</VCard>
|
</VCard>
|
||||||
</VCol>
|
</VCol>
|
||||||
<VCol cols="12">
|
<VCol cols="12">
|
||||||
@@ -267,7 +350,7 @@ onMounted(() => {
|
|||||||
</VForm>
|
</VForm>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
<VCardText>
|
<VCardText>
|
||||||
<VBtn type="submit" @click="saveTorrentPriority"> 保存 </VBtn>
|
<VBtn type="submit" @click="saveTorrentPriority"> 保存</VBtn>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
</VCard>
|
</VCard>
|
||||||
</VCol>
|
</VCol>
|
||||||
|
|||||||
Reference in New Issue
Block a user