From 9a4392ecebd5f1dec52298c7c681a901119c2429 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 15 Jan 2025 13:31:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E4=BA=AB=E4=BA=BA?= =?UTF-8?q?=E5=94=AF=E4=B8=80ID=EF=BC=8C=E6=94=AF=E6=8C=81=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E8=AE=A2=E9=98=85=E5=88=86=E4=BA=AB=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=BC=98=E5=8C=96=E7=9B=B8=E5=85=B3=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/types.ts | 2 + src/components/cards/SubscribeShareCard.vue | 16 ++++- src/components/dialog/ForkSubscribeDialog.vue | 66 +++++++++++++++---- src/views/subscribe/SubscribeShareView.vue | 7 +- 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/src/api/types.ts b/src/api/types.ts index 0c9ebe11..4e4ddcda 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -88,6 +88,8 @@ export interface SubscribeShare { share_comment?: string // 分享人 share_user?: string + // 分享人唯一ID + share_uid?: string // 订阅名称 name?: string // 订阅年份 diff --git a/src/components/cards/SubscribeShareCard.vue b/src/components/cards/SubscribeShareCard.vue index 20a47f8a..a42a2ebe 100644 --- a/src/components/cards/SubscribeShareCard.vue +++ b/src/components/cards/SubscribeShareCard.vue @@ -10,6 +10,9 @@ const props = defineProps({ media: Object as PropType, }) +// 定义删除事件 +const emit = defineEmits(['delete']) + // 从 provide 中获取全局设置 const globalSettings: any = inject('globalSettings') @@ -70,8 +73,18 @@ function showForkSubscribe() { // 完成复用订阅 function finishForkSubscribe(subid: number) { subscribeId.value = subid + forkSubscribeDialog.value=false subscribeEditDialog.value = true } + +// 删除订阅分享时处理 +function doDelete() { + forkSubscribeDialog.value=false + // 通知父组件刷新 + emit('delete') +} + + diff --git a/src/components/dialog/ForkSubscribeDialog.vue b/src/components/dialog/ForkSubscribeDialog.vue index 0e118084..8b90d340 100644 --- a/src/components/dialog/ForkSubscribeDialog.vue +++ b/src/components/dialog/ForkSubscribeDialog.vue @@ -12,7 +12,7 @@ const props = defineProps({ }) // 定义事件 -const emit = defineEmits(['close', 'done']) +const emit = defineEmits(['fork', 'delete', 'close']) // 从 provide 中获取全局设置 const globalSettings: any = inject('globalSettings') @@ -23,6 +23,9 @@ const $toast = useToast() // 处理中 const processing = ref(false) +// 删除中 +const deleting = ref(false) + // 计算海报图片地址 const posterUrl = computed(() => { const url = props.media?.poster @@ -55,7 +58,7 @@ async function doFork() { if (result.success) { $toast.success(`${props.media?.share_title} 添加订阅成功!`) // 完成 - emit('done', result.data.id) + emit('fork', result.data.id) } else { $toast.error(`${props.media?.share_title} 添加订阅失败:${result.message}!`) } @@ -66,6 +69,34 @@ async function doFork() { doneNProgress() } } + +// 删除订阅分享 +async function doDelete() { + // 开始处理 + startNProgress() + try { + deleting.value = true + // 请求API + const result: { [key: string]: any } = await api.delete(`subscribe/share/${props.media?.id}`, { + params: { + share_uid: globalSettings.USER_UNIQUE_ID, + }, + }) + // 订阅状态 + if (result.success) { + $toast.success(`${props.media?.share_title} 取消分享成功!`) + // 完成 + emit('delete', result.data.id) + } else { + $toast.error(`${props.media?.share_title} 取消分享失败:${result.message}!`) + } + } catch (error) { + console.error(error) + } finally { + deleting.value = false + doneNProgress() + } +}