add request to index page

yhy
Dawn_Ocean 2024-03-11 21:27:11 +08:00
parent afdedea344
commit 7aaad7563f
1 changed files with 41 additions and 0 deletions

View File

@ -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() {