Merge pull request #98 from rubickCenter/feature/hotkey-tips

🚀 添加快捷键修改提示
This commit is contained in:
璃白 2022-04-02 10:57:10 +08:00 committed by GitHub
commit 65932ca22a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,18 +25,21 @@
<div class="settings-detail"> <div class="settings-detail">
<div v-if="currentSelect[0] === 'normal'"> <div v-if="currentSelect[0] === 'normal'">
<div class="setting-item"> <div class="setting-item">
<div class="title"> <div class="title">快捷键</div>
快捷键(需要使用 option/ctrl/shift/command 键修饰)
</div>
<div class="settings-item-li"> <div class="settings-item-li">
<div class="label">显示/隐藏快捷键</div> <div class="label">显示/隐藏快捷键</div>
<div <a-tooltip placement="top" trigger="click">
class="value" <template #title>
tabIndex="-1" <span>{{ tipText }} </span>
@keyup="(e) => changeShortCut(e, 'showAndHidden')" </template>
> <div
{{ shortCut.showAndHidden }} class="value"
</div> tabIndex="-1"
@keyup="(e) => changeShortCut(e, 'showAndHidden')"
>
{{ shortCut.showAndHidden }}
</div>
</a-tooltip>
</div> </div>
</div> </div>
<div class="setting-item"> <div class="setting-item">
@ -73,8 +76,8 @@
<div> <div>
按下快捷键自动搜索对应关键字当关键字结果完全匹配且结果唯一时会直接指向该功能 按下快捷键自动搜索对应关键字当关键字结果完全匹配且结果唯一时会直接指向该功能
</div> </div>
<h3 style="margin-top: 10px;">示例</h3> <h3 style="margin-top: 10px">示例</h3>
<a-divider style="margin: 5px 0;" /> <a-divider style="margin: 5px 0" />
<a-list item-layout="horizontal" :data-source="examples"> <a-list item-layout="horizontal" :data-source="examples">
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
@ -93,9 +96,7 @@
<div>快捷键</div> <div>快捷键</div>
<a-tooltip placement="top" trigger="click"> <a-tooltip placement="top" trigger="click">
<template #title> <template #title>
<span>先按功能键CtrlShiftAltOptionCommand再按其他普通键或按 <span>{{ tipText }}或按 F1-F12 单键 </span>
F1-F12 单键
</span>
</template> </template>
<div <div
:key="index" :key="index"
@ -128,9 +129,13 @@
</template> </template>
<script setup> <script setup>
import { ToolOutlined, LaptopOutlined, DatabaseOutlined } from "@ant-design/icons-vue"; import {
ToolOutlined,
LaptopOutlined,
DatabaseOutlined,
} from "@ant-design/icons-vue";
import debounce from "lodash.debounce"; import debounce from "lodash.debounce";
import { ref, reactive, watch, toRefs, toRaw } from "vue"; import { ref, reactive, watch, toRefs, computed, toRaw } from "vue";
import keycodes from "./keycode"; import keycodes from "./keycode";
import Localhost from "./localhost.vue"; import Localhost from "./localhost.vue";
@ -154,9 +159,14 @@ const state = reactive({
global: [], global: [],
}); });
const tipText = computed(() => {
const optionKeyName = window.rubick.isMacOs() ? "Option、Command" : "Alt";
return `先按功能键Ctrl、Shift、${optionKeyName}),再按其他普通键。`;
});
const currentSelect = ref(["normal"]); const currentSelect = ref(["normal"]);
const {perf, global: defaultGlobal} = remote.getGlobal("OP_CONFIG").get(); const { perf, global: defaultGlobal } = remote.getGlobal("OP_CONFIG").get();
state.shortCut = perf.shortCut; state.shortCut = perf.shortCut;
state.common = perf.common; state.common = perf.common;
@ -164,14 +174,18 @@ state.local = perf.local;
state.global = defaultGlobal; state.global = defaultGlobal;
const setConfig = debounce(() => { const setConfig = debounce(() => {
remote.getGlobal("OP_CONFIG").set(JSON.parse(JSON.stringify({ remote.getGlobal("OP_CONFIG").set(
perf: { JSON.parse(
shortCut: state.shortCut, JSON.stringify({
common: state.common, perf: {
local: state.local, shortCut: state.shortCut,
}, common: state.common,
global: state.global, local: state.local,
}))); },
global: state.global,
})
)
);
ipcRenderer.send("re-register"); ipcRenderer.send("re-register");
}, 2000); }, 2000);
@ -224,7 +238,7 @@ const changeGlobalKey = (e, index) => {
const changeGlobalValue = (index, value) => { const changeGlobalValue = (index, value) => {
state.global[index].value = value; state.global[index].value = value;
} };
const addConfig = () => { const addConfig = () => {
state.global.push({ state.global.push({
@ -233,11 +247,11 @@ const addConfig = () => {
}); });
}; };
const {shortCut, common, local, global} = toRefs(state); const { shortCut, common, local, global } = toRefs(state);
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@import '~@/assets/common.less'; @import "~@/assets/common.less";
.settings { .settings {
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 100%;