- 在 .gitignore 中添加 public/audio/* 以忽略音频文件。 - 更新 bun.lock,添加 eslint-config-prettier 和 eslint-plugin-prettier 依赖,确保 ESLint 与 Prettier 的兼容性。 - 修改 eslint.config.ts,整合 Prettier 规则,优化代码风格一致性。 - 在 package.json 中添加 lint:fix 和 format 脚本,简化代码格式化和修复流程。 - 更新 tailwind.config.ts 和其他组件文件,统一代码风格,提升可读性。
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
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') {
|
|
const ua = window.navigator.userAgent.toLowerCase()
|
|
const isMobile = /iphone|ipad|ipod|android|mobile/.test(ua)
|
|
|
|
if (isMobile) {
|
|
// 动态加载,避免生产环境打包 & 未安装时报错
|
|
import('vconsole')
|
|
.then((mod) => {
|
|
const VConsole = (mod as any).default || (mod as any)
|
|
|
|
new VConsole()
|
|
})
|
|
.catch(() => {
|
|
// vconsole 未安装或加载失败时静默忽略
|
|
})
|
|
}
|
|
}
|
|
|
|
// 全局键盘快捷键: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')
|
|
}
|
|
|
|
createRoot(rootElement).render(
|
|
<StrictMode>
|
|
<App />
|
|
</StrictMode>
|
|
)
|