crud-page-react 0.3.0 → 0.3.2

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
@@ -760,8 +760,7 @@ function DynamicForm({ schema, mode, visible, initialValues, onSubmit, onCancel,
760
760
  view: `查看${entityName}`,
761
761
  };
762
762
  const formFields = schema.fields.filter((f) => {
763
- if (mode === 'view')
764
- return f.table !== false && f.table !== undefined;
763
+ // 查看模式和编辑模式都应该遵循form字段配置
765
764
  return f.form !== false && f.form !== undefined;
766
765
  });
767
766
  react.useEffect(() => {
@@ -1256,8 +1255,10 @@ const CrudPage = ({ schema, initialData = [], apiRequest: customApiRequest, loca
1256
1255
  }
1257
1256
  const updateApiConfig = schema.api.update;
1258
1257
  try {
1258
+ // 使用原始记录数据进行模板变量替换(来自detail或列表数据)
1259
+ const templateData = modalState.record || {};
1259
1260
  // 构建 URL,动态替换占位符
1260
- let url = buildUrl(updateApiConfig.url, values);
1261
+ let url = buildUrl(updateApiConfig.url, templateData);
1261
1262
  // 构建请求选项
1262
1263
  const options = {
1263
1264
  method: updateApiConfig.method || 'PUT',
@@ -1266,7 +1267,8 @@ const CrudPage = ({ schema, initialData = [], apiRequest: customApiRequest, loca
1266
1267
  // 处理请求体数据
1267
1268
  let requestData = Object.assign({}, values);
1268
1269
  if (updateApiConfig.data) {
1269
- const processedData = processTemplateData(updateApiConfig.data, values);
1270
+ // 使用原始记录数据处理模板变量,而不是表单值
1271
+ const processedData = processTemplateData(updateApiConfig.data, templateData);
1270
1272
  requestData = Object.assign(Object.assign(Object.assign({}, requestData), processedData), { timestamp: new Date().toISOString() });
1271
1273
  }
1272
1274
  options.body = JSON.stringify(requestData);
@@ -1281,7 +1283,7 @@ const CrudPage = ({ schema, initialData = [], apiRequest: customApiRequest, loca
1281
1283
  }
1282
1284
  }
1283
1285
  }, [
1284
- request, modalState.mode, schema.api, fetchList, messageApi,
1286
+ request, modalState.mode, modalState.record, schema.api, fetchList, messageApi,
1285
1287
  ]);
1286
1288
  return (jsxRuntime.jsx(antd.ConfigProvider, { locale: locale, children: jsxRuntime.jsxs("div", { style: { padding: 24, background: '#f5f6fa', minHeight: '100vh' }, children: [contextHolder, jsxRuntime.jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }, children: [jsxRuntime.jsx(Title, { level: 4, style: { margin: 0 }, children: schema.title }), schema.api.create && (jsxRuntime.jsx(antd.Button, { type: "primary", icon: jsxRuntime.jsx(icons.PlusOutlined, {}), onClick: () => setModalState({ open: true, mode: 'create', record: undefined }), children: schema.createButtonLabel || '新增' }))] }), jsxRuntime.jsx(DynamicFilter, { schema: schema, onSearch: handleSearch, onReset: () => handleSearch({}) }), jsxRuntime.jsx(DynamicTable, { schema: schema, data: data, loading: loading, pagination: {
1287
1289
  current: page,