Browse Source

Merge branch 'master' of http://192.168.1.3:3000/zhangjiming/Outline

feat_upload_server_url_0416
LiLongLong 4 months ago
parent
commit
19d437b571
  1. 30
      src/pages/system/Setting.tsx
  2. 3
      src/pages/system/types.ts

30
src/pages/system/Setting.tsx

@ -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>

3
src/pages/system/types.ts

@ -25,6 +25,7 @@ export type systemItem = {
export type bleItem = {
"name": string;
"address": string;
"connect": boolean
"connect": boolean;
loading: boolean;
}
Loading…
Cancel
Save