Просмотр исходного кода

web: 源编辑快捷键保存逻辑

Xwite 3 лет назад
Родитель
Сommit
f491aa4355

+ 35 - 23
modules/web/scripts/sync.js

@@ -1,28 +1,40 @@
 import { URL } from "node:url";
 import fs from "node:fs";
 
-const LEGADO_ASSETS_WEB_VUE_DIR = new URL("../../../app/src/main/assets/web/vue", import.meta.url)
-const VUE_DIST_DIR = new URL("../dist", import.meta.url)
+const LEGADO_ASSETS_WEB_VUE_DIR = new URL(
+  "../../../app/src/main/assets/web/vue",
+  import.meta.url
+);
+const VUE_DIST_DIR = new URL("../dist", import.meta.url);
 
-console.log("> delete", LEGADO_ASSETS_WEB_VUE_DIR.pathname)
+console.log("> delete", LEGADO_ASSETS_WEB_VUE_DIR.pathname);
 // 删除
-fs.rm(LEGADO_ASSETS_WEB_VUE_DIR, {
-  force: true,
-  recursive: true
-}, (error) => {
-  if (error) console.log(error);
-  console.log("> mkdir", LEGADO_ASSETS_WEB_VUE_DIR.pathname);
-  fs.mkdir(LEGADO_ASSETS_WEB_VUE_DIR, error => {
-    if (error) return console.error(error)
-    console.log("> cp dist files")
-    fs.cp(VUE_DIST_DIR, LEGADO_ASSETS_WEB_VUE_DIR, {
-      recursive: true
-    }, (error) => {
-      if (error) {
-        console.warn("> cp error, you may copy files yourshelf");
-        throw error;
-      }
-      console.log("> cp success")
-    })
-  })
-});
+fs.rm(
+  LEGADO_ASSETS_WEB_VUE_DIR,
+  {
+    force: true,
+    recursive: true,
+  },
+  (error) => {
+    if (error) console.log(error);
+    console.log("> mkdir", LEGADO_ASSETS_WEB_VUE_DIR.pathname);
+    fs.mkdir(LEGADO_ASSETS_WEB_VUE_DIR, (error) => {
+      if (error) return console.error(error);
+      console.log("> cp dist files");
+      fs.cp(
+        VUE_DIST_DIR,
+        LEGADO_ASSETS_WEB_VUE_DIR,
+        {
+          recursive: true,
+        },
+        (error) => {
+          if (error) {
+            console.warn("> cp error, you may copy files yourshelf");
+            throw error;
+          }
+          console.log("> cp success");
+        }
+      );
+    });
+  }
+);

+ 30 - 13
modules/web/src/components/ToolBar.vue

@@ -27,7 +27,7 @@
         </div>
         <el-button
           :disabled="recordKeyDowning"
-          @click="bindHotKeys"
+          @click="saveHotKeys"
           :icon="CircleCheckFilled"
           >保存</el-button
         >
@@ -230,7 +230,13 @@ const stopRecordKeyDown = () => {
 watch(
   hotkeysDialogVisible,
   (visibale) => {
-    if (!visibale) return hotkeys.unbind("*");
+    if (!visibale) {
+      hotkeys.unbind("*");
+      readHotkeysConfig();
+      bindHotKeys();
+      return;
+    }
+    readHotkeysConfig();
     hotkeys.unbind();
     /**监听按键 */
     hotkeys("*", (event) => {
@@ -257,39 +263,50 @@ const recordKeyDown = (index) => {
   recordKeyDownIndex.value = index;
 };
 
-const bindHotKeys = () => {
-  hotkeysDialogVisible.value = false;
+const saveHotKeys = () => {
   const hotKeysConfig = [];
+  buttons.value.forEach(({ hotKeys }) => {
+    hotKeysConfig.push(hotKeys);
+  });
+  saveHotkeysConfig(hotKeysConfig);
+  hotkeysDialogVisible.value = false;
+};
+
+const bindHotKeys = () => {
   buttons.value.forEach(({ hotKeys, action }) => {
+    if (hotKeys.length == 0) return;
     hotkeys(hotKeys.join("+"), (event) => {
       event.preventDefault();
       action.call(null);
     });
-    hotKeysConfig.push(hotKeys);
   });
-  saveHotkeysConfig(hotKeysConfig);
 };
-
 const saveHotkeysConfig = (config) => {
   localStorage.setItem("legado_web_hotkeys", JSON.stringify(config));
 };
 
-const readHotkeysConfig = () => {
+/**
+ * 读取快捷键配置
+ * @return 是否成功读取配置
+ */
+function readHotkeysConfig() {
   try {
     const config = JSON.parse(localStorage.getItem("legado_web_hotkeys"));
-    if (!Array.isArray(config) || config.length == 0) return;
+    if (!Array.isArray(config) || config.length == 0) return false;
     buttons.value.forEach((button, index) => (button.hotKeys = config[index]));
-    hotkeysDialogVisible.value = false;
-    bindHotKeys();
+    return true;
   } catch {
     ElMessage({ message: "快捷键配置错误", type: "error" });
     localStorage.removeItem("legado_web_hotkeys");
   }
-};
+  return false;
+}
 
 onMounted(() => {
   /**读取热键配置 */
-  readHotkeysConfig();
+  if (readHotkeysConfig()) {
+    hotkeysDialogVisible.value = false;
+  }
 });
 </script>
 

+ 5 - 5
modules/web/src/config/bookSourceEditConfig.js

@@ -69,13 +69,13 @@ export default {
         title: "并发率",
         id: "concurrentRate",
         type: "String",
-        hint: "并发率",
+        hint: "并发率,如1000(访问间隔1000ms)或者1/1000(1000ms内访问1次)",
       },
       {
         title: "js库",
         id: "jsLib",
         type: "String",
-        hint: "js库",
+        hint: "js库, 可填写js或者key-value object获取在线js文件",
       },
       {
         title: "请求头",
@@ -105,7 +105,7 @@ export default {
         namespace: "ruleSearch",
         id: "checkKeyWord",
         type: "String",
-        hint: "校验关键字",
+        hint: "校验关键字,强烈建议填写",
       },
       {
         title: "列表规则",
@@ -179,7 +179,7 @@ export default {
         title: "发现地址",
         id: "exploreUrl",
         type: "String",
-        hint: "内容能显示在发现菜单\n每行一条发现分类(网址域名可省略),例:\n名称1::网址(Url)1\n名称2::网址(Url)2\n...",
+        hint: "单个发现格式<name>::<url>或者{url:<url>,title:<name>,style:...};前者用换行符或者&&连接,后者放在数组内;可用js动态生成",
       },
       {
         title: "发现筛选",
@@ -370,7 +370,7 @@ export default {
         namespace: "ruleToc",
         id: "formatJs",
         type: "String",
-        hint: "直接填写js, 提供index和tittle变量",
+        hint: "遍历去重后的章节列表的回调,提供index(章节序号从1开始)、title(章节标题)变量,额外提供gInt(初始值0),返回值作为新的标题",
       },
       {
         title: "卷名标识",