feat: 添加全局键盘快捷键和更新故居数据,提升用户体验
- 在 main.tsx 中添加全局键盘快捷键功能,允许用户通过 Ctrl+Shift+R 重置所有缓存。 - 更新多个故居的拼图数据,增加黄炎培和鲁迅的相关信息,丰富学习内容。 - 调整 ResidenceLayout 组件以支持新的故居,确保数据一致性。 - 清理不再使用的拼图布局配置文件,提升代码整洁性。
This commit is contained in:
1 parent
8ba36a4a1a
commit
a365964f54
155 files changed
+1387
-348
No files matched your search
@@ -2,6 +2,12 @@ import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import "./index.css";
|
||||
import App from "./App";
|
||||
import {
|
||||
useChenyunStore,
|
||||
useHuangyanpeiStore,
|
||||
usePuzzleStore,
|
||||
useClueStore,
|
||||
} from "./store";
|
||||
|
||||
// 在开发模式的移动端启用 vConsole(需先安装 vconsole 依赖)
|
||||
if (import.meta.env.DEV && typeof window !== "undefined") {
|
||||
@@ -22,6 +28,43 @@ if (import.meta.env.DEV && typeof window !== "undefined") {
|
||||
}
|
||||
}
|
||||
|
||||
// 全局键盘快捷键:Ctrl+Shift+R 重置所有缓存
|
||||
const setupGlobalKeyboardShortcuts = () => {
|
||||
if (typeof window !== "undefined") {
|
||||
document.addEventListener("keydown", (event) => {
|
||||
// Ctrl+Shift+R: 重置所有缓存
|
||||
if (event.ctrlKey && event.shiftKey && event.key === "R") {
|
||||
event.preventDefault(); // 阻止默认的页面刷新行为
|
||||
|
||||
// 显示确认对话框
|
||||
const confirmed = window.confirm(
|
||||
"确定要重置所有缓存吗?这将清除所有已收集的拼图碎片、已完成的展品和线索。"
|
||||
);
|
||||
|
||||
if (confirmed) {
|
||||
try {
|
||||
// 重置所有store
|
||||
useChenyunStore.getState().resetAll();
|
||||
useHuangyanpeiStore.getState().resetAll();
|
||||
usePuzzleStore.getState().resetAll();
|
||||
useClueStore.getState().resetAll();
|
||||
|
||||
// 显示成功消息
|
||||
alert("所有缓存已重置!页面将刷新。");
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
console.error("重置缓存时出错:", error);
|
||||
alert("重置缓存失败,请查看控制台错误信息。");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 设置全局键盘快捷键
|
||||
setupGlobalKeyboardShortcuts();
|
||||
|
||||
const rootElement = document.getElementById("root");
|
||||
if (!rootElement) {
|
||||
throw new Error("Root element not found");
|
||||
|
||||
Reference in new issue
Block a user