|
|
@ -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> |
|
|
|