Skip to content

Commit 97a0aab

Browse files
donaldshenlevy9527
authored andcommitted
feat: px-to-viewport (#55)
1 parent a783907 commit 97a0aab

File tree

11 files changed

+97
-50
lines changed

11 files changed

+97
-50
lines changed

template/_package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@commitlint/config-conventional": "^8.0.0",
5858
<%_ if (template === 'mobile') { _%>
5959
"babel-plugin-import": "^1.12.0",
60+
"postcss-px-to-viewport": "^1.1.1",
6061
<%_ } else { _%>
6162
"babel-plugin-component": "^1.1.0",
6263
<%_ } _%>

template/frameworks/mobile/README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33

44
## Table of Contents
55

6-
- **[Feature](#feature)**
7-
- **[快速开始](#快速开始)**
8-
- **[工程结构](#工程结构)**
9-
- **[开发](#开发)**
10-
- **[新建页面](#新建页面)**
11-
- **[调用接口](#调用接口)**
12-
- **[CRUD](#CRUD)**
13-
- **[设置代理](#设置代理)**
14-
- **[环境变量](#环境变量)**
15-
- **[构建](#构建)**
16-
- **[License](#license)**
6+
- [Feature](#feature)
7+
- [快速开始](#快速开始)
8+
- [工程结构](#工程结构)
9+
- [开发](#开发)
10+
- [新建页面](#新建页面)
11+
- [调用接口](#调用接口)
12+
- [CRUD](#crud)
13+
- [设置代理](#设置代理)
14+
- [样式自适应宽度](#样式自适应宽度)
15+
- [环境变量](#环境变量)
16+
- [构建](#构建)
17+
- [License](#license)
1718

1819
## Feature
1920

@@ -25,6 +26,7 @@
2526
- css预处理器:[less](http://lesscss.org/)
2627
- 代码格式化:[prettier](https://github.com/prettier/prettier)
2728
- 环境变量: [dotenv](https://www.npmjs.com/package/dotenv)
29+
- 样式自适应屏幕宽度: [px-to-viewport](https://www.npmjs.com/package/postcss-px-to-viewport)
2830

2931
[⬆ Back to Top](#table-of-contents)
3032

@@ -227,6 +229,14 @@ env: {
227229

228230
[⬆ Back to Top](#table-of-contents)
229231

232+
### 样式自适应宽度
233+
234+
项目自带了`postcss-px-to-viewport`插件。这样页面在不同宽度的手机📱上使用了`px`的样式会自适应缩放。
235+
236+
模板内的`px`样式默认是按`750px`宽度的设计稿填写。也即:设计稿`10px`,css就是写`10px`
237+
238+
如果产品设计稿的宽度是`375px`,则修改`postcss.config.js`文件中的`vwUnit`属性为`375`
239+
230240
## 环境变量
231241

232242
使用.env设置环境变量, 即在项目根目录新建一个.env文件, 填写环境变量即可。
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
body {
2-
font-size: 14px;
2+
font-size: 28px;
33
}
44
.text-center {
55
text-align: center;
@@ -11,21 +11,21 @@ body {
1111
color: #828282;
1212
}
1313
.font-s {
14-
font-size: 12px;
14+
font-size: 24px;
1515
}
1616

1717
.font-m {
18-
font-size: 14px;
18+
font-size: 28px;
1919
}
2020

2121
.font-l {
22-
font-size: 16px;
22+
font-size: 32px;
2323
}
2424

2525
.font-xl {
26-
font-size: 18px;
26+
font-size: 36px;
2727
}
2828
.fixed-box { // fixed-btn 用relative的父元素站位
2929
position: relative;
30-
height: 60px;
30+
height: 120px;
3131
}

template/frameworks/mobile/components/agreement.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ export default {
173173
<style lang="less">
174174
.agreement {
175175
.content-wrapper {
176-
margin-top: 50px;
177-
padding: 0 10px;
176+
margin-top: 100px;
177+
padding: 0 20px;
178178
height: 100%;
179179
overflow-y: auto;
180180
}

template/frameworks/mobile/components/header-nav-bar.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ export default {
2424
.header-nav-bar {
2525
position: relative;
2626
z-index: 100;
27-
height: 50px;
27+
height: 100px;
2828
2929
.van-nav-bar {
30-
height: 50px;
31-
line-height: 50px;
30+
height: 100px;
31+
line-height: 100px;
3232
}
3333
3434
.van-nav-bar__text:active {

template/frameworks/mobile/pages/cart.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,16 @@ export default {
111111
.van-checkbox__label {
112112
width: 100%;
113113
height: auto;
114-
padding: 0 10px 0 15px;
114+
padding: 0 20px 0 30px;
115115
box-sizing: border-box;
116116
}
117117
118118
.van-checkbox__icon {
119119
top: 50%;
120-
left: 10px;
120+
left: 20px;
121121
z-index: 1;
122122
position: absolute;
123-
margin-top: -10px;
123+
margin-top: -20px;
124124
}
125125
126126
.van-card__price {
@@ -130,7 +130,7 @@ export default {
130130
}
131131
132132
.van-submit-bar {
133-
bottom: 50px;
133+
bottom: 100px;
134134
}
135135
}
136136
</style>

template/frameworks/mobile/pages/goods-detail.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default {
105105
}
106106
107107
.title {
108-
font-size: 16px;
108+
font-size: 32px;
109109
}
110110
111111
.price {
@@ -114,20 +114,20 @@ export default {
114114
115115
.express {
116116
color: #999;
117-
font-size: 12px;
118-
padding: 5px 15px;
117+
font-size: 24px;
118+
padding: 10px 30px;
119119
}
120120
121121
.cell-group {
122-
margin: 15px 0;
122+
margin: 30px 0;
123123
124124
.van-cell__value {
125125
color: #999;
126126
}
127127
}
128128
129129
.tag {
130-
margin-left: 5px;
130+
margin-left: 10px;
131131
}
132132
}
133133
</style>

template/frameworks/mobile/pages/index.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default {
9494
<style lang="less">
9595
.index {
9696
.van-swipe {
97-
height: 200px;
97+
height: 400px;
9898
9999
.banner {
100100
max-height: 100%;
@@ -104,14 +104,14 @@ export default {
104104
105105
.goods {
106106
.van-row {
107-
padding: 5px;
107+
padding: 10px;
108108
}
109109
110110
.block {
111-
margin: 5px;
112-
box-shadow: 0 0 2px 1px rgba(0, 0, 0, 0.1);
113-
border-radius: 5px;
114-
font-size: 14px;
111+
margin: 10px;
112+
box-shadow: 0 0 4px 2px rgba(0, 0, 0, 0.1);
113+
border-radius: 10px;
114+
font-size: 28px;
115115
}
116116
117117
.price {
@@ -121,7 +121,7 @@ export default {
121121
.name,
122122
.price {
123123
margin: 0;
124-
margin-left: 10px;
124+
margin-left: 20px;
125125
}
126126
127127
.good-img {

template/frameworks/mobile/pages/my.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,33 +97,33 @@ export default {
9797
}
9898
9999
&-group {
100-
margin-bottom: 15px;
100+
margin-bottom: 30px;
101101
}
102102
103103
&-links {
104-
padding: 15px 0;
105-
font-size: 12px;
104+
padding: 30px 0;
105+
font-size: 24px;
106106
text-align: center;
107107
background-color: #fff;
108108
109109
.van-icon {
110110
display: block;
111-
font-size: 24px;
111+
font-size: 48px;
112112
}
113113
}
114114
115115
.login {
116-
padding: 10px;
116+
padding: 20px;
117117
118118
.title {
119-
margin-bottom: 20px;
119+
margin-bottom: 40px;
120120
}
121121
}
122122
123123
.login-btn {
124124
width: 100%;
125125
background: #6495fe;
126-
border: 1px solid #6495fe;
126+
border: 2px solid #6495fe;
127127
}
128128
}
129129
</style>

template/frameworks/mobile/pages/order-list.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ export default {
3131
.order-list {
3232
.order {
3333
display: flex;
34-
height: 50px;
35-
line-height: 50px;
36-
margin: 0 10px;
34+
height: 100px;
35+
line-height: 100px;
36+
margin: 0 20px;
3737
justify-content: space-between;
3838
3939
img {
40-
height: 40px;
41-
margin-right: 10px;
40+
height: 80px;
41+
margin-right: 20px;
4242
}
4343
}
4444
}

0 commit comments

Comments
 (0)