Skip to content

Commit 0d5b2fe

Browse files
committed
1 parent 0652ab7 commit 0d5b2fe

File tree

7 files changed

+89
-9
lines changed

7 files changed

+89
-9
lines changed

packages/taro-demo-react/babel.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,16 @@ module.exports = {
1010
},
1111
],
1212
],
13+
plugins: [
14+
[
15+
'import',
16+
{
17+
libraryName: '@nutui/nutui-react-taro',
18+
libraryDirectory: 'dist/esm',
19+
style: 'css',
20+
camel2DashComponentName: false,
21+
},
22+
'nutui-react-taro',
23+
],
24+
],
1325
};

packages/taro-demo-react/config/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import prodConfig from './prod';
77
export default defineConfig(async (merge) => {
88
const baseConfig: UserConfigExport = {
99
projectName: 'taro-demo-react',
10-
designWidth: 750,
10+
designWidth: 375, // 全局使用 NutUI 的 375 尺寸
1111
deviceRatio: {
1212
640: 2.34 / 2,
1313
750: 1,

packages/taro-demo-react/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@
3535
],
3636
"dependencies": {
3737
"@babel/runtime": "7.24.4",
38+
"@nutui/icons-react-taro": "1.0.4",
39+
"@nutui/nutui-react-taro": "2.6.0",
3840
"@tarojs/components": "3.6.25",
3941
"@tarojs/helper": "3.6.25",
4042
"@tarojs/plugin-framework-react": "3.6.25",
43+
"@tarojs/plugin-html": "3.6.25",
4144
"@tarojs/plugin-platform-alipay": "3.6.25",
4245
"@tarojs/plugin-platform-h5": "3.6.25",
4346
"@tarojs/plugin-platform-harmony-hybrid": "3.6.25",
@@ -64,6 +67,7 @@
6467
"@types/jest": "29.5.12",
6568
"@types/react": "18.2.74",
6669
"@types/webpack-env": "1.18.4",
70+
"babel-plugin-import": "1.13.8",
6771
"babel-preset-taro": "3.6.25",
6872
"eslint-config-taro": "3.6.25",
6973
"eslint-plugin-import": "2.12.0",

packages/taro-demo-react/src/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useLaunch } from '@tarojs/taro';
22
import type { PropsWithChildren } from 'react';
3+
import '@nutui/nutui-react-taro/dist/style.css';
34
import './app.scss';
45

56
function App({ children }: PropsWithChildren<any>) {

packages/taro-demo-react/src/pages/index/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ export interface NavGroupConfig extends NavConfig {
77
children: NavConfig[];
88
}
99

10+
export const NUT_UI_LOGO =
11+
'https://img14.360buyimg.com/imagetools/jfs/t1/117879/25/28831/6279/6329723bE66715a2f/5f099b8feca9e8cc.png';
12+
1013
export const navs: NavGroupConfig[] = [];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.index {
2+
height: 100%;
3+
width: 100%;
4+
5+
&__header {
6+
display: flex;
7+
align-items: center;
8+
padding: 0 34px;
9+
height: 117px;
10+
> image {
11+
width: 67px;
12+
height: 67px;
13+
margin-right: 18px;
14+
flex-shrink: 0;
15+
}
16+
&__info {
17+
display: flex;
18+
flex-direction: column;
19+
h1 {
20+
height: 48px;
21+
line-height: 48px;
22+
font-size: 34px;
23+
color: rgb(51 51 51 / 100%);
24+
font-weight: 500;
25+
}
26+
p {
27+
height: 18px;
28+
line-height: 18px;
29+
font-size: 12px;
30+
color: rgb(154 155 157 / 100%);
31+
}
32+
}
33+
}
34+
&__navs {
35+
background: #f7f8fa;
36+
border-radius: 30px 30px 0 0;
37+
overflow: hidden;
38+
padding: 30px 25px;
39+
}
40+
}
Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
import { Text, View } from '@tarojs/components';
2-
import { useLoad } from '@tarojs/taro';
1+
import { Image, View } from '@tarojs/components';
2+
import Taro from '@tarojs/taro';
3+
import { ArrowRight } from '@nutui/icons-react-taro';
4+
import { Cell, CellGroup } from '@nutui/nutui-react-taro';
5+
import { navs, NUT_UI_LOGO } from './constants';
6+
import styles from './index.module.scss';
37

4-
export default function Index() {
5-
useLoad(() => {
6-
console.log('Page loaded.');
7-
});
8+
async function navigateTo(group: string, path: string) {
9+
await Taro.navigateTo({ url: `/pages/${group}/${path}` });
10+
}
811

12+
export default function Index() {
913
return (
10-
<View className="index">
11-
<Text>Hello world!</Text>
14+
<View className={styles.index}>
15+
<View className={styles.index__header}>
16+
<Image src={NUT_UI_LOGO} />
17+
<View className={styles.index__header__info}>
18+
<h1>NutUI React</h1>
19+
<p>京东风格的轻量级小程序组件库 React 版</p>
20+
</View>
21+
</View>
22+
<View className={styles.index__navs}>
23+
{navs.map((group) => (
24+
<CellGroup key={group.path} title={group.name}>
25+
{group.children.map(({ name, path }) => {
26+
const onClick = () => navigateTo(group.path, path);
27+
return <Cell key={path} title={name} extra={<ArrowRight />} onClick={onClick} />;
28+
})}
29+
</CellGroup>
30+
))}
31+
</View>
1232
</View>
1333
);
1434
}

0 commit comments

Comments
 (0)