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