seeder-st2110-components 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +124 -34
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +124 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -617,7 +617,8 @@ const useSystemOperations = function () {
|
|
|
617
617
|
onRestart,
|
|
618
618
|
confirmTitle = "Confirm",
|
|
619
619
|
cancelText = "No",
|
|
620
|
-
okText = "Yes"
|
|
620
|
+
okText = "Yes",
|
|
621
|
+
run
|
|
621
622
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
622
623
|
const {
|
|
623
624
|
modal: AntdModal
|
|
@@ -635,6 +636,11 @@ const useSystemOperations = function () {
|
|
|
635
636
|
} else if (action === 'restart' && onRestart) {
|
|
636
637
|
onRestart();
|
|
637
638
|
}
|
|
639
|
+
|
|
640
|
+
// Call the run callback after successful operation
|
|
641
|
+
if (typeof run === 'function') {
|
|
642
|
+
run();
|
|
643
|
+
}
|
|
638
644
|
}
|
|
639
645
|
});
|
|
640
646
|
} catch (error) {
|
|
@@ -1907,7 +1913,8 @@ const SystemOperations = _ref => {
|
|
|
1907
1913
|
iconClassName = "iconfont icon-guanji1 text-2xl text-neutral-400",
|
|
1908
1914
|
confirmTitle = "Confirm",
|
|
1909
1915
|
cancelText = "No",
|
|
1910
|
-
okText = "Yes"
|
|
1916
|
+
okText = "Yes",
|
|
1917
|
+
run
|
|
1911
1918
|
} = _ref;
|
|
1912
1919
|
const {
|
|
1913
1920
|
modal: AntdModal
|
|
@@ -1937,6 +1944,11 @@ const SystemOperations = _ref => {
|
|
|
1937
1944
|
} else if (action === 'restart' && onRestart) {
|
|
1938
1945
|
onRestart();
|
|
1939
1946
|
}
|
|
1947
|
+
|
|
1948
|
+
// Call the run callback after successful operation
|
|
1949
|
+
if (typeof run === 'function') {
|
|
1950
|
+
run();
|
|
1951
|
+
}
|
|
1940
1952
|
}
|
|
1941
1953
|
});
|
|
1942
1954
|
} catch (error) {
|
|
@@ -1971,7 +1983,8 @@ SystemOperations.propTypes = {
|
|
|
1971
1983
|
iconClassName: PropTypes.string,
|
|
1972
1984
|
confirmTitle: PropTypes.string,
|
|
1973
1985
|
cancelText: PropTypes.string,
|
|
1974
|
-
okText: PropTypes.string
|
|
1986
|
+
okText: PropTypes.string,
|
|
1987
|
+
run: PropTypes.func
|
|
1975
1988
|
};
|
|
1976
1989
|
|
|
1977
1990
|
const defaultFieldConfigs = {
|
|
@@ -2230,6 +2243,7 @@ const NetworkFieldGroup = _ref => {
|
|
|
2230
2243
|
interfaces,
|
|
2231
2244
|
fieldConfig = {}
|
|
2232
2245
|
} = _ref;
|
|
2246
|
+
// 默认字段配置
|
|
2233
2247
|
const defaultFieldConfig = {
|
|
2234
2248
|
name: {
|
|
2235
2249
|
label: "Name",
|
|
@@ -2241,7 +2255,7 @@ const NetworkFieldGroup = _ref => {
|
|
|
2241
2255
|
},
|
|
2242
2256
|
netmask: {
|
|
2243
2257
|
label: "Netmask",
|
|
2244
|
-
enabled:
|
|
2258
|
+
enabled: true
|
|
2245
2259
|
}
|
|
2246
2260
|
};
|
|
2247
2261
|
const mergedFieldConfig = {
|
|
@@ -2286,14 +2300,22 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2286
2300
|
open,
|
|
2287
2301
|
onClose,
|
|
2288
2302
|
getLanConfig,
|
|
2303
|
+
// 可选 - 单独获取LAN配置的函数
|
|
2289
2304
|
getSysConfig,
|
|
2305
|
+
// 可选 - 单独获取QSFP配置的函数
|
|
2306
|
+
getConfig,
|
|
2307
|
+
// 可选 - 统一获取配置的函数
|
|
2290
2308
|
updateLanConfig,
|
|
2291
2309
|
updateSysConfig,
|
|
2292
2310
|
restart,
|
|
2293
2311
|
modalProps = {},
|
|
2294
2312
|
formProps = {},
|
|
2295
2313
|
fieldConfig = {},
|
|
2296
|
-
sections = ['LAN', 'QSFP']
|
|
2314
|
+
sections = ['LAN', 'QSFP'],
|
|
2315
|
+
showNetmask = {
|
|
2316
|
+
LAN: true,
|
|
2317
|
+
QSFP: false
|
|
2318
|
+
}
|
|
2297
2319
|
} = _ref2;
|
|
2298
2320
|
const {
|
|
2299
2321
|
message,
|
|
@@ -2308,30 +2330,63 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2308
2330
|
hasFetched: false,
|
|
2309
2331
|
hasInitialized: false
|
|
2310
2332
|
});
|
|
2333
|
+
const preparedFieldConfig = useMemo(() => {
|
|
2334
|
+
const config = {
|
|
2335
|
+
...fieldConfig
|
|
2336
|
+
};
|
|
2337
|
+
|
|
2338
|
+
// 确保LAN和QSFP的配置存在
|
|
2339
|
+
config.LAN = config.LAN || {};
|
|
2340
|
+
config.QSFP = config.QSFP || {};
|
|
2341
|
+
if (sections.includes('LAN')) {
|
|
2342
|
+
config.LAN.netmask = {
|
|
2343
|
+
...(config.LAN.netmask || {}),
|
|
2344
|
+
enabled: showNetmask.LAN
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
if (sections.includes('QSFP')) {
|
|
2348
|
+
config.QSFP.netmask = {
|
|
2349
|
+
...(config.QSFP.netmask || {}),
|
|
2350
|
+
enabled: showNetmask.QSFP
|
|
2351
|
+
};
|
|
2352
|
+
}
|
|
2353
|
+
return config;
|
|
2354
|
+
}, [fieldConfig, showNetmask, sections]);
|
|
2311
2355
|
useEffect(() => {
|
|
2312
2356
|
if (!open) return;
|
|
2313
2357
|
const fetchData = async () => {
|
|
2314
2358
|
if (initializationStatus.current.hasFetched) return;
|
|
2315
2359
|
try {
|
|
2316
2360
|
initializationStatus.current.hasFetched = true;
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
promises.push(getSysConfig());
|
|
2323
|
-
}
|
|
2324
|
-
const results = await Promise.allSettled(promises);
|
|
2325
|
-
if (sections.includes('LAN')) {
|
|
2326
|
-
const lanResult = results[0];
|
|
2327
|
-
if (lanResult.status === 'fulfilled') {
|
|
2328
|
-
setLanConfigs(lanResult.value || []);
|
|
2361
|
+
if (getConfig) {
|
|
2362
|
+
// 使用统一接口获取数据
|
|
2363
|
+
const config = await getConfig();
|
|
2364
|
+
if (sections.includes('LAN') && config.lan_interfaces) {
|
|
2365
|
+
setLanConfigs(config.lan_interfaces);
|
|
2329
2366
|
}
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2367
|
+
if (sections.includes('QSFP') && config.interfaces) {
|
|
2368
|
+
setSt2110Interfaces(config.interfaces);
|
|
2369
|
+
}
|
|
2370
|
+
} else {
|
|
2371
|
+
const promises = [];
|
|
2372
|
+
if (sections.includes('LAN')) {
|
|
2373
|
+
promises.push(getLanConfig());
|
|
2374
|
+
}
|
|
2375
|
+
if (sections.includes('QSFP')) {
|
|
2376
|
+
promises.push(getSysConfig());
|
|
2377
|
+
}
|
|
2378
|
+
const results = await Promise.allSettled(promises);
|
|
2379
|
+
if (sections.includes('LAN') && getLanConfig) {
|
|
2380
|
+
const lanResult = results[0];
|
|
2381
|
+
if (lanResult.status === 'fulfilled') {
|
|
2382
|
+
setLanConfigs(lanResult.value || []);
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
if (sections.includes('QSFP') && getSysConfig) {
|
|
2386
|
+
const sysResult = sections.includes('LAN') ? results[1] : results[0];
|
|
2387
|
+
if (sysResult.status === 'fulfilled' && sysResult.value) {
|
|
2388
|
+
setSt2110Interfaces(sysResult.value.st2110_interfaces || []);
|
|
2389
|
+
}
|
|
2335
2390
|
}
|
|
2336
2391
|
}
|
|
2337
2392
|
setIsInitialized(true);
|
|
@@ -2365,18 +2420,27 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2365
2420
|
connection_id: config.connection_id,
|
|
2366
2421
|
display_name: config.display_name,
|
|
2367
2422
|
ip_address: config.ip_address,
|
|
2368
|
-
|
|
2423
|
+
...(showNetmask.LAN ? {
|
|
2424
|
+
netmask: config.netmask
|
|
2425
|
+
} : {})
|
|
2369
2426
|
}));
|
|
2370
2427
|
}
|
|
2371
2428
|
if (sections.includes('QSFP') && st2110Interfaces.length > 0) {
|
|
2372
2429
|
values.QSFP = st2110Interfaces.map(iface => ({
|
|
2373
|
-
|
|
2430
|
+
// 只有当iface中存在id字段时才包含id
|
|
2431
|
+
...(iface.id !== undefined && {
|
|
2432
|
+
id: iface.id
|
|
2433
|
+
}),
|
|
2374
2434
|
display_name: iface.display_name,
|
|
2375
|
-
ip_address: iface.ip_address
|
|
2435
|
+
ip_address: iface.ip_address || iface.ip,
|
|
2436
|
+
// 优先取ip_address,没有则取ip
|
|
2437
|
+
...(showNetmask.QSFP ? {
|
|
2438
|
+
netmask: iface.netmask
|
|
2439
|
+
} : {})
|
|
2376
2440
|
}));
|
|
2377
2441
|
}
|
|
2378
2442
|
return values;
|
|
2379
|
-
}, [lanConfigs, st2110Interfaces, sections]);
|
|
2443
|
+
}, [lanConfigs, st2110Interfaces, sections, showNetmask]);
|
|
2380
2444
|
|
|
2381
2445
|
// 当初始值准备好后设置表单值
|
|
2382
2446
|
useEffect(() => {
|
|
@@ -2386,10 +2450,28 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2386
2450
|
}
|
|
2387
2451
|
}, [isInitialized, form, initialValues]);
|
|
2388
2452
|
const handleSuccess = useCallback(async function () {
|
|
2389
|
-
let
|
|
2390
|
-
|
|
2453
|
+
let {
|
|
2454
|
+
messageText = 'Success',
|
|
2455
|
+
isPopup = !!restart,
|
|
2456
|
+
refresh = !restart
|
|
2457
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2391
2458
|
message.success(messageText);
|
|
2392
|
-
if (
|
|
2459
|
+
if (refresh && getConfig) {
|
|
2460
|
+
try {
|
|
2461
|
+
const newConfig = await getConfig();
|
|
2462
|
+
if (sections.includes('LAN') && newConfig.lan_interfaces) {
|
|
2463
|
+
setLanConfigs(newConfig.lan_interfaces);
|
|
2464
|
+
}
|
|
2465
|
+
if (sections.includes('QSFP') && newConfig.interfaces) {
|
|
2466
|
+
setSt2110Interfaces(newConfig.interfaces);
|
|
2467
|
+
}
|
|
2468
|
+
} catch (error) {
|
|
2469
|
+
console.error('Failed to refresh config:', error);
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
// 如果有restart函数,则显示重启确认框
|
|
2474
|
+
if (isPopup && restart) {
|
|
2393
2475
|
try {
|
|
2394
2476
|
const updatedConfig = await getSysConfig();
|
|
2395
2477
|
if (updatedConfig && updatedConfig.is_restart_required) {
|
|
@@ -2420,7 +2502,9 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2420
2502
|
const lanData = values.LAN.map((item, index) => ({
|
|
2421
2503
|
connection_id: lanConfigs[index]?.connection_id,
|
|
2422
2504
|
ip_address: item.ip_address,
|
|
2423
|
-
|
|
2505
|
+
...(showNetmask.LAN ? {
|
|
2506
|
+
netmask: item.netmask
|
|
2507
|
+
} : {})
|
|
2424
2508
|
}));
|
|
2425
2509
|
updatePromises.push(updateLanConfig(lanData));
|
|
2426
2510
|
}
|
|
@@ -2429,8 +2513,14 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2429
2513
|
if (sections.includes('QSFP') && values.QSFP) {
|
|
2430
2514
|
const st2110Data = {
|
|
2431
2515
|
st2110_interfaces: values.QSFP.map((item, index) => ({
|
|
2432
|
-
|
|
2433
|
-
|
|
2516
|
+
// 只有当原始数据中存在id时才包含id
|
|
2517
|
+
...(st2110Interfaces?.[index]?.id !== undefined && {
|
|
2518
|
+
id: st2110Interfaces?.[index]?.id
|
|
2519
|
+
}),
|
|
2520
|
+
ip_address: item.ip_address,
|
|
2521
|
+
...(showNetmask.QSFP ? {
|
|
2522
|
+
netmask: item.netmask
|
|
2523
|
+
} : {})
|
|
2434
2524
|
}))
|
|
2435
2525
|
};
|
|
2436
2526
|
updatePromises.push(updateSysConfig(st2110Data));
|
|
@@ -2491,12 +2581,12 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2491
2581
|
children: [/*#__PURE__*/jsx(NetworkFieldGroup, {
|
|
2492
2582
|
prefix: "LAN",
|
|
2493
2583
|
interfaces: lanConfigs,
|
|
2494
|
-
fieldConfig:
|
|
2584
|
+
fieldConfig: preparedFieldConfig.LAN
|
|
2495
2585
|
}), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsx(Divider, {})]
|
|
2496
2586
|
}), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsx(NetworkFieldGroup, {
|
|
2497
2587
|
prefix: "QSFP",
|
|
2498
2588
|
interfaces: st2110Interfaces,
|
|
2499
|
-
fieldConfig:
|
|
2589
|
+
fieldConfig: preparedFieldConfig.QSFP
|
|
2500
2590
|
})]
|
|
2501
2591
|
})
|
|
2502
2592
|
});
|