-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathClient.vue
71 lines (61 loc) · 1.4 KB
/
Client.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<script lang="ts" setup>
import { VirtList } from 'vue-virt-list'
import { demos } from './config'
const props = defineProps<{
msgList: IMsg[]
customStyle?: ICustomStyle
sample: string
}>()
const demo = computed(() => {
return demos.find(item => item.id === props.sample) || demos[0]
})
const { autoScroll } = storeToRefs(useAppStore())
const danmuRef: Ref<InstanceType<typeof VirtList> | null> = ref(null)
watch(() => props.msgList, () => {
if (!danmuRef.value || !autoScroll.value)
return
nextTick(() => {
danmuRef.value?.scrollToBottom()
})
}, {
deep: true,
})
watch(autoScroll, (val) => {
if (val)
danmuRef.value?.scrollToBottom()
})
</script>
<template>
<div class="danmu">
<slot />
<VirtList
ref="danmuRef" item-key="id" :list="msgList" :min-size="30" :fixed="false" :buffer="2"
>
<template #default="{ itemData }">
<div
class="p1 text-sm"
:style="{
paddingBottom: `${customStyle?.msgGap}px`,
}"
>
<component
:is="demo.component"
:custom-style="{
...demo.baseStyle,
...customStyle,
}"
:danmaku="itemData"
/>
</div>
</template>
</VirtList>
</div>
</template>
<style lang="scss" scoped>
::-webkit-scrollbar {
display: none;
}
.danmu{
@apply h-100vh w-full p-2 relative;
}
</style>