From 7e3ad80121bb0be5fed739ec0d2dec952a9415a1 Mon Sep 17 00:00:00 2001 From: Dawn_Ocean <1785590531@qq.com> Date: Tue, 23 Apr 2024 17:10:22 +0800 Subject: [PATCH] fix: memberDutyInfo api; dutyInfo card in MainPage --- .env.dev | 3 ++- doc/api.md | 18 +++++++++++++++--- mock/api.ts | 10 +++++++--- src/pages/index/DutyInfo.tsx | 14 +++++++------- src/pages/index/index.tsx | 10 +++++----- src/plain-text/common.ts | 5 ++++- src/service/changeDutyCount.ts | 2 +- src/service/conclude.ts | 2 ++ src/service/dutyInfo.ts | 17 +++++++++++++++-- src/service/memberDutyInfo.ts | 34 +++++++++++++++++++--------------- 10 files changed, 77 insertions(+), 38 deletions(-) diff --git a/.env.dev b/.env.dev index a42fc89..cc0b86f 100644 --- a/.env.dev +++ b/.env.dev @@ -1,3 +1,4 @@ # 配置文档参考 https://taro-docs.jd.com/docs/next/env-mode-config TARO_APP_ID="wx636eb7cf2b84f305" -TARO_APP_API="https://ate.zjueva.net" \ No newline at end of file +TARO_APP_API="https://ate.zjueva.net" +# TARO_APP_API="http://127.0.0.1:9527" \ No newline at end of file diff --git a/doc/api.md b/doc/api.md index 2c4f942..0f36e18 100644 --- a/doc/api.md +++ b/doc/api.md @@ -461,9 +461,14 @@ data: ```json { - "isInDuty": true, + "isInDuty": true, // 指示成员其当前是否在值班 "inDutyCnt": 3, - "currentDuty": "2" + "currentDuty": "others", + "place": "蓝田", // 只有当 currentDuty 为 others 时,place 才不为空 + "otherDutyStart": "2024-03-07T11:52:48.523303", // Timestamp + "otherDutyEnd": "2024-03-07T13:52:48.523303", + "offDutyReason": "", + "dutyRecoverTime": "" } ``` @@ -474,7 +479,12 @@ data: ```json { "isInDuty": false, - "offDutyReason": "学园维修", + "inDutyCnt": 0, + "currentDuty": "off", // "0" => 正常值班下班,"others" => 其他值班下班,"off" => 值班暂停 + "place": "", // 只有当 currentDuty 为 others 时,place 才不为空 + "otherDutyStart": "", + "otherDutyEnd": "", + "offDutyReason": "期中考试周", "dutyRecoverTime": "下周一" } ``` @@ -500,6 +510,8 @@ Request ```json { "token": "token_test", + "week": "2", + "shift": "3", "conclusion": "周四第三班,一人请假,共收两台电脑,均劝退已取回。由上一班交接两台电脑,其中一台维修成功已取回,一台仍在维修。" } ``` diff --git a/mock/api.ts b/mock/api.ts index 696f9f2..0d8364a 100644 --- a/mock/api.ts +++ b/mock/api.ts @@ -120,9 +120,13 @@ export default { success: true, data: { isInDuty: true, - inDutyCnt: 6, - currentDuty: '3', - place: '204', + inDutyCnt: 3, + currentDuty: 'others', + otherDutyStart: '2024-03-07T09:30:48.523303', + otherDutyEnd: '2024-03-07T13:30:48.523303', + place: '蓝田', + offDutyReason: '', + dutyRecoverTime: '', }, }, 'POST /member/askleave': { diff --git a/src/pages/index/DutyInfo.tsx b/src/pages/index/DutyInfo.tsx index 569f027..6a6db10 100644 --- a/src/pages/index/DutyInfo.tsx +++ b/src/pages/index/DutyInfo.tsx @@ -20,19 +20,19 @@ export class DutyData { } isInDuty: boolean; - inDutyCnt?: number; - currentDuty?: 'off' | '0' | '1' | '2' | '3' | 'others'; - otherDutyStart?: string; - otherDutyEnd?: string; - offDutyReason?: string; - dutyRecoverTime?: string; + inDutyCnt: number; + currentDuty: 'off' | '0' | '1' | '2' | '3' | 'others'; + otherDutyStart: string; + otherDutyEnd: string; + offDutyReason: string; + dutyRecoverTime: string; place: string; } class Card extends Component { props = { isInDuty: false, - place: '东三-204', + place: pt.get().common.place, }; render(): ReactNode { const inDuty = this.props.isInDuty; diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index e93da39..27bd490 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -51,7 +51,6 @@ interface MainPageState { fixList: Array; rs: RequestState; dutyData: DutyData; - inDutyCnt: number; dutyInfoCard: CardContent; stepInfoCard: CardContent; tipsInfoCard: CardContent; @@ -62,7 +61,6 @@ interface MainPageState { export default class MainPage extends Component<{}, MainPageState> { state = { dutyData: new DutyData(), - inDutyCnt: 0, dutyInfoCard: { title: '', note: '', @@ -91,7 +89,6 @@ export default class MainPage extends Component<{}, MainPageState> { const ptPage = wechatUser.getAccess() ? 'memberPage' : 'mainPage'; this.setState({ dutyData: new DutyData(), - inDutyCnt: 0, dutyInfoCard: { title: pt.get()[ptPage].cardTitle.dutyInfo, note: pt.get()[ptPage].cardTips.dutyInfo, @@ -130,7 +127,10 @@ export default class MainPage extends Component<{}, MainPageState> { handleCnt(inDutyCnt: number) { this.setState({ - inDutyCnt: inDutyCnt, + dutyData: { + ...this.state.dutyData, + inDutyCnt: inDutyCnt, + }, }); return inDutyCnt; } @@ -217,7 +217,7 @@ export default class MainPage extends Component<{}, MainPageState> { min={0} max={10} step={1} - value={this.state.inDutyCnt} + value={this.state.dutyData.inDutyCnt} onChange={this.handleCnt.bind(this)} /> diff --git a/src/plain-text/common.ts b/src/plain-text/common.ts index 827b04c..a3df5be 100644 --- a/src/plain-text/common.ts +++ b/src/plain-text/common.ts @@ -4,6 +4,7 @@ export interface CommonText { createdAtText(time: Moment): string; offDutyReason: string; place: string; + dutyRecoverTime: string; } export const commonTextZhCn: CommonText = { @@ -11,7 +12,8 @@ export const commonTextZhCn: CommonText = { return '创建于 ' + time.format('YYYY-MM-DD HH:mm'); }, offDutyReason: '正常值班下班', - place: '东三-204', + place: '204', + dutyRecoverTime: '明天 13:30', }; export const commonTextEnUs: CommonText = { @@ -20,4 +22,5 @@ export const commonTextEnUs: CommonText = { }, offDutyReason: 'Normal Shift', place: 'E3-204', + dutyRecoverTime: 'Tomorrow 13:30', }; diff --git a/src/service/changeDutyCount.ts b/src/service/changeDutyCount.ts index 7f55735..83b5880 100644 --- a/src/service/changeDutyCount.ts +++ b/src/service/changeDutyCount.ts @@ -15,7 +15,7 @@ export function changeDutyCnt(that: MainPage) { method: 'POST', data: { token: wechatUser.getToken(), - dutyCnt: that.state.inDutyCnt, + dutyCnt: that.state.dutyData.inDutyCnt, }, }) .then((res) => { diff --git a/src/service/conclude.ts b/src/service/conclude.ts index cf7c7e0..ab63fd4 100644 --- a/src/service/conclude.ts +++ b/src/service/conclude.ts @@ -14,6 +14,8 @@ export function conclude(that: ConclusionPage) { data: { token: wechatUser.getToken(), conclusion: that.state.conclusion, + week: (that.state.shift[0] + 1).toString(), + shift: (that.state.shift[1] + 1).toString(), }, }) .then((res) => { diff --git a/src/service/dutyInfo.ts b/src/service/dutyInfo.ts index 5220bee..c2daa29 100644 --- a/src/service/dutyInfo.ts +++ b/src/service/dutyInfo.ts @@ -25,14 +25,23 @@ export function getDutyInfo(that: MainPage) { rs: former.trans(true), dutyData: data, }); - if (data.currentDuty === '0') { + if (!data.isInDuty) { that.setState({ dutyData: { ...that.state.dutyData, - place: pt.get().common.place, offDutyReason: pt.get().common.offDutyReason, }, }); + if (data.currentDuty === '0') { + that.setState({ + dutyData: { + ...that.state.dutyData, + place: pt.get().common.place, + offDutyReason: pt.get().common.offDutyReason, + dutyRecoverTime: pt.get().common.dutyRecoverTime, + }, + }); + } } }) .catch((err) => { @@ -42,6 +51,10 @@ export function getDutyInfo(that: MainPage) { rs: former.trans(false), dutyData: { isInDuty: false, + inDutyCnt: 0, + currentDuty: '0', + otherDutyStart: '', + otherDutyEnd: '', offDutyReason: '获取失败!Network Error!', dutyRecoverTime: '获取失败!Network Error!', place: '204', diff --git a/src/service/memberDutyInfo.ts b/src/service/memberDutyInfo.ts index 74b35e7..0223930 100644 --- a/src/service/memberDutyInfo.ts +++ b/src/service/memberDutyInfo.ts @@ -1,6 +1,7 @@ import MainPage from '@/pages/index'; import Taro from '@tarojs/taro'; import wechatUser from '@/wechat'; +import pt from '@/plain-text'; import { getUrl } from '.'; export function getMemberDutyInfo(that: MainPage) { @@ -13,25 +14,24 @@ export function getMemberDutyInfo(that: MainPage) { }) .then((res) => { const data = res.data.data; - if (data.isInDuty) { + that.setState({ + dutyData: data, + }); + if (!data.isInDuty) { that.setState({ dutyData: { - isInDuty: data.isInDuty, - inDutyCnt: data.inDutyCnt, - currentDuty: data.currentDuty, - place: data.place, - }, - inDutyCnt: data.inDutyCnt, - }); - } else { - that.setState({ - dutyData: { - isInDuty: data.isInDuty, - offDutyReason: data.offDutyReason, - dutyRecoverTime: data.dutyRecoverTime, - place: data.place, + ...that.state.dutyData, + offDutyReason: pt.get().common.offDutyReason, }, }); + if (data.currentDuty === '0') { + that.setState({ + dutyData: { + ...that.state.dutyData, + place: pt.get().common.place, + }, + }); + } } }) .catch((err) => { @@ -39,6 +39,10 @@ export function getMemberDutyInfo(that: MainPage) { that.setState({ dutyData: { isInDuty: false, + inDutyCnt: 0, + currentDuty: '0', + otherDutyStart: '', + otherDutyEnd: '', offDutyReason: '获取失败!Network Error!', dutyRecoverTime: '获取失败!Network Error!', place: '204',