Skip to content

Commit 7bba787

Browse files
authored
Feat: 适配 Taro h5。处理样式兼容问题。 (jdf2e#307)
* chore: 升级Taro版本。 * chore: 调整@tarojs/cli * feat: 适配Taro h5,主要是样式处理
1 parent 13ebda8 commit 7bba787

File tree

6 files changed

+143
-12
lines changed

6 files changed

+143
-12
lines changed

src/packages/icon/demo.taro.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@ const copyTag = (text: string) => {
3232
document.body.removeChild(input)
3333
}
3434

35+
const style = `
36+
.nut-cell > .nutui-iconfont {
37+
margin-right: 10px;
38+
}
39+
ul {
40+
display: flex;
41+
flex-wrap: wrap;
42+
padding: 0;
43+
width: 100%;
44+
}
45+
ul li {
46+
flex: 0 0 25%;
47+
max-width: 25%;
48+
display: flex;
49+
flex-direction: column;
50+
align-items: center;
51+
justify-content: center;
52+
}
53+
ul li span {
54+
height: 40px;
55+
font-size: 12px;
56+
text-align: center;
57+
}
58+
ul li span .nutui-iconfont {
59+
margin: 16px 0 16px;
60+
}
61+
`
62+
3563
const IconDemo = () => {
3664
const [translated] = useTranslate<T>({
3765
'zh-CN': {
@@ -59,6 +87,7 @@ const IconDemo = () => {
5987

6088
return (
6189
<>
90+
<style>{style}</style>
6291
<div className="demo">
6392
<h2>{translated['84aa6bce']}</h2>
6493
<Cell>

src/packages/layout/demo.taro.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
import React from 'react'
2+
import { useTranslate } from '@/sites/assets/locale/taro'
23
import { Row, Col } from '@/packages/nutui.react.taro'
34
import '@/packages/layout/demo.scss'
5+
type TLayoutDemo = {
6+
title1: string
7+
title2: string
8+
title3: string
9+
}
410

511
const LayoutDemo = () => {
12+
const [translated] = useTranslate<TLayoutDemo>({
13+
'zh-CN': {
14+
title1: '基础布局',
15+
title2: '搜索框形状及最大长度',
16+
title3: '搜索框内外背景设置',
17+
},
18+
'zh-TW': {
19+
title1: '基礎佈局',
20+
title2: '分欄間隔',
21+
title3: 'Flex佈局',
22+
},
23+
'en-US': {
24+
title1: 'Basic layout',
25+
title2: 'column interval',
26+
title3: 'Flex layout',
27+
},
28+
'id-ID': {
29+
title1: 'Tata letak dasar',
30+
title2: 'interval kolom',
31+
title3: 'Tata letak fleksibel',
32+
},
33+
})
634
return (
735
<>
836
<div className="demo full">
9-
<h2>基础布局</h2>
37+
<h2>{translated.title1}</h2>
1038
<div className="box-item">
1139
<Row>
1240
<Col span="24">
@@ -47,7 +75,7 @@ const LayoutDemo = () => {
4775
</Col>
4876
</Row>
4977
</div>
50-
<h2>分栏间隔</h2>
78+
<h2>{translated.title2}</h2>
5179
<div className="box-item">
5280
<Row gutter="10">
5381
<Col span="8">
@@ -61,7 +89,7 @@ const LayoutDemo = () => {
6189
</Col>
6290
</Row>
6391
</div>
64-
<h2>Flex布局</h2>
92+
<h2>{translated.title3}</h2>
6593
<div className="box-item">
6694
<Row type="flex" wrap="nowrap">
6795
<Col span="6">

src/sites/mobile-taro/config/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const config = {
3737
postcss: {
3838
pxtransform: {
3939
enable: true,
40-
config: {},
4140
// 包含 `nut-` 的类名选择器中的 px 单位不会被解析
4241
config: { selectorBlackList: ['nut-'] },
4342
},
@@ -60,6 +59,11 @@ const config = {
6059
publicPath: '/',
6160
staticDirectory: 'static',
6261
postcss: {
62+
pxtransform: {
63+
enable: true,
64+
// 包含 `nut-` 的类名选择器中的 px 单位不会被解析
65+
config: { selectorBlackList: ['nut-'] },
66+
},
6367
autoprefixer: {
6468
enable: true,
6569
config: {},
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
@import '@/sites/assets/styles/reset.scss';
2+
.nut-demo-index {
3+
height: 100%;
4+
width: 100%;
5+
padding-top: 30px;
6+
.nut-demo-index-header {
7+
display: flex;
8+
align-items: center;
9+
padding: 0 34px;
10+
height: 117px;
11+
.nut-demo-img {
12+
width: 67px;
13+
height: 67px;
14+
margin-right: 18px;
15+
flex-shrink: 0;
16+
}
17+
.nut-demo-info {
18+
display: flex;
19+
flex-direction: column;
20+
.nut-demo-title {
21+
height: 48px;
22+
line-height: 48px;
23+
font-size: 34px;
24+
color: rgba(51, 51, 51, 1);
25+
}
26+
p {
27+
height: 18px;
28+
line-height: 18px;
29+
font-size: 12px;
30+
color: rgba(154, 155, 157, 1);
31+
}
32+
}
33+
}
34+
.nut-demo-index-components {
35+
background: #f7f8fa;
36+
border-radius: 30px 30px 0 0;
37+
padding: 30px 25px;
38+
> ol {
39+
margin-bottom: 17px;
40+
> li {
41+
line-height: 20px;
42+
font-size: 14px;
43+
color: rgba(144, 156, 164, 1);
44+
margin-bottom: 10px;
45+
}
46+
> ul {
47+
li {
48+
display: flex;
49+
align-items: center;
50+
padding: 0 24px;
51+
height: 45px;
52+
line-height: 45px;
53+
background: rgba(255, 255, 255, 1);
54+
border-radius: 22px;
55+
box-shadow: 0px 1px 4px 0px rgba(102, 102, 102, 0.06);
56+
margin-bottom: 13px;
57+
a {
58+
width: 100%;
59+
height: 100%;
60+
font-size: 15px;
61+
font-weight: bold;
62+
display: block;
63+
color: rgba(51, 51, 51, 1);
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
@import '@/sites/mobile/Links.scss';
1+
@import './Links.scss';
22

3-
.index-header .info .h5-h1 {
3+
.nutui-demo-index-header .nutui-demo-info .nutui-demo-title {
44
font-weight: 500;
5-
font-size: 48rpx;
5+
font-size: 24px;
66
}

src/sites/mobile-taro/src/pages/index/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@ const Index = () => {
3030

3131
return (
3232
<>
33-
<div className="index">
34-
<div className="index-header">
33+
<div className="nut-demo-index">
34+
<div className="nut-demo-index-header">
3535
<img
3636
src={`https://img14.360buyimg.com/imagetools/jfs/t1/117879/25/28831/6279/6329723bE66715a2f/5f099b8feca9e8cc.png`}
3737
alt=""
3838
srcSet=""
39+
className="nut-demo-img"
3940
/>
40-
<div className="info">
41-
<h1>NutUI React</h1>
41+
<div className="nut-demo-info">
42+
<h1 className="nut-demo-title">NutUI React</h1>
4243
<p>京东风格的轻量级小程序组件库 React 版</p>
4344
</div>
4445
</div>
45-
<div className="index-components">
46+
<div className="nut-demo-index-components">
4647
{navs.map((nav) => (
4748
<ol key={nav.name}>
4849
<li>{nav.name}</li>

0 commit comments

Comments
 (0)