Skip to content

Commit 5659853

Browse files
author
Taois
committed
feat:正确备份还源数据/重置数据
1 parent 2f3f9dd commit 5659853

File tree

6 files changed

+130
-3
lines changed

6 files changed

+130
-3
lines changed

dashboard/src/api/services/site.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ class SiteService {
403403
const sites = await configService.getSites(forceRefresh)
404404

405405
if (sites && sites.length > 0) {
406+
// 保存当前站点信息用于智能切换
407+
const previousCurrentSite = this.currentSite
408+
406409
// 清空现有站点(保留本地添加的站点)
407410
const localSites = Array.from(this.sites.values()).filter(site => site.isLocal)
408411
this.sites.clear()
@@ -419,6 +422,9 @@ class SiteService {
419422
this.sites.set(siteInfo.key, siteInfo)
420423
})
421424

425+
// 智能源切换逻辑
426+
this.handleSmartSiteSwitch(previousCurrentSite)
427+
422428
this.saveSitesToStorage()
423429
console.log(`从配置加载了 ${sites.length} 个站点`)
424430

@@ -496,6 +502,70 @@ class SiteService {
496502
}))
497503
}
498504
}
505+
506+
/**
507+
* 智能站点切换处理
508+
* @param {object} previousCurrentSite - 之前的当前站点
509+
*/
510+
handleSmartSiteSwitch(previousCurrentSite) {
511+
let needReload = false
512+
513+
if (previousCurrentSite && previousCurrentSite.key) {
514+
// 检查之前的当前站点是否还在新的站点列表中
515+
const siteStillExists = this.sites.has(previousCurrentSite.key)
516+
517+
if (siteStillExists) {
518+
// 如果站点仍然存在,保持当前选择
519+
this.currentSite = this.sites.get(previousCurrentSite.key)
520+
console.log('保持当前源:', this.currentSite.name)
521+
} else {
522+
// 如果站点不存在,切换到第一个可用站点
523+
const availableSites = this.getAllSites()
524+
if (availableSites.length > 0) {
525+
// 优先选择type为4的站点,如果没有则选择第一个
526+
const firstSite = availableSites.find(site => site.type === 4) || availableSites[0]
527+
this.currentSite = firstSite
528+
needReload = true
529+
console.log('自动切换到新源:', this.currentSite.name)
530+
531+
// 触发站点切换事件
532+
this.emitSiteChange(this.currentSite)
533+
}
534+
}
535+
} else {
536+
// 如果之前没有当前站点,设置第一个可用站点
537+
const availableSites = this.getAllSites()
538+
if (availableSites.length > 0) {
539+
const firstSite = availableSites.find(site => site.type === 4) || availableSites[0]
540+
this.currentSite = firstSite
541+
needReload = true
542+
console.log('设置默认源:', this.currentSite.name)
543+
544+
// 触发站点切换事件
545+
this.emitSiteChange(this.currentSite)
546+
}
547+
}
548+
549+
// 如果需要重载,触发重载源事件
550+
if (needReload) {
551+
this.emitReloadSource()
552+
}
553+
}
554+
555+
/**
556+
* 触发重载源事件
557+
*/
558+
emitReloadSource() {
559+
if (typeof window !== 'undefined') {
560+
window.dispatchEvent(new CustomEvent('reloadSource', {
561+
detail: {
562+
site: this.currentSite,
563+
timestamp: Date.now()
564+
}
565+
}))
566+
console.log('触发重载源事件')
567+
}
568+
}
499569
}
500570

501571
// 创建单例实例

dashboard/src/services/backupService.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { Message } from '@arco-design/web-vue'
7+
import siteService from '@/api/services/site'
78

89
// 备份数据版本号,用于兼容性检查
910
const BACKUP_VERSION = '1.0.0'
@@ -344,15 +345,44 @@ export const restoreBackupData = (backupData) => {
344345
currentSite: BACKUP_KEYS.CURRENT_SITE
345346
}
346347

