Browse Source

添加系统设置碳

feat_upload_server_url_0416
LiLongLong 4 months ago
parent
commit
088446eb62
  1. 24
      src/App.tsx
  2. 14
      src/components/SideMenu.tsx
  3. 17
      src/pages/measure/components/MeasureAction.tsx
  4. 35
      src/pages/measure/components/MeasureConfig.tsx
  5. 119
      src/pages/system/Setting.tsx
  6. 4
      src/pages/system/types.ts
  7. 5
      src/store/index.ts
  8. 36
      src/store/system/systemSlice.ts
  9. 6
      src/types.ts

24
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,

14
src/components/SideMenu.tsx

@ -45,15 +45,11 @@ const items: MenuItem[] = [
// label: '任务列表'
// }]
// },
// {
// key: "system",
// label: "系统设置",
// icon: <img src={icon_task} alt=""/>,
// children: [{
// key: '/system',
// label: '系统设置'
// }]
// },
{
key: "system",
label: "系统设置",
icon: <img src={icon_task} width="10" className="ml-[5px]" alt=""/>,
},
];
export default function SideMenu() {

17
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;

35
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<GwdDicItem[]>([]);
const [gwdCodeValue, setGwdCodeValue] = useState<string>();
@ -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})
}

119
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<systemItem[]>([])
const [accountInfo, setAccountInfo] = useState<systemItem>({})
const [orgInfo, setOrgInfo] = useState<systemItem>({})
const [orgValues, setOrgValues] = useState<string[]>([])
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<orgCascaderType[]>([]);
@ -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 <div>
<section className='p-[20px]'>
<div><Cascader className='w-[300px]' options={KTJOrgList} onChange={onOrgChange} placeholder="请选择局段线" /></div>
<div><Cascader className='w-[300px]' key={orgValues.length} defaultValue={orgValues} options={KTJOrgList} onChange={onOrgChange} placeholder="请选择局段线" /></div>
<div className='mt-[10px]'>
{accountInfo.name}
<Input key={accountInfo.value} defaultValue={accountInfo.value} onChange={(e)=>{setAccountInfo({...accountInfo, value:e.target.value})}} className='w-[300px]'></Input>
<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>

4
src/pages/system/types.ts

@ -16,7 +16,9 @@ export type orgCascaderType = {
}
export type systemItem = {
id?:string | number;
code?: string;
name?: string;
value?: string;
}
}

5
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
},
});

36
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;

6
src/types.ts

@ -0,0 +1,6 @@
export type system = {
id?:string;
name?:string;
value?:string;
code?:string;
}
Loading…
Cancel
Save