seeder-st2110-components 1.0.4 → 1.0.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 CHANGED
@@ -2268,10 +2268,12 @@ const NetworkFieldGroup = _ref => {
2268
2268
  }), mergedFieldConfig.ip.enabled && /*#__PURE__*/jsx(Form.Item, {
2269
2269
  label: mergedFieldConfig.ip.label,
2270
2270
  name: [prefix, index, "ip_address"],
2271
+ initialValue: iface.ip_address,
2271
2272
  children: /*#__PURE__*/jsx(Input, {})
2272
2273
  }), mergedFieldConfig.netmask.enabled && /*#__PURE__*/jsx(Form.Item, {
2273
2274
  label: mergedFieldConfig.netmask.label,
2274
2275
  name: [prefix, index, "netmask"],
2276
+ initialValue: iface.netmask,
2275
2277
  children: /*#__PURE__*/jsx(Input, {})
2276
2278
  }), index < interfaces.length - 1 && /*#__PURE__*/jsx(Divider, {
2277
2279
  style: {
@@ -2305,7 +2307,7 @@ const NetworkSettingsModal = _ref2 => {
2305
2307
  const [submitLoading, setSubmitLoading] = useState(false);
2306
2308
  const [isInitialized, setIsInitialized] = useState(false);
2307
2309
  const fetchData = useCallback(async () => {
2308
- if (!open || isInitialized) return;
2310
+ if (!open) return;
2309
2311
  try {
2310
2312
  const promises = [];
2311
2313
  if (sections.includes('LAN')) {
@@ -2318,7 +2320,7 @@ const NetworkSettingsModal = _ref2 => {
2318
2320
  if (sections.includes('LAN')) {
2319
2321
  const lanResult = results[0];
2320
2322
  if (lanResult.status === 'fulfilled') {
2321
- setLanConfigs(lanResult.value);
2323
+ setLanConfigs(lanResult.value || []);
2322
2324
  }
2323
2325
  }
2324
2326
  if (sections.includes('QSFP')) {
@@ -2331,14 +2333,14 @@ const NetworkSettingsModal = _ref2 => {
2331
2333
  } catch (error) {
2332
2334
  console.error('Failed to fetch data:', error);
2333
2335
  }
2334
- }, [open, isInitialized, getLanConfig, getSysConfig, sections]);
2336
+ }, [open, getLanConfig, getSysConfig, sections]);
2335
2337
  useEffect(() => {
2336
2338
  if (open) {
2337
2339
  fetchData();
2338
2340
  }
2339
2341
  }, [open, fetchData]);
2340
2342
 
2341
- // 当模态框关闭时重置初始化状态
2343
+ // 当模态框关闭时重置状态
2342
2344
  useEffect(() => {
2343
2345
  if (!open) {
2344
2346
  setIsInitialized(false);
@@ -2351,23 +2353,30 @@ const NetworkSettingsModal = _ref2 => {
2351
2353
  // 动态初始值配置
2352
2354
  const initialValues = useMemo(() => {
2353
2355
  const values = {};
2354
- if (sections.includes('LAN')) {
2356
+ if (sections.includes('LAN') && lanConfigs.length > 0) {
2355
2357
  values.LAN = lanConfigs.map(config => ({
2356
2358
  connection_id: config.connection_id,
2357
2359
  display_name: config.display_name,
2358
2360
  ip_address: config.ip_address,
2359
2361
  netmask: config.netmask
2360
- })) ?? [];
2362
+ }));
2361
2363
  }
2362
- if (sections.includes('QSFP')) {
2363
- values.QSFP = st2110Interfaces?.map(iface => ({
2364
+ if (sections.includes('QSFP') && st2110Interfaces.length > 0) {
2365
+ values.QSFP = st2110Interfaces.map(iface => ({
2364
2366
  id: iface.id,
2365
2367
  display_name: iface.display_name,
2366
2368
  ip_address: iface.ip_address
2367
- })) ?? [];
2369
+ }));
2368
2370
  }
2369
2371
  return values;
2370
2372
  }, [lanConfigs, st2110Interfaces, sections]);
2373
+
2374
+ // 当初始值准备好后设置表单值
2375
+ useEffect(() => {
2376
+ if (isInitialized && Object.keys(initialValues).length > 0) {
2377
+ form.setFieldsValue(initialValues);
2378
+ }
2379
+ }, [initialValues, isInitialized, form]);
2371
2380
  const handleSuccess = useCallback(async function () {
2372
2381
  let isPopup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
2373
2382
  let messageText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Success';
@@ -2456,7 +2465,6 @@ const NetworkSettingsModal = _ref2 => {
2456
2465
  // 合并默认表单属性和传入的属性
2457
2466
  const mergedFormProps = {
2458
2467
  form: form,
2459
- initialValues: initialValues,
2460
2468
  labelCol: {
2461
2469
  span: 6
2462
2470
  },
@@ -2470,15 +2478,15 @@ const NetworkSettingsModal = _ref2 => {
2470
2478
  ...mergedModalProps,
2471
2479
  children: /*#__PURE__*/jsxs(Form, {
2472
2480
  ...mergedFormProps,
2473
- children: [sections.includes('LAN') && initialValues.LAN && initialValues.LAN.length > 0 && /*#__PURE__*/jsxs(Fragment, {
2481
+ children: [sections.includes('LAN') && lanConfigs.length > 0 && /*#__PURE__*/jsxs(Fragment, {
2474
2482
  children: [/*#__PURE__*/jsx(NetworkFieldGroup, {
2475
2483
  prefix: "LAN",
2476
- interfaces: initialValues.LAN,
2484
+ interfaces: lanConfigs,
2477
2485
  fieldConfig: fieldConfig.LAN
2478
- }), sections.includes('QSFP') && initialValues.QSFP && initialValues.QSFP.length > 0 && /*#__PURE__*/jsx(Divider, {})]
2479
- }), sections.includes('QSFP') && initialValues.QSFP && initialValues.QSFP.length > 0 && /*#__PURE__*/jsx(NetworkFieldGroup, {
2486
+ }), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsx(Divider, {})]
2487
+ }), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsx(NetworkFieldGroup, {
2480
2488
  prefix: "QSFP",
2481
- interfaces: initialValues.QSFP,
2489
+ interfaces: st2110Interfaces,
2482
2490
  fieldConfig: fieldConfig.QSFP
2483
2491
  })]
2484
2492
  })