seeder-st2110-components 1.0.3 → 1.0.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.js CHANGED
@@ -2305,37 +2305,50 @@ const NetworkSettingsModal = _ref2 => {
2305
2305
  const [st2110Interfaces, setSt2110Interfaces] = react.useState([]);
2306
2306
  const [lanConfigs, setLanConfigs] = react.useState([]);
2307
2307
  const [submitLoading, setSubmitLoading] = react.useState(false);
2308
- react.useEffect(() => {
2309
- const fetchInitialData = async () => {
2310
- try {
2311
- const promises = [];
2312
- if (sections.includes('LAN')) {
2313
- promises.push(getLanConfig());
2314
- }
2315
- if (sections.includes('QSFP')) {
2316
- promises.push(getSysConfig());
2317
- }
2318
- const results = await Promise.allSettled(promises);
2319
- if (sections.includes('LAN')) {
2320
- const lanResult = results[sections.indexOf('LAN')];
2321
- if (lanResult.status === 'fulfilled') {
2322
- setLanConfigs(lanResult.value);
2323
- }
2308
+ const [isInitialized, setIsInitialized] = react.useState(false);
2309
+ const fetchData = react.useCallback(async () => {
2310
+ if (!open || isInitialized) return;
2311
+ try {
2312
+ const promises = [];
2313
+ if (sections.includes('LAN')) {
2314
+ promises.push(getLanConfig());
2315
+ }
2316
+ if (sections.includes('QSFP')) {
2317
+ promises.push(getSysConfig());
2318
+ }
2319
+ const results = await Promise.allSettled(promises);
2320
+ if (sections.includes('LAN')) {
2321
+ const lanResult = results[0];
2322
+ if (lanResult.status === 'fulfilled') {
2323
+ setLanConfigs(lanResult.value);
2324
2324
  }
2325
- if (sections.includes('QSFP')) {
2326
- const sysResult = results[sections.indexOf('QSFP')];
2327
- if (sysResult.status === 'fulfilled' && sysResult.value) {
2328
- setSt2110Interfaces(sysResult.value.st2110_interfaces || []);
2329
- }
2325
+ }
2326
+ if (sections.includes('QSFP')) {
2327
+ const sysResult = sections.includes('LAN') ? results[1] : results[0];
2328
+ if (sysResult.status === 'fulfilled' && sysResult.value) {
2329
+ setSt2110Interfaces(sysResult.value.st2110_interfaces || []);
2330
2330
  }
2331
- } catch (error) {
2332
- console.error('Failed to fetch data:', error);
2333
2331
  }
2334
- };
2332
+ setIsInitialized(true);
2333
+ } catch (error) {
2334
+ console.error('Failed to fetch data:', error);
2335
+ }
2336
+ }, [open, isInitialized, getLanConfig, getSysConfig, sections]);
2337
+ react.useEffect(() => {
2335
2338
  if (open) {
2336
- fetchInitialData();
2339
+ fetchData();
2340
+ }
2341
+ }, [open, fetchData]);
2342
+
2343
+ // 当模态框关闭时重置初始化状态
2344
+ react.useEffect(() => {
2345
+ if (!open) {
2346
+ setIsInitialized(false);
2347
+ setLanConfigs([]);
2348
+ setSt2110Interfaces([]);
2349
+ form.resetFields();
2337
2350
  }
2338
- }, [open, getLanConfig, getSysConfig, sections]);
2351
+ }, [open, form]);
2339
2352
 
2340
2353
  // 动态初始值配置
2341
2354
  const initialValues = react.useMemo(() => {
@@ -2357,7 +2370,7 @@ const NetworkSettingsModal = _ref2 => {
2357
2370
  }
2358
2371
  return values;
2359
2372
  }, [lanConfigs, st2110Interfaces, sections]);
2360
- const handleSuccess = async function () {
2373
+ const handleSuccess = react.useCallback(async function () {
2361
2374
  let isPopup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
2362
2375
  let messageText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Success';
2363
2376
  message.success(messageText);
@@ -2378,8 +2391,8 @@ const NetworkSettingsModal = _ref2 => {
2378
2391
  }
2379
2392
  }
2380
2393
  onClose();
2381
- };
2382
- const handleSubmit = async () => {
2394
+ }, [message, modal, getSysConfig, restart, onClose]);
2395
+ const handleSubmit = react.useCallback(async () => {
2383
2396
  setSubmitLoading(true);
2384
2397
  try {
2385
2398
  const values = await form.validateFields();
@@ -2421,7 +2434,7 @@ const NetworkSettingsModal = _ref2 => {
2421
2434
  } finally {
2422
2435
  setSubmitLoading(false);
2423
2436
  }
2424
- };
2437
+ }, [form, sections, lanConfigs, st2110Interfaces, updateLanConfig, updateSysConfig, handleSuccess, message]);
2425
2438
 
2426
2439
  // 合并默认模态框属性和传入的属性
2427
2440
  const mergedModalProps = {
@@ -2464,7 +2477,7 @@ const NetworkSettingsModal = _ref2 => {
2464
2477
  prefix: "LAN",
2465
2478
  interfaces: initialValues.LAN,
2466
2479
  fieldConfig: fieldConfig.LAN
2467
- }), sections.includes('QSFP') && /*#__PURE__*/jsxRuntime.jsx(antd.Divider, {})]
2480
+ }), sections.includes('QSFP') && initialValues.QSFP && initialValues.QSFP.length > 0 && /*#__PURE__*/jsxRuntime.jsx(antd.Divider, {})]
2468
2481
  }), sections.includes('QSFP') && initialValues.QSFP && initialValues.QSFP.length > 0 && /*#__PURE__*/jsxRuntime.jsx(NetworkFieldGroup, {
2469
2482
  prefix: "QSFP",
2470
2483
  interfaces: initialValues.QSFP,