Browse Source

fix:系统配置还原

feature/0607-opt
guoapeng 4 months ago
parent
commit
7afaf80981
  1. 23
      src/App.tsx
  2. 112
      src/pages/system/Setting.tsx
  3. 51
      src/store/system/systemSlice.ts

23
src/App.tsx

@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import "./App.scss"; import "./App.scss";
import { Outlet, useNavigate, useLocation } from "react-router";
import { Outlet, useNavigate } from "react-router";
import { Layout, ConfigProvider, message} from "antd"; import { Layout, ConfigProvider, message} from "antd";
import { default as AppHeader } from "./components/Header"; import { default as AppHeader } from "./components/Header";
import { default as AppFooter } from "./components/Footer"; import { default as AppFooter } from "./components/Footer";
@ -15,22 +15,15 @@ import { updateDevice } from "./store/features/contextSlice";
import { getStatus, update } from "./services/ktj/org"; import { getStatus, update } from "./services/ktj/org";
import SyncData from "./components/syncData"; import SyncData from "./components/syncData";
import { sysSet } from "./services/user/system"; import { sysSet } from "./services/user/system";
import {
updateSystemAccountState,
updateSystemAllState,
updateSystemOrgState,
updateUploadServerUrlState
} from "./store/system/systemSlice";
import { updateSystemAccountState, updateSystemAllState, updateSystemOrgState } from "./store/system/systemSlice";
import { system } from "./types"; import { system } from "./types";
import Home from "./home";
const { Header, Footer, Sider, Content } = Layout; const { Header, Footer, Sider, Content } = Layout;
function App() { function App() {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation();
const isRootRoute = location.pathname === '/';
useEffect(() => { useEffect(() => {
//连接websocket //连接websocket
const wsClient = createWebSocket(sharedWsUrl); const wsClient = createWebSocket(sharedWsUrl);
@ -80,7 +73,7 @@ function App() {
},[]) },[])
useEffect(() => { useEffect(() => {
if (localStorage.getItem("user")) { if (localStorage.getItem("user")) {
// navigate("/measure/action", { replace: true }); // navigate("/measure/action", { replace: true });
} else { } else {
@ -97,7 +90,7 @@ function App() {
}) })
} }
const querySystemInfo = () => { const querySystemInfo = () => {
sysSet({}, "GET").then(res=>{ sysSet({}, "GET").then(res=>{
if(res.status === 0 && res.data && res.data.length){ if(res.status === 0 && res.data && res.data.length){
@ -110,11 +103,8 @@ function App() {
if(item.code === 'UPLOAD_USERNAME'){ if(item.code === 'UPLOAD_USERNAME'){
dispatch(updateSystemAccountState(item)) dispatch(updateSystemAccountState(item))
} }
if(item.code === 'UPLOAD_SERVER_URL'){
dispatch(updateUploadServerUrlState(item))
}
}) })
} }
}) })
} }
@ -149,7 +139,6 @@ function App() {
<AppHeader /> <AppHeader />
</Header> </Header>
<Content> <Content>
{/* {isRootRoute && <Home></Home>} */}
<Outlet /> <Outlet />
</Content> </Content>
<Footer style={footerStyle}> <Footer style={footerStyle}>

112
src/pages/system/Setting.tsx

@ -8,11 +8,7 @@ import { OrgItem } from '../../services/ktjTypes';
import {bleItem, child, GwdItem, orgCascaderType, systemItem} from './types'; import {bleItem, child, GwdItem, orgCascaderType, systemItem} from './types';
import { sysSet } from '../../services/user/system'; import { sysSet } from '../../services/user/system';
import { useAppDispatch, useAppSelector } from "../../utils/hooks"; import { useAppDispatch, useAppSelector } from "../../utils/hooks";
import {
updateSystemAccountState,
updateSystemOrgState,
updateUploadServerUrlState
} from '../../store/system/systemSlice';
import { updateSystemAccountState, updateSystemOrgState } from '../../store/system/systemSlice';
import {createWebSocket, sharedWsUrl} from "../../services/socket"; import {createWebSocket, sharedWsUrl} from "../../services/socket";
import {start, stop, disconnect, connect} from "../../services/ble/ble"; import {start, stop, disconnect, connect} from "../../services/ble/ble";
@ -31,15 +27,14 @@ export default function Setting(){
const [systemList, setSystemList] = useState<systemItem[]>([]) const [systemList, setSystemList] = useState<systemItem[]>([])
const [accountInfo, setAccountInfo] = useState<systemItem>({}) const [accountInfo, setAccountInfo] = useState<systemItem>({})
const [orgInfo, setOrgInfo] = useState<systemItem>({}) const [orgInfo, setOrgInfo] = useState<systemItem>({})
const [uploadServerUrl, setUploadServerUrl] = useState<systemItem>({})
const [orgValues, setOrgValues] = useState<string[]>([]) const [orgValues, setOrgValues] = useState<string[]>([])
const [bleList, setBleList] = useState<bleItem[]>([]) const [bleList, setBleList] = useState<bleItem[]>([])
// 创建 websocket 客户端 // 创建 websocket 客户端
const wsClient = createWebSocket(sharedWsUrl); const wsClient = createWebSocket(sharedWsUrl);
function querySettingData(){ function querySettingData(){
let systemInfo = systemState.systemInfo
setSystemList(systemInfo)
let systemInfo = systemState.systemInfo
setSystemList(systemInfo)
} }
@ -70,8 +65,6 @@ export default function Setting(){
value: cloneOrgItem.value value: cloneOrgItem.value
} }
setOrgInfo(orgItem) setOrgInfo(orgItem)
let systemInfo = systemState.systemInfo
setSystemList(systemInfo)
} }
}, [systemState.orgInfo]) }, [systemState.orgInfo])
@ -91,19 +84,6 @@ export default function Setting(){
useEffect(()=>{ useEffect(()=>{
if(systemState.uploadServerUrl){
const cloneUploadServerUrl = systemState.uploadServerUrl
let uploadServerUrl:systemItem = {
id: cloneUploadServerUrl.id,
name: cloneUploadServerUrl.name,
code: cloneUploadServerUrl.code,
value: cloneUploadServerUrl.value
}
setUploadServerUrl(uploadServerUrl)
}
}, [systemState.uploadServerUrl])
useEffect(()=>{
if(orgInfo && orgInfo.value){ if(orgInfo && orgInfo.value){
let orgIds:string[] = [] let orgIds:string[] = []
const values:child[] = JSON.parse(orgInfo.value) const values:child[] = JSON.parse(orgInfo.value)
@ -166,38 +146,9 @@ export default function Setting(){
}) })
} }
/**
*
* @param uploadServerUrlValue
*/
function onUploadServerUrlChange(uploadServerUrlValue:string){
const uploadServerUrlParams = {
code:"UPLOAD_SERVER_URL",
name:uploadServerUrl.name,
value:uploadServerUrlValue,
id:uploadServerUrl.id
}
sysSet(uploadServerUrlParams, "PUT").then(res=>{
if(res.status === 0){
dispatch(updateUploadServerUrlState(uploadServerUrlParams))
message.success("修改成功")
}
})
}
function onAccountChange(accountValue:string){ function onAccountChange(accountValue:string){
const accountParams = {
code:accountInfo.code,
name:accountInfo.name,
value:accountValue,
id:accountInfo.id
}
sysSet(accountParams, "PUT").then(res=>{
if(res.status === 0){
dispatch(updateSystemAccountState(accountParams))
message.success("修改成功")
}
})
newAccountInfo.name = accountInfo.name || '';
newAccountInfo.value = accountValue;
} }
function convertToCascaderData(data:OrgItem[]) { function convertToCascaderData(data:OrgItem[]) {
@ -214,8 +165,8 @@ export default function Setting(){
}; };
if (gwdItem.railDicList && gwdItem.railDicList.length > 0) { if (gwdItem.railDicList && gwdItem.railDicList.length > 0) {
newGwdItem.children = gwdItem.railDicList.map(railItem => ({ newGwdItem.children = gwdItem.railDicList.map(railItem => ({
value: railItem.key,
label: railItem.value || railItem.input
value: railItem.key,
label: railItem.value || railItem.input
})); }));
} }
return newGwdItem; return newGwdItem;
@ -322,29 +273,52 @@ export default function Setting(){
} }
}; };
const saveSet = (item:systemItem, value:string) => {
const params = {
id:item.id,
value
}
sysSet(params, "PUT").then(res=>{
})
}
const form = () =>{
return <Form
name="basic"
labelCol={{ span: 3, offset: 1 }}
wrapperCol={{ span: 16 }}
style={{ maxWidth: 600 }}
autoComplete="off"
>
{
systemList.map((item, index) => {
return <Form.Item
key={index}
label={item.name}
name={item.code}
>
{item.code === 'ORG' ?
<Cascader className='w-[300px]' key={orgValues.length} defaultValue={orgValues} options={KTJOrgList} onChange={onOrgChange} placeholder="请选择局段线" />
: <Input defaultValue={item.value} onBlur={(e) => saveSet(item, e.target.value)}/>}
</Form.Item>
})
}
</Form>
}
// @ts-ignore // @ts-ignore
return <><div className={'pr-2.5 pl-2.5 w-full h-full'}> return <><div className={'pr-2.5 pl-2.5 w-full h-full'}>
<div className={'h-full w-full bg-white p-10 rounded-2xl'}> <div className={'h-full w-full bg-white p-10 rounded-2xl'}>
<h1 className='text-[20px]'></h1> <h1 className='text-[20px]'></h1>
<section className='p-[20px]'> <section className='p-[20px]'>
<div>
<span></span>
<Cascader className='w-[300px]' key={orgValues.length} defaultValue={orgValues} options={KTJOrgList} onChange={onOrgChange} placeholder="请选择局段线" /></div>
<div className='mt-[10px]'>
<span> {accountInfo.name}</span>
<Input key={accountInfo.value} defaultValue={accountInfo.value} onBlur={(e)=>{onAccountChange(e.target.value)}} className='w-[300px]'></Input>
</div>
<div className='mt-[10px]'>
<span> {uploadServerUrl.name}</span>
<Input key={uploadServerUrl.value} defaultValue={uploadServerUrl.value} onBlur={(e)=>{onUploadServerUrlChange(e.target.value)}} className='w-[300px]'></Input>
</div>
{form()}
</section> </section>
<h1 className='text-[20px]'></h1> <h1 className='text-[20px]'></h1>
{connectionStatus()} {connectionStatus()}
</div> </div>
</div> </div>
</>
</>
} }

51
src/store/system/systemSlice.ts

@ -1,20 +1,14 @@
// counterSlice.ts 文件 // counterSlice.ts 文件
import { createSlice } from "@reduxjs/toolkit"; import { createSlice } from "@reduxjs/toolkit";
const initialState = { const initialState = {
systemInfo:[],
orgInfo:{
id:'',
name:'',
value:'',
code:''
},
accountInfo:{
id:'',
name:'',
value:'',
code:''
},
uploadServerUrl: {
systemInfo:[],
orgInfo:{
id:'',
name:'',
value:'',
code:''
},
accountInfo:{
id:'', id:'',
name:'', name:'',
value:'', value:'',
@ -23,23 +17,20 @@ const initialState = {
}; };
// 创建一个 Slice // 创建一个 Slice
export const systemStateSlice = createSlice({ export const systemStateSlice = createSlice({
name: "systemState",
initialState,
reducers: {
updateSystemAllState: (state, { payload }) => {
state.systemInfo = payload
},
updateSystemOrgState: (state, { payload }) => {
state.orgInfo = payload
},
name: "systemState",
initialState,
reducers: {
updateSystemAllState: (state, { payload }) => {
state.systemInfo = payload
},
updateSystemOrgState: (state, { payload }) => {
state.orgInfo = payload
},
updateSystemAccountState: (state, { payload }) => { updateSystemAccountState: (state, { payload }) => {
state.accountInfo = payload
},
updateUploadServerUrlState: (state, { payload }) => {
state.uploadServerUrl = payload
}
},
state.accountInfo = payload
},
},
}); });
export const {updateSystemAllState, updateSystemOrgState, updateSystemAccountState, updateUploadServerUrlState } = systemStateSlice.actions;
export const {updateSystemAllState, updateSystemOrgState, updateSystemAccountState } = systemStateSlice.actions;
// 默认导出 // 默认导出
export default systemStateSlice.reducer; export default systemStateSlice.reducer;
Loading…
Cancel
Save