Compare commits

..

2 Commits

Author SHA1 Message Date
FrozenArcher 7f84b72ddc fix prettier 2024-03-04 19:47:35 +08:00
FrozenArcher 08fbd58c61 add tab bar 2024-03-04 19:47:18 +08:00
9 changed files with 104 additions and 7 deletions

View File

@ -1,5 +1,5 @@
{
"printWidth": 120,
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,

View File

@ -3,7 +3,7 @@ export default defineAppConfig({
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'WeChat',
navigationBarTitleText: 'EVA Notify',
navigationBarTextStyle: 'black',
},
tabBar: {

View File

@ -0,0 +1,3 @@
export default {
component: true,
};

View File

@ -0,0 +1,3 @@
@import "~taro-ui/dist/style/components/tab-bar.scss";
@import "~taro-ui/dist/style/components/badge.scss";
@import "~taro-ui/dist/style/components/icon.scss";

View File

@ -0,0 +1,66 @@
import { Component, ReactNode } from 'react';
import { AtTabBar } from 'taro-ui';
import Taro from '@tarojs/taro';
import 'taro-ui/dist/style/index.scss';
import './index.scss';
const navList: Array<Taro.TabBarItem> = [
{
pagePath: '/pages/index/index',
text: '主页',
},
{
pagePath: '/pages/repair/repair',
text: '维修',
},
{
pagePath: '/pages/user/user',
text: '我的',
},
];
export default class Index extends Component {
state = {
selected: 0,
tabList: [
{
title: '主页',
iconType: 'home',
},
{
title: '维修',
iconType: 'settings',
},
{
title: '我的',
iconType: 'user',
},
],
};
handleClick(idx: number) {
this.switchTab(idx, navList[idx].pagePath);
}
switchTab(idx: number, url: string) {
this.setSelected(idx);
Taro.switchTab({ url });
}
setSelected(idx: number) {
this.setState({
selected: idx,
});
}
render(): ReactNode {
return (
<AtTabBar
fixed
tabList={this.state.tabList}
onClick={this.handleClick.bind(this)}
current={this.state.selected}
/>
);
}
}

View File

@ -1,4 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '首页',
usingComponents: {},
});

View File

@ -1,6 +1,7 @@
import { View, Text } from '@tarojs/components';
import { Component, ReactNode } from 'react';
import { AtButton } from 'taro-ui';
import Taro from '@tarojs/taro';
import type CustomTabBar from '../../custom-tab-bar';
import './index.scss';
class Index extends Component {
@ -8,14 +9,17 @@ class Index extends Component {
msg: 'Hello World!',
};
onReady() {
console.log('Index is ready');
// 以下是TabBar相关
pageCtx = Taro.getCurrentInstance().page;
componentDidShow() {
const tabbar = Taro.getTabBar<CustomTabBar>(this.pageCtx);
tabbar?.setSelected(0);
}
// 以上是TabBar相关
render(): ReactNode {
return (
<View>
<AtButton type='primary' size='normal'></AtButton>
<Text>{this.state.msg}</Text>
</View>
);

View File

@ -1,7 +1,18 @@
import { View, Text } from '@tarojs/components';
import { Component, ReactNode } from 'react';
import Taro from '@tarojs/taro';
import type CustomTabBar from '../../custom-tab-bar';
import './repair.scss';
export default class RepairPage extends Component {
// 以下是TabBar相关
pageCtx = Taro.getCurrentInstance().page;
componentDidShow() {
const tabbar = Taro.getTabBar<CustomTabBar>(this.pageCtx);
tabbar?.setSelected(1);
}
// 以上是TabBar相关
render(): ReactNode {
return (
<View>

View File

@ -1,7 +1,18 @@
import { View, Text } from '@tarojs/components';
import { Component, ReactNode } from 'react';
import Taro from '@tarojs/taro';
import type CustomTabBar from '../../custom-tab-bar';
import './user.scss';
export default class UserPage extends Component {
// 以下是TabBar相关
pageCtx = Taro.getCurrentInstance().page;
componentDidShow() {
const tabbar = Taro.getTabBar<CustomTabBar>(this.pageCtx);
tabbar?.setSelected(2);
}
// 以上是TabBar相关
render(): ReactNode {
return (
<View>