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

This commit is contained in:
Xwite
2023-05-20 17:12:11 +08:00
parent 56d1a20a07
commit cc40be92dd
3 changed files with 70 additions and 41 deletions
+28 -16
View File
@@ -1,28 +1,40 @@
import { URL } from "node:url"; import { URL } from "node:url";
import fs from "node:fs"; import fs from "node:fs";
const LEGADO_ASSETS_WEB_VUE_DIR = new URL("../../../app/src/main/assets/web/vue", import.meta.url) const LEGADO_ASSETS_WEB_VUE_DIR = new URL(
const VUE_DIST_DIR = new URL("../dist", import.meta.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, { fs.rm(
LEGADO_ASSETS_WEB_VUE_DIR,
{
force: true, force: true,
recursive: true recursive: true,
}, (error) => { },
(error) => {
if (error) console.log(error); if (error) console.log(error);
console.log("> mkdir", LEGADO_ASSETS_WEB_VUE_DIR.pathname); console.log("> mkdir", LEGADO_ASSETS_WEB_VUE_DIR.pathname);
fs.mkdir(LEGADO_ASSETS_WEB_VUE_DIR, error => { fs.mkdir(LEGADO_ASSETS_WEB_VUE_DIR, (error) => {
if (error) return console.error(error) if (error) return console.error(error);
console.log("> cp dist files") console.log("> cp dist files");
fs.cp(VUE_DIST_DIR, LEGADO_ASSETS_WEB_VUE_DIR, { fs.cp(
recursive: true VUE_DIST_DIR,
}, (error) => { LEGADO_ASSETS_WEB_VUE_DIR,
{
recursive: true,
},
(error) => {
if (error) { if (error) {
console.warn("> cp error, you may copy files yourshelf"); console.warn("> cp error, you may copy files yourshelf");
throw error; throw error;
} }
console.log("> cp success") console.log("> cp success");
}) }
}) );
}); });
}
);
+30 -13
View File
@@ -27,7 +27,7 @@
</div> </div>
<el-button <el-button
:disabled="recordKeyDowning" :disabled="recordKeyDowning"
@click="bindHotKeys" @click="saveHotKeys"
:icon="CircleCheckFilled" :icon="CircleCheckFilled"
>保存</el-button >保存</el-button
> >
@@ -230,7 +230,13 @@ const stopRecordKeyDown = () => {
watch( watch(
hotkeysDialogVisible, hotkeysDialogVisible,
(visibale) => { (visibale) => {
if (!visibale) return hotkeys.unbind("*"); if (!visibale) {
hotkeys.unbind("*");
readHotkeysConfig();
bindHotKeys();
return;
}
readHotkeysConfig();
hotkeys.unbind(); hotkeys.unbind();
/**监听按键 */ /**监听按键 */
hotkeys("*", (event) => { hotkeys("*", (event) => {
@@ -257,39 +263,50 @@ const recordKeyDown = (index) => {
recordKeyDownIndex.value = index; recordKeyDownIndex.value = index;
}; };
const bindHotKeys = () => { const saveHotKeys = () => {
hotkeysDialogVisible.value = false;
const hotKeysConfig = []; const hotKeysConfig = [];
buttons.value.forEach(({ hotKeys }) => {
hotKeysConfig.push(hotKeys);
});
saveHotkeysConfig(hotKeysConfig);
hotkeysDialogVisible.value = false;
};
const bindHotKeys = () => {
buttons.value.forEach(({ hotKeys, action }) => { buttons.value.forEach(({ hotKeys, action }) => {
if (hotKeys.length == 0) return;
hotkeys(hotKeys.join("+"), (event) => { hotkeys(hotKeys.join("+"), (event) => {
event.preventDefault(); event.preventDefault();
action.call(null); action.call(null);
}); });
hotKeysConfig.push(hotKeys);
}); });
saveHotkeysConfig(hotKeysConfig);
}; };
const saveHotkeysConfig = (config) => { const saveHotkeysConfig = (config) => {
localStorage.setItem("legado_web_hotkeys", JSON.stringify(config)); localStorage.setItem("legado_web_hotkeys", JSON.stringify(config));
}; };
const readHotkeysConfig = () => { /**
* 读取快捷键配置
* @return 是否成功读取配置
*/
function readHotkeysConfig() {
try { try {
const config = JSON.parse(localStorage.getItem("legado_web_hotkeys")); 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])); buttons.value.forEach((button, index) => (button.hotKeys = config[index]));
hotkeysDialogVisible.value = false; return true;
bindHotKeys();
} catch { } catch {
ElMessage({ message: "快捷键配置错误", type: "error" }); ElMessage({ message: "快捷键配置错误", type: "error" });
localStorage.removeItem("legado_web_hotkeys"); localStorage.removeItem("legado_web_hotkeys");
} }
}; return false;
}
onMounted(() => { onMounted(() => {
/**读取热键配置 */ /**读取热键配置 */
readHotkeysConfig(); if (readHotkeysConfig()) {
hotkeysDialogVisible.value = false;
}
}); });
</script> </script>
@@ -69,13 +69,13 @@ export default {
title: "并发率", title: "并发率",
id: "concurrentRate", id: "concurrentRate",
type: "String", type: "String",
hint: "并发率", hint: "并发率,如1000(访问间隔1000ms)或者1/1000(1000ms内访问1次)",
}, },
{ {
title: "js库", title: "js库",
id: "jsLib", id: "jsLib",
type: "String", type: "String",
hint: "js库", hint: "js库, 可填写js或者key-value object获取在线js文件",
}, },
{ {
title: "请求头", title: "请求头",
@@ -105,7 +105,7 @@ export default {
namespace: "ruleSearch", namespace: "ruleSearch",
id: "checkKeyWord", id: "checkKeyWord",
type: "String", type: "String",
hint: "校验关键字", hint: "校验关键字,强烈建议填写",
}, },
{ {
title: "列表规则", title: "列表规则",
@@ -179,7 +179,7 @@ export default {
title: "发现地址", title: "发现地址",
id: "exploreUrl", id: "exploreUrl",
type: "String", type: "String",
hint: "内容能显示在发现菜单\n每行一条发现分类(网址域名可省略),例:\n名称1::网址(Url)1\n名称2::网址(Url)2\n...", hint: "单个发现格式<name>::<url>或者{url:<url>,title:<name>,style:...};前者用换行符或者&&连接,后者放在数组内;可用js动态生成",
}, },
{ {
title: "发现筛选", title: "发现筛选",
@@ -370,7 +370,7 @@ export default {
namespace: "ruleToc", namespace: "ruleToc",
id: "formatJs", id: "formatJs",
type: "String", type: "String",
hint: "直接填写js, 提供index和tittle变量", hint: "遍历去重后的章节列表的回调,提供index(章节序号从1开始)、title(章节标题)变量,额外提供gInt(初始值0),返回值作为新的标题",
}, },
{ {
title: "卷名标识", title: "卷名标识",