refactor main page service
parent
2fd629d479
commit
dd56725575
|
|
@ -15,10 +15,10 @@ export class DutyData {
|
||||||
}
|
}
|
||||||
|
|
||||||
isInDuty: boolean;
|
isInDuty: boolean;
|
||||||
inDutyCnt: number;
|
inDutyCnt?: number;
|
||||||
currentDuty: 'off' | '1' | '2' | '3';
|
currentDuty?: 'off' | '1' | '2' | '3';
|
||||||
offDutyReason: string; // from backend
|
offDutyReason?: string;
|
||||||
dutyRecoverTime: string; // from backend
|
dutyRecoverTime?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Card extends Component {
|
class Card extends Component {
|
||||||
|
|
@ -73,8 +73,8 @@ export class DutyInfo extends Component {
|
||||||
<Card isInDuty={data.isInDuty} />
|
<Card isInDuty={data.isInDuty} />
|
||||||
<AtTimeline
|
<AtTimeline
|
||||||
items={[
|
items={[
|
||||||
{ title: od.reason(data.offDutyReason) },
|
{ title: od.reason(data.offDutyReason as string) },
|
||||||
{ title: od.recoverTime(data.dutyRecoverTime) },
|
{ title: od.recoverTime(data.dutyRecoverTime as string) },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
@ -89,8 +89,8 @@ export class DutyInfo extends Component {
|
||||||
<Card isInDuty={data.isInDuty} />
|
<Card isInDuty={data.isInDuty} />
|
||||||
<AtTimeline
|
<AtTimeline
|
||||||
items={[
|
items={[
|
||||||
{ title: id.currentDutyText(data.currentDuty) },
|
{ title: id.currentDutyText(data.currentDuty || 'off') },
|
||||||
{ title: id.inDutyCnt(data.inDutyCnt) },
|
{ title: id.inDutyCnt(data.inDutyCnt as number) },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { AtCard, AtAccordion } from 'taro-ui';
|
||||||
import type CustomTabBar from '@/custom-tab-bar';
|
import type CustomTabBar from '@/custom-tab-bar';
|
||||||
import PageFooter from '@/components/PageFooter/PageFooter';
|
import PageFooter from '@/components/PageFooter/PageFooter';
|
||||||
import pt from '@/plain-text';
|
import pt from '@/plain-text';
|
||||||
import { getUrl } from '@/service';
|
import { getDutyInfo } from '@/service/MainPage';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
import TitleCard from './TitleCard';
|
import TitleCard from './TitleCard';
|
||||||
import { DutyInfo, DutyData } from './DutyInfo';
|
import { DutyInfo, DutyData } from './DutyInfo';
|
||||||
|
|
@ -56,7 +56,15 @@ class ExpandItem extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Index extends Component {
|
interface MainPageState {
|
||||||
|
dutyData: DutyData;
|
||||||
|
dutyInfoCard: CardContent;
|
||||||
|
stepInfoCard: CardContent;
|
||||||
|
tipsInfoCard: CardContent;
|
||||||
|
//rs: RequestState;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class MainPage extends Component<{}, MainPageState> {
|
||||||
state = {
|
state = {
|
||||||
dutyData: new DutyData(),
|
dutyData: new DutyData(),
|
||||||
dutyInfoCard: {
|
dutyInfoCard: {
|
||||||
|
|
@ -77,46 +85,11 @@ export default class Index extends Component {
|
||||||
extra: '额外信息',
|
extra: '额外信息',
|
||||||
content: () => <TipsInfo />,
|
content: () => <TipsInfo />,
|
||||||
},
|
},
|
||||||
|
// rs: new RequestState(),
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount(): void {
|
componentDidMount(): void {
|
||||||
Taro.request({
|
getDutyInfo(this);
|
||||||
url: getUrl('/dutyinfo'),
|
|
||||||
method: 'GET',
|
|
||||||
data: {
|
|
||||||
token: 'token_test',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
const data = res.data.data;
|
|
||||||
if (data.isInDuty) {
|
|
||||||
this.setState({
|
|
||||||
dutyData: {
|
|
||||||
isInDuty: data.isInDuty,
|
|
||||||
inDutyCnt: data.inDutyCnt,
|
|
||||||
currentDuty: data.currentDuty,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.setState({
|
|
||||||
dutyData: {
|
|
||||||
isInDuty: data.isInDuty,
|
|
||||||
offDutyReason: data.offDutyReason,
|
|
||||||
dutyRecoverTime: data.dutyRecoverTime,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
this.setState({
|
|
||||||
dutyData: {
|
|
||||||
isInDuty: false,
|
|
||||||
offDutyReason: '获取失败!Network Error!',
|
|
||||||
dutyRecoverTime: '获取失败!Network Error!',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 以下是TabBar相关
|
// 以下是TabBar相关
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
import MainPage from '@/pages/index';
|
||||||
|
import Taro from '@tarojs/taro';
|
||||||
|
import { getUrl } from '.';
|
||||||
|
|
||||||
|
export function getDutyInfo(that: MainPage) {
|
||||||
|
Taro.request({
|
||||||
|
url: getUrl('/dutyinfo'),
|
||||||
|
method: 'GET',
|
||||||
|
data: {
|
||||||
|
token: 'token_test',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
const data = res.data.data;
|
||||||
|
if (data.isInDuty) {
|
||||||
|
that.setState({
|
||||||
|
dutyData: {
|
||||||
|
isInDuty: data.isInDuty,
|
||||||
|
inDutyCnt: data.inDutyCnt,
|
||||||
|
currentDuty: data.currentDuty,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
that.setState({
|
||||||
|
dutyData: {
|
||||||
|
isInDuty: data.isInDuty,
|
||||||
|
offDutyReason: data.offDutyReason,
|
||||||
|
dutyRecoverTime: data.dutyRecoverTime,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
that.setState({
|
||||||
|
dutyData: {
|
||||||
|
isInDuty: false,
|
||||||
|
offDutyReason: '获取失败!Network Error!',
|
||||||
|
dutyRecoverTime: '获取失败!Network Error!',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue