Skip to content

Commit 52c083b

Browse files
committed
refactor: 重构subscribe
1 parent 2c9c478 commit 52c083b

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

src/layout/default/SubscribeList.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
<script setup lang="ts"></script>
1+
<script setup lang="ts">
2+
import type { uni } from '@delta-comic/model'
3+
import { shallowRef } from 'vue'
4+
5+
import SubscribeRow from './SubscribeRow.vue'
6+
7+
defineProps<{
8+
union?: uni.item.Item
9+
page: uni.content.ContentPage
10+
}>()
11+
const showDetailUsers = shallowRef(false)
12+
</script>
213

314
<template>
415
<div
@@ -9,7 +20,12 @@
920
<span class="ml-3 font-bold">创作团队</span>
1021
<span class="absolute right-3 text-(--van-text-color-2)">共{{ union?.author.length }}位</span>
1122
<DcPopup v-model:show="showDetailUsers" position="bottom" round class="h-[50vh]">
12-
<SubscribeRow :author v-for="author of union.author" class="van-hairline--bottom py-2" />
23+
<SubscribeRow
24+
:page
25+
:author
26+
v-for="author of union?.author"
27+
class="van-hairline--bottom py-2"
28+
/>
1329
</DcPopup>
1430
</div>
1531
<div
@@ -18,7 +34,7 @@
1834
@click.stop
1935
@pointermove.stop
2036
>
21-
<SubscribeRow :author="union.author[0]" v-if="union?.author.length === 1" class="mt-3" />
37+
<SubscribeRow :page :author="union.author[0]" v-if="union?.author.length === 1" class="mt-3" />
2238
<div v-else class="scroll flex overflow-x-scroll overflow-y-hidden" @click.stop>
2339
<SubscribeSmallRow
2440
class="flex items-center gap-3 text-nowrap"

src/layout/default/SubscribeRow.vue

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { uni } from '@delta-comic/model'
44
import { Global } from '@delta-comic/plugin'
55
import { createLoadingMessage } from '@delta-comic/ui'
66
import { createReusableTemplate } from '@vueuse/core'
7+
import type { PopoverAction } from 'vant'
78
89
const $props = defineProps<{
910
page: uni.content.ContentPage
@@ -22,22 +23,28 @@ const getIsSubscribe = (author: uni.item.Author) =>
2223
.then(v => v.length != 0)
2324
)
2425
26+
const { upsert } = SubscribeDB.useUpsert()
2527
const addSubscribe = (author: uni.item.Author) =>
2628
createLoadingMessage('关注中').bind(
27-
SubscribeDB.upsert({
28-
type: 'author',
29-
author,
30-
plugin: author.$$plugin,
31-
key: SubscribeDB.key.toString([author.$$plugin, author.label]),
32-
itemKey: null
29+
upsert({
30+
items: [
31+
{
32+
type: 'author',
33+
author,
34+
plugin: author.$$plugin,
35+
key: SubscribeDB.key.toString([author.$$plugin, author.label]),
36+
itemKey: null
37+
}
38+
]
3339
})
3440
)
41+
42+
const { remove } = SubscribeDB.useRemove()
3543
const removeSubscribe = (author: uni.item.Author) =>
3644
createLoadingMessage('取消中').bind(
37-
db.value
38-
.deleteFrom('subscribe')
39-
.where('key', '=', SubscribeDB.key.toString([author.$$plugin, author.label]))
40-
.execute()
45+
remove({
46+
keys: [SubscribeDB.key.toString([author.$$plugin, author.label])]
47+
})
4148
)
4249
4350
const getActionInfo = (key: string) => Global.userActions.get([$props.page.plugin, key])!

0 commit comments

Comments
 (0)