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() + } +}