Merge pull request #2 from wswmsword/main

chore: 使用 postcss-mobile-forever 进行屏幕适配,提升各端可访问性
This commit is contained in:
傲慢或香橙 2023-03-07 17:42:33 +08:00 committed by GitHub
commit bb7448af2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 33 deletions

View File

@ -75,7 +75,7 @@
"postcss": "^8.4.16", "postcss": "^8.4.16",
"postcss-html": "^1.0.0", "postcss-html": "^1.0.0",
"postcss-less": "^6.0.0", "postcss-less": "^6.0.0",
"postcss-px-to-viewport-8-plugin": "^1.1.5", "postcss-mobile-forever": "^2.2.2",
"prettier": "^2.7.1", "prettier": "^2.7.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"rollup": "^2.79.0", "rollup": "^2.79.0",

18
pnpm-lock.yaml generated
View File

@ -43,7 +43,7 @@ specifiers:
postcss: ^8.4.16 postcss: ^8.4.16
postcss-html: ^1.0.0 postcss-html: ^1.0.0
postcss-less: ^6.0.0 postcss-less: ^6.0.0
postcss-px-to-viewport-8-plugin: ^1.1.5 postcss-mobile-forever: ^2.2.2
prettier: ^2.7.1 prettier: ^2.7.1
qs: ^6.11.0 qs: ^6.11.0
rimraf: ^3.0.2 rimraf: ^3.0.2
@ -121,7 +121,7 @@ devDependencies:
postcss: 8.4.16 postcss: 8.4.16
postcss-html: 1.5.0 postcss-html: 1.5.0
postcss-less: 6.0.0_postcss@8.4.16 postcss-less: 6.0.0_postcss@8.4.16
postcss-px-to-viewport-8-plugin: 1.1.5 postcss-mobile-forever: 2.2.2_postcss@8.4.16
prettier: 2.7.1 prettier: 2.7.1
rimraf: 3.0.2 rimraf: 3.0.2
rollup: 2.79.0 rollup: 2.79.0
@ -4068,6 +4068,14 @@ packages:
resolution: {integrity: sha512-3sOlxmbKcSHMjlUXQZKQ06jOswE7oVkXPxmZdoB1r5l0q6gTFTQSHxNxOrCccElbW7dxNytifNEo8qidX2Vsig==} resolution: {integrity: sha512-3sOlxmbKcSHMjlUXQZKQ06jOswE7oVkXPxmZdoB1r5l0q6gTFTQSHxNxOrCccElbW7dxNytifNEo8qidX2Vsig==}
dev: true dev: true
/postcss-mobile-forever/2.2.2_postcss@8.4.16:
resolution: {integrity: sha512-biAaA41V0eiabqZ6fAykhByK+rYADUYQLg6Wvf1FcvJSEE98XRrDykSKAgrK6/+5UhIMJHBjoUJIfEouI5bhHA==}
peerDependencies:
postcss: ^8.0.0
dependencies:
postcss: 8.4.16
dev: true
/postcss-prefix-selector/1.16.0_postcss@5.2.18: /postcss-prefix-selector/1.16.0_postcss@5.2.18:
resolution: {integrity: sha512-rdVMIi7Q4B0XbXqNUEI+Z4E+pueiu/CS5E6vRCQommzdQ/sgsS4dK42U7GX8oJR+TJOtT+Qv3GkNo6iijUMp3Q==} resolution: {integrity: sha512-rdVMIi7Q4B0XbXqNUEI+Z4E+pueiu/CS5E6vRCQommzdQ/sgsS4dK42U7GX8oJR+TJOtT+Qv3GkNo6iijUMp3Q==}
peerDependencies: peerDependencies:
@ -4076,12 +4084,6 @@ packages:
postcss: 5.2.18 postcss: 5.2.18
dev: true dev: true
/postcss-px-to-viewport-8-plugin/1.1.5:
resolution: {integrity: sha512-qM6x2NyGbRj8R15o/LCbw5hacU+XK1s80zTvWgLjHsOP8B9P1KbDZbNS11BG6/WPut8LR8DvEU5iKw8JnQn9MQ==}
dependencies:
object-assign: 4.1.1
dev: true
/postcss-resolve-nested-selector/0.1.1: /postcss-resolve-nested-selector/0.1.1:
resolution: {integrity: sha512-HvExULSwLqHLgUy1rl3ANIqCsvMS0WHss2UOsXhXnQaZ9VCc2oBvIpXrl00IUFT5ZDITME0o6oiXeiHr2SAIfw==} resolution: {integrity: sha512-HvExULSwLqHLgUy1rl3ANIqCsvMS0WHss2UOsXhXnQaZ9VCc2oBvIpXrl00IUFT5ZDITME0o6oiXeiHr2SAIfw==}
dev: true dev: true

View File

