Skip to content

Commit db71294

Browse files
author
Taois
committed
feat: 关闭弹幕
1 parent f50db5b commit db71294

3 files changed

Lines changed: 42 additions & 15 deletions

File tree

dashboard/src/components/players/ArtVideoPlayer.vue

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const currentPlayingUrl = ref('')
206206
const proxySettingsVersion = ref(0)
207207
208208
// 弹幕相关状态
209-
const danmakuEnabled = ref(JSON.parse(localStorage.getItem('danmakuEnabled') || 'true'))
209+
const danmakuEnabled = ref(JSON.parse(localStorage.getItem('danmakuEnabled') || 'false'))
210210
const danmakuData = ref([])
211211
const danmakuLoading = ref(false)
212212
const currentDanmakuUrl = ref('') // 当前弹幕iframe的URL
@@ -952,7 +952,7 @@ const initArtPlayer = async (url) => {
952952
}
953953
],
954954
// 插件配置
955-
plugins: [
955+
plugins: danmakuEnabled.value ? [
956956
artplayerPluginDanmuku({
957957
// 使用函数返回以支持后续异步替换
958958
danmuku: () => danmakuData.value,
@@ -964,7 +964,7 @@ const initArtPlayer = async (url) => {
964964
filter: (danmu) => (danmu?.text || '').trim().length > 0 && (danmu?.text || '').length <= 80,
965965
visible: danmakuEnabled.value,
966966
})
967-
]
967+
] : []
968968
})
969969
970970
// 事件监听
@@ -1095,19 +1095,19 @@ const initArtPlayer = async (url) => {
10951095
})
10961096
10971097
// 监听弹幕插件的显示/隐藏事件,实现与 danmakuEnabled 的双向同步
1098-
art.on('artplayerPluginDanmuku:hide', () => {
1099-
console.log('弹幕已隐藏,更新 danmakuEnabled 状态')
1100-
danmakuEnabled.value = false
1101-
// 持久化到 localStorage
1102-
localStorage.setItem('danmakuEnabled', 'false')
1103-
})
1098+
if (danmakuEnabled.value) {
1099+
art.on('artplayerPluginDanmuku:hide', () => {
1100+
console.log('弹幕已隐藏,更新 danmakuEnabled 状态')
1101+
danmakuEnabled.value = false
1102+
localStorage.setItem('danmakuEnabled', 'false')
1103+
})
11041104
1105-
art.on('artplayerPluginDanmuku:show', () => {
1106-
console.log('弹幕已显示,更新 danmakuEnabled 状态')
1107-
danmakuEnabled.value = true
1108-
// 持久化到 localStorage
1109-
localStorage.setItem('danmakuEnabled', 'true')
1110-
})
1105+
art.on('artplayerPluginDanmuku:show', () => {
1106+
console.log('弹幕已显示,更新 danmakuEnabled 状态')
1107+
danmakuEnabled.value = true
1108+
localStorage.setItem('danmakuEnabled', 'true')
1109+
})
1110+
}
11111111
11121112
art.on('destroy', () => {
11131113
console.log('ArtPlayer 已销毁')

dashboard/src/config/defaults.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,8 @@ export const initDefaultLocalStorage = () => {
101101
if (!localStorage.getItem('loopEnabled')) {
102102
localStorage.setItem('loopEnabled', JSON.stringify(getEnvBoolean('VITE_DEFAULT_LOOP_ENABLED', false)))
103103
}
104+
105+
if (!localStorage.getItem('danmakuEnabled')) {
106+
localStorage.setItem('danmakuEnabled', JSON.stringify(getEnvBoolean('VITE_DEFAULT_DANMAKU_ENABLED', false)))
107+
}
104108
}

dashboard/src/views/Settings.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,19 @@
597597
</div>
598598
</div>
599599

600+
<div class="setting-item" @click="handleSettingClick('danmaku')">
601+
<div class="setting-info">
602+
<icon-live-broadcast class="setting-icon"/>
603+
<div class="setting-text">
604+
<div class="setting-title">弹幕组件</div>
605+
<div class="setting-desc">启用播放器弹幕功能</div>
606+
</div>
607+
</div>
608+
<div class="setting-value">
609+
<a-switch v-model="danmakuEnabled"/>
610+
</div>
611+
</div>
612+
600613
<div class="setting-item" @click="handleSettingClick('ad-filter')">
601614
<div class="setting-info">
602615
<icon-safe class="setting-icon"/>
@@ -1051,6 +1064,9 @@ const playerTypes = [
10511064
// 设置项状态
10521065
const settings = reactive(getDefaultAppSettings())
10531066
1067+
// 弹幕组件开关(独立 localStorage key)
1068+
const danmakuEnabled = ref(JSON.parse(localStorage.getItem('danmakuEnabled') || 'false'))
1069+
10541070
// 开发者调试设置
10551071
const debugSettings = reactive({
10561072
enabled: false, // 是否启用调试功能
@@ -1521,6 +1537,8 @@ const handleSettingClick = (settingKey) => {
15211537
case 'player-type':
15221538
playerSelectVisible.value = true
15231539
break
1540+
case 'danmaku':
1541+
break
15241542
case 'window-preview':
15251543
Message.info('窗口预览设置')
15261544
break
@@ -1656,6 +1674,11 @@ watch(() => settings.themeMode, (mode) => {
16561674
// 监听设置项变化并自动保存
16571675
watch(settings, saveSettings, {deep: true})
16581676
1677+
// 监听弹幕开关变化
1678+
watch(danmakuEnabled, (val) => {
1679+
localStorage.setItem('danmakuEnabled', JSON.stringify(val))
1680+
})
1681+
16591682
// 保存开发者调试设置
16601683
const saveDebugSettings = () => {
16611684
try {

0 commit comments

Comments
 (0)