seeder-st2110-components 1.1.2 → 1.1.4
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 +113 -35
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +113 -35
- 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,23 @@ 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,
|
|
2311
|
+
refreshSettings,
|
|
2293
2312
|
modalProps = {},
|
|
2294
2313
|
formProps = {},
|
|
2295
2314
|
fieldConfig = {},
|
|
2296
|
-
sections = ['LAN', 'QSFP']
|
|
2315
|
+
sections = ['LAN', 'QSFP'],
|
|
2316
|
+
showNetmask = {
|
|
2317
|
+
LAN: true,
|
|
2318
|
+
QSFP: false
|
|
2319
|
+
} // 控制各部分的netmask显示
|
|
2297
2320
|
} = _ref2;
|
|
2298
2321
|
const {
|
|
2299
2322
|
message,
|
|
@@ -2308,30 +2331,63 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2308
2331
|
hasFetched: false,
|
|
2309
2332
|
hasInitialized: false
|
|
2310
2333
|
});
|
|
2334
|
+
const preparedFieldConfig = useMemo(() => {
|
|
2335
|
+
const config = {
|
|
2336
|
+
...fieldConfig
|
|
2337
|
+
};
|
|
2338
|
+
|
|
2339
|
+
// 确保LAN和QSFP的配置存在
|
|
2340
|
+
config.LAN = config.LAN || {};
|
|
2341
|
+
config.QSFP = config.QSFP || {};
|
|
2342
|
+
if (sections.includes('LAN')) {
|
|
2343
|
+
config.LAN.netmask = {
|
|
2344
|
+
...(config.LAN.netmask || {}),
|
|
2345
|
+
enabled: showNetmask.LAN
|
|
2346
|
+
};
|
|
2347
|
+
}
|
|
2348
|
+
if (sections.includes('QSFP')) {
|
|
2349
|
+
config.QSFP.netmask = {
|
|
2350
|
+
...(config.QSFP.netmask || {}),
|
|
2351
|
+
enabled: showNetmask.QSFP
|
|
2352
|
+
};
|
|
2353
|
+
}
|
|
2354
|
+
return config;
|
|
2355
|
+
}, [fieldConfig, showNetmask, sections]);
|
|
2311
2356
|
useEffect(() => {
|
|
2312
2357
|
if (!open) return;
|
|
2313
2358
|
const fetchData = async () => {
|
|
2314
2359
|
if (initializationStatus.current.hasFetched) return;
|
|
2315
2360
|
try {
|
|
2316
2361
|
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 || []);
|
|
2362
|
+
if (getConfig) {
|
|
2363
|
+
// 使用统一接口获取数据
|
|
2364
|
+
const config = await getConfig();
|
|
2365
|
+
if (sections.includes('LAN') && config.lan_interfaces) {
|
|
2366
|
+
setLanConfigs(config.lan_interfaces);
|
|
2329
2367
|
}
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2368
|
+
if (sections.includes('QSFP') && config.interfaces) {
|
|
2369
|
+
setSt2110Interfaces(config.interfaces);
|
|
2370
|
+
}
|
|
2371
|
+
} else {
|
|
2372
|
+
const promises = [];
|
|
2373
|
+
if (sections.includes('LAN')) {
|
|
2374
|
+
promises.push(getLanConfig());
|
|
2375
|
+
}
|
|
2376
|
+
if (sections.includes('QSFP')) {
|
|
2377
|
+
promises.push(getSysConfig());
|
|
2378
|
+
}
|
|
2379
|
+
const results = await Promise.allSettled(promises);
|
|
2380
|
+
if (sections.includes('LAN') && getLanConfig) {
|
|
2381
|
+
const lanResult = results[0];
|
|
2382
|
+
if (lanResult.status === 'fulfilled') {
|
|
2383
|
+
setLanConfigs(lanResult.value || []);
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
if (sections.includes('QSFP') && getSysConfig) {
|
|
2387
|
+
const sysResult = sections.includes('LAN') ? results[1] : results[0];
|
|
2388
|
+
if (sysResult.status === 'fulfilled' && sysResult.value) {
|
|
2389
|
+
setSt2110Interfaces(sysResult.value.st2110_interfaces || []);
|
|
2390
|
+
}
|
|
2335
2391
|
}
|
|
2336
2392
|
}
|
|
2337
2393
|
setIsInitialized(true);
|
|
@@ -2365,18 +2421,27 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2365
2421
|
connection_id: config.connection_id,
|
|
2366
2422
|
display_name: config.display_name,
|
|
2367
2423
|
ip_address: config.ip_address,
|
|
2368
|
-
|
|
2424
|
+
...(showNetmask.LAN ? {
|
|
2425
|
+
netmask: config.netmask
|
|
2426
|
+
} : {})
|
|
2369
2427
|
}));
|
|
2370
2428
|
}
|
|
2371
2429
|
if (sections.includes('QSFP') && st2110Interfaces.length > 0) {
|
|
2372
2430
|
values.QSFP = st2110Interfaces.map(iface => ({
|
|
2373
|
-
|
|
2431
|
+
// 只有当iface中存在id字段时才包含id
|
|
2432
|
+
...(iface.id !== undefined && {
|
|
2433
|
+
id: iface.id
|
|
2434
|
+
}),
|
|
2374
2435
|
display_name: iface.display_name,
|
|
2375
|
-
ip_address: iface.ip_address
|
|
2436
|
+
ip_address: iface.ip_address || iface.ip,
|
|
2437
|
+
// 优先取ip_address,没有则取ip
|
|
2438
|
+
...(showNetmask.QSFP ? {
|
|
2439
|
+
netmask: iface.netmask
|
|
2440
|
+
} : {})
|
|
2376
2441
|
}));
|
|
2377
2442
|
}
|
|
2378
2443
|
return values;
|
|
2379
|
-
}, [lanConfigs, st2110Interfaces, sections]);
|
|
2444
|
+
}, [lanConfigs, st2110Interfaces, sections, showNetmask]);
|
|
2380
2445
|
|
|
2381
2446
|
// 当初始值准备好后设置表单值
|
|
2382
2447
|
useEffect(() => {
|
|
@@ -2386,10 +2451,16 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2386
2451
|
}
|
|
2387
2452
|
}, [isInitialized, form, initialValues]);
|
|
2388
2453
|
const handleSuccess = useCallback(async function () {
|
|
2389
|
-
let
|
|
2390
|
-
|
|
2454
|
+
let {
|
|
2455
|
+
messageText = 'Success',
|
|
2456
|
+
isPopup = !!restart,
|
|
2457
|
+
refresh = !!refreshSettings
|
|
2458
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2391
2459
|
message.success(messageText);
|
|
2392
|
-
if (
|
|
2460
|
+
if (refresh && refreshSettings) {
|
|
2461
|
+
await refreshSettings();
|
|
2462
|
+
}
|
|
2463
|
+
if (isPopup && restart) {
|
|
2393
2464
|
try {
|
|
2394
2465
|
const updatedConfig = await getSysConfig();
|
|
2395
2466
|
if (updatedConfig && updatedConfig.is_restart_required) {
|
|
@@ -2406,7 +2477,7 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2406
2477
|
}
|
|
2407
2478
|
}
|
|
2408
2479
|
onClose();
|
|
2409
|
-
}, [message, modal, getSysConfig, restart, onClose]);
|
|
2480
|
+
}, [message, modal, getSysConfig, restart, refreshSettings, onClose]);
|
|
2410
2481
|
const handleSubmit = useCallback(async () => {
|
|
2411
2482
|
setSubmitLoading(true);
|
|
2412
2483
|
try {
|
|
@@ -2420,7 +2491,9 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2420
2491
|
const lanData = values.LAN.map((item, index) => ({
|
|
2421
2492
|
connection_id: lanConfigs[index]?.connection_id,
|
|
2422
2493
|
ip_address: item.ip_address,
|
|
2423
|
-
|
|
2494
|
+
...(showNetmask.LAN ? {
|
|
2495
|
+
netmask: item.netmask
|
|
2496
|
+
} : {})
|
|
2424
2497
|
}));
|
|
2425
2498
|
updatePromises.push(updateLanConfig(lanData));
|
|
2426
2499
|
}
|
|
@@ -2429,9 +2502,14 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2429
2502
|
if (sections.includes('QSFP') && values.QSFP) {
|
|
2430
2503
|
const st2110Data = {
|
|
2431
2504
|
st2110_interfaces: values.QSFP.map((item, index) => ({
|
|
2432
|
-
|
|
2505
|
+
// 只有当原始数据中存在id时才包含id
|
|
2506
|
+
...(st2110Interfaces?.[index]?.id !== undefined && {
|
|
2507
|
+
id: st2110Interfaces?.[index]?.id
|
|
2508
|
+
}),
|
|
2433
2509
|
ip_address: item.ip_address,
|
|
2434
|
-
|
|
2510
|
+
...(showNetmask.QSFP ? {
|
|
2511
|
+
netmask: item.netmask
|
|
2512
|
+
} : {})
|
|
2435
2513
|
}))
|
|
2436
2514
|
};
|
|
2437
2515
|
updatePromises.push(updateSysConfig(st2110Data));
|
|
@@ -2492,12 +2570,12 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2492
2570
|
children: [/*#__PURE__*/jsx(NetworkFieldGroup, {
|
|
2493
2571
|
prefix: "LAN",
|
|
2494
2572
|
interfaces: lanConfigs,
|
|
2495
|
-
fieldConfig:
|
|
2573
|
+
fieldConfig: preparedFieldConfig.LAN
|
|
2496
2574
|
}), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsx(Divider, {})]
|
|
2497
2575
|
}), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsx(NetworkFieldGroup, {
|
|
2498
2576
|
prefix: "QSFP",
|
|
2499
2577
|
interfaces: st2110Interfaces,
|
|
2500
|
-
fieldConfig:
|
|
2578
|
+
fieldConfig: preparedFieldConfig.QSFP
|
|
2501
2579
|
})]
|
|
2502
2580
|
})
|
|
2503
2581
|
});
|