diff --git a/src/components/App.jsx b/src/components/App.jsx index ae349a6..ffd5a39 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -12,6 +12,7 @@ import useDialog from '../libs/useDialog.jsx' // 其他 import getStaredImages from '../libs/getStaredImages.js' import clearDB from '../libs/clearDB.js' +import checkBrowser from '../libs/checkBrowser.js' // 清除 sessionStorage sessionStorage.clear() @@ -19,6 +20,8 @@ sessionStorage.clear() const versionInfo = await clearDB(2024041522) // 获取已收藏图片列表 const staredImages = await getStaredImages() +// 检查浏览器 +checkBrowser() // 主组件 function App() { diff --git a/src/libs/checkBrowser.js b/src/libs/checkBrowser.js new file mode 100644 index 0000000..b401754 --- /dev/null +++ b/src/libs/checkBrowser.js @@ -0,0 +1,25 @@ +/** + * 检查浏览器版本是否符合要求 + * 如果不符合要求,弹出提示框 + */ +export default function checkBrowser() { + const ua = navigator.userAgent + const chrome = ua.match(/Chrome\/(\d+)/) + const firefox = ua.match(/Firefox\/(\d+)/) + const edge = ua.match(/Edge\/(\d+)/) + const safari = ua.match(/Safari\/(\d+)/) + if ( + (chrome && Number(chrome[1]) < 108) || + (firefox && Number(firefox[1]) < 101) || + (edge && Number(edge[1]) < 108) || + (safari && Number(safari[1]) < 15.4) + ) { + alert(` + 您的浏览器版本过低 + 可能无法正常使用本应用 + 建议使用最新版本 + Chrome/Edge/Firefox/Safari + 等现代浏览器 + `) + } +} \ No newline at end of file diff --git a/vite.config.js b/vite.config.js index 8f9c930..724f6d6 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,6 +4,7 @@ import react from '@vitejs/plugin-react' export default defineConfig({ plugins: [react()], build: { + // 修改编译目标后记得同步修改 checkBrowser.js 中的版本号 target: ['chrome108', 'edge108', 'firefox101', 'safari15.4'], rollupOptions: { output: {