@ -11,43 +11,38 @@
*/ */
const autoprefixer = require('autoprefixer'); const autoprefixer = require('autoprefixer');
const px2viewport = require('postcss-px-to-viewport-8-plugin'); const viewport = require('postcss-mobile-forever');
const basePx2viewport = { const baseViewportOpts = {
unitToConvert: 'px', // 需要转换的单位,默认为 px rootSelector: '#app', // 根元素选择器,用于设置桌面端和横屏时的居中样式
// viewportWidth: 750, // 设计稿的视口宽度 viewportWidth: 750, // 设计稿的视口宽度,可传递函数动态生成视图宽度
unitPrecision: 3, // 单位转换后保留的精度(很多时候无法整除) unitPrecision: 3, // 单位转换后保留的精度(很多时候无法整除)
propList: [ propList: [
'*', '*',
// '!font-size' // '!font-size'
], // 能转化为vw的属性列表!font-size表示font-size后面的单位不会被转换 ], // 能转化为vw的属性列表!font-size表示font-size后面的单位不会被转换
viewportUnit: 'vw', // 指定需要转换成的视口单位,建议使用 vw
fontViewportUnit: 'vw', // 字体使用的视口单位
// 指定不转换为视口单位的类,可以自定义,可以无限添加,建议定义一至两个通用的类名 // 指定不转换为视口单位的类,可以自定义,可以无限添加,建议定义一至两个通用的类名
// 需要忽略的CSS选择器不会转为视口单位使用原有的px等单位。 // 需要忽略的CSS选择器不会转为视口单位使用原有的px等单位。
// 下面配置表示类名中含有'keep-px'以及'.ignore'类都不会被转换 // 下面配置表示类名中含有'keep-px'以及'.ignore'类都不会被转换
selectorBlackList: ['.ignore', 'keep-px'], selectorBlackList: ['.ignore', 'keep-px'],
minPixelValue: 1, // 设置最小的转换数值,这里小于或等于 1px 不转换为视口单位
mediaQuery: false, // 媒体查询里的单位是否需要转换单位
// exclude: [/node_modules/], // 忽略某些文件夹下的文件或特定文件 // exclude: [/node_modules/], // 忽略某些文件夹下的文件或特定文件
// include: [/src/], // 如果设置了include那将只有匹配到的文件才会被转换 // include: [/src/], // 如果设置了include那将只有匹配到的文件才会被转换
border: true, // 为桌面端和横屏视图添加边框
disableDesktop: false, // 关闭桌面端适配
disableLandscape: false, // 关闭横屏适配
mobileConfig: {
viewportUnit: 'vw', // 指定需要转换成的视口单位,建议使用 vw
fontViewportUnit: 'vw', // 字体使用的视口单位
},
}; };
module.exports = { module.exports = {
plugins: [ plugins: [
autoprefixer(), autoprefixer(),
// 只将vant转为350设计稿的viewport viewport({
px2viewport({ ...baseViewportOpts,
...basePx2viewport, // 只将 vant 转为 350 设计稿的 viewport其它样式的视图宽度为 750
viewportWidth: 375, viewportWidth: (file) => (file.includes('node_modules/vant/') ? 375 : 750),
exclude: [/^(?!.*node_modules\/vant)/],
// include: [/node_modules\/vant/],
}),
// 除了vant都转为750设计稿的viewport
px2viewport({
...basePx2viewport,
viewportWidth: 750,
exclude: [/node_modules\/vant/],
}), }),
], ],
}; };

View File

@ -17,7 +17,7 @@
<component v-else :is="Component" :key="route.fullPath" /> <component v-else :is="Component" :key="route.fullPath" />
</template> </template>
</routerView> </routerView>
<van-tabbar placeholder route> <van-tabbar route class="tabbar">
<van-tabbar-item <van-tabbar-item
fixed fixed
replace replace
@ -53,4 +53,9 @@
const getShowHeader = computed(() => !currentRoute.meta.hiddenHeader); const getShowHeader = computed(() => !currentRoute.meta.hiddenHeader);
</script> </script>
<style scoped lang="less"></style> <style scoped lang="less">
.tabbar {
position: fixed;
width: 100%;
}
</style>

View File

@ -1,10 +1,14 @@
#app,
body, body,
html { html {
height: 100%; height: 100%;
width: 100%; width: 100%;
} }
#app {
height: 100%;
width: 100%;
}
[data-theme='dark'] { [data-theme='dark'] {
&, &,

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="enter-y fixed bottom-0 w-full !-z-5"> <div class="enter-y fixed bottom-0 w-full !-z-5 wave-wrapper">
<svg <svg
class="ignore-waves" class="ignore-waves"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -52,6 +52,12 @@
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
.wave-wrapper {
position: fixed;
width: 100%;
left: 0;
bottom: 0;
}
.ignore-waves { .ignore-waves {
position: relative; position: relative;
display: block; display: block;