4949 <Updates />
5050 </ul >
5151 <div class =" menu-body" >
52- <div class =" menu-body-item" v-show =" activeIndex == 0" >
53- <div class =" menu-about" >
52+ <div class =" menu-body-item" v-show =" activeIndex == 0" >
53+ <div v-if =" !dataLoaded" style =" text-align : center ; padding : 20px ;" >
54+ <p >正在加载设置数据...</p >
55+ </div >
56+ <div v-if =" dataLoaded" >
57+ <div class =" menu-about" >
5458 <p >请注意,该设置面板数据全部保存在本地浏览器缓存中,注意备份。</p >
5559
5660 <!-- 添加设置搜索框 -->
179183 <MenuBookmark :sort =" 1 " v-model =" settingData .checked40 " v-show =" matchesSearch (' 收藏功能' )" />
180184 <!-- 是否在右下角显示收藏按钮 -->
181185 <MenuBookmarkBtn :sort =" 2 " v-model =" settingData .checked52 " v-show =" matchesSearch (' 右下角显示收藏按钮' )" />
182- <!-- 是否显示跳转到文件夹按钮 -->
183- <MenuBookmarkFolderBtn :sort =" 3 " v-model =" settingData .checked53 " v-show =" matchesSearch (' 右下角显示收藏按钮' )" />
184- </div >
186+ <!-- 是否显示跳转到文件夹按钮 -->
187+ <MenuBookmarkFolderBtn :sort =" 3 " v-model =" settingData .checked53 " v-show =" matchesSearch (' 右下角显示收藏按钮' )" />
188+ </div >
189+ </div >
185190 <div class =" menu-body-item" v-show =" activeIndex == 1" >
186191 <!-- 自定义论坛 logo -->
187192 <MenuLogoUrl :sort =" 1 " v-model :value =" settingData .logourl " />
234239
235240<script >
236241import $ from " jquery" ;
242+ import settingsManager from " ./utilities/settingsManager.js" ;
237243
238244// 基础设置
239245import packageJson from " ../package.json" ;
@@ -544,6 +550,7 @@ export default {
544550 showviewhistorylist: false ,
545551 settingsSearchQuery: " " , // 添加搜索查询字段
546552 observer: null ,
553+ dataLoaded: false , // 数据加载完成标志
547554
548555 isMenuOpen: false ,
549556 };
@@ -601,12 +608,24 @@ export default {
601608 this .opacity = false ;
602609 },
603610 // 保存设置
604- save () {
605- localStorage .setItem (" linuxdoscriptssettingDMI" , JSON .stringify (this .settingData ));
606-
607- this .messageToast (" 保存成功!" );
608- this .showdialog = false ;
609- this .opacity = false ;
611+ async save () {
612+ try {
613+ const success = await settingsManager .saveSettings (this .settingData );
614+ if (success) {
615+ this .messageToast (" 保存成功!" );
616+ this .showdialog = false ;
617+ this .opacity = false ;
618+ } else {
619+ this .messageToast (" 保存失敗,請檢查控制台獲取詳細信息" );
620+ }
621+ } catch (error) {
622+ console .error (' 保存設置失敗:' , error);
623+ if (error .name === ' DataCloneError' ) {
624+ this .messageToast (" 數據格式錯誤,請檢查設置內容" );
625+ } else {
626+ this .messageToast (" 保存失敗,請重試!" );
627+ }
628+ }
610629 },
611630 // 保存并刷新
612631 saveload () {
@@ -619,12 +638,17 @@ export default {
619638 this .activeIndex = index;
620639 },
621640 // 初始化设置
622- initialization () {
623- localStorage .removeItem (" linuxdoscriptssettingDMI" );
624- this .messageToast (" 初始化设置成功,即将自动刷新!" );
625- setTimeout (() => {
626- location .reload ();
627- }, 1000 );
641+ async initialization () {
642+ try {
643+ await settingsManager .clearSettings ();
644+ this .messageToast (" 初始化设置成功,即将自动刷新!" );
645+ setTimeout (() => {
646+ location .reload ();
647+ }, 1000 );
648+ } catch (error) {
649+ console .error (' 初始化設置失敗:' , error);
650+ this .messageToast (" 初始化失敗,請重試!" );
651+ }
628652 },
629653 // 搜索设置项
630654 matchesSearch (settingName ) {
@@ -665,7 +689,7 @@ export default {
665689 this .observer .disconnect ();
666690 }
667691 },
668- created () {
692+ async created () {
669693 this .initObserver ();
670694 const browserAPI = typeof browser !== " undefined" ? browser : chrome;
671695 $ (" body" ).append (' <div id="messageToast"></div>' );
@@ -675,38 +699,48 @@ export default {
675699 " padding: 2px 1px; color: #fff; background: #42c02e;"
676700 );
677701
678- let linxudoscriptssettingDMI = localStorage . getItem ( " linxudoscriptssettingDMI " ); // 错误写法(旧版本兼容)
679- let linuxdoscriptssettingDMI = localStorage . getItem ( " linuxdoscriptssettingDMI " );
680- if (linxudoscriptssettingDMI && ! linuxdoscriptssettingDMI) {
681- localStorage . setItem ( " linuxdoscriptssettingDMI " , linxudoscriptssettingDMI); // 重新保存为正确的参数名
682- linuxdoscriptssettingDMI = linxudoscriptssettingDMI; // 赋值正确的参数名
683- }
684- if (linuxdoscriptssettingDMI ) {
685- function deepMerge ( target , source ) {
686- for ( const key in source ) {
687- if (source[key] instanceof Object && key in target) {
688- target[key] = deepMerge (target[key], source[key]);
689- } else {
690- target[key] = source[key];
702+
703+ // 使用 IndexedDB 加载设置数据
704+ try {
705+ const existingData = await settingsManager . getSettings ();
706+
707+ if (existingData) {
708+ function deepMerge ( target , source ) {
709+ for ( const key in source) {
710+ if (source[key] instanceof Object && key in target ) {
711+ target[ key] = deepMerge ( target[key], source[key]);
712+ } else {
713+ target[key] = source[key];
714+ }
691715 }
716+ return target;
692717 }
693- return target;
718+
719+ this .settingData = deepMerge (this .settingData , existingData);
720+ await settingsManager .saveSettings (this .settingData );
721+
722+ this .showlookop = this .settingData .checked9 ;
723+ this .showlevelsearch = this .settingData .checked12 ;
724+ this .showreplybtn = this .settingData .checked25 ;
725+ this .showbacktotop = this .settingData .checked34 ;
726+ this .showbacktoonefloor = this .settingData .checked48 ;
727+ this .showbookmarkbtn = this .settingData .checked52 ;
728+ this .showbookmarkfolderbtn = this .settingData .checked53 ;
729+ this .showviewhistorylist = this .settingData .checked56 ;
730+
731+ } else {
732+ // 如果没有现有数据,保存默认设置
733+ await settingsManager .saveSettings (this .settingData );
694734 }
695- let existingData = JSON .parse (localStorage .getItem (" linuxdoscriptssettingDMI" ));
696- this .settingData = deepMerge (this .settingData , existingData);
697- localStorage .setItem (" linuxdoscriptssettingDMI" , JSON .stringify (this .settingData ));
698-
699- this .showlookop = this .settingData .checked9 ;
700- this .showlevelsearch = this .settingData .checked12 ;
701- this .showreplybtn = this .settingData .checked25 ;
702- this .showbacktotop = this .settingData .checked34 ;
703- this .showbacktoonefloor = this .settingData .checked48 ;
704- this .showbookmarkbtn = this .settingData .checked52 ;
705- this .showbookmarkfolderbtn = this .settingData .checked53 ;
706- this .showviewhistorylist = this .settingData .checked56 ;
707735
708- } else {
709- localStorage .setItem (" linuxdoscriptssettingDMI" , JSON .stringify (this .settingData ));
736+ // 数据加载完成,可以渲染组件了
737+ this .dataLoaded = true ;
738+ } catch (error) {
739+ console .error (' 加載設置數據失敗:' , error);
740+ // 如果 IndexedDB 失敗,可以考慮回退到 localStorage 作為備用
741+ this .messageToast (" 加載設置失敗,使用默認設置" );
742+ // 即使加载失败也要显示界面
743+ this .dataLoaded = true ;
710744 }
711745
712746 browserAPI .runtime .onMessage .addListener ((request , sender , sendResponse ) => {
0 commit comments