|
|
@ -8,6 +8,7 @@ import { useAppDispatch, useAppSelector } from "../../utils/hooks"; |
|
|
|
import { updateSystemAccountState, updateSystemOrgState } from '../../store/system/systemSlice'; |
|
|
|
import {createWebSocket, sharedWsUrl} from "../../services/socket"; |
|
|
|
import {start, stop, disconnect, connect} from "../../services/ble/ble"; |
|
|
|
import {JointContent} from "antd/es/message/interface"; |
|
|
|
export default function Setting(){ |
|
|
|
useEffect(()=>{ |
|
|
|
queryRailData() |
|
|
@ -39,7 +40,12 @@ export default function Setting(){ |
|
|
|
// @ts-ignore
|
|
|
|
if (data.messageType === "STATE" && data.path === "/api/ble/ble-list") { |
|
|
|
// @ts-ignore
|
|
|
|
setBleList(data.data) |
|
|
|
setBleList(data.data.map(item => { |
|
|
|
return { |
|
|
|
...item, |
|
|
|
loading: item.address === connecting, |
|
|
|
} |
|
|
|
})) |
|
|
|
} |
|
|
|
}); |
|
|
|
wsClient.connect(); |
|
|
@ -178,13 +184,31 @@ export default function Setting(){ |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
let connecting = '' |
|
|
|
|
|
|
|
function bleConnect(address: string) { |
|
|
|
setBleList(bleList.map(item => { |
|
|
|
if (item.address === address) { |
|
|
|
item.loading = true |
|
|
|
} |
|
|
|
return item |
|
|
|
})) |
|
|
|
connecting = address; |
|
|
|
connect(address).then((res) => { |
|
|
|
if (res.status !== 0) { |
|
|
|
message.error(res.data.info); |
|
|
|
// @ts-ignore
|
|
|
|
message.error(res.data?.info || res.message) |
|
|
|
return |
|
|
|
} |
|
|
|
message.success('蓝牙连接成功') |
|
|
|
}).finally(() => { |
|
|
|
setBleList(bleList.map(item => { |
|
|
|
if (item.address === address) { |
|
|
|
item.loading = false |
|
|
|
} |
|
|
|
return item |
|
|
|
})) |
|
|
|
connecting = ''; |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
@ -207,7 +231,7 @@ export default function Setting(){ |
|
|
|
<p className={'text-[12px] text-gray-400'}>{item.address}</p> |
|
|
|
</p> |
|
|
|
{ |
|
|
|
item.connect ? <p className={'text-[12px] text-gray-400'}>已连接</p> : <Button type={'primary'} onClick={() =>bleConnect(item.address)}>连接</Button> |
|
|
|
item.connect ? <p className={'text-[12px] text-gray-400'}>已连接</p> : <Button loading={item.loading} type={'primary'} onClick={() =>bleConnect(item.address)}>连接</Button> |
|
|
|
} |
|
|
|
|
|
|
|
</div> |
|
|
|