348+
let restoredCurrentSite = null
349+
347350
for (const [key, value] of Object.entries(backupData.siteData)) {
348351
const storageKey = siteDataMapping[key]
349352
if (storageKey && setLocalStorageData(storageKey, value)) {
350353
restoredCount++
354+
355+
// 记录还原的当前站点信息
356+
if (key === 'currentSite' && value) {
357+
restoredCurrentSite = value
358+
}
351359
} else {
352360
failedCount++
353361
errors.push(`站点数据 ${key}`)
354362
}
355363
}
364+
365+
// 如果还原了当前站点,需要同步到siteService
366+
if (restoredCurrentSite) {
367+
try {
368+
// 解析当前站点数据(可能是字符串或对象)
369+
const currentSiteData = typeof restoredCurrentSite === 'string'
370+
? JSON.parse(restoredCurrentSite)
371+
: restoredCurrentSite
372+
373+
if (currentSiteData && currentSiteData.key) {
374+
// 同步到siteService(如果站点存在)
375+
const success = siteService.setCurrentSite(currentSiteData.key)
376+
if (success) {
377+
console.log('已同步还原的当前站点到siteService:', currentSiteData.name)
378+
} else {
379+
console.warn('还原的当前站点在站点列表中不存在,可能需要重新配置:', currentSiteData.key)
380+
}
381+
}
382+
} catch (error) {
383+
console.error('同步还原的当前站点到siteService失败:', error)
384+
}
385+
}
356386
}
357387

358388
// 显示还原结果

dashboard/src/services/resetService.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ const CLEAR_DATA_KEYS = [
6868
'drplayer_config_url', // 配置地址
6969
'drplayer_live_config_url', // 直播配置地址
7070
'drplayer_current_site', // 当前站点
71+
'drplayer_sites', // 站点列表数据
72+
'site-nowSite', // 当前站点(兼容旧系统)
73+
74+
// 配置数据
75+
'drplayer_config_data', // 配置数据缓存
76+
'drplayer_config_fetch_time', // 配置获取时间
77+
78+
// 播放器相关
79+
'drplayer_preferred_player_type', // 首选播放器类型
80+
'selectedParser', // 选中的解析器
81+
'last-clicked-video', // 最后点击的视频
82+
83+
// 界面状态
84+
'sidebar-collapsed', // 侧边栏折叠状态
7185

7286
// 地址配置历史
7387
'drplayer_vod_config_history',

dashboard/src/views/Parser.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@
249249
</a-form-item>
250250

251251
<a-form-item label="解析地址" required>
252-
<a-input v-model="parserForm.url" placeholder="请输入解析地址,使用{url}作为视频地址占位符" />
252+
<a-input v-model="parserForm.url" placeholder="请输入解析地址,视频地址会直接与解析地址相加" />
253253
<template #extra>
254254
<div class="form-help">
255-
示例: https://jx.example.com/api?url={url}
255+
示例: https://jx.example.com/api?url=
256256
</div>
257257
</template>
258258
</a-form-item>

dashboard/src/views/Settings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ const handleProxyPlayEnabledChange = (enabled) => {
13111311
13121312
// 下载代理播放器
13131313
const downloadProxyPlayer = () => {
1314-
const url = 'https://wwvy.lanzouo.com/i527V37opr4b'
1314+
const url = 'https://wwvy.lanzouo.com/iPNGu37snuna'
13151315
window.open(url, '_blank')
13161316
Message.success('正在打开代理播放器下载页面')
13171317
}

dashboard/src/views/Video.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ const refreshPage = () => {
276276
window.location.reload();
277277
};
278278
279+
// 处理重载源事件
280+
const handleReloadSource = (event) => {
281+
console.log('收到重载源事件:', event.detail);
282+
// 执行重载源功能(相当于点击重载源按钮)
283+
refreshPage();
284+
};
285+
279286
const minimize = () => {};
280287
const maximize = () => {};
281288
const closeWindow = () => {};
@@ -803,6 +810,9 @@ onMounted(async () => {
803810
getData(); // 页面加载时获取数据
804811
getNowSite(); // 获取储存的当前源
805812
813+
// 监听重载源事件
814+
window.addEventListener('reloadSource', handleReloadSource);
815+
806816
// 检查是否需要恢复搜索状态
807817
const restoreSearch = route.query._restoreSearch;
808818
const returnToActiveKey = route.query._returnToActiveKey;
@@ -950,6 +960,9 @@ onBeforeUnmount(() => {
950960
clearInterval(timer.value); // 销毁时清除定时器
951961
}
952962
963+
// 移除重载源事件监听器
964+
window.removeEventListener('reloadSource', handleReloadSource);
965+
953966
// 保存当前页面状态
954967
if (currentActiveKey.value && videoListRef.value) {
955968
const currentState = videoListRef.value.getCurrentState();

0 commit comments

Comments
 (0)