perf: 优化快捷键设置

This commit is contained in:
Pang 2023-12-17 16:19:32 +08:00
parent 37ccf4dacb
commit 211f9f0c15
5 changed files with 63 additions and 41 deletions

View File

@ -297,7 +297,7 @@ export default {
key: 'manifest',
url: $A.apiUrl("../manifest")
})
$A.bindScreenshotKey($A.jsonParse(window.localStorage.getItem("__keyboard:data__")) || {});
$A.bindScreenshotKey(this.$store.state.cacheKeyboard);
//
this.$Electron.sendMessage('setMenuLanguage', {
openInBrowser: this.$L("在浏览器中打开"),

View File

@ -236,10 +236,6 @@ export default {
type: Boolean,
default: false
},
enterSend: {
type: [String, Boolean],
default: null
},
emojiBottom: {
type: Boolean,
default: false
@ -386,13 +382,15 @@ export default {
'cacheDialogs',
'dialogMsgs',
'cacheKeyboard',
]),
isEnterSend({enterSend}) {
if (typeof enterSend === "boolean") {
return enterSend;
isEnterSend({cacheKeyboard}) {
if (this.$isEEUiApp) {
return cacheKeyboard.send_button_app === 'enter';
} else {
return true;
return cacheKeyboard.send_button_desktop === 'enter';
}
},
@ -495,11 +493,6 @@ export default {
}
return null;
},
separateSendButton() {
return $A.jsonParse(window.localStorage.getItem("__keyboard:data__"))?.separate_send_button !== 'close';
},
},
watch: {
// Watch content change
@ -669,11 +662,6 @@ export default {
shortKey: true,
handler: _ => {
if (!this.isEnterSend) {
if (this.separateSendButton) {
const length = this.quill.getSelection(true).index;
this.quill.insertText(length, "\r\n");
return false;
}
this.onSend();
return false;
}
@ -685,11 +673,6 @@ export default {
shiftKey: false,
handler: _ => {
if (this.isEnterSend) {
if (this.separateSendButton) {
const length = this.quill.getSelection(true).index;
this.quill.insertText(length, "\r\n");
return false;
}
this.onSend();
return false;
}
@ -798,9 +781,18 @@ export default {
if (e.key === '\r\r' && e.keyCode === 229) {
const length = this.quill.getSelection(true).index;
this.quill.insertText(length, "\r\n");
//
this.keyTimer && clearTimeout(this.keyTimer)
this.keyTimer = setTimeout(_ => {
this.$refs.editor.firstChild.childNodes.forEach(child => {
if (/^\r+/.test(child.innerHTML)) {
child.innerHTML = child.innerHTML.replace(/^\r+/, "") || "<br>"
}
})
}, 200)
}
});
if (!this.separateSendButton) {
if (this.$isEEUiApp && this.cacheKeyboard.send_button_app === 'enter') {
this.quill.root.setAttribute('enterkeyhint', 'send')
}
})

View File

@ -28,13 +28,21 @@
</div>
</FormItem>
</template>
<FormItem :label="$L('发送按钮')" prop="anonMessage">
<RadioGroup v-model="formData.separate_send_button">
<Radio label="open">{{$L('开启')}}</Radio>
<Radio label="close">{{$L('关闭')}}</Radio>
<FormItem v-if="$isEEUiApp" :label="$L('发送按钮')">
<RadioGroup v-model="formData.send_button_app">
<Radio label="button">{{$L('开启')}}</Radio>
<Radio label="enter">{{$L('关闭')}}</Radio>
</RadioGroup>
<div class="form-tip">{{$L('开启后,发送消息时键盘上的发送按钮会被替换成换行')}}</div>
</FormItem>
<FormItem v-else-if="$Electron" :label="$L('发送按钮')">
<RadioGroup v-model="formData.send_button_desktop" vertical>
<Radio label="enter">Enter {{$L('发送')}}</Radio>
<Radio label="button" class="input-box">
{{mateName}}<div class="input-box-push">+</div>Enter {{$L('发送')}}
</Radio>
</RadioGroup>
</FormItem>
</Form>
<div class="setting-footer">
<Button :loading="loadIng > 0" type="primary" @click="submitForm">{{$L('保存')}}</Button>
@ -67,7 +75,8 @@ export default {
formData: {
screenshot_key: '',
separate_send_button: 'open'
send_button_app: '',
send_button_desktop: '',
},
ruleData: {
@ -98,29 +107,26 @@ export default {
methods: {
initData() {
this.formData = Object.assign({
screenshot_key: '',
separate_send_button: 'open',
}, $A.jsonParse(window.localStorage.getItem("__keyboard:data__")) || {});
//
this.formData = $A.cloneJSON(this.$store.state.cacheKeyboard);
this.formData_bak = $A.cloneJSON(this.formData);
},
submitForm() {
this.$refs.formData.validate((valid) => {
if (valid) {
window.localStorage.setItem("__keyboard:data__", $A.jsonStringify(this.formData));
if (this.$Electron) {
$A.bindScreenshotKey(this.formData);
}
$A.messageSuccess('保存成功');
this.$store.dispatch('handleKeyboard', this.formData).then((data) => {
if (this.$Electron) {
$A.bindScreenshotKey(data);
}
$A.messageSuccess('保存成功');
});
}
})
},
resetForm() {
this.formData = $A.cloneJSON(this.formData_bak);
}
},
}
}
</script>

View File

@ -57,6 +57,9 @@ export default {
// 主题皮肤
await dispatch("synchTheme")
// Keyboard
await dispatch("handleKeyboard")
// 客户端ID
if (!state.clientId) {
state.clientId = $A.randomString(6)
@ -826,6 +829,24 @@ export default {
});
},
/**
* 处理快捷键配置
* @param state
* @param newData
* @returns {Promise<unknown>}
*/
handleKeyboard({state}, newData) {
return new Promise(resolve => {
const data = $A.isJson(newData) ? newData : ($A.jsonParse(window.localStorage.getItem("__keyboard:data__")) || {})
data.screenshot_key = (data.screenshot_key || "").trim().toLowerCase()
data.send_button_app = data.send_button_app || 'button' // button, enter 移动端发送按钮,默认 button (页面按钮发送)
data.send_button_desktop = data.send_button_desktop || 'enter' // button, enter 桌面端发送按钮,默认 enter (键盘回车发送)
window.localStorage.setItem("__keyboard:data__", $A.jsonStringify(data))
state.cacheKeyboard = data
resolve(data)
})
},
/**
* 清除缓存
* @param state

View File

@ -77,6 +77,9 @@ export default {
// ServerUrl
cacheServerUrl: "",
// keyboard
cacheKeyboard: {},
// Ajax
ajaxWsReady: false,
ajaxWsListener: [],