Skip to content

Commit edd05c2

Browse files
author
Taois
committed
feat:重置功能
1 parent 95b2f71 commit edd05c2

File tree

2 files changed

+188
-43
lines changed

2 files changed

+188
-43
lines changed
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/**
2+
* 重置服务
3+
* 负责应用的出厂重置功能
4+
*/
5+
6+
import { Message, Modal } from '@arco-design/web-vue'
7+
import { saveCSPConfig, setGlobalReferrerPolicy } from '@/utils/csp'
8+
9+
// 默认配置值
10+
const DEFAULT_CONFIGS = {
11+
// 地址设置默认值
12+
addressSettings: {
13+
vodConfig: '',
14+
liveConfig: '',
15+
proxyAccess: '',
16+
proxyAccessEnabled: false,
17+
proxyPlay: 'http://localhost:57572/proxy?form=base64&url=${url}&headers=${headers}&type=${type}#嗷呜',
18+
proxyPlayEnabled: false,
19+
proxySniff: 'http://localhost:57573/sniffer',
20+
proxySniffEnabled: false,
21+
snifferTimeout: 10
22+
},
23+
24+
// 应用设置默认值
25+
appSettings: {
26+
datasourceDisplay: true,
27+
windowPreview: true,
28+
playerType: 'ijk',
29+
adFilter: true,
30+
ijkCache: false,
31+
autoLive: false,
32+
secureDns: false,
33+
cspBypass: true,
34+
referrerPolicy: 'no-referrer'
35+
},
36+
37+
// CSP配置默认值
38+
cspConfig: {
39+
enabled: true,
40+
referrerPolicy: 'no-referrer'
41+
},
42+
43+
// 跳过设置默认值
44+
skipSettings: {},
45+
46+
// 解析器配置默认值
47+
parserConfig: {},
48+
49+
// 页面状态默认值
50+
pageState: {},
51+
52+
// 侧边栏状态默认值
53+
sidebarCollapsed: false
54+
}
55+
56+
// 需要完全清空的数据键
57+
const CLEAR_DATA_KEYS = [
58+
// 用户数据
59+
'drplayer-favorites', // 收藏列表
60+
'drplayer_watch_history', // 观看历史
61+
'drplayer_histories', // 历史页面数据
62+
'drplayer_daily_stats', // 每日统计
63+
'drplayer_weekly_stats', // 周统计
64+
'drplayer_parsers', // 解析器数据
65+
66+
// 站点数据
67+
'siteStore', // 站点存储
68+
'drplayer_config_url', // 配置地址
69+
'drplayer_live_config_url', // 直播配置地址
70+
'drplayer_current_site', // 当前站点
71+
72+
// 地址配置历史
73+
'drplayer_vod_config_history',
74+
'drplayer_live_config_history',
75+
'drplayer_proxy_access_history',
76+
'drplayer_proxy_play_history',
77+
'drplayer_proxy_sniff_history'
78+
]
79+
80+
/**
81+
* 显示重置确认对话框
82+
*/
83+
export const showResetConfirmation = () => {
84+
return new Promise((resolve) => {
85+
Modal.confirm({
86+
title: '确认重置',
87+
content: `此操作将执行完整的出厂重置,包括:
88+
89+
• 重置所有配置接口地址为默认值
90+
• 清空收藏列表
91+
• 清空观看历史记录
92+
• 清空解析器数据
93+
• 清空站点数据
94+
• 重置所有应用设置
95+
96+
⚠️ 此操作不可撤销,请确认是否继续?`,
97+
width: 480,
98+
closable: true,
99+
okText: '确认重置',
100+
cancelText: '取消',
101+
okButtonProps: {
102+
status: 'danger'
103+
},
104+
onOk: () => {
105+
resolve(true)
106+
},
107+
onCancel: () => {
108+
resolve(false)
109+
}
110+
})
111+
})
112+
}
113+
114+
/**
115+
* 执行完整的出厂重置
116+
*/
117+
export const performFactoryReset = async () => {
118+
try {
119+
// 1. 清空需要删除的数据
120+
CLEAR_DATA_KEYS.forEach(key => {
121+
localStorage.removeItem(key)
122+
})
123+
124+
// 2. 重置配置为默认值
125+
Object.entries(DEFAULT_CONFIGS).forEach(([key, defaultValue]) => {
126+
if (defaultValue !== null && defaultValue !== undefined) {
127+
localStorage.setItem(key, JSON.stringify(defaultValue))
128+
}
129+
})
130+
131+
// 3. 重置CSP配置
132+
try {
133+
saveCSPConfig(DEFAULT_CONFIGS.cspConfig)
134+
setGlobalReferrerPolicy('no-referrer')
135+
} catch (error) {
136+
console.warn('CSP配置重置失败:', error)
137+
}
138+
139+
// 4. 显示成功消息
140+
Message.success({
141+
content: '出厂重置完成!应用已恢复到初始状态',
142+
duration: 3000
143+
})
144+
145+
// 5. 建议用户刷新页面
146+
setTimeout(() => {
147+
Modal.info({
148+
title: '重置完成',
149+
content: '为确保所有更改生效,建议刷新页面。是否立即刷新?',
150+
okText: '立即刷新',
151+
cancelText: '稍后刷新',
152+
onOk: () => {
153+
window.location.reload()
154+
}
155+
})
156+
}, 1000)
157+
158+
return true
159+
} catch (error) {
160+
console.error('出厂重置失败:', error)
161+
Message.error({
162+
content: '出厂重置失败,请重试',
163+
duration: 3000
164+
})
165+
return false
166+
}
167+
}
168+
169+
/**
170+
* 带确认的出厂重置函数
171+
*/
172+
export const factoryResetWithConfirmation = async () => {
173+
const confirmed = await showResetConfirmation()
174+
if (confirmed) {
175+
return await performFactoryReset()
176+
}
177+
return false
178+
}
179+
180+
export default {
181+
showResetConfirmation,
182+
performFactoryReset,
183+
factoryResetWithConfirmation
184+
}

dashboard/src/views/Settings.vue

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ import PlayerSelector from '@/components/PlayerSelector.vue'
861861
import BackupRestoreDialog from '@/components/BackupRestoreDialog.vue'
862862
import configService from '@/api/services/config'
863863
import siteService from '@/api/services/site'
864+
import { factoryResetWithConfirmation } from '@/services/resetService'
864865
import {
865866
getCSPConfig,
866867
saveCSPConfig,
@@ -1370,49 +1371,9 @@ const handlePlayerSelect = (playerType) => {
13701371
Message.success(`已切换到 ${getCurrentPlayerName()}`)
13711372
}
13721373
1373-
// 重置所有设置到默认状态
1374-
const resetAllSettings = () => {
1375-
// 重置地址设置
1376-
Object.assign(addressSettings, {
1377-
vodConfig: '',
1378-
liveConfig: '',
1379-
proxyAccess: '',
1380-
proxyAccessEnabled: false,
1381-
proxyPlay: 'http://localhost:57572/proxy?form=base64&url=${url}&headers=${headers}&type=${type}#嗷呜',
1382-
proxyPlayEnabled: false,
1383-
proxySniff: 'http://localhost:57573/sniffer',
1384-
proxySniffEnabled: false
1385-
})
1386-
1387-
// 重置其他设置
1388-
Object.assign(settings, {
1389-
datasourceDisplay: true,
1390-
windowPreview: true,
1391-
playerType: 'ijk',
1392-
adFilter: true,
1393-
ijkCache: false,
1394-
autoLive: false,
1395-
secureDns: false,
1396-
cspBypass: true,
1397-
referrerPolicy: 'no-referrer'
1398-
})
1399-
1400-
// 清除本地存储
1401-
localStorage.removeItem('addressSettings')
1402-
localStorage.removeItem('appSettings')
1403-
1404-
// 重置CSP配置
1405-
try {
1406-
saveCSPConfig({
1407-
enabled: true,
1408-
referrerPolicy: 'no-referrer'
1409-
})
1410-
setGlobalReferrerPolicy('no-referrer')
1411-
} catch (error) {
1412-
console.error('Failed to reset CSP config:', error)
1413-
}
1414-
1415-
Message.success('所有设置已重置为默认状态')
1374+
// 执行出厂重置
1375+
const resetAllSettings = async () => {
1376+
await factoryResetWithConfirmation()
14161377
}
14171378
14181379
// 处理设置项点击

0 commit comments

Comments
 (0)