Skip to content

Commit

Permalink
提高编译目标, 新增浏览器检查
Browse files Browse the repository at this point in the history
  • Loading branch information
LeafYeeXYZ committed Apr 15, 2024
1 parent ac22a7b commit 3b60879
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import useDialog from '../libs/useDialog.jsx'
// 其他
import getStaredImages from '../libs/getStaredImages.js'
import clearDB from '../libs/clearDB.js'
import checkBrowser from '../libs/checkBrowser.js'

// 获取已收藏图片列表
const staredImages = await getStaredImages()
// 如果存在非目标版本数据,确认后清空 IndexedDB
const versionInfo = await clearDB(2024041517)
// 检测浏览器版本是否符合编译目标
checkBrowser()

// 主组件
function App() {
Expand Down
18 changes: 18 additions & 0 deletions src/libs/checkBrowser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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 浏览器
`)
}
}
4 changes: 0 additions & 4 deletions src/styles/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
--prompt-btn-width: 100%;
--prompt-btn-gap: 0;

/* 如果不支持 dvw 则使用 vw */
--images-height: calc(100vh - var(--prompt-height));
--images-height: calc(100dvh - var(--prompt-height));
--image-margin: calc( (var(--images-height) - var(--image-size)) / 2 ) calc( (100vw - var(--image-size)) / 2 );
--image-margin: calc( (var(--images-height) - var(--image-size)) / 2 ) calc( (100dvw - var(--image-size)) / 2 );
--image-size: min((100vh - var(--prompt-height))*0.9, 100vw*0.9);
--image-size: min((100dvh - var(--prompt-height))*0.9, 100dvw*0.9);

--text: #ff7171;
Expand Down
3 changes: 2 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
build: {
target: ['chrome89', 'firefox89', 'safari15', 'edge89'],
// 如果改了编译目标记得同步修改 src/libs/checkBroswer.js
target: ['chrome108', 'edge108', 'firefox101', 'safari15.4'],
rollupOptions: {
output: {
manualChunks: {
Expand Down

0 comments on commit 3b60879

Please sign in to comment.