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+ }
0 commit comments