danmaku.vue
2.1 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!--
* @Date: 2024-04-10 14:16:36
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-04-13 10:40:09
* @FilePath: /fxPark/src/components/danmaku.vue
* @Description: 弹幕组件
-->
<template>
<div class="danmaku-page">
<vue-danmaku ref="danmakuRef" class="danmu-boxer" v-model:danmus="danmus" useSlot loop :channels="4" :speeds="30" :top="0">
<template v-slot:dm="{ index, danmu }">
<div class="dm-item">
<van-icon v-if="danmu.status === '2'" name="fire-o" color="red" />
<span>{{ danmu.note }}</span>
</div>
</template>
</vue-danmaku>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import vueDanmaku from 'vue3-danmaku'
import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js'
//import { } from '@/utils/generateModules.js'
//import { } from '@/utils/generateIcons.js'
//import { } from '@/composables'
import { getDanmuAPI } from '@/api/carbon.js';
const $route = useRoute();
const $router = useRouter();
useTitle($route.meta.title);
const props = defineProps({
text: {
type: Object,
default: {}
},
show: {
type: Boolean,
default: false
}
});
watch(() => props.text, (v) => {
if (v.note) {
danmakuRef.value.add(v)
}
});
watch(() => props.show, (v) => {
nextTick(() => {
if (v) {
danmakuRef.value.show();
$('.danmu-boxer').css('zIndex', '10');
} else {
danmakuRef.value.hide();
$('.danmu-boxer').css('zIndex', '0');
}
})
}, {
immediate: true
});
const danmakuRef = ref(null)
const danmus = ref([]);
onMounted(async () => {
const { code, data } = await getDanmuAPI();
if (code) {
danmus.value = data;
}
})
</script>
<style lang="less" scoped>
.danmaku-page {
.danmu-boxer {
height:15rem;
width:100vw;
position: absolute;
top:0;
z-index: 10;
padding-top: 1rem;
}
.dm-item {
background-color: rgba(48, 48, 48, 0.50);
padding: 0.25rem 1rem;
border-radius: 14px;
margin-top: 1rem;
font-size: 0.95rem;
}
}
</style>