feat: 添加快捷键 以及快捷键管理功能

ref #39
This commit is contained in:
alger
2025-01-15 00:30:00 +08:00
parent 072025a543
commit 45cbc15c0f
9 changed files with 681 additions and 12 deletions
+40
View File
@@ -0,0 +1,40 @@
import { createVNode, render } from 'vue';
import ShortcutToast from '@/components/ShortcutToast.vue';
let container: HTMLDivElement | null = null;
let toastInstance: any = null;
export function showShortcutToast(message: string, iconName: string) {
// 如果容器不存在,创建一个新的容器
if (!container) {
container = document.createElement('div');
document.body.appendChild(container);
}
// 如果已经有实例,先销毁它
if (toastInstance) {
render(null, container);
toastInstance = null;
}
// 创建新的 toast 实例
const vnode = createVNode(ShortcutToast, {
onDestroy: () => {
if (container) {
render(null, container);
document.body.removeChild(container);
container = null;
}
}
});
// 渲染 toast
render(vnode, container);
toastInstance = vnode.component?.exposed;
// 显示 toast
if (toastInstance) {
toastInstance.show(message, iconName);
}
}