settings.vue 9.3 KB
Newer Older
M
muwoo 已提交
1
<template>
M
muwoo 已提交
2 3 4 5 6 7 8
  <div class="pg-settings">
    <div class="dev-detail">
      <a-menu v-model="currentSelect" style="width: 256px; height: 100%" mode="vertical">
        <a-menu-item :key="0">
          偏好设置
        </a-menu-item>
        <a-menu-item :key="1">
9
          超级面板
M
muwoo 已提交
10
        </a-menu-item>
11 12 13
        <a-menu-item :key="2">
          全局快捷键
        </a-menu-item>
M
muwoo 已提交
14 15 16 17
      </a-menu>
      <div class="settings-detail">
        <div v-if="currentSelect[0] === 0">
          <div class="setting-item">
18
            <div class="title">快捷键(需要使用 option/ctrl/shift/command 键修饰)</div>
M
muwoo 已提交
19 20
            <div class="settings-item-li">
              <div class="label">显示/隐藏快捷键</div>
21
              <div class="value" tabIndex=-1 @keyup="(e) => changeShortCut(e, 'showAndHidden')">{{ config.perf.shortCut.showAndHidden }}</div>
M
muwoo 已提交
22 23 24
            </div>
            <div class="settings-item-li">
              <div class="label">插件分离快捷键</div>
25
              <div class="value" tabIndex=-1 @keyup="(e) => changeShortCut(e, 'separate')">{{ config.perf.shortCut.separate }}</div>
M
muwoo 已提交
26
            </div>
27 28
            <div class="settings-item-li">
              <div class="label">返回主界面</div>
29
              <div class="value" tabIndex=-1 @keyup="(e) => changeShortCut(e, 'quit')">{{ config.perf.shortCut.quit }}</div>
30
            </div>
M
muwoo 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
          </div>
          <div class="setting-item">
            <div class="title">通用</div>
            <div class="settings-item-li">
              <div class="label">开机启动</div>
              <a-switch v-model:checked="config.perf.common.start" checked-children="开" un-checked-children="关"></a-switch>
            </div>
            <div class="settings-item-li">
              <div class="label">空格执行</div>
              <a-switch v-model:checked="config.perf.common.space" checked-children="开" un-checked-children="关"></a-switch>
            </div>
          </div>
          <div class="setting-item">
            <div class="title">本地搜索启动</div>
            <div class="settings-item-li">
              <div class="label">搜索启动应用&文件</div>
              <a-switch v-model:checked="config.perf.local.search" checked-children="开" un-checked-children="关"></a-switch>
            </div>
          </div>
        </div>
51 52 53 54 55 56 57 58 59 60 61 62
        <div  v-if="currentSelect[0] === 1">
          <div class="setting-item">
            <div class="title">弹出面板</div>
            <a-select value="mouseRight" style="width: 200px" disabled>
              <a-select-option value="mouseRight">长按鼠标右键</a-select-option>
            </a-select>
          </div>
          <div class="setting-item">
            <div class="title">长按以下设置的毫秒响应</div>
            <a-slider :step="100" v-model:value="config.superPanel.mouseDownTime" :min="200" :max="1000" />
          </div>
        </div>
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
        <div v-if="currentSelect[0] === 2">
          <a-collapse>
            <a-collapse-panel key="1" header="说明及示例">
              <div>按下快捷键,自动搜索对应关键字,当关键字结果完全匹配,且结果唯一时,会直接指向该功能。</div>
              <h3 style="margin-top: 10px;">示例</h3>
              <a-divider style="margin: 5px 0;" />
              <a-list item-layout="horizontal" :data-source="examples">
                <a-list-item slot="renderItem" slot-scope="item, index">
                  <a-list-item-meta
                      :description="item.desc"
                  >
                    <div slot="title">{{ item.title }}</div>
                  </a-list-item-meta>
                </a-list-item>
              </a-list>
            </a-collapse-panel>
          </a-collapse>
          <div class="feature-container">
            <div class="keywords item">
              <div>快捷键</div>
              <a-tooltip placement="top" trigger="click">
                <template slot="title">
                  <span>先按功能键(Ctrl、Shift、Alt、Option、Command),再按其他普通键。或按 F1-F12 单键</span>
                </template>
                <div
M
muwoo 已提交
88
                    v-for="(item, index) in config.global"
89 90
                    class="value"
                    tabIndex=-1
91
                    @keyup="(e) => changeGlobalKey(e, index)"
92 93 94 95 96 97 98 99 100 101
                >
                  {{ item.key }}
                </div>
              </a-tooltip>

            </div>
            <div class="short-cut item">
              <div>功能关键字</div>
              <a-input
                  :value="item.value"
M
muwoo 已提交
102
                  v-for="(item, index) in config.global"
103 104 105 106 107 108 109 110
                  class="value"
                  :disabled="!item.key"
                  @change="(e) => changeGlobalValue(index, e.target.value)"
              />
            </div>
          </div>
          <div @click="addConfig" class="add-global"> +  新增全局快捷功能</div>
        </div>
M
muwoo 已提交
111 112 113 114
      </div>
    </div>
  </div>

M
muwoo 已提交
115 116 117
</template>

<script>
M
muwoo 已提交
118 119 120 121 122
import keycodes from '../../../assets/keycode';
import {ipcRenderer, remote} from 'electron';

const opConfig = remote.getGlobal('opConfig');

M
muwoo 已提交
123
export default {
M
muwoo 已提交
124 125 126
  data() {
    return {
      currentSelect: [0],
127
      config: JSON.parse(JSON.stringify(opConfig.get())),
128 129 130 131 132 133 134 135 136 137
      examples: [
        {
          title: '快捷键 「 Alt + W」 关键字 「 微信」',
          desc: '按下Alt + W 直接打开本地微信应用'
        },
        {
          title: '快捷键 「 Alt + Q」 关键字 「 取色」',
          desc: '按下Alt + Q 直接打开屏幕取色功能'
        }
      ]
M
muwoo 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
    }
  },
  methods: {
    changeShortCut(e, key) {
      let change = false;
      if(e.altKey && e.keyCode !== 18){
        const compose = `Option+${keycodes[e.keyCode].toUpperCase()}`;
        this.config.perf.shortCut[key] = compose;
        change = true;
      }
      if(e.ctrlKey && e.keyCode !== 17){
        const compose = `Ctrl+${keycodes[e.keyCode].toUpperCase()}`;
        this.config.perf.shortCut[key] = compose;
        change = true;
      }
      if(e.shiftKey && e.keyCode !== 16){
        const compose = `Shift+${keycodes[e.keyCode].toUpperCase()}`;
        this.config.perf.shortCut[key] = compose;
        change = true;
      }
      if(e.metaKey && e.keyCode !== 93){
        const compose = `Command+${keycodes[e.keyCode].toUpperCase()}`;
        this.config.perf.shortCut[key] = compose;
        change = true;
      }
163 164 165 166 167 168 169 170 171 172 173
    },
    addConfig() {
      this.config.global.push({
        key: '',
        value: ''
      });
    },

    changeGlobalKey(e, index) {
      let compose;
      if(e.altKey && e.keyCode !== 18){
174
        compose = `Alt+${keycodes[e.keyCode].toUpperCase()}`;
175 176 177 178 179 180 181 182 183 184 185 186 187
      }
      if(e.ctrlKey && e.keyCode !== 17){
        compose = `Ctrl+${keycodes[e.keyCode].toUpperCase()}`;
      }
      if(e.shiftKey && e.keyCode !== 16){
        compose = `Shift+${keycodes[e.keyCode].toUpperCase()}`;
      }
      if(e.metaKey && e.keyCode !== 93){
        compose = `Command+${keycodes[e.keyCode].toUpperCase()}`;
      }
      if (compose) {
        this.$set(this.config.global[index], 'key', compose);
      }
M
muwoo 已提交
188 189 190 191 192 193 194
      // f1 - f12
      if (e.keyCode >= 112 && e.keyCode <= 123) {
        compose = keycodes[e.keyCode].toUpperCase();
      }
      if (compose) {
        this.$set(this.config.global[index], 'key', compose);
      }
195 196 197
    },
    changeGlobalValue(index, value) {
      this.$set(this.config.global[index], 'value', value);
M
muwoo 已提交
198 199 200 201 202 203 204
    }
  },
  watch: {
    config: {
      deep: true,
      handler() {
        opConfig.set('perf', this.config.perf);
205
        opConfig.set('superPanel', this.config.superPanel);
M
muwoo 已提交
206
        opConfig.set('global', this.config.global);
M
muwoo 已提交
207 208 209 210
        ipcRenderer.send('re-register');
      }
    }
  }
M
muwoo 已提交
211 212 213
}
</script>

M
muwoo 已提交
214 215 216 217 218 219 220 221
<style lang="less">
  .pg-settings {
    height: calc(~'100vh - 110px');
    overflow: auto;
    .dev-detail {
      height: 100%;
      display: flex;
      align-items: flex-start;
222
      background: #fff;
M
muwoo 已提交
223 224 225 226 227
    }
    .settings-detail {
      padding: 20px;
      box-sizing: border-box;
      flex: 1;
228 229
      overflow: auto;
      height: 100%;
M
muwoo 已提交
230 231
      .setting-item {
        margin-bottom: 20px;
232 233 234
        .ant-form-item {
          margin-bottom: 0;
        }
M
muwoo 已提交
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
        .title {
          color: #6C9FE2;
          font-size: 15px;
          margin-bottom: 10px;
        }
        .settings-item-li {
          padding-left: 20px;
          display: flex;
          width: 100%;
          align-items: center;
          justify-content: space-between;
          margin-bottom: 10px;
          .label {
            color: #646464;
          }
          .value {
            width: 300px;
            text-align: center;
            border: 1px solid #ddd;
            color: #6C9FE2;
            font-size: 14px;
            height: 24px;
            font-weight: lighter;
          }
        }
      }
    }
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
    .feature-container {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-top: 10px;
      font-size: 14px;
      .item {
        flex: 1;

      }
      .short-cut {
        margin-left: 20px;
      }
      .value {
        text-align: center;
        border: 1px solid #ddd;
        color: #6C9FE2;
        font-size: 14px;
        height: 24px;
        font-weight: lighter;
        margin-top: 10px;
      }
    }
    .add-global {
      color: #6C9FE2;
      margin-top: 20px;
      width: 100%;
      text-align: center;
      cursor: pointer;
    }
M
muwoo 已提交
292
  }
M
muwoo 已提交
293
</style>