Browse Source

优化

feature/0607-opt
LiLongLong 4 months ago
parent
commit
2abaf9385b
  1. 3
      .env
  2. 3
      .gitignore
  3. 4
      package-lock.json
  4. 2
      package.json
  5. 13
      src/App.tsx
  6. 59
      src/pages/system/Setting.tsx
  7. 53
      src/store/system/systemSlice.ts

3
.env

@ -1,2 +1 @@
REACT_APP_WS_URL=127.1.1.0:8080/ws
PORT= 3000
REACT_APP_WS_URL=192.168.1.127:8080/ws

3
.gitignore

@ -22,3 +22,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
*.zip
.idea
package-lock.json

4
package-lock.json

@ -48,6 +48,7 @@
"jest": "^27.4.3",
"jest-resolve": "^27.4.2",
"jest-watch-typeahead": "^1.0.0",
"konva": "^8.3.5",
"mini-css-extract-plugin": "^2.4.5",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-loader": "^6.2.1",
@ -12277,8 +12278,7 @@
"url": "https://github.com/sponsors/lavrton"
}
],
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/language-subtag-registry": {
"version": "0.3.23",

2
package.json

@ -2,7 +2,7 @@
"name": "outline",
"version": "0.1.0",
"private": true,
"proxy": "http://127.1.1.0:8080",
"proxy": "http://192.168.1.127:8080",
"dependencies": {
"@ant-design/icons": "^6.0.0",
"@babel/core": "^7.16.0",

13
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";
@ -17,15 +17,13 @@ import SyncData from "./components/syncData";
import { sysSet } from "./services/user/system";
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);
@ -75,7 +73,7 @@ function App() {
},[])
useEffect(() => {
if (localStorage.getItem("user")) {
// navigate("/measure/action", { replace: true });
} else {
@ -92,7 +90,7 @@ function App() {
})
}
const querySystemInfo = () => {
sysSet({}, "GET").then(res=>{
if(res.status === 0 && res.data && res.data.length){
@ -106,7 +104,7 @@ function App() {
dispatch(updateSystemAccountState(item))
}
})
}
})
}
@ -141,7 +139,6 @@ function App() {
<AppHeader />
</Header>
<Content>
{/* {isRootRoute && <Home></Home>} */}
<Outlet />
</Content>
<Footer style={footerStyle}>

59
src/pages/system/Setting.tsx

@ -8,7 +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, updateSystemAllState, updateSystemOrgState } 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";
@ -33,8 +33,8 @@ export default function Setting(){
// 创建 websocket 客户端
const wsClient = createWebSocket(sharedWsUrl);
function querySettingData(){
let systemInfo = systemState.systemInfo
setSystemList(systemInfo)
let systemInfo = systemState.systemInfo
setSystemList(systemInfo)
}
@ -65,8 +65,7 @@ export default function Setting(){
value: cloneOrgItem.value
}
setOrgInfo(orgItem)
let systemInfo = systemState.systemInfo
setSystemList(systemInfo)
querySettingData()
}
}, [systemState.orgInfo])
@ -81,6 +80,7 @@ export default function Setting(){
value: cloneAccountItem.value
}
setAccountInfo(accountInfo)
querySettingData()
}
}, [systemState.accountInfo])
@ -129,6 +129,30 @@ export default function Setting(){
}
}
let newAccountInfo = {
name:'',
value: ''
}
function onSaveAccount(){
const accountParams = {
code:"UPLOAD_USERNAME",
name:accountInfo.name,
value:newAccountInfo.value,
id:accountInfo.id
}
sysSet(accountParams, "PUT").then(res=>{
if(res.status === 0){
dispatch(updateSystemAccountState(accountParams))
message.success("修改成功")
}
})
}
function onAccountChange(accountValue:string){
newAccountInfo.name = accountInfo.name || '';
newAccountInfo.value = accountValue;
}
function convertToCascaderData(data:OrgItem[]) {
return data.map(item => {
const newItem:orgCascaderType = {
@ -143,8 +167,8 @@ export default function Setting(){
};
if (gwdItem.railDicList && gwdItem.railDicList.length > 0) {
newGwdItem.children = gwdItem.railDicList.map(railItem => ({
value: railItem.key,
label: railItem.value || railItem.input
value: railItem.key,
label: railItem.value || railItem.input
}));
}
return newGwdItem;
@ -257,17 +281,8 @@ export default function Setting(){
value
}
sysSet(params, "PUT").then(res=>{
if(res.status === 0){
const list:systemItem[] = JSON.parse(JSON.stringify(systemList))
list.forEach(el => {
if(item.id === el.id){
el.value = value
}
})
dispatch(updateSystemAllState(list))
message.success("修改成功")
}
})
}
const form = () =>{
@ -301,19 +316,11 @@ export default function Setting(){
<h1 className='text-[20px]'></h1>
<section className='p-[20px]'>
{form()}
{/*<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} onChange={(e)=>{onAccountChange(e.target.value)}} className='w-[300px]'></Input>*/}
{/* <Button className='ml-[10px]' size='small' type="primary" onClick={onSaveAccount}>保存</Button>*/}
{/*</div>*/}
</section>
<h1 className='text-[20px]'></h1>
{connectionStatus()}
</div>
</div>
</>
</>
}

53
src/store/system/systemSlice.ts

@ -1,35 +1,36 @@
// counterSlice.ts 文件
import { createSlice } from "@reduxjs/toolkit";
const initialState = {
systemInfo:[],
orgInfo:{
id:'',
name:'',
value:'',
code:''
},
accountInfo:{
id:'',
name:'',
value:'',
code:''
}
systemInfo:[],
orgInfo:{
id:'',
name:'',
value:'',
code:''
},
accountInfo:{
id:'',
name:'',
value:'',
code:''
}
};
// 创建一个 Slice
export const systemStateSlice = createSlice({
name: "systemState",
initialState,
reducers: {
updateSystemAllState: (state, { payload }) => {
state.systemInfo = payload
},
updateSystemOrgState: (state, { payload }) => {
state.orgInfo = payload
},
updateSystemAccountState: (state, { payload }) => {
state.accountInfo = payload
},
},
name: "systemState",
initialState,
reducers: {
updateSystemAllState: (state, { payload }) => {
state.systemInfo = payload
},
updateSystemOrgState: (state, { payload }) => {
console.log('systemState.orgInfo------11----', payload)
state.orgInfo = payload
},
updateSystemAccountState: (state, { payload }) => {
state.accountInfo = payload
},
},
});
export const {updateSystemAllState, updateSystemOrgState, updateSystemAccountState } = systemStateSlice.actions;
// 默认导出

Loading…
Cancel
Save