From ed4071aa8603db94a15a40ffc9d13c3778c777b3 Mon Sep 17 00:00:00 2001 From: zhangjiming Date: Thu, 3 Apr 2025 22:06:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E9=87=8F=E8=AE=B0=E5=BD=95mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/MeasureGroups.tsx | 10 +-- src/pages/MeasurementList.tsx | 85 ++++++++++++++----- src/utils/bridge.ts | 99 +++++++++++++--------- src/utils/constant.ts | 178 --------------------------------------- 4 files changed, 128 insertions(+), 244 deletions(-) diff --git a/src/components/MeasureGroups.tsx b/src/components/MeasureGroups.tsx index 9ef02ca..30561c2 100644 --- a/src/components/MeasureGroups.tsx +++ b/src/components/MeasureGroups.tsx @@ -14,7 +14,7 @@ export default function MeasureGroups({ onGroupSelect, selectedIds, }: { - dataList: Array<{ groupName: string; list: Measurement[] }>; + dataList: Array<{ date: string; records: Measurement[] }>; editMode: boolean; hasMore: boolean; loadMore: () => Promise; @@ -31,15 +31,15 @@ export default function MeasureGroups({ {dataList.length > 0 ? ( <> {dataList.map((group, idx) => ( -
+
item.id))} + selected={isSubset(group.records.map((item) => item.id))} onGroupSelect={() => onGroupSelect(idx)} /> - {group.list.map((item) => ( + {group.records.map((item) => ( ([]); + const [noMore, setNoMore] = useState(false); const [editMode, setEditMode] = useState(false); const [selectedIds, setSelectedIds] = useState([]); - async function loadMoreRecords() {} + + const loadData = useCallback(() => { + Bridge.getRecordList({ pageNum: 1, size: PAGE_SIZE }).then((res) => { + if (res.success) { + setDataList(res.data.list); + setNoMore(res.data.list.length < PAGE_SIZE); + } else { + Toast.show(res.message); + } + }); + }, []); + + async function loadMoreData() { + const pageNum = Math.floor(dataList.length / PAGE_SIZE); + const res = await Bridge.getRecordList({ pageNum: pageNum + 1, size: PAGE_SIZE }); + if (res.success) { + setDataList((list) => list.concat(res.data.list)); + setNoMore(res.data.list.length < PAGE_SIZE); + } else { + Toast.show(res.message); + } + } + + useEffect(() => { + loadData(); + }, [loadData]); const onItemSelect = (groupIdx: number, id: number) => { if (selectedIds.includes(id)) { @@ -26,7 +52,7 @@ export default function MeasurementList() { }; const onGroupSelect = (groupIdx: number) => { - const ids = dataList[groupIdx].list.map((item) => item.id); + const ids = dataList[groupIdx].records.map((item) => item.id); if (R.intersection(selectedIds, ids).length === ids.length) { setSelectedIds(R.difference(selectedIds, ids)); } else { @@ -34,17 +60,30 @@ export default function MeasurementList() { } }; - const onUploadClick = () => { - navigate("/measure/upload") - } + const onUploadClick = async () => { + const res = await Bridge.uploadRecords({ ids: selectedIds }); + if (res.success) { + navigate('/measure/upload'); + } else { + Toast.show(res.message); + } + }; + + const onDeleteClick = async () => { + const res = await Bridge.deleteRecords({ ids: selectedIds }); + if (res.success) { + setSelectedIds([]); + setEditMode(false); + loadData(); + } else { + Toast.show(res.message); + } + }; const right = ( -
- navigate("/measure/search")} /> - setEditMode(!editMode)}/> +
+ navigate('/measure/search')} /> + setEditMode(!editMode)} />
); @@ -61,8 +100,8 @@ export default function MeasurementList() { - - diff --git a/src/utils/bridge.ts b/src/utils/bridge.ts index 3097ab0..e909715 100644 --- a/src/utils/bridge.ts +++ b/src/utils/bridge.ts @@ -200,21 +200,6 @@ export default class Bridge { } } - static uploadRecords(param: { ids: number[] }) { - if (appWebview) { - return new Promise((resolve) => { - const res = window.SyncBridgeJS.call('uploadRecords', JSON.stringify(param)); - resolve(JSON.parse(res)); - }); - } else { - return httpRequest({ - url: '/api/mobile/uploadRecords', - method: 'POST', - params: param, - }); - } - } - static scanPeripherals() { return httpRequest({ url: '/api/ble/list/start', @@ -258,45 +243,75 @@ export default class Bridge { }); } static getSyncTaskList(params: { pageNum: number; size: number }) { - return httpRequest>({ - url: '/api/sync/list', - method: "POST", - params - }) + return httpRequest>({ + url: '/api/sync/list', + method: 'POST', + params, + }); } - static addSyncTask(params: {ids: number[]}) { + static addSyncTask(params: { ids: number[] }) { return httpRequest({ - url: '/api/sync/add', - method: "POST", - params - }) + url: '/api/sync/add', + method: 'POST', + params, + }); } static getSyncProcess() { - return httpRequest>({ - url: '/api/sync/progress', - method: "POST", - params:{} - }) + return httpRequest>({ + url: '/api/sync/progress', + method: 'POST', + params: {}, + }); } static clearSyncList() { return httpRequest({ - url: '/api/sync/empty-all', - method: "POST", - params:{} - }) + url: '/api/sync/empty-all', + method: 'POST', + params: {}, + }); } static clearFinishedSync() { return httpRequest({ - url: '/api/sync/empty-finish', - method: "POST", - params:{} - }) + url: '/api/sync/empty-finish', + method: 'POST', + params: {}, + }); } static retryFailureSync() { return httpRequest({ - url: '/api/sync/re-fail', - method: "POST", - params:{} - }) + url: '/api/sync/re-fail', + method: 'POST', + params: {}, + }); + } + static getRecordList(params: { pageNum: number; size: number }) { + return httpRequest }>>( + { + url: '/api/record/list', + method: 'POST', + params, + } + ); + } + static getRecordDetail(params: { id: number }) { + return httpRequest>({ + url: '/api/record/detail', + method: 'POST', + params, + }); + } + static deleteRecords(params: { ids: number[] }) { + return httpRequest({ + url: '/api/record/delete', + method: 'POST', + params, + }); + } + static uploadRecords(params: { ids: number[] }) { + return httpRequest({ + url: '/api/sync/add', + method: 'POST', + params, + }); } } diff --git a/src/utils/constant.ts b/src/utils/constant.ts index e206347..457dfcf 100644 --- a/src/utils/constant.ts +++ b/src/utils/constant.ts @@ -1,4 +1,3 @@ -import { Measurement } from '../services/apiTypes'; export const rail6001 = { id: 1, @@ -1676,180 +1675,3 @@ export const railTypes = [ name: '43轨', }, ]; - -export const bureauList = [ - { - id: 1, - name: '北京铁路局', - }, - { - id: 2, - name: '南京铁路局', - }, - { - id: 3, - name: '上海铁路局', - }, - { - id: 4, - name: '广州铁路局', - }, -]; - -export const lineList = [ - { - id: 1, - name: '京沪线', - }, - { - id: 2, - name: '京九线', - }, - { - id: 3, - name: '陇海线', - }, - { - id: 4, - name: '京广线', - }, -]; - -export const sectionList = [ - { - id: 1, - name: '路段一', - }, - { - id: 2, - name: '路段二', - }, - { - id: 3, - name: '路段三', - }, - { - id: 4, - name: '路段四', - }, -]; - -// export const dataListFlat: Measurement[] = [ -// { -// id: 1, -// name: '测量名称1', -// createAt: '2025-03-02 10:20', -// line: '京沪线', -// section: 'A段', -// direction: '上行', -// railId: 2, -// leftPoints: '[]', -// rightPoints: '[]', -// bureau: '北京铁路局', -// upload: false, -// }, -// { -// id: 2, -// name: '测量名称2', -// createAt: '2025-03-02 12:22', -// line: '京沪线', -// section: 'B段', -// direction: '下行', -// railId: 2, -// leftPoints: '[]', -// rightPoints: '[]', -// bureau: '北京铁路局', -// upload: false, -// }, -// { -// id: 3, -// name: '测量名称3', -// createAt: '2025-03-02 12:20', -// line: '京沪线', -// section: 'C段', -// direction: '上行', -// railId: 2, -// leftPoints: '[]', -// rightPoints: '[]', -// bureau: '北京铁路局', -// upload: false, -// }, -// ]; - -export const dataList: Array<{ groupName: string; list: Measurement[] }> = [ -// { -// groupName: '2025-03-02', -// list: [ -// { -// id: 1, -// name: '测量名称1', -// createAt: '2025-03-02 10:20', -// line: '京沪线', -// section: 'A段', -// direction: '上行', -// railId: 2, -// leftPoints: '[]', -// rightPoints: '[]', -// bureau: '北京铁路局', -// upload: false, -// }, -// { -// id: 2, -// name: '测量名称2', -// createAt: '2025-03-02 12:22', -// line: '京沪线', -// section: 'B段', -// direction: '下行', -// railId: 2, -// leftPoints: '[]', -// rightPoints: '[]', -// bureau: '北京铁路局', -// upload: false, -// }, -// { -// id: 3, -// name: '测量名称3', -// createAt: '2025-03-02 12:20', -// line: '京沪线', -// section: 'C段', -// direction: '上行', -// railId: 2, -// leftPoints: '[]', -// rightPoints: '[]', -// bureau: '北京铁路局', -// upload: false, -// }, -// ], -// }, -// { -// groupName: '2025-02-01', -// list: [ -// { -// id: 4, -// name: '测量名称2', -// createAt: '2025-03-02 10:20', -// line: '京沪线', -// section: 'D段', -// direction: '下行', -// railId: 2, -// leftPoints: '[]', -// rightPoints: '[]', -// bureau: '北京铁路局', -// upload: false, -// }, -// { -// id: 5, -// name: '测量名称2', -// createAt: '2025-03-02 10:20', -// line: '京沪线', -// section: 'E段', -// direction: '下行', -// railId: 2, -// leftPoints: '[]', -// rightPoints: '[]', -// bureau: '北京铁路局', -// upload: false, -// }, -// ], -// }, -];