Browse Source

feat:增加服务器上传地址配置功能

feat_upload_server_url_0416
黄翔 4 months ago
parent
commit
a5308e76f8
  1. 2
      .env
  2. 3
      .gitignore
  3. 4
      package-lock.json
  4. 2
      package.json
  5. 10
      src/App.tsx
  6. 108
      src/pages/system/Setting.tsx
  7. 15
      src/store/system/systemSlice.ts

2
.env

@ -1 +1 @@
REACT_APP_WS_URL=192.168.1.146:8080/ws
REACT_APP_WS_URL=192.168.1.102:8080/ws

3
.gitignore

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

4
package-lock.json

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

2
package.json

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

10
src/App.tsx

@ -15,7 +15,12 @@ import { updateDevice } from "./store/features/contextSlice";
import { getStatus, update } from "./services/ktj/org"; import { getStatus, update } from "./services/ktj/org";
import SyncData from "./components/syncData"; import SyncData from "./components/syncData";
import { sysSet } from "./services/user/system"; import { sysSet } from "./services/user/system";
import { updateSystemAccountState, updateSystemAllState, updateSystemOrgState } from "./store/system/systemSlice";
import {
updateSystemAccountState,
updateSystemAllState,
updateSystemOrgState,
updateUploadServerUrlState
} from "./store/system/systemSlice";
import { system } from "./types"; import { system } from "./types";
const { Header, Footer, Sider, Content } = Layout; const { Header, Footer, Sider, Content } = Layout;
@ -103,6 +108,9 @@ function App() {
if(item.code === 'UPLOAD_USERNAME'){ if(item.code === 'UPLOAD_USERNAME'){
dispatch(updateSystemAccountState(item)) dispatch(updateSystemAccountState(item))
} }
if(item.code === 'UPLOAD_SERVER_URL'){
dispatch(updateUploadServerUrlState(item))
}
}) })
} }

108
src/pages/system/Setting.tsx

@ -8,7 +8,11 @@ import { OrgItem } from '../../services/ktjTypes';
import {bleItem, child, GwdItem, orgCascaderType, systemItem} from './types'; import {bleItem, child, GwdItem, orgCascaderType, systemItem} from './types';
import { sysSet } from '../../services/user/system'; import { sysSet } from '../../services/user/system';
import { useAppDispatch, useAppSelector } from "../../utils/hooks"; import { useAppDispatch, useAppSelector } from "../../utils/hooks";
import { updateSystemAccountState, updateSystemOrgState } from '../../store/system/systemSlice';
import {
updateSystemAccountState,
updateSystemOrgState,
updateUploadServerUrlState
} from '../../store/system/systemSlice';
import {createWebSocket, sharedWsUrl} from "../../services/socket"; import {createWebSocket, sharedWsUrl} from "../../services/socket";
import {start, stop, disconnect, connect} from "../../services/ble/ble"; import {start, stop, disconnect, connect} from "../../services/ble/ble";
@ -27,6 +31,7 @@ export default function Setting(){
const [systemList, setSystemList] = useState<systemItem[]>([]) const [systemList, setSystemList] = useState<systemItem[]>([])
const [accountInfo, setAccountInfo] = useState<systemItem>({}) const [accountInfo, setAccountInfo] = useState<systemItem>({})
const [orgInfo, setOrgInfo] = useState<systemItem>({}) const [orgInfo, setOrgInfo] = useState<systemItem>({})
const [uploadServerUrl, setUploadServerUrl] = useState<systemItem>({})
const [orgValues, setOrgValues] = useState<string[]>([]) const [orgValues, setOrgValues] = useState<string[]>([])
const [bleList, setBleList] = useState<bleItem[]>([]) const [bleList, setBleList] = useState<bleItem[]>([])
@ -84,6 +89,19 @@ export default function Setting(){
useEffect(()=>{ 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){ if(orgInfo && orgInfo.value){
let orgIds:string[] = [] let orgIds:string[] = []
const values:child[] = JSON.parse(orgInfo.value) const values:child[] = JSON.parse(orgInfo.value)
@ -146,9 +164,38 @@ export default function Setting(){
}) })
} }
/**
*
* @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){ function onAccountChange(accountValue:string){
newAccountInfo.name = accountInfo.name || '';
newAccountInfo.value = accountValue;
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[]) { function convertToCascaderData(data:OrgItem[]) {
@ -273,55 +320,24 @@ export default function Setting(){
} }
}; };
const saveSet = (item:systemItem, value:string) => {
const params = {
id:item.id,
value
}
sysSet(params, "PUT").then(res=>{
})
}
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 // @ts-ignore
return <><div className={'pr-2.5 pl-2.5 w-full h-full'}> 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'}> <div className={'h-full w-full bg-white p-10 rounded-2xl'}>
<h1 className='text-[20px]'></h1> <h1 className='text-[20px]'></h1>
<section className='p-[20px]'> <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> </section>
<h1 className='text-[20px]'></h1> <h1 className='text-[20px]'></h1>
{connectionStatus()} {connectionStatus()}

15
src/store/system/systemSlice.ts

@ -13,7 +13,13 @@ const initialState = {
name:'', name:'',
value:'', value:'',
code:'' code:''
}
},
uploadServerUrl: {
id:'',
name:'',
value:'',
code:''
}
}; };
// 创建一个 Slice // 创建一个 Slice
export const systemStateSlice = createSlice({ export const systemStateSlice = createSlice({
@ -26,11 +32,14 @@ export const systemStateSlice = createSlice({
updateSystemOrgState: (state, { payload }) => { updateSystemOrgState: (state, { payload }) => {
state.orgInfo = payload state.orgInfo = payload
}, },
updateSystemAccountState: (state, { payload }) => {
updateSystemAccountState: (state, { payload }) => {
state.accountInfo = payload state.accountInfo = payload
}, },
updateUploadServerUrlState: (state, { payload }) => {
state.uploadServerUrl = payload
}
}, },
}); });
export const {updateSystemAllState, updateSystemOrgState, updateSystemAccountState } = systemStateSlice.actions;
export const {updateSystemAllState, updateSystemOrgState, updateSystemAccountState, updateUploadServerUrlState } = systemStateSlice.actions;
// 默认导出 // 默认导出
export default systemStateSlice.reducer; export default systemStateSlice.reducer;
Loading…
Cancel
Save