|
|
@ -8,7 +8,11 @@ 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, |
|
|
|
updateUploadServerUrlState |
|
|
|
} from '../../store/system/systemSlice'; |
|
|
|
import {createWebSocket, sharedWsUrl} from "../../services/socket"; |
|
|
|
import {start, stop, disconnect, connect} from "../../services/ble/ble"; |
|
|
|
|
|
|
@ -27,6 +31,7 @@ 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[]>([]) |
|
|
|
|
|
|
@ -86,6 +91,19 @@ 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) |
|
|
@ -129,6 +147,59 @@ 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("修改成功") |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 上传服务器地址输入框内容变更 |
|
|
|
* @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("修改成功") |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function convertToCascaderData(data:OrgItem[]) { |
|
|
|
return data.map(item => { |
|
|
|
const newItem:orgCascaderType = { |
|
|
@ -251,64 +322,24 @@ export default function Setting(){ |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const saveSet = (item:systemItem, value:string) => { |
|
|
|
const params = { |
|
|
|
id:item.id, |
|
|
|
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 = () =>{ |
|
|
|
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]'> |
|
|
|
{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>*/} |
|
|
|
<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> |
|
|
|
</section> |
|
|
|
<h1 className='text-[20px]'>设备配置</h1> |
|
|
|
{connectionStatus()} |
|
|
|