Skip to content

Commit fb33bc6

Browse files
author
Taois
committed
fix:修复历史记录选择。新增代理播放配置
1 parent a630901 commit fb33bc6

File tree

6 files changed

+565
-49
lines changed

6 files changed

+565
-49
lines changed

dashboard/src/components/AddressHistory.vue

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
<div class="address-history-content">
1010
<div class="history-header">
1111
<span class="history-title">历史配置</span>
12-
<span class="history-count">{{ histories.length }}/10</span>
12+
<span class="history-count">{{ filteredHistories.length }}/10</span>
1313
</div>
1414

15-
<div v-if="histories.length === 0" class="empty-state">
15+
<div v-if="filteredHistories.length === 0" class="empty-state">
1616
<icon-history class="empty-icon" />
17-
<span class="empty-text">暂无历史配置</span>
17+
<span class="empty-text">{{ histories.length === 0 ? '暂无历史配置' : '无其他历史配置' }}</span>
1818
</div>
1919

2020
<div v-else class="history-list">
2121
<div
22-
v-for="(item, index) in histories"
22+
v-for="(item, index) in filteredHistories"
2323
:key="index"
2424
class="history-item"
2525
@click="selectHistory(item)"
@@ -66,7 +66,7 @@
6666
</template>
6767

6868
<script setup>
69-
import { ref, computed, watch } from 'vue'
69+
import { ref, computed, watch, nextTick } from 'vue'
7070
import { Message } from '@arco-design/web-vue'
7171
import {
7272
IconHistory,
@@ -92,6 +92,23 @@ const histories = ref([])
9292
// 获取存储键名
9393
const storageKey = computed(() => `address-history-${props.configKey}`)
9494
95+
96+
97+
// 过滤后的历史记录(隐藏与当前输入框相同的地址)
98+
const filteredHistories = computed(() => {
99+
if (!props.currentValue || !props.currentValue.trim()) {
100+
return histories.value
101+
}
102+
103+
const currentUrl = props.currentValue.trim().toLowerCase()
104+
const filtered = histories.value.filter(item => {
105+
const historyUrl = (item.url || '').trim().toLowerCase()
106+
return historyUrl !== currentUrl
107+
})
108+
109+
return filtered
110+
})
111+
95112
// 加载历史记录
96113
const loadHistories = () => {
97114
try {
@@ -123,24 +140,24 @@ const addHistory = (url) => {
123140
// 检查是否已存在
124141
const existingIndex = histories.value.findIndex(item => item.url === trimmedUrl)
125142
if (existingIndex !== -1) {
126-
// 如果已存在,移到最前面并更新时间
127-
const existing = histories.value.splice(existingIndex, 1)[0]
128-
existing.timestamp = Date.now()
129-
histories.value.unshift(existing)
130-
} else {
131-
// 添加新记录
132-
histories.value.unshift({
133-
url: trimmedUrl,
134-
timestamp: Date.now()
135-
})
143+
// 如果已存在,不做任何操作,避免重复添加
144+
console.log('地址已存在于历史记录中,跳过添加:', trimmedUrl)
145+
return
136146
}
137147
148+
// 只在不存在时添加新记录
149+
histories.value.unshift({
150+
url: trimmedUrl,
151+
timestamp: Date.now()
152+
})
153+
138154
// 保持最多10条记录
139155
if (histories.value.length > 10) {
140156
histories.value = histories.value.slice(0, 10)
141157
}
142158
143159
saveHistories()
160+
console.log('已添加新地址到历史记录:', trimmedUrl)
144161
}
145162
146163
// 选择历史记录
@@ -152,9 +169,20 @@ const selectHistory = (item) => {
152169
153170
// 删除单个历史记录
154171
const deleteHistory = (index) => {
155-
histories.value.splice(index, 1)
156-
saveHistories()
157-
Message.success('已删除历史记录')
172+
// 从过滤后的列表中获取要删除的项
173+
const itemToDelete = filteredHistories.value[index]
174+
if (!itemToDelete) return
175+
176+
// 在原始列表中找到对应的索引并删除
177+
const originalIndex = histories.value.findIndex(item =>
178+
item.url === itemToDelete.url && item.timestamp === itemToDelete.timestamp
179+
)
180+
181+
if (originalIndex !== -1) {
182+
histories.value.splice(originalIndex, 1)
183+
saveHistories()
184+
Message.success('已删除历史记录')
185+
}
158186
}
159187
160188
// 清空所有历史记录
@@ -184,12 +212,7 @@ const formatTime = (timestamp) => {
184212
}
185213
}
186214
187-
// 监听当前值变化,自动保存到历史记录
188-
watch(() => props.currentValue, (newValue, oldValue) => {
189-
if (oldValue && oldValue.trim() && newValue !== oldValue) {
190-
addHistory(oldValue)
191-
}
192-
}, { flush: 'post' })
215+
// 注释:移除自动保存逻辑,改为只在点击保存按钮时手动调用 addHistory
193216
194217
// 暴露添加历史记录的方法
195218
defineExpose({

dashboard/src/components/players/ArtVideoPlayer.vue

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@player-change="handlePlayerTypeChange"
1414
@open-skip-settings="openSkipSettingsDialog"
1515
@toggle-debug="toggleDebugDialog"
16+
@proxy-change="handleProxyChange"
1617
@close="closePlayer"
1718
/>
1819
<div class="art-player-wrapper" v-show="props.visible">
@@ -81,6 +82,7 @@ import SkipSettingsDialog from './SkipSettingsDialog.vue'
8182
import DebugInfoDialog from './DebugInfoDialog.vue'
8283
import { useSkipSettings } from '@/composables/useSkipSettings'
8384
import { applyCSPBypass, setVideoReferrerPolicy, REFERRER_POLICIES, getCSPConfig } from '@/utils/csp'
85+
import { processVideoUrl, isProxyPlayEnabled } from '@/utils/proxyPlayer'
8486
8587
// Props - 已添加 HLS 支持、动态高度自适应和自动下一集功能
8688
const props = defineProps({
@@ -279,11 +281,24 @@ const initArtPlayer = async (url) => {
279281
280282
// 如果播放器实例已存在,使用 switchUrl 方法切换视频源
281283
if (artPlayerInstance.value) {
282-
console.log('使用 switchUrl 方法切换视频源:', url)
284+
// 准备自定义请求头
285+
const cspConfig = getCSPConfig()
286+
const headers = {
287+
...(props.headers || {}),
288+
...(cspConfig.autoBypass ? {} : {})
289+
}
290+
291+
// 处理代理播放地址
292+
const finalUrl = processVideoUrl(url, headers)
293+
if (finalUrl !== url) {
294+
console.log('🔄 [代理播放] switchUrl使用代理地址')
295+
}
296+
297+
console.log('使用 switchUrl 方法切换视频源:', finalUrl)
283298
284299
try {
285300
// 使用 switchUrl 方法切换视频源,这样可以保持全屏状态和其他用户设置
286-
await artPlayerInstance.value.switchUrl(url)
301+
await artPlayerInstance.value.switchUrl(finalUrl)
287302
console.log('视频源切换成功')
288303
289304
// 重置片头片尾跳过状态
@@ -308,15 +323,28 @@ const initArtPlayer = async (url) => {
308323
}
309324
310325
try {
326+
// 准备自定义请求头
327+
const cspConfig = getCSPConfig()
328+
const headers = {
329+
...(props.headers || {}),
330+
...(cspConfig.autoBypass ? {} : {})
331+
}
332+
333+
// 处理代理播放地址
334+
const finalUrl = processVideoUrl(url, headers)
335+
if (finalUrl !== url) {
336+
console.log('🔄 [代理播放] 使用代理地址播放视频')
337+
}
338+
311339
// 检测视频格式
312-
const videoFormat = detectVideoFormat(url)
340+
const videoFormat = detectVideoFormat(finalUrl)
313341
detectedFormat.value = videoFormat
314342
console.log('检测到视频格式:', videoFormat)
315343
316344
// 创建 ArtPlayer 实例
317345
const art = new Artplayer({
318346
container: artPlayerContainer.value,
319-
url: url,
347+
url: finalUrl,
320348
poster: props.poster,
321349
volume: 0.7,
322350
isLive: false,
@@ -588,6 +616,41 @@ const handlePlayerTypeChange = (newType) => {
588616
emit('player-change', newType)
589617
}
590618
619+
// 处理代理播放地址变更
620+
const handleProxyChange = (proxyUrl) => {
621+
console.log('代理播放地址变更:', proxyUrl)
622+
623+
try {
624+
// 获取当前的addressSettings
625+
const savedAddresses = JSON.parse(localStorage.getItem('addressSettings') || '{}')
626+
627+
if (proxyUrl === 'disabled') {
628+
// 关闭代理播放
629+
savedAddresses.proxyPlayEnabled = false
630+
savedAddresses.proxyPlay = ''
631+
} else {
632+
// 启用代理播放并设置地址
633+
savedAddresses.proxyPlayEnabled = true
634+
savedAddresses.proxyPlay = proxyUrl
635+
}
636+
637+
// 保存到localStorage
638+
localStorage.setItem('addressSettings', JSON.stringify(savedAddresses))
639+
640+
// 触发自定义事件,通知其他组件设置已变化
641+
window.dispatchEvent(new CustomEvent('addressSettingsChanged'))
642+
643+
// 重新加载视频以应用新的代理设置
644+
if (props.videoUrl) {
645+
nextTick(() => {
646+
initArtPlayer(props.videoUrl)
647+
})
648+
}
649+
} catch (error) {
650+
console.error('保存代理播放设置失败:', error)
651+
}
652+
}
653+
591654
// 打开片头片尾设置弹窗
592655
const openSkipSettingsDialog = () => {
593656
showSkipSettingsDialog.value = true

0 commit comments

Comments
 (0)