mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-08-28 03:27:54 +08:00
feat 整合站点编辑组件
This commit is contained in:
+2
-2
@@ -416,13 +416,13 @@ export interface Site {
|
|||||||
ua?: string
|
ua?: string
|
||||||
|
|
||||||
// 是否使用代理
|
// 是否使用代理
|
||||||
proxy?: number
|
proxy?: any
|
||||||
|
|
||||||
// 过滤规则
|
// 过滤规则
|
||||||
filter?: string
|
filter?: string
|
||||||
|
|
||||||
// 是否演染
|
// 是否演染
|
||||||
render?: number
|
render?: any
|
||||||
|
|
||||||
// 是否公开站点
|
// 是否公开站点
|
||||||
public?: number
|
public?: number
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { PropType } from 'vue'
|
import type { PropType } from 'vue'
|
||||||
import { useToast } from 'vue-toast-notification'
|
import { useToast } from 'vue-toast-notification'
|
||||||
|
import SiteAddEditForm from '../form/SiteAddEditForm.vue'
|
||||||
import { formatFileSize } from '@core/utils/formatters'
|
import { formatFileSize } from '@core/utils/formatters'
|
||||||
import { numberValidator, requiredValidator } from '@/@validators'
|
import { requiredValidator } from '@/@validators'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import type { Site, TorrentInfo } from '@/api/types'
|
import type { Site, TorrentInfo } from '@/api/types'
|
||||||
import ExistIcon from '@core/components/ExistIcon.vue'
|
import ExistIcon from '@core/components/ExistIcon.vue'
|
||||||
@@ -15,7 +16,7 @@ const cardProps = defineProps({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 定义触发的自定义事件
|
// 定义触发的自定义事件
|
||||||
const emit = defineEmits(['remove', 'update'])
|
const emit = defineEmits(['update', 'remove'])
|
||||||
|
|
||||||
// 密码输入
|
// 密码输入
|
||||||
const isPasswordVisible = ref(false)
|
const isPasswordVisible = ref(false)
|
||||||
@@ -42,7 +43,7 @@ const updateButtonDisable = ref(false)
|
|||||||
const siteCookieDialog = ref(false)
|
const siteCookieDialog = ref(false)
|
||||||
|
|
||||||
// 站点编辑弹窗
|
// 站点编辑弹窗
|
||||||
const siteInfoDialog = ref(false)
|
const siteEditDialog = ref(false)
|
||||||
|
|
||||||
// 资源浏览弹窗
|
// 资源浏览弹窗
|
||||||
const resourceDialog = ref(false)
|
const resourceDialog = ref(false)
|
||||||
@@ -78,27 +79,6 @@ const userPwForm = ref({
|
|||||||
password: '',
|
password: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
// 状态下拉项
|
|
||||||
const statusItems = [
|
|
||||||
{ title: '启用', value: true },
|
|
||||||
{ title: '停用', value: false },
|
|
||||||
]
|
|
||||||
|
|
||||||
// 生成1到50的优先级下拉框选项
|
|
||||||
const priorityItems = ref(
|
|
||||||
Array.from({ length: 50 }, (_, i) => i + 1).map(item => ({
|
|
||||||
title: item,
|
|
||||||
value: item,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
|
|
||||||
// 站点编辑表单数据
|
|
||||||
const siteForm = reactive<any>(cardProps.site ?? {})
|
|
||||||
|
|
||||||
// 类型转换
|
|
||||||
siteForm.proxy = siteForm.proxy === 1
|
|
||||||
siteForm.render = siteForm.render === 1
|
|
||||||
|
|
||||||
// 打开种子详情页面
|
// 打开种子详情页面
|
||||||
function openTorrentDetail(page_url: string) {
|
function openTorrentDetail(page_url: string) {
|
||||||
window.open(page_url, '_blank')
|
window.open(page_url, '_blank')
|
||||||
@@ -144,11 +124,6 @@ async function handleSiteUpdate() {
|
|||||||
siteCookieDialog.value = true
|
siteCookieDialog.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打开站点编辑弹窗
|
|
||||||
async function handleSiteInfo() {
|
|
||||||
siteInfoDialog.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打开资源浏览弹窗
|
// 打开资源浏览弹窗
|
||||||
async function handleResourceBrowse() {
|
async function handleResourceBrowse() {
|
||||||
resourceDialog.value = true
|
resourceDialog.value = true
|
||||||
@@ -189,42 +164,6 @@ async function updateSiteCookie() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用API删除站点信息
|
|
||||||
async function deleteSiteInfo() {
|
|
||||||
try {
|
|
||||||
siteInfoDialog.value = false
|
|
||||||
const result: { [key: string]: any } = await api.delete(`site/${cardProps.site?.id}`)
|
|
||||||
if (result.success) {
|
|
||||||
$toast.success(`${cardProps.site?.name} 删除成功!`)
|
|
||||||
emit('remove')
|
|
||||||
}
|
|
||||||
else { $toast.error(`${cardProps.site?.name} 删除失败:${result.message}`) }
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
$toast.error(`${cardProps.site?.name} 删除失败!`)
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用API更新站点信息
|
|
||||||
async function updateSiteInfo() {
|
|
||||||
try {
|
|
||||||
// 更新按钮状态
|
|
||||||
siteInfoDialog.value = false
|
|
||||||
|
|
||||||
const result: { [key: string]: any } = await api.put('site/', siteForm)
|
|
||||||
if (result.success) {
|
|
||||||
$toast.success(`${cardProps.site?.name} 更新成功!`)
|
|
||||||
emit('update')
|
|
||||||
}
|
|
||||||
else { $toast.error(`${cardProps.site?.name} 更新失败:${result.message}`) }
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
$toast.error(`${cardProps.site?.name} 更新失败!`)
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 促销Chip类
|
// 促销Chip类
|
||||||
function getVolumeFactorClass(downloadVolume: number, uploadVolume: number) {
|
function getVolumeFactorClass(downloadVolume: number, uploadVolume: number) {
|
||||||
if (downloadVolume === 0)
|
if (downloadVolume === 0)
|
||||||
@@ -264,9 +203,9 @@ onMounted(() => {
|
|||||||
<VCard
|
<VCard
|
||||||
:height="cardProps.height"
|
:height="cardProps.height"
|
||||||
:width="cardProps.width"
|
:width="cardProps.width"
|
||||||
:flat="!siteForm.is_active"
|
:flat="!cardProps.site?.is_active"
|
||||||
class="overflow-hidden"
|
class="overflow-hidden"
|
||||||
@click="handleSiteInfo"
|
@click="siteEditDialog = true"
|
||||||
>
|
>
|
||||||
<template #image>
|
<template #image>
|
||||||
<VAvatar
|
<VAvatar
|
||||||
@@ -279,20 +218,18 @@ onMounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
<VCardItem>
|
<VCardItem>
|
||||||
<VCardTitle class="font-bold">
|
<VCardTitle class="font-bold">
|
||||||
{{ cardProps.site?.name }}
|
<span @click.stop="openSitePage">{{ cardProps.site?.name }}</span>
|
||||||
</VCardTitle>
|
</VCardTitle>
|
||||||
<VCardSubtitle
|
<VCardSubtitle>
|
||||||
@click.stop="openSitePage"
|
|
||||||
>
|
|
||||||
{{ cardProps.site?.url }}
|
{{ cardProps.site?.url }}
|
||||||
</VCardSubtitle>
|
</VCardSubtitle>
|
||||||
</VCardItem>
|
</VCardItem>
|
||||||
|
|
||||||
<ExistIcon v-if="siteForm.is_active" />
|
<ExistIcon v-if="cardProps.site?.is_active" />
|
||||||
|
|
||||||
<VCardText class="py-2">
|
<VCardText class="py-2">
|
||||||
<VTooltip
|
<VTooltip
|
||||||
v-if="siteForm.render"
|
v-if="cardProps.site?.render === 1"
|
||||||
text="浏览器仿真"
|
text="浏览器仿真"
|
||||||
>
|
>
|
||||||
<template #activator="{ props }">
|
<template #activator="{ props }">
|
||||||
@@ -306,7 +243,7 @@ onMounted(() => {
|
|||||||
</VTooltip>
|
</VTooltip>
|
||||||
|
|
||||||
<VTooltip
|
<VTooltip
|
||||||
v-if="siteForm.proxy"
|
v-if="cardProps.site?.proxy === 1"
|
||||||
text="代理"
|
text="代理"
|
||||||
>
|
>
|
||||||
<template #activator="{ props }">
|
<template #activator="{ props }">
|
||||||
@@ -320,7 +257,7 @@ onMounted(() => {
|
|||||||
</VTooltip>
|
</VTooltip>
|
||||||
|
|
||||||
<VTooltip
|
<VTooltip
|
||||||
v-if="siteForm.limit_interval"
|
v-if="cardProps.site?.limit_interval"
|
||||||
text="流控"
|
text="流控"
|
||||||
>
|
>
|
||||||
<template #activator="{ props }">
|
<template #activator="{ props }">
|
||||||
@@ -334,7 +271,7 @@ onMounted(() => {
|
|||||||
</VTooltip>
|
</VTooltip>
|
||||||
|
|
||||||
<VTooltip
|
<VTooltip
|
||||||
v-if="siteForm.filter"
|
v-if="cardProps.site?.filter"
|
||||||
text="过滤"
|
text="过滤"
|
||||||
>
|
>
|
||||||
<template #activator="{ props }">
|
<template #activator="{ props }">
|
||||||
@@ -423,146 +360,22 @@ onMounted(() => {
|
|||||||
|
|
||||||
<VCardActions>
|
<VCardActions>
|
||||||
<VSpacer />
|
<VSpacer />
|
||||||
<VBtn @click="updateSiteCookie">
|
<VBtn
|
||||||
|
variant="tonal"
|
||||||
|
@click="updateSiteCookie"
|
||||||
|
>
|
||||||
开始更新
|
开始更新
|
||||||
</VBtn>
|
</VBtn>
|
||||||
</VCardActions>
|
</VCardActions>
|
||||||
</VCard>
|
</VCard>
|
||||||
</VDialog>
|
</VDialog>
|
||||||
<!-- 站点编辑弹窗 -->
|
<SiteAddEditForm
|
||||||
<VDialog
|
v-model="siteEditDialog"
|
||||||
v-model="siteInfoDialog"
|
:siteid="cardProps.site?.id"
|
||||||
max-width="50rem"
|
@save="siteEditDialog = false; emit('update')"
|
||||||
persistent
|
@remove="emit('remove')"
|
||||||
scrollable
|
@close="siteEditDialog = false"
|
||||||
>
|
/>
|
||||||
<!-- Dialog Content -->
|
|
||||||
<VCard :title="`编辑站点 - ${cardProps.site?.name}`">
|
|
||||||
<VCardText class="pt-2">
|
|
||||||
<DialogCloseBtn @click="siteInfoDialog = false" />
|
|
||||||
<VForm @submit.prevent="() => {}">
|
|
||||||
<VRow>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="6"
|
|
||||||
>
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.url"
|
|
||||||
label="站点地址"
|
|
||||||
:rules="[requiredValidator]"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="3"
|
|
||||||
>
|
|
||||||
<VSelect
|
|
||||||
v-model="siteForm.pri"
|
|
||||||
label="优先级"
|
|
||||||
:items="priorityItems"
|
|
||||||
:rules="[requiredValidator]"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="3"
|
|
||||||
>
|
|
||||||
<VSelect
|
|
||||||
v-model="siteForm.is_active"
|
|
||||||
:items="statusItems"
|
|
||||||
label="状态"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
</VRow>
|
|
||||||
<VRow>
|
|
||||||
<VCol cols="12">
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.rss"
|
|
||||||
label="RSS地址"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol cols="12">
|
|
||||||
<VTextarea
|
|
||||||
v-model="siteForm.cookie"
|
|
||||||
label="站点Cookie"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol cols="12">
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.ua"
|
|
||||||
label="站点User-Agent"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
</VRow>
|
|
||||||
<VRow>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="4"
|
|
||||||
>
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.limit_interval"
|
|
||||||
label="单位周期(秒)"
|
|
||||||
:rules="[numberValidator]"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="4"
|
|
||||||
>
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.limit_seconds"
|
|
||||||
label="访问次数"
|
|
||||||
:rules="[numberValidator]"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="4"
|
|
||||||
>
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.limit_seconds"
|
|
||||||
label="访问间隔(秒)"
|
|
||||||
:rules="[numberValidator]"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
</VRow>
|
|
||||||
<VRow>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="6"
|
|
||||||
>
|
|
||||||
<VSwitch
|
|
||||||
v-model="siteForm.proxy"
|
|
||||||
label="代理"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="6"
|
|
||||||
>
|
|
||||||
<VSwitch
|
|
||||||
v-model="siteForm.render"
|
|
||||||
label="仿真"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
</VRow>
|
|
||||||
</VForm>
|
|
||||||
</VCardText>
|
|
||||||
|
|
||||||
<VCardActions>
|
|
||||||
<VBtn color="error" @click="deleteSiteInfo">
|
|
||||||
删除
|
|
||||||
</VBtn>
|
|
||||||
<VSpacer />
|
|
||||||
<VBtn
|
|
||||||
variant="tonal"
|
|
||||||
@click="updateSiteInfo"
|
|
||||||
>
|
|
||||||
确定
|
|
||||||
</VBtn>
|
|
||||||
</VCardActions>
|
|
||||||
</VCard>
|
|
||||||
</VDialog>
|
|
||||||
<!-- 站点资源弹窗 -->
|
<!-- 站点资源弹窗 -->
|
||||||
<VDialog
|
<VDialog
|
||||||
v-model="resourceDialog"
|
v-model="resourceDialog"
|
||||||
|
|||||||
@@ -0,0 +1,271 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { useToast } from 'vue-toast-notification'
|
||||||
|
import type { Site } from '@/api/types'
|
||||||
|
import { doneNProgress, startNProgress } from '@/api/nprogress'
|
||||||
|
import { numberValidator, requiredValidator } from '@/@validators'
|
||||||
|
import api from '@/api'
|
||||||
|
|
||||||
|
// 输入参数
|
||||||
|
const props = defineProps({
|
||||||
|
siteid: Number,
|
||||||
|
oper: String,
|
||||||
|
})
|
||||||
|
|
||||||
|
// 注册事件
|
||||||
|
const emit = defineEmits(['save', 'remove', 'close'])
|
||||||
|
|
||||||
|
// 站点编辑表单数据
|
||||||
|
const siteForm = ref<Site>({
|
||||||
|
id: props.siteid ?? 0,
|
||||||
|
url: '',
|
||||||
|
rss: '',
|
||||||
|
cookie: '',
|
||||||
|
ua: '',
|
||||||
|
pri: 0,
|
||||||
|
is_active: true,
|
||||||
|
limit_interval: 0,
|
||||||
|
limit_seconds: 0,
|
||||||
|
name: '',
|
||||||
|
domain: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
// 提示框
|
||||||
|
const $toast = useToast()
|
||||||
|
|
||||||
|
// 状态下拉项
|
||||||
|
const statusItems = [
|
||||||
|
{ title: '启用', value: true },
|
||||||
|
{ title: '停用', value: false },
|
||||||
|
]
|
||||||
|
|
||||||
|
// 生成1到50的优先级下拉框选项
|
||||||
|
const priorityItems = ref(
|
||||||
|
Array.from({ length: 50 }, (_, i) => i + 1).map(item => ({
|
||||||
|
title: item,
|
||||||
|
value: item,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
// 监控输入参数
|
||||||
|
watchEffect(async () => {
|
||||||
|
if (props.siteid)
|
||||||
|
fetchSiteInfo()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 查询站点信息
|
||||||
|
async function fetchSiteInfo() {
|
||||||
|
try {
|
||||||
|
siteForm.value = await api.get(`site/${props.siteid}`)
|
||||||
|
siteForm.value.proxy = siteForm.value.proxy === 1
|
||||||
|
siteForm.value.render = siteForm.value.render === 1
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用API 新增站点
|
||||||
|
async function addSite() {
|
||||||
|
if (!siteForm.value?.url)
|
||||||
|
return
|
||||||
|
startNProgress()
|
||||||
|
try {
|
||||||
|
const result: { [key: string]: string } = await api.post('site/', siteForm.value)
|
||||||
|
if (result.success) {
|
||||||
|
$toast.success('新增站点成功')
|
||||||
|
emit('save')
|
||||||
|
}
|
||||||
|
|
||||||
|
else { $toast.error(`新增站点失败:${result.message}`) }
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
doneNProgress()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用API删除站点信息
|
||||||
|
async function deleteSiteInfo() {
|
||||||
|
try {
|
||||||
|
const result: { [key: string]: any } = await api.delete(`site/${siteForm.value?.id}`)
|
||||||
|
if (result.success)
|
||||||
|
emit('remove')
|
||||||
|
|
||||||
|
else $toast.error(`${siteForm.value?.name} 删除失败:${result.message}`)
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
$toast.error(`${siteForm.value?.name} 删除失败!`)
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用API更新站点信息
|
||||||
|
async function updateSiteInfo() {
|
||||||
|
startNProgress()
|
||||||
|
try {
|
||||||
|
const result: { [key: string]: any } = await api.put('site/', siteForm.value)
|
||||||
|
if (result.success) {
|
||||||
|
$toast.success(`${siteForm.value?.name} 更新成功!`)
|
||||||
|
emit('save')
|
||||||
|
}
|
||||||
|
else { $toast.error(`${siteForm.value?.name} 更新失败:${result.message}`) }
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
$toast.error(`${siteForm.value?.name} 更新失败!`)
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
doneNProgress()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VBottomSheet
|
||||||
|
inset
|
||||||
|
scrollable
|
||||||
|
>
|
||||||
|
<VCard :title="`${props.oper === 'add' ? '新增' : '编辑'}站点${props.oper !== 'add' ? ` - ${siteForm.name}` : ''}`">
|
||||||
|
<DialogCloseBtn @click="emit('close')" />
|
||||||
|
<VCardText class="pt-2">
|
||||||
|
<VForm @submit.prevent="() => {}">
|
||||||
|
<VRow>
|
||||||
|
<VCol
|
||||||
|
cols="12"
|
||||||
|
md="6"
|
||||||
|
>
|
||||||
|
<VTextField
|
||||||
|
v-model="siteForm.url"
|
||||||
|
label="站点地址"
|
||||||
|
:rules="[requiredValidator]"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
<VCol
|
||||||
|
cols="12"
|
||||||
|
md="3"
|
||||||
|
>
|
||||||
|
<VSelect
|
||||||
|
v-model="siteForm.pri"
|
||||||
|
label="优先级"
|
||||||
|
:items="priorityItems"
|
||||||
|
:rules="[requiredValidator]"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
<VCol
|
||||||
|
cols="12"
|
||||||
|
md="3"
|
||||||
|
>
|
||||||
|
<VSelect
|
||||||
|
v-model="siteForm.is_active"
|
||||||
|
:items="statusItems"
|
||||||
|
label="状态"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
</VRow>
|
||||||
|
<VRow>
|
||||||
|
<VCol cols="12">
|
||||||
|
<VTextField
|
||||||
|
v-model="siteForm.rss"
|
||||||
|
label="RSS地址"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
<VCol cols="12">
|
||||||
|
<VTextarea
|
||||||
|
v-model="siteForm.cookie"
|
||||||
|
label="站点Cookie"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
<VCol cols="12">
|
||||||
|
<VTextField
|
||||||
|
v-model="siteForm.ua"
|
||||||
|
label="站点User-Agent"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
</VRow>
|
||||||
|
<VRow>
|
||||||
|
<VCol
|
||||||
|
cols="12"
|
||||||
|
md="4"
|
||||||
|
>
|
||||||
|
<VTextField
|
||||||
|
v-model="siteForm.limit_interval"
|
||||||
|
label="单位周期(秒)"
|
||||||
|
:rules="[numberValidator]"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
<VCol
|
||||||
|
cols="12"
|
||||||
|
md="4"
|
||||||
|
>
|
||||||
|
<VTextField
|
||||||
|
v-model="siteForm.limit_seconds"
|
||||||
|
label="访问次数"
|
||||||
|
:rules="[numberValidator]"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
<VCol
|
||||||
|
cols="12"
|
||||||
|
md="4"
|
||||||
|
>
|
||||||
|
<VTextField
|
||||||
|
v-model="siteForm.limit_seconds"
|
||||||
|
label="访问间隔(秒)"
|
||||||
|
:rules="[numberValidator]"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
</VRow>
|
||||||
|
<VRow>
|
||||||
|
<VCol
|
||||||
|
cols="12"
|
||||||
|
md="6"
|
||||||
|
>
|
||||||
|
<VSwitch
|
||||||
|
v-model="siteForm.proxy"
|
||||||
|
label="代理"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
<VCol
|
||||||
|
cols="12"
|
||||||
|
md="6"
|
||||||
|
>
|
||||||
|
<VSwitch
|
||||||
|
v-model="siteForm.render"
|
||||||
|
label="仿真"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
</VRow>
|
||||||
|
</VForm>
|
||||||
|
</VCardText>
|
||||||
|
<VCardActions>
|
||||||
|
<VBtn
|
||||||
|
v-if="props.oper === 'add'"
|
||||||
|
@click="emit('close')"
|
||||||
|
>
|
||||||
|
取消
|
||||||
|
</VBtn>
|
||||||
|
<VBtn
|
||||||
|
v-else
|
||||||
|
color="error"
|
||||||
|
@click="deleteSiteInfo"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</VBtn>
|
||||||
|
<VSpacer />
|
||||||
|
<VBtn
|
||||||
|
v-if="props.oper === 'add'"
|
||||||
|
color="primary"
|
||||||
|
variant="tonal"
|
||||||
|
@click="addSite"
|
||||||
|
>
|
||||||
|
新增
|
||||||
|
</VBtn>
|
||||||
|
<VBtn
|
||||||
|
v-else
|
||||||
|
color="primary"
|
||||||
|
variant="tonal"
|
||||||
|
@click="updateSiteInfo"
|
||||||
|
>
|
||||||
|
保存
|
||||||
|
</VBtn>
|
||||||
|
</VCardActions>
|
||||||
|
</VCard>
|
||||||
|
</vBottomSheet>
|
||||||
|
</template>
|
||||||
@@ -1,14 +1,9 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useToast } from 'vue-toast-notification'
|
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import type { Site } from '@/api/types'
|
import type { Site } from '@/api/types'
|
||||||
import SiteCard from '@/components/cards/SiteCard.vue'
|
import SiteCard from '@/components/cards/SiteCard.vue'
|
||||||
import NoDataFound from '@/components/NoDataFound.vue'
|
import NoDataFound from '@/components/NoDataFound.vue'
|
||||||
import { numberValidator, requiredValidator } from '@/@validators'
|
import SiteAddEditForm from '@/components/form/SiteAddEditForm.vue'
|
||||||
import { doneNProgress, startNProgress } from '@/api/nprogress'
|
|
||||||
|
|
||||||
// 提示框
|
|
||||||
const $toast = useToast()
|
|
||||||
|
|
||||||
// 数据列表
|
// 数据列表
|
||||||
const dataList = ref<Site[]>([])
|
const dataList = ref<Site[]>([])
|
||||||
@@ -16,45 +11,9 @@ const dataList = ref<Site[]>([])
|
|||||||
// 是否刷新过
|
// 是否刷新过
|
||||||
const isRefreshed = ref(false)
|
const isRefreshed = ref(false)
|
||||||
|
|
||||||
// 新增按钮文本
|
|
||||||
const addBtnText = ref('新增站点')
|
|
||||||
// 新增按钮状态
|
|
||||||
const addBtnState = ref(false)
|
|
||||||
|
|
||||||
// 新增站点对话框
|
// 新增站点对话框
|
||||||
const siteAddDialog = ref(false)
|
const siteAddDialog = ref(false)
|
||||||
|
|
||||||
// 状态下拉项
|
|
||||||
const statusItems = [
|
|
||||||
{ title: '启用', value: true },
|
|
||||||
{ title: '停用', value: false },
|
|
||||||
]
|
|
||||||
|
|
||||||
// 生成1到50的优先级下拉框选项
|
|
||||||
const priorityItems = ref(
|
|
||||||
Array.from({ length: 50 }, (_, i) => i + 1).map(item => ({
|
|
||||||
title: item,
|
|
||||||
value: item,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
|
|
||||||
// 站点编辑表单数据
|
|
||||||
const siteForm = reactive<Site>({
|
|
||||||
id: 0,
|
|
||||||
url: '',
|
|
||||||
pri: 1,
|
|
||||||
is_active: true,
|
|
||||||
cookie: '',
|
|
||||||
ua: '',
|
|
||||||
limit_interval: 0,
|
|
||||||
limit_seconds: 0,
|
|
||||||
limit_count: 0,
|
|
||||||
proxy: 0,
|
|
||||||
render: 0,
|
|
||||||
name: '',
|
|
||||||
domain: '',
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取站点列表数据
|
// 获取站点列表数据
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
try {
|
try {
|
||||||
@@ -66,57 +25,6 @@ async function fetchData() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用API 新增站点
|
|
||||||
async function addSite() {
|
|
||||||
if (!siteForm.url)
|
|
||||||
return
|
|
||||||
|
|
||||||
startNProgress()
|
|
||||||
|
|
||||||
addBtnText.value = '新增中...'
|
|
||||||
addBtnState.value = true
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result: { [key: string]: string } = await api.post('site/', siteForm)
|
|
||||||
if (result.success) {
|
|
||||||
$toast.success('新增站点成功')
|
|
||||||
|
|
||||||
// 刷新数据
|
|
||||||
fetchData()
|
|
||||||
}
|
|
||||||
|
|
||||||
else { $toast.error(`新增站点失败:${result.message}`) }
|
|
||||||
siteAddDialog.value = false
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
doneNProgress()
|
|
||||||
|
|
||||||
addBtnText.value = '新增站点'
|
|
||||||
addBtnState.value = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打开新增站点对话框
|
|
||||||
function openSiteAddDialog() {
|
|
||||||
// 清空输入项
|
|
||||||
siteForm.id = 0
|
|
||||||
siteForm.url = ''
|
|
||||||
siteForm.pri = 1
|
|
||||||
siteForm.is_active = true
|
|
||||||
siteForm.cookie = ''
|
|
||||||
siteForm.ua = ''
|
|
||||||
siteForm.limit_interval = 0
|
|
||||||
siteForm.limit_seconds = 0
|
|
||||||
siteForm.limit_count = 0
|
|
||||||
siteForm.proxy = 0
|
|
||||||
siteForm.render = 0
|
|
||||||
siteForm.name = ''
|
|
||||||
siteForm.domain = ''
|
|
||||||
siteAddDialog.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载时获取数据
|
// 加载时获取数据
|
||||||
onBeforeMount(fetchData)
|
onBeforeMount(fetchData)
|
||||||
</script>
|
</script>
|
||||||
@@ -151,151 +59,20 @@ onBeforeMount(fetchData)
|
|||||||
error-title="没有站点"
|
error-title="没有站点"
|
||||||
error-description="已添加并支持的站点将会在这里显示。"
|
error-description="已添加并支持的站点将会在这里显示。"
|
||||||
/>
|
/>
|
||||||
<!-- Dialog Content -->
|
<!-- 新增站点按钮 -->
|
||||||
<VDialog
|
<VBtn
|
||||||
|
icon="mdi-plus"
|
||||||
|
size="x-large"
|
||||||
|
class="fixed right-5 bottom-5"
|
||||||
|
oper="add"
|
||||||
|
@click="siteAddDialog = true"
|
||||||
|
/>
|
||||||
|
<SiteAddEditForm
|
||||||
v-model="siteAddDialog"
|
v-model="siteAddDialog"
|
||||||
max-width="50rem"
|
oper="add"
|
||||||
persistent
|
@save="siteAddDialog = false; fetchData()"
|
||||||
scrollable
|
@close="siteAddDialog = false"
|
||||||
>
|
/>
|
||||||
<!-- Dialog Activator -->
|
|
||||||
<template #activator="{ props }">
|
|
||||||
<VBtn
|
|
||||||
icon="mdi-plus"
|
|
||||||
v-bind="props"
|
|
||||||
size="x-large"
|
|
||||||
class="fixed right-5 bottom-5"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
<VCard title="新增站点">
|
|
||||||
<DialogCloseBtn @click="siteAddDialog = false" />
|
|
||||||
<VCardText class="pt-2">
|
|
||||||
<VForm @submit.prevent="() => {}">
|
|
||||||
<VRow>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="6"
|
|
||||||
>
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.url"
|
|
||||||
label="站点地址"
|
|
||||||
:rules="[requiredValidator]"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="3"
|
|
||||||
>
|
|
||||||
<VSelect
|
|
||||||
v-model="siteForm.pri"
|
|
||||||
label="优先级"
|
|
||||||
:items="priorityItems"
|
|
||||||
:rules="[requiredValidator]"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="3"
|
|
||||||
>
|
|
||||||
<VSelect
|
|
||||||
v-model="siteForm.is_active"
|
|
||||||
:items="statusItems"
|
|
||||||
label="状态"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
</VRow>
|
|
||||||
<VRow>
|
|
||||||
<VCol cols="12">
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.rss"
|
|
||||||
label="RSS地址"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol cols="12">
|
|
||||||
<VTextarea
|
|
||||||
v-model="siteForm.cookie"
|
|
||||||
label="站点Cookie"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol cols="12">
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.ua"
|
|
||||||
label="站点User-Agent"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
</VRow>
|
|
||||||
<VRow>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="4"
|
|
||||||
>
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.limit_interval"
|
|
||||||
label="单位周期(秒)"
|
|
||||||
:rules="[numberValidator]"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="4"
|
|
||||||
>
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.limit_seconds"
|
|
||||||
label="访问次数"
|
|
||||||
:rules="[numberValidator]"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="4"
|
|
||||||
>
|
|
||||||
<VTextField
|
|
||||||
v-model="siteForm.limit_seconds"
|
|
||||||
label="访问间隔(秒)"
|
|
||||||
:rules="[numberValidator]"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
</VRow>
|
|
||||||
<VRow>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="6"
|
|
||||||
>
|
|
||||||
<VSwitch
|
|
||||||
v-model="siteForm.proxy"
|
|
||||||
label="代理"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
<VCol
|
|
||||||
cols="12"
|
|
||||||
md="6"
|
|
||||||
>
|
|
||||||
<VSwitch
|
|
||||||
v-model="siteForm.render"
|
|
||||||
label="仿真"
|
|
||||||
/>
|
|
||||||
</VCol>
|
|
||||||
</VRow>
|
|
||||||
</VForm>
|
|
||||||
</VCardText>
|
|
||||||
<VCardActions>
|
|
||||||
<VBtn
|
|
||||||
@click="siteAddDialog = false"
|
|
||||||
>
|
|
||||||
取消
|
|
||||||
</VBtn>
|
|
||||||
<VSpacer />
|
|
||||||
<VBtn
|
|
||||||
color="primary"
|
|
||||||
:disabled="addBtnState"
|
|
||||||
variant="tonal"
|
|
||||||
@click="addSite"
|
|
||||||
>
|
|
||||||
{{ addBtnText }}
|
|
||||||
</VBtn>
|
|
||||||
</VCardActions>
|
|
||||||
</VCard>
|
|
||||||
</VDialog>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|||||||
Reference in New Issue
Block a user