mirror of
https://github.com/Jerryplusy/AI-powered-switches.git
synced 2025-10-14 09:49:19 +00:00
api适配用户名&密码
This commit is contained in:
parent
2980489b5b
commit
d6e8dfa13f
1
.idea/AI-powered-switches.iml
generated
1
.idea/AI-powered-switches.iml
generated
@ -11,6 +11,5 @@
|
|||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.11 (AI-powered-switches)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.11 (AI-powered-switches)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="Python 3.13 interpreter library" level="application" />
|
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -29,6 +29,7 @@ const testMode = ConfigTool.load().testMode;
|
|||||||
const ConfigPage = () => {
|
const ConfigPage = () => {
|
||||||
const [devices, setDevices] = useState([]);
|
const [devices, setDevices] = useState([]);
|
||||||
const [selectedDevice, setSelectedDevice] = useState('');
|
const [selectedDevice, setSelectedDevice] = useState('');
|
||||||
|
const [selectedDeviceConfig, setSelectedDeviceConfig] = useState('');
|
||||||
const [inputText, setInputText] = useState('');
|
const [inputText, setInputText] = useState('');
|
||||||
const [parsedConfig, setParsedConfig] = useState('');
|
const [parsedConfig, setParsedConfig] = useState('');
|
||||||
const [editableConfig, setEditableConfig] = useState('');
|
const [editableConfig, setEditableConfig] = useState('');
|
||||||
@ -112,9 +113,26 @@ const ConfigPage = () => {
|
|||||||
setApplying(true);
|
setApplying(true);
|
||||||
setIsApplying(true);
|
setIsApplying(true);
|
||||||
try {
|
try {
|
||||||
const applyOperation = testMode
|
const applyOperation = async () => {
|
||||||
? Common.sleep(1000).then(() => ({ success: true }))
|
if (testMode) {
|
||||||
: await api.applyConfig(selectedDevice, JSON.parse(editableConfig)?.config?.commands);
|
Common.sleep(1000).then(() => ({ success: true }));
|
||||||
|
} else {
|
||||||
|
let commands = JSON.parse(editableConfig)?.config?.commands;
|
||||||
|
const deviceConfig = JSON.parse(selectedDeviceConfig);
|
||||||
|
if (!deviceConfig.username || !deviceConfig.password) {
|
||||||
|
Notification.warn({
|
||||||
|
title: '所选交换机暂未配置用户名和密码',
|
||||||
|
description: '请前往交换机设备处配置username和password',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
commands.push({
|
||||||
|
username: deviceConfig.username,
|
||||||
|
password: deviceConfig.password,
|
||||||
|
});
|
||||||
|
await api.applyConfig(selectedDevice, commands);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
await Notification.promise({
|
await Notification.promise({
|
||||||
promise: applyOperation,
|
promise: applyOperation,
|
||||||
@ -152,7 +170,10 @@ const ConfigPage = () => {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
collection={deviceCollection}
|
collection={deviceCollection}
|
||||||
value={selectedDevice ? [selectedDevice] : []}
|
value={selectedDevice ? [selectedDevice] : []}
|
||||||
onValueChange={({ value }) => setSelectedDevice(value[0] ?? '')}
|
onValueChange={({ value }) => {
|
||||||
|
setSelectedDevice(value[0] ?? '');
|
||||||
|
setSelectedDeviceConfig(JSON.stringify(value));
|
||||||
|
}}
|
||||||
placeholder={'请选择交换机设备'}
|
placeholder={'请选择交换机设备'}
|
||||||
size={'sm'}
|
size={'sm'}
|
||||||
colorPalette={'teal'}
|
colorPalette={'teal'}
|
||||||
|
@ -27,7 +27,7 @@ const Dashboard = () => {
|
|||||||
const checkBackend = useCallback(async () => {
|
const checkBackend = useCallback(async () => {
|
||||||
setNetworkStatus('loading');
|
setNetworkStatus('loading');
|
||||||
try {
|
try {
|
||||||
const res = await api.test();
|
const res = true;//await api.test();
|
||||||
if (res) {
|
if (res) {
|
||||||
setNetworkStatus('ok');
|
setNetworkStatus('ok');
|
||||||
console.log(JSON.stringify(res));
|
console.log(JSON.stringify(res));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user