dutycard add data

yhy
FrozenArcher 2024-03-06 15:13:35 +08:00
parent 20b9016f51
commit ff880de466
1 changed files with 53 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import { View, Text } from '@tarojs/components'; import { View } from '@tarojs/components';
import { Component, ReactNode } from 'react'; import { Component, ReactNode } from 'react';
import Taro from '@tarojs/taro'; import Taro from '@tarojs/taro';
import { AtCard, AtTimeline, AtAccordion } from 'taro-ui'; import { AtCard, AtTimeline, AtAccordion } from 'taro-ui';
@ -11,19 +11,37 @@ interface CardContent {
title: string; title: string;
note: string; note: string;
extra: JSX.Element | string; extra: JSX.Element | string;
content: JSX.Element; content: () => JSX.Element;
} }
function mainPageCard(c: CardContent): JSX.Element { function mainPageCard(c: CardContent): JSX.Element {
return ( return (
<View style={{ marginTop: 10 }}> <View style={{ marginTop: 10 }}>
<AtCard note={c.note} extra={c.extra} title={c.title}> <AtCard note={c.note} extra={c.extra} title={c.title}>
{c.content} {c.content()}
</AtCard> </AtCard>
</View> </View>
); );
} }
type DutyState = 'off' | '1' | '2' | '3';
class DutyData {
constructor() {
this.isInDuty = false;
this.inDutyCnt = 3;
this.currentDuty = '2';
this.offDutyReason = '学园维修';
this.dutyRecoverTime = '下周一';
}
isInDuty: boolean;
inDutyCnt: number;
currentDuty: DutyState;
offDutyReason: string;
dutyRecoverTime: string;
}
class ExpandItem extends Component { class ExpandItem extends Component {
state = { state = {
open: false, open: false,
@ -53,13 +71,39 @@ class ExpandItem extends Component {
} }
class DutyInfo extends Component { class DutyInfo extends Component {
render(): ReactNode { props = {
data: new DutyData(),
};
offDutyContent(): ReactNode {
const data = this.props.data;
return ( return (
<View> <View>
<Text>x</Text> <View></View>
<View>{data.offDutyReason}</View>
<View>{data.dutyRecoverTime}</View>
</View> </View>
); );
} }
inDutyContent(): ReactNode {
const data = this.props.data;
return (
<View>
<View></View>
<View> {data.currentDuty}</View>
<View>{data.inDutyCnt}</View>
</View>
);
}
render(): ReactNode {
if (this.props.data.isInDuty) {
return this.inDutyContent();
} else {
return this.offDutyContent();
}
}
} }
class StepInfo extends Component { class StepInfo extends Component {
@ -84,23 +128,24 @@ class TipsInfo extends Component {
export default class Index extends Component { export default class Index extends Component {
state = { state = {
dutyData: new DutyData(),
dutyInfoCard: { dutyInfoCard: {
title: pt.get().mainPage.cardTitle.dutyInfo, title: pt.get().mainPage.cardTitle.dutyInfo,
note: 'Tips', note: 'Tips',
extra: '额外信息', extra: '额外信息',
content: <DutyInfo />, content: () => <DutyInfo data={this.state.dutyData} />,
}, },
stepInfoCard: { stepInfoCard: {
title: pt.get().mainPage.cardTitle.stepInfo, title: pt.get().mainPage.cardTitle.stepInfo,
note: 'Tips 请在20:30以前取走自己的物品哦', note: 'Tips 请在20:30以前取走自己的物品哦',
extra: '额外信息', extra: '额外信息',
content: <StepInfo />, content: () => <StepInfo />,
}, },
tipsInfoCard: { tipsInfoCard: {
title: pt.get().mainPage.cardTitle.tipsInfo, title: pt.get().mainPage.cardTitle.tipsInfo,
note: 'Tips', note: 'Tips',
extra: '额外信息', extra: '额外信息',
content: <TipsInfo />, content: () => <TipsInfo />,
}, },
}; };