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