Browse Source

fix:系统配置还原

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

17
src/App.tsx

@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";
import "./App.scss";
import { Outlet, useNavigate, useLocation } from "react-router";
import { Outlet, useNavigate } from "react-router";
import { Layout, ConfigProvider, message} from "antd";
import { default as AppHeader } from "./components/Header";
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 SyncData from "./components/syncData";
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 Home from "./home";
const { Header, Footer, Sider, Content } = Layout;
function App() {
const dispatch = useAppDispatch();
const navigate = useNavigate();
const location = useLocation();
const isRootRoute = location.pathname === '/';
useEffect(() => {
//连接websocket
const wsClient = createWebSocket(sharedWsUrl);
@ -110,9 +103,6 @@ function App() {
if(item.code === 'UPLOAD_USERNAME'){
dispatch(updateSystemAccountState(item))
}
if(item.code === 'UPLOAD_SERVER_URL'){
dispatch(updateUploadServerUrlState(item))
}
})
}
@ -149,7 +139,6 @@ function App() {
<AppHeader />
</Header>
<Content>
{/* {isRootRoute && <Home></Home>} */}
<Outlet />
</Content>
<Footer style={footerStyle}>

102
src/pages/system/Setting.tsx

@ -8,11 +8,7 @@ import { OrgItem } from '../../services/ktjTypes';
import {bleItem, child, GwdItem, orgCascaderType, systemItem} from './types';
import { sysSet } from '../../services/user/system';
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 {start, stop, disconnect, connect} from "../../services/ble/ble";
@ -31,7 +27,6 @@ export default function Setting(){
const [systemList, setSystemList] = useState<systemItem[]>([])
const [accountInfo, setAccountInfo] = useState<systemItem>({})
const [orgInfo, setOrgInfo] = useState<systemItem>({})
const [uploadServerUrl, setUploadServerUrl] = useState<systemItem>({})
const [orgValues, setOrgValues] = useState<string[]>([])
const [bleList, setBleList] = useState<bleItem[]>([])
@ -70,8 +65,6 @@ export default function Setting(){
value: cloneOrgItem.value
}
setOrgInfo(orgItem)
let systemInfo = systemState.systemInfo
setSystemList(systemInfo)
}
}, [systemState.orgInfo])
@ -91,19 +84,6 @@ export default function Setting(){
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){
let orgIds:string[] = []
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){
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[]) {
@ -322,24 +273,47 @@ 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
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'}>
<h1 className='text-[20px]'></h1>
<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>
<h1 className='text-[20px]'></h1>
{connectionStatus()}

11
src/store/system/systemSlice.ts

@ -13,12 +13,6 @@ const initialState = {
name:'',
value:'',
code:''
},
uploadServerUrl: {
id:'',
name:'',
value:'',
code:''
}
};
// 创建一个 Slice
@ -35,11 +29,8 @@ export const systemStateSlice = createSlice({
updateSystemAccountState: (state, { payload }) => {
state.accountInfo = payload
},
updateUploadServerUrlState: (state, { payload }) => {
state.uploadServerUrl = payload
}
},
});
export const {updateSystemAllState, updateSystemOrgState, updateSystemAccountState, updateUploadServerUrlState } = systemStateSlice.actions;
export const {updateSystemAllState, updateSystemOrgState, updateSystemAccountState } = systemStateSlice.actions;
// 默认导出
export default systemStateSlice.reducer;
Loading…
Cancel
Save