From cc40be92dd08345910ca7d85d1fa73cc41be01e8 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sat, 20 May 2023 17:12:11 +0800 Subject: [PATCH] =?UTF-8?q?web:=20=E6=BA=90=E7=BC=96=E8=BE=91=E5=BF=AB?= =?UTF-8?q?=E6=8D=B7=E9=94=AE=E4=BF=9D=E5=AD=98=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/web/scripts/sync.js | 58 +++++++++++-------- modules/web/src/components/ToolBar.vue | 43 +++++++++----- .../web/src/config/bookSourceEditConfig.js | 10 ++-- 3 files changed, 70 insertions(+), 41 deletions(-) diff --git a/modules/web/scripts/sync.js b/modules/web/scripts/sync.js index fb61acf81..ef9eb9039 100644 --- a/modules/web/scripts/sync.js +++ b/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") - }) - }) -}); \ No newline at end of file +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"); + } + ); + }); + } +); diff --git a/modules/web/src/components/ToolBar.vue b/modules/web/src/components/ToolBar.vue index 5a742b9b4..cb11c8a97 100644 --- a/modules/web/src/components/ToolBar.vue +++ b/modules/web/src/components/ToolBar.vue @@ -27,7 +27,7 @@ 保存 @@ -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; + } }); diff --git a/modules/web/src/config/bookSourceEditConfig.js b/modules/web/src/config/bookSourceEditConfig.js index 08cfed671..0b95e18f8 100644 --- a/modules/web/src/config/bookSourceEditConfig.js +++ b/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: "单个发现格式::或者{url:,title:,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: "卷名标识",