diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index f001c83..04f38fb 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -5,6 +5,7 @@ import { AtCard, AtAccordion } from 'taro-ui'; import type CustomTabBar from '@/custom-tab-bar'; import PageFooter from '@/components/PageFooter/PageFooter'; import pt from '@/plain-text'; +import { getUrl } from '@/service'; import './index.scss'; import TitleCard from './TitleCard'; import { DutyInfo, DutyData } from './DutyInfo'; @@ -78,6 +79,46 @@ export default class Index extends Component { }, }; + componentDidMount(): void { + Taro.request({ + 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相关 pageCtx = Taro.getCurrentInstance().page; componentDidShow() {