|
@ -1,5 +1,11 @@ |
|
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; |
|
|
|
|
|
import { BleList, PeripheralStatus, SyncItemFinish, SyncProgress } from '../../services/mobileWsType'; |
|
|
|
|
|
|
|
|
import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit'; |
|
|
|
|
|
import { |
|
|
|
|
|
BleList, |
|
|
|
|
|
PeripheralStatus, |
|
|
|
|
|
SyncItemFinish, |
|
|
|
|
|
SyncProgress, |
|
|
|
|
|
} from '../../services/mobileWsType'; |
|
|
|
|
|
import Bridge from '../../utils/bridge'; |
|
|
|
|
|
|
|
|
interface ContextState { |
|
|
interface ContextState { |
|
|
device: PeripheralStatus['data']; |
|
|
device: PeripheralStatus['data']; |
|
@ -8,9 +14,13 @@ interface ContextState { |
|
|
currGWDCode: string; // 工务段
|
|
|
currGWDCode: string; // 工务段
|
|
|
currXMCode: string; // 线名
|
|
|
currXMCode: string; // 线名
|
|
|
|
|
|
|
|
|
bleList: BleList["data"]; |
|
|
|
|
|
syncProgress: SyncProgress["data"]; |
|
|
|
|
|
syncItems: Array<SyncItemFinish["data"]> |
|
|
|
|
|
|
|
|
bleList: BleList['data']; |
|
|
|
|
|
syncProgress: SyncProgress['data']; |
|
|
|
|
|
syncItems: Array<SyncItemFinish['data']>; |
|
|
|
|
|
|
|
|
|
|
|
setting: { |
|
|
|
|
|
server: string; |
|
|
|
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const orgGwdXmStr = localStorage.getItem('org_gwd_xm'); |
|
|
const orgGwdXmStr = localStorage.getItem('org_gwd_xm'); |
|
@ -41,9 +51,27 @@ const initialState: ContextState = { |
|
|
total: 0, |
|
|
total: 0, |
|
|
finish: true, |
|
|
finish: true, |
|
|
}, |
|
|
}, |
|
|
syncItems:[] |
|
|
|
|
|
|
|
|
syncItems: [], |
|
|
|
|
|
|
|
|
|
|
|
setting: { |
|
|
|
|
|
server: '', |
|
|
|
|
|
}, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export const fetchConfig = createAsyncThunk('context/fetchConfig', async () => { |
|
|
|
|
|
const conf = await Bridge.getConfig(); |
|
|
|
|
|
return conf.success ? conf.data : null; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
export const saveConfig = createAsyncThunk( |
|
|
|
|
|
'context/saveConfig', |
|
|
|
|
|
async (param: { server: string }, thunkAPI) => { |
|
|
|
|
|
const res = await Bridge.saveConfig(param); |
|
|
|
|
|
res.success && thunkAPI.dispatch(fetchConfig()); |
|
|
|
|
|
return res |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
export const contextSlice = createSlice({ |
|
|
export const contextSlice = createSlice({ |
|
|
name: 'context', |
|
|
name: 'context', |
|
|
initialState, |
|
|
initialState, |
|
@ -52,7 +80,7 @@ export const contextSlice = createSlice({ |
|
|
state.currOrgCode = action.payload[0]; |
|
|
state.currOrgCode = action.payload[0]; |
|
|
state.currGWDCode = action.payload[1]; |
|
|
state.currGWDCode = action.payload[1]; |
|
|
state.currXMCode = action.payload[2]; |
|
|
state.currXMCode = action.payload[2]; |
|
|
localStorage.setItem('org_gwd_xm', action.payload.join(',')) |
|
|
|
|
|
|
|
|
localStorage.setItem('org_gwd_xm', action.payload.join(',')); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
updateDevice: (state, action: PayloadAction<PeripheralStatus['data']>) => { |
|
|
updateDevice: (state, action: PayloadAction<PeripheralStatus['data']>) => { |
|
@ -63,16 +91,23 @@ export const contextSlice = createSlice({ |
|
|
state.currRailTypeId = action.payload; |
|
|
state.currRailTypeId = action.payload; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
updateBleList:(state, action: PayloadAction<BleList["data"]>) => { |
|
|
|
|
|
state.bleList = action.payload |
|
|
|
|
|
|
|
|
updateBleList: (state, action: PayloadAction<BleList['data']>) => { |
|
|
|
|
|
state.bleList = action.payload; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
updateSyncProgress: (state, action: PayloadAction<SyncProgress["data"]>) => { |
|
|
|
|
|
|
|
|
updateSyncProgress: (state, action: PayloadAction<SyncProgress['data']>) => { |
|
|
state.syncProgress = action.payload; |
|
|
state.syncProgress = action.payload; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
extraReducers: (builder) => { |
|
|
|
|
|
builder.addCase(fetchConfig.fulfilled, (state, action) => { |
|
|
|
|
|
if (action.payload) { |
|
|
|
|
|
state.setting = action.payload; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
export const { updateOrg, updateDevice, updateRailTypeId, updateBleList, updateSyncProgress } = contextSlice.actions; |
|
|
|
|
|
|
|
|
export const { updateOrg, updateDevice, updateRailTypeId, updateBleList, updateSyncProgress } = |
|
|
|
|
|
contextSlice.actions; |
|
|
export default contextSlice.reducer; |
|
|
export default contextSlice.reducer; |