Explorar o código

chore(web): sync readconfig only when readSetting unvisible

Xwite %!s(int64=2) %!d(string=hai) anos
pai
achega
bbc944c95f
Modificáronse 1 ficheiros con 10 adicións e 1 borrados
  1. 10 1
      modules/web/src/components/ReadSettings.vue

+ 10 - 1
modules/web/src/components/ReadSettings.vue

@@ -192,16 +192,25 @@ import API from "@api";
 const store = useBookStore();
 const store = useBookStore();
 
 
 //阅读界面设置改变时保存同步配置
 //阅读界面设置改变时保存同步配置
+let configChanged = false;
 watch(
 watch(
   () => store.config,
   () => store.config,
   (newValue) => {
   (newValue) => {
     localStorage.setItem("config", JSON.stringify(newValue));
     localStorage.setItem("config", JSON.stringify(newValue));
-    API.saveReadConfig(newValue);
+    configChanged = true;
   },
   },
   {
   {
     deep: 2, //深度为2
     deep: 2, //深度为2
   },
   },
 );
 );
+// 设置页面关闭时同步设置到阅读APP
+watch(
+  () => store.readSettingsVisible,
+  (visbile) => {
+    if (!visbile && configChanged)
+      API.saveReadConfig(store.config).then(() => (configChanged = false));
+  },
+);
 
 
 //主题颜色
 //主题颜色
 const theme = computed(() => store.theme);
 const theme = computed(() => store.theme);