From 088446eb62bbbac83097f227063172aeb7ccd089 Mon Sep 17 00:00:00 2001 From: LiLongLong <13717757313@163.com> Date: Tue, 15 Apr 2025 20:04:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=B3=BB=E7=BB=9F=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=A2=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 24 +++++ src/components/SideMenu.tsx | 14 ++- src/pages/measure/components/MeasureAction.tsx | 17 +++- src/pages/measure/components/MeasureConfig.tsx | 35 +++++++- src/pages/system/Setting.tsx | 119 ++++++++++++++++++------- src/pages/system/types.ts | 4 +- src/store/index.ts | 5 +- src/store/system/systemSlice.ts | 36 ++++++++ src/types.ts | 6 ++ 9 files changed, 215 insertions(+), 45 deletions(-) create mode 100644 src/store/system/systemSlice.ts create mode 100644 src/types.ts diff --git a/src/App.tsx b/src/App.tsx index 22f213e..4d65bf1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,6 +14,9 @@ import zhCN from 'antd/lib/locale/zh_CN'; // 引入中文语言包 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 } from "./store/system/systemSlice"; +import { system } from "./types"; const { Header, Footer, Sider, Content } = Layout; @@ -65,6 +68,8 @@ function App() { useEffect(()=>{ //是否需要同步数据 queryStatus() + //查询系统信息 + querySystemInfo() },[]) useEffect(() => { @@ -85,6 +90,25 @@ function App() { }) } + + const querySystemInfo = () => { + sysSet({}, "GET").then(res=>{ + if(res.status === 0 && res.data && res.data.length){ + let data:system[] = res.data; + dispatch(updateSystemAllState(data)) + data.map(item => { + if(item.code === 'ORG'){ + dispatch(updateSystemOrgState(item)) + } + if(item.code === 'UPLOAD_USERNAME'){ + dispatch(updateSystemAccountState(item)) + } + }) + + } + }) + } + const headerStyle: React.CSSProperties = { height: 64, padding: 0, diff --git a/src/components/SideMenu.tsx b/src/components/SideMenu.tsx index b758a90..ba0e8c4 100644 --- a/src/components/SideMenu.tsx +++ b/src/components/SideMenu.tsx @@ -45,15 +45,11 @@ const items: MenuItem[] = [ // label: '任务列表' // }] // }, - // { - // key: "system", - // label: "系统设置", - // icon: , - // children: [{ - // key: '/system', - // label: '系统设置' - // }] - // }, + { + key: "system", + label: "系统设置", + icon: , + }, ]; export default function SideMenu() { diff --git a/src/pages/measure/components/MeasureAction.tsx b/src/pages/measure/components/MeasureAction.tsx index d40df11..e8a3845 100644 --- a/src/pages/measure/components/MeasureAction.tsx +++ b/src/pages/measure/components/MeasureAction.tsx @@ -6,6 +6,7 @@ import { fetchAnalysisReport, getAlignPointsByRailSize, startMeasurement, + stopMeasurement, } from "../../../services/measure/analysis"; import { getBaseRecordPointSetByCode, gx_list } from "../../../services/track/trackShape" import { createWebSocket, sharedWsUrl } from "../../../services/socket"; @@ -146,6 +147,18 @@ export default function MeasureAction() { }); }, [initialStatusList, startBtnText]); + //停止测量 + const onStop = () => { + stopMeasurement().then(res=>{ + if (res.status !== 0) { + }else{ + message.error('已停止测量') + } + }).catch(e=>{ + message.error('调用出错') + }) + } + // 保存按钮点击事件 const onSaveBtnClick = () => { dispatch(updateMeasureData(newMeasureData)) @@ -274,8 +287,8 @@ export default function MeasureAction() { }); // 把状态全部置灰 updated.forEach(u => (u.color = STEP_COLOR_GREY)); - // 调用重新测量 - onStart(); + // 调用停止测量 + onStop(); break; default: break; diff --git a/src/pages/measure/components/MeasureConfig.tsx b/src/pages/measure/components/MeasureConfig.tsx index 55190b2..5d1bf3b 100644 --- a/src/pages/measure/components/MeasureConfig.tsx +++ b/src/pages/measure/components/MeasureConfig.tsx @@ -23,9 +23,11 @@ import type { } from "../../../services/ktjTypes"; import { RAIN_TYPES, XB_CODES, DATA_SOURCE } from "../../../constant/index"; import "./MeasureAction.scss"; +import { systemItem } from "../../system/types"; export default function MeasureConfig() { const { Option } = Select; const navigate = useNavigate(); + const systemState = useAppSelector((store) => store.systemState); const [messageApi, contextHolder] = message.useMessage(); const dispatch = useAppDispatch(); const context = useAppSelector((store) => store.context); @@ -69,7 +71,6 @@ export default function MeasureConfig() { localStorage.setItem('orgInfo', JSON.stringify(orgItem)); params.extraDesc = JSON.stringify(extraDesc) let measureData = measureState.measureData; - console.log('measureState=====1===', measureState.measureData) if(measureData && measureData.length){ params.alignPoints = measureData } @@ -200,6 +201,7 @@ export default function MeasureConfig() { .catch((e) => {}); }; + //选择机构时change const [gwdDicList, setGwdDicList] = useState([]); const [gwdCodeValue, setGwdCodeValue] = useState(); @@ -275,6 +277,37 @@ export default function MeasureConfig() { }) } + + useEffect(()=>{ + if(systemState.orgInfo){ + const cloneOrgItem = systemState.orgInfo + if(cloneOrgItem.value){ + const org = JSON.parse(cloneOrgItem.value) + onOrgChange(org[0].value, org[0]) + onGwdChange(org[1].value, org[1]) + form.setFieldsValue({ + tljCode:org[0].value, + gwdCode: org[1].value, + xmCode: org[2].value + }); + queryStation(org[2].value, org[2]) + } + } + },[KTJOrgList, xmCodeValue, gwdCodeValue, systemState.orgInfo]) + + + useEffect(()=>{ + if(systemState.accountInfo){ + const cloneAccountItem = systemState.accountInfo + if(cloneAccountItem.value){ + form.setFieldsValue({ + operator:cloneAccountItem.value + }) + } + } + },[systemState.accountInfo]) + + const onRailTypeChange = (value:string, option:any) => { setExtraDesc({...extraDesc,railSizeName:option.label}) } diff --git a/src/pages/system/Setting.tsx b/src/pages/system/Setting.tsx index 1754767..1bb7e24 100644 --- a/src/pages/system/Setting.tsx +++ b/src/pages/system/Setting.tsx @@ -1,40 +1,66 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect, ReactNode } from 'react'; import type { CascaderProps } from 'antd'; -import { Button, Cascader, Input } from 'antd'; +import { Button, Cascader, Input, message } from 'antd'; import { getOrgListService } from '../../services/ktj/org'; import { options, OrgItem } from '../../services/ktjTypes'; -import { GwdItem, orgCascaderType, systemItem } from './types'; +import { child, GwdItem, orgCascaderType, systemItem } from './types'; import { sysSet } from '../../services/user/system'; +import { useAppDispatch, useAppSelector } from "../../utils/hooks"; +import { updateSystemAccountState, updateSystemOrgState } from '../../store/system/systemSlice'; export default function Setting(){ useEffect(()=>{ queryRailData() querySettingData() },[]) - + const dispatch = useAppDispatch(); + const systemState = useAppSelector((store) => store.systemState); const [systemList, setSystemList] = useState([]) const [accountInfo, setAccountInfo] = useState({}) + const [orgInfo, setOrgInfo] = useState({}) + const [orgValues, setOrgValues] = useState([]) function querySettingData(){ - sysSet({}, "GET").then(res=>{ - setSystemList(res.data) - let data:systemItem[] = res.data; - let accountInfo:systemItem = {} - data.map(item => { - if(item.code === 'UPLOAD_USERNAME'){ - accountInfo = { - name: item.name, - code: item.code, - value: item.value - } - } - }) - console.log('accountInfo---', accountInfo) - setAccountInfo(accountInfo) - }) + let systemInfo = systemState.systemInfo + setSystemList(systemInfo) } useEffect(()=>{ + if(systemState.orgInfo){ + const cloneOrgItem = systemState.orgInfo + let orgItem:systemItem = { + id: cloneOrgItem.id, + name: cloneOrgItem.name, + code: cloneOrgItem.code, + value: cloneOrgItem.value + } + setOrgInfo(orgItem) + } + }, [systemState.orgInfo]) - }, [accountInfo]) + + useEffect(()=>{ + if(systemState.accountInfo){ + const cloneAccountItem = systemState.accountInfo + let accountInfo:systemItem = { + id: cloneAccountItem.id, + name: cloneAccountItem.name, + code: cloneAccountItem.code, + value: cloneAccountItem.value + } + setAccountInfo(accountInfo) + } + }, [systemState.accountInfo]) + + + useEffect(()=>{ + if(orgInfo && orgInfo.value){ + let orgIds:string[] = [] + const values:child[] = JSON.parse(orgInfo.value) + values.map(item => { + orgIds.push(item.value) + }) + setOrgValues(orgIds) + } + }, [orgInfo]) //获取铁路局数据 const [KTJOrgList, setKTJOrgList] = useState([]); @@ -48,20 +74,51 @@ export default function Setting(){ }).catch((e) => {}); } - function onOrgChange(value:string[]){ - console.log('value===', value) - if(value && value.length) - sysSet({code:"ORG",name:"org",value:JSON.stringify(value)}, "PUT").then(res=>{ - console.log('res===', res) - }) + function onOrgChange(value:string[], selectedOptions: orgCascaderType[]){ + if(selectedOptions && selectedOptions.length){ + let orgList = selectedOptions.map(item => { + return { + value:item.value, + label:item.label + } + }) + const orgParams = { + ...orgInfo, + value:JSON.stringify(orgList) + } + sysSet(orgParams, "PUT").then(res=>{ + if(res.status === 0){ + dispatch(updateSystemOrgState(orgParams)) + message.success("修改成功") + } + }) + } } + let newAccountInfo = { + name:'', + value: '' + } function onSaveAccount(){ - sysSet({code:"UPLOAD_USERNAME", name:accountInfo.name,value:accountInfo.value}, "PUT").then(res=>{ - console.log('res===', res) + 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 = { @@ -89,10 +146,10 @@ export default function Setting(){ return
-
铁路局:
+
铁路局:
{accountInfo.name}: - {setAccountInfo({...accountInfo, value:e.target.value})}} className='w-[300px]'> + {onAccountChange(e.target.value)}} className='w-[300px]'>
diff --git a/src/pages/system/types.ts b/src/pages/system/types.ts index abfc809..bf9aa64 100644 --- a/src/pages/system/types.ts +++ b/src/pages/system/types.ts @@ -16,7 +16,9 @@ export type orgCascaderType = { } export type systemItem = { + id?:string | number; code?: string; name?: string; value?: string; -} \ No newline at end of file +} + diff --git a/src/store/index.ts b/src/store/index.ts index 5ae86cd..c39f325 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -6,6 +6,8 @@ import contextSlice from "./features/contextSlice"; import deviceStateSlice from "./device/deviceState"; import orgStateSlice from "./ktj/orgState"; import measureStateSlice from "./measure/measureState"; +import systemStateSlice from "./system/systemSlice"; + // configureStore创建一个redux数据 const store = configureStore({ // 合并多个Slice @@ -14,7 +16,8 @@ const store = configureStore({ context: contextSlice, deviceState: deviceStateSlice, orgState: orgStateSlice, - measureState:measureStateSlice + measureState:measureStateSlice, + systemState:systemStateSlice }, }); diff --git a/src/store/system/systemSlice.ts b/src/store/system/systemSlice.ts new file mode 100644 index 0000000..6321803 --- /dev/null +++ b/src/store/system/systemSlice.ts @@ -0,0 +1,36 @@ +// counterSlice.ts 文件 +import { createSlice } from "@reduxjs/toolkit"; +const initialState = { + 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 + }, + }, +}); +export const {updateSystemAllState, updateSystemOrgState, updateSystemAccountState } = systemStateSlice.actions; +// 默认导出 +export default systemStateSlice.reducer; diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..0bc6849 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,6 @@ +export type system = { + id?:string; + name?:string; + value?:string; + code?:string; +} \ No newline at end of file