From ff407255c985ceabd30f665f131a5b1d75df96b2 Mon Sep 17 00:00:00 2001 From: zhangjiming Date: Mon, 7 Apr 2025 11:42:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=93=9D=E7=89=99=E8=BF=9E=E6=8E=A5=E5=90=8E?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Bluetooth.tsx | 8 +++++++- src/store/features/contextSlice.ts | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/pages/Bluetooth.tsx b/src/pages/Bluetooth.tsx index e212ff7..2e7f586 100644 --- a/src/pages/Bluetooth.tsx +++ b/src/pages/Bluetooth.tsx @@ -1,10 +1,12 @@ import { NavBar, SpinLoading, Toast } from 'antd-mobile'; import './Bluetooth.scss'; import { useEffect } from 'react'; -import { useAppSelector } from '../utils/hooks'; +import { useAppDispatch, useAppSelector } from '../utils/hooks'; import Bridge from '../utils/bridge'; +import { updateBleLinkStatus } from '../store/features/contextSlice'; export default function Bluetooth() { + const dispatch = useAppDispatch(); const contextState = useAppSelector((state) => state.context); useEffect(() => { @@ -22,6 +24,8 @@ export default function Bluetooth() { Bridge.connectPeripheral({ id }).then((res) => { if (!res.success) { Toast.show(res.message); + } else { + dispatch(updateBleLinkStatus({id, link: true})) } }); }; @@ -29,6 +33,8 @@ export default function Bluetooth() { Bridge.disconnectPeripheral().then((res) => { if (!res.success) { Toast.show(res.message); + } else { + dispatch(updateBleLinkStatus({id, link: false})) } }); }; diff --git a/src/store/features/contextSlice.ts b/src/store/features/contextSlice.ts index 4e71528..d46ddf2 100644 --- a/src/store/features/contextSlice.ts +++ b/src/store/features/contextSlice.ts @@ -100,6 +100,15 @@ export const contextSlice = createSlice({ state.bleList = action.payload; }, + updateBleLinkStatus: (state, action: PayloadAction<{ id: string; link: boolean }>) => { + state.bleList = state.bleList.map((ble) => { + if (ble.mac === action.payload.id) { + ble.linked = action.payload.link; + } + return ble; + }); + }, + updateSyncProgress: (state, action: PayloadAction) => { state.syncProgress = action.payload; }, @@ -118,6 +127,12 @@ export const contextSlice = createSlice({ }, }); -export const { updateOrg, updateDevice, updateRailTypeId, updateBleList, updateSyncProgress } = - contextSlice.actions; +export const { + updateOrg, + updateDevice, + updateRailTypeId, + updateBleList, + updateBleLinkStatus, + updateSyncProgress, +} = contextSlice.actions; export default contextSlice.reducer;