mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-08 17:26:41 +08:00
优化 SiteCard 组件,添加删除确认功能并调整样式
This commit is contained in:
@@ -9,6 +9,7 @@ import api from '@/api'
|
|||||||
import type { Site, SiteStatistic, SiteUserData } from '@/api/types'
|
import type { Site, SiteStatistic, SiteUserData } from '@/api/types'
|
||||||
import { isNullOrEmptyObject } from '@/@core/utils'
|
import { isNullOrEmptyObject } from '@/@core/utils'
|
||||||
import { formatFileSize } from '@/@core/utils/formatters'
|
import { formatFileSize } from '@/@core/utils/formatters'
|
||||||
|
import { useConfirm } from 'vuetify-use-dialog'
|
||||||
|
|
||||||
// 输入参数
|
// 输入参数
|
||||||
const cardProps = defineProps({
|
const cardProps = defineProps({
|
||||||
@@ -19,6 +20,9 @@ const cardProps = defineProps({
|
|||||||
// 定义触发的自定义事件
|
// 定义触发的自定义事件
|
||||||
const emit = defineEmits(['update', 'remove'])
|
const emit = defineEmits(['update', 'remove'])
|
||||||
|
|
||||||
|
// 确认框
|
||||||
|
const createConfirm = useConfirm()
|
||||||
|
|
||||||
// 图标
|
// 图标
|
||||||
const siteIcon = ref<string>('')
|
const siteIcon = ref<string>('')
|
||||||
|
|
||||||
@@ -103,6 +107,25 @@ function openSitePage() {
|
|||||||
window.open(cardProps.site?.url, '_blank')
|
window.open(cardProps.site?.url, '_blank')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 调用API删除站点信息
|
||||||
|
async function deleteSiteInfo() {
|
||||||
|
const isConfirmed = await createConfirm({
|
||||||
|
title: '确认',
|
||||||
|
content: `是否确认删除站点?`,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!isConfirmed) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result: { [key: string]: any } = await api.delete(`site/${cardProps.site?.id}`)
|
||||||
|
if (result.success) emit('remove')
|
||||||
|
else $toast.error(`${cardProps.site?.name} 删除失败:${result.message}`)
|
||||||
|
} catch (error) {
|
||||||
|
$toast.error(`${cardProps.site?.name} 删除失败!`)
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 根据站点状态显示不同的状态图标
|
// 根据站点状态显示不同的状态图标
|
||||||
const statColor = computed(() => {
|
const statColor = computed(() => {
|
||||||
if (isNullOrEmptyObject(siteStats.value)) {
|
if (isNullOrEmptyObject(siteStats.value)) {
|
||||||
@@ -309,7 +332,6 @@ onMounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
<span>测试站点连通性</span>
|
<span>测试站点连通性</span>
|
||||||
</VTooltip>
|
</VTooltip>
|
||||||
|
|
||||||
<VTooltip>
|
<VTooltip>
|
||||||
<template #activator="{ props }">
|
<template #activator="{ props }">
|
||||||
<IconBtn v-bind="props" elevation="0" class="site-action-btn" @click.stop="handleSiteUserData">
|
<IconBtn v-bind="props" elevation="0" class="site-action-btn" @click.stop="handleSiteUserData">
|
||||||
@@ -318,7 +340,6 @@ onMounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
<span>查看站点数据</span>
|
<span>查看站点数据</span>
|
||||||
</VTooltip>
|
</VTooltip>
|
||||||
|
|
||||||
<VTooltip v-if="!cardProps.site?.public">
|
<VTooltip v-if="!cardProps.site?.public">
|
||||||
<template #activator="{ props }">
|
<template #activator="{ props }">
|
||||||
<IconBtn v-bind="props" elevation="0" class="site-action-btn" @click.stop="handleSiteUpdate">
|
<IconBtn v-bind="props" elevation="0" class="site-action-btn" @click.stop="handleSiteUpdate">
|
||||||
@@ -327,7 +348,6 @@ onMounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
<span>更新Cookie/UA</span>
|
<span>更新Cookie/UA</span>
|
||||||
</VTooltip>
|
</VTooltip>
|
||||||
|
|
||||||
<VTooltip>
|
<VTooltip>
|
||||||
<template #activator="{ props }">
|
<template #activator="{ props }">
|
||||||
<IconBtn v-bind="props" elevation="0" class="site-action-btn more-btn">
|
<IconBtn v-bind="props" elevation="0" class="site-action-btn more-btn">
|
||||||
@@ -340,7 +360,7 @@ onMounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
<VListItemTitle>编辑站点</VListItemTitle>
|
<VListItemTitle>编辑站点</VListItemTitle>
|
||||||
</VListItem>
|
</VListItem>
|
||||||
<VListItem variant="plain" @click.stop="emit('remove')">
|
<VListItem variant="plain" @click.stop="deleteSiteInfo">
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<VIcon icon="mdi-delete-outline" size="small" color="error" />
|
<VIcon icon="mdi-delete-outline" size="small" color="error" />
|
||||||
</template>
|
</template>
|
||||||
@@ -666,9 +686,8 @@ onMounted(() => {
|
|||||||
|
|
||||||
/* 数据统计 */
|
/* 数据统计 */
|
||||||
.site-stats {
|
.site-stats {
|
||||||
border-block-start: 1px solid rgba(var(--v-theme-on-surface), 0.05);
|
|
||||||
margin-block-start: auto;
|
margin-block-start: auto;
|
||||||
padding-block-start: 6px;
|
padding-block-start: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.site-data-values {
|
.site-data-values {
|
||||||
@@ -960,12 +979,12 @@ onMounted(() => {
|
|||||||
border: none;
|
border: none;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background-color: rgba(var(--v-theme-surface), 1);
|
background-color: rgba(var(--v-theme-surface), 1);
|
||||||
block-size: 36px;
|
block-size: 32px;
|
||||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 5%);
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 5%);
|
||||||
color: rgba(var(--v-theme-on-surface), 0.8);
|
color: rgba(var(--v-theme-on-surface), 0.8);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
inline-size: 36px;
|
inline-size: 36px;
|
||||||
margin-block-end: 8px;
|
margin-block-end: 4px;
|
||||||
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,10 @@ import { doneNProgress, startNProgress } from '@/api/nprogress'
|
|||||||
import { numberValidator, requiredValidator } from '@/@validators'
|
import { numberValidator, requiredValidator } from '@/@validators'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { useDisplay } from 'vuetify'
|
import { useDisplay } from 'vuetify'
|
||||||
import { useConfirm } from 'vuetify-use-dialog'
|
|
||||||
|
|
||||||
// 显示器宽度
|
// 显示器宽度
|
||||||
const display = useDisplay()
|
const display = useDisplay()
|
||||||
|
|
||||||
// 确认框
|
|
||||||
const createConfirm = useConfirm()
|
|
||||||
|
|
||||||
// 输入参数
|
// 输入参数
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
siteid: Number,
|
siteid: Number,
|
||||||
@@ -108,25 +104,6 @@ async function addSite() {
|
|||||||
doneNProgress()
|
doneNProgress()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用API删除站点信息
|
|
||||||
async function deleteSiteInfo() {
|
|
||||||
const isConfirmed = await createConfirm({
|
|
||||||
title: '确认',
|
|
||||||
content: `是否确认删除站点?`,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!isConfirmed) return
|
|
||||||
|
|
||||||
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更新站点信息
|
// 调用API更新站点信息
|
||||||
async function updateSiteInfo() {
|
async function updateSiteInfo() {
|
||||||
startNProgress()
|
startNProgress()
|
||||||
@@ -338,9 +315,6 @@ onMounted(async () => {
|
|||||||
</VForm>
|
</VForm>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
<VCardActions class="pt-3">
|
<VCardActions class="pt-3">
|
||||||
<VBtn v-if="props.oper !== 'add'" color="error" @click="deleteSiteInfo" variant="outlined" class="me-3">
|
|
||||||
删除
|
|
||||||
</VBtn>
|
|
||||||
<VSpacer />
|
<VSpacer />
|
||||||
<VBtn
|
<VBtn
|
||||||
v-if="props.oper === 'add'"
|
v-if="props.oper === 'add'"
|
||||||
|
|||||||
Reference in New Issue
Block a user