From 8c2e91774491b61cc84d6c2e75ec243892ad8eab Mon Sep 17 00:00:00 2001 From: zhangjiming Date: Mon, 7 Apr 2025 16:25:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=93=9D=E7=89=99=E5=8F=8A=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 6 +++--- src/pages/Bluetooth.tsx | 10 +++++----- src/services/mobileWsType.ts | 14 ++++++-------- src/store/features/contextSlice.ts | 4 ++-- src/store/features/measureSlice.ts | 3 ++- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8c5bf03..88309a9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -13,10 +13,9 @@ import icon_4_u from './assets/tabIcon/icon_tab4_u.svg'; import { appWebview, bridgeOb, emitBridgeEvent, registerBridgeFunc } from './utils/bridge'; import { useAppDispatch } from './utils/hooks'; import { addNewPoint, updateTaskState } from './store/features/measureSlice'; -import { DeviceStatus, TrackRecordSig } from './services/wsTypes'; import { updateBleList, updateDevice, updateSyncProgress } from './store/features/contextSlice'; import { createWebSocket, sharedWsUrl } from './services/socket'; -import { updateUploadStatus } from './store/features/historySlice'; +import { fetchRailTypes } from './store/features/baseData'; const BottomBar = () => { const navigate = useNavigate(); @@ -70,11 +69,12 @@ const BottomBar = () => { function App() { const dispatch = useAppDispatch(); + dispatch(fetchRailTypes()); useEffect(() => { const subscription = bridgeOb.subscribe((datagram) => { if (datagram.type === 'measure-event') { - dispatch(updateTaskState(datagram.data.event)); + dispatch(updateTaskState(datagram.data)); } else if (datagram.type === 'measure-point') { dispatch(addNewPoint(datagram.data)); } else if (datagram.type === 'peripheral-status') { diff --git a/src/pages/Bluetooth.tsx b/src/pages/Bluetooth.tsx index 2e7f586..cacffd3 100644 --- a/src/pages/Bluetooth.tsx +++ b/src/pages/Bluetooth.tsx @@ -20,21 +20,21 @@ export default function Bluetooth() { }; }, []); - const onConnect = (id: string) => { - Bridge.connectPeripheral({ id }).then((res) => { + const onConnect = (mac: string) => { + Bridge.connectPeripheral({ mac }).then((res) => { if (!res.success) { Toast.show(res.message); } else { - dispatch(updateBleLinkStatus({id, link: true})) + dispatch(updateBleLinkStatus({mac, link: true})) } }); }; - const onDisconnect = (id: string) => { + const onDisconnect = (mac: string) => { Bridge.disconnectPeripheral().then((res) => { if (!res.success) { Toast.show(res.message); } else { - dispatch(updateBleLinkStatus({id, link: false})) + dispatch(updateBleLinkStatus({mac, link: false})) } }); }; diff --git a/src/services/mobileWsType.ts b/src/services/mobileWsType.ts index 12346aa..94b5029 100644 --- a/src/services/mobileWsType.ts +++ b/src/services/mobileWsType.ts @@ -11,14 +11,12 @@ export type PeripheralStatus = { export type MeasureEvent = { type: 'measure-event'; - data: { - event: - | 'START_RECORD_LEFT' - | 'FINISH_RECORD_LEFT' - | 'START_RECORD_RIGHT' - | 'FINISH_RECORD_RIGHT' - | 'WRONG_SIDE'; - }; + data: + | 'START_RECORD_LEFT' + | 'FINISH_RECORD_LEFT' + | 'START_RECORD_RIGHT' + | 'FINISH_RECORD_RIGHT' + | 'WRONG_SIDE'; }; export type MeasurePoint = { diff --git a/src/store/features/contextSlice.ts b/src/store/features/contextSlice.ts index d46ddf2..a3c856d 100644 --- a/src/store/features/contextSlice.ts +++ b/src/store/features/contextSlice.ts @@ -100,9 +100,9 @@ export const contextSlice = createSlice({ state.bleList = action.payload; }, - updateBleLinkStatus: (state, action: PayloadAction<{ id: string; link: boolean }>) => { + updateBleLinkStatus: (state, action: PayloadAction<{ mac: string; link: boolean }>) => { state.bleList = state.bleList.map((ble) => { - if (ble.mac === action.payload.id) { + if (ble.mac === action.payload.mac) { ble.linked = action.payload.link; } return ble; diff --git a/src/store/features/measureSlice.ts b/src/store/features/measureSlice.ts index e86be54..e550537 100644 --- a/src/store/features/measureSlice.ts +++ b/src/store/features/measureSlice.ts @@ -18,7 +18,8 @@ function isLeftFinished(state: MeasureState) { if ( state.taskState === 'FINISH_RECORD_LEFT' || state.taskState === 'START_RECORD_RIGHT' || - state.taskState === 'FINISH_RECORD_RIGHT' + state.taskState === 'FINISH_RECORD_RIGHT' || + state.taskState === 'FINISH_RECORD' ) return true; return false;