feat(admin-web): add Ctrl/Cmd+S save shortcut to article editor

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-25 22:45:27 +08:00
parent 2846968cf7
commit c0617b70d8
+30 -2
View File
@@ -2,7 +2,7 @@
import { LeftOutlined } from "@ant-design/icons-vue";
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
import { message } from "ant-design-vue";
import { computed, ref, watch } from "vue";
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRoute, useRouter } from "vue-router";
@@ -187,6 +187,20 @@ async function handleSave(): Promise<void> {
await saveArticle();
}
function handleSaveShortcut(event: KeyboardEvent): void {
if (!(event.ctrlKey || event.metaKey) || event.key.toLowerCase() !== "s") {
return;
}
event.preventDefault();
event.stopPropagation();
if (event.repeat || saveDisabled.value) {
return;
}
void handleSave();
}
async function handlePublish(): Promise<void> {
if (editorLocked.value) {
return;
@@ -344,6 +358,14 @@ function serializePlatformSelection(platformIds: string[]): string {
.sort()
.join(",");
}
onMounted(() => {
window.addEventListener("keydown", handleSaveShortcut);
});
onBeforeUnmount(() => {
window.removeEventListener("keydown", handleSaveShortcut);
});
</script>
<template>
@@ -355,7 +377,13 @@ function serializePlatformSelection(platformIds: string[]): string {
</button>
<div class="article-editor-view__actions">
<a-button :disabled="saveDisabled" :loading="saveMutation.isPending.value" @click="handleSave">
<a-button
:disabled="saveDisabled"
:loading="saveMutation.isPending.value"
title="Ctrl/Cmd + S"
aria-keyshortcuts="Control+S Meta+S"
@click="handleSave"
>
{{ t("common.save") }}
</a-button>
<a-button type="primary" :disabled="editorLocked" @click="handlePublish">