ShortcutPanel.vue
4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<template>
<div class="shortcut-panel">
<div class="settings-content-header">
<h1>{{ $t("settings.shortcut.title") }}</h1>
<p>{{ $t("settings.shortcut.desc") }}</p>
</div>
<!-- 发送消息快捷键 -->
<div class="section section-shortcut">
<div class="section-title">{{ $t("settings.shortcut.sendMessage") }}</div>
<div class="section-desc">
{{ $t("settings.shortcut.sendMessageDesc") }}
</div>
<div class="form-group">
<el-select
v-model="sendMessageShortcut"
class="select"
@change="changeShortcut"
>
<el-option value="Enter">{{
$t("settings.shortcut.enter")
}}</el-option>
<el-option value="Ctrl+Enter">
{{ $t("settings.shortcut.ctrlEnter") }}
</el-option>
</el-select>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from "vue";
import { useI18n } from "vue-i18n";
import { useSettingsStore } from "@/stores/settings";
const { t } = useI18n();
const settingsStore = useSettingsStore();
// 快捷键相关
const sendMessageShortcut = ref("Ctrl+Enter");
// 从 store 中获取快捷键设置
const keyboardShortcuts = computed(() => settingsStore.keyboardShortcuts);
const changeShortcut = async () => {
try {
// 调用 updateKeyboardShortcuts 接口
await settingsStore.updateKeyboardShortcuts({
sendMessageShortcut: sendMessageShortcut.value,
});
// 触发自定义事件,通知同标签页内的其他组件更新
window.dispatchEvent(new CustomEvent("shortcutSettingChanged"));
} catch (error) {
console.error("保存快捷键设置失败:", error);
}
};
// 组件挂载时初始化快捷键
onMounted(async () => {
try {
// 从服务器获取快捷键设置
const data = await settingsStore.fetchKeyboardShortcuts();
// 从 store 中读取 sendMessageShortcut 的值
// 支持多种可能的数据结构:sendMessageShortcut、shortcut 等
const savedShortcut =
keyboardShortcuts.value?.sendMessageShortcut ||
keyboardShortcuts.value?.shortcut ||
data?.sendMessageShortcut ||
data?.shortcut;
if (
savedShortcut &&
(savedShortcut === "Enter" || savedShortcut === "Ctrl+Enter")
) {
sendMessageShortcut.value = savedShortcut;
} else {
// 如果服务器没有数据,使用默认值并保存到服务器
sendMessageShortcut.value = "Ctrl+Enter";
await settingsStore.updateKeyboardShortcuts({
sendMessageShortcut: sendMessageShortcut.value,
});
}
} catch (error) {
console.error("获取快捷键设置失败:", error);
// 如果获取失败,使用默认值
sendMessageShortcut.value = "Ctrl+Enter";
}
});
</script>
<style scoped lang="scss">
.shortcut-panel {
width: 100%;
max-width: 800px;
margin: 0 auto;
color: var(--color-text);
background: var(--color-bg);
}
.settings-content-header {
margin-bottom: 20px;
text-align: left;
h1 {
font-size: 28px;
font-weight: 800;
color: var(--color-text);
margin-bottom: 10px;
letter-spacing: 1px;
}
p {
font-size: 16px;
color: var(--color-secondary);
font-weight: 400;
}
}
.section {
width: 100%;
margin-bottom: 56px;
display: flex;
flex-direction: column;
align-items: flex-start;
}
.section-title {
font-size: 18px;
font-weight: 700;
color: var(--color-text);
margin-bottom: 10px;
text-align: left;
letter-spacing: 1px;
}
.section-desc {
font-size: 14px;
color: var(--color-secondary);
margin-bottom: 10px;
}
.form-group {
margin-bottom: 0;
width: 100%;
}
.select {
color: var(--color-text);
font-size: 15px;
outline: none;
width: 100%;
min-width: 200px;
max-width: 300px;
box-sizing: border-box;
transition: border-color 0.2s;
&:focus {
border-color: var(--color-primary);
box-shadow: 0 0 0 2px rgba(51, 153, 255, 0.1);
}
option {
background: var(--color-card);
color: var(--color-text);
padding: 8px 16px;
}
}
@media (max-width: 1024px) {
.shortcut-panel {
max-width: 100%;
padding: 0 4px 20px 4px;
}
.settings-content-header {
margin-top: 16px;
margin-bottom: 24px;
h1 {
font-size: 22px;
}
p {
font-size: 13px;
}
}
.section-title {
font-size: 15px;
margin-bottom: 8px;
}
.section-desc {
font-size: 12px;
margin-bottom: 10px;
}
}
</style>