crud-page-react 0.1.4 → 0.2.0

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/README.md CHANGED
@@ -66,6 +66,39 @@ function App() {
66
66
  }
67
67
  ```
68
68
 
69
+ ## 国际化支持
70
+
71
+ 组件库支持 Ant Design 的国际化配置,默认使用中文。
72
+
73
+ ```tsx
74
+ import React from 'react';
75
+ import { CrudPage, enUS, zhCN } from 'crud-page-react';
76
+
77
+ // 使用英文
78
+ function EnglishApp() {
79
+ return <CrudPage schema={schema} locale={enUS} />;
80
+ }
81
+
82
+ // 使用中文(默认)
83
+ function ChineseApp() {
84
+ return <CrudPage schema={schema} locale={zhCN} />;
85
+ }
86
+
87
+ // 不指定 locale 时默认使用中文
88
+ function DefaultApp() {
89
+ return <CrudPage schema={schema} />;
90
+ }
91
+ ```
92
+
93
+ ### 支持的语言
94
+
95
+ - `zhCN` - 简体中文(默认)
96
+ - `enUS` - 英文
97
+ - `jaJP` - 日文
98
+ - `koKR` - 韩文
99
+
100
+ 更多语言包请参考 [Ant Design 国际化文档](https://ant.design/docs/react/i18n-cn)。
101
+
69
102
  ## 新特性:操作按钮分组 (v0.1.3)
70
103
 
71
104
  自定义操作现在会自动折叠到"其它操作"下拉菜单中,保持界面整洁:
@@ -1,9 +1,12 @@
1
1
  import React from 'react';
2
+ import type { Locale } from 'antd/es/locale';
2
3
  import type { CrudPageSchema, ApiRequest } from '../types/schema';
3
4
  interface CrudPageProps {
4
5
  schema: CrudPageSchema;
5
6
  initialData?: Record<string, unknown>[];
6
7
  apiRequest?: ApiRequest;
8
+ /** Ant Design 语言配置,默认为中文 */
9
+ locale?: Locale;
7
10
  }
8
11
  declare const CrudPage: React.FC<CrudPageProps>;
9
12
  export default CrudPage;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import React from 'react';
2
+ import { Locale } from 'antd/es/locale';
3
+ export { Locale } from 'antd/es/locale';
2
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
5
  import { Rule } from 'antd/es/form';
6
+ export { default as zhCN } from 'antd/locale/zh_CN';
7
+ export { default as enUS } from 'antd/locale/en_US';
8
+ export { default as jaJP } from 'antd/locale/ja_JP';
9
+ export { default as koKR } from 'antd/locale/ko_KR';
4
10
 
5
11
  /** API 请求函数类型 */
6
12
  interface ApiRequest {
@@ -208,6 +214,8 @@ interface CrudPageProps {
208
214
  schema: CrudPageSchema;
209
215
  initialData?: Record<string, unknown>[];
210
216
  apiRequest?: ApiRequest;
217
+ /** Ant Design 语言配置,默认为中文 */
218
+ locale?: Locale;
211
219
  }
212
220
  declare const CrudPage: React.FC<CrudPageProps>;
213
221
 
package/dist/index.esm.js CHANGED
@@ -1,9 +1,14 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { useState, useEffect, useRef, useCallback } from 'react';
3
- import { DatePicker, Form, Row, Col, Space, Button, Input, Switch, Radio, Select, InputNumber, Tooltip, Popconfirm, Dropdown, Table, message, Tag, Modal, Divider, Card, Checkbox, Typography } from 'antd';
4
- import { SearchOutlined, ReloadOutlined, EyeOutlined, EditOutlined, DeleteOutlined, MoreOutlined, CopyOutlined, FormOutlined, CodeOutlined, PlusOutlined } from '@ant-design/icons';
3
+ import { DatePicker, Form, Row, Col, Space, Button, Input, Switch, Radio, Select, InputNumber, Tooltip, Popconfirm, Dropdown, Table, message, Tag, Modal, Divider, Card, Checkbox, Typography, ConfigProvider } from 'antd';
4
+ import { SearchOutlined, ReloadOutlined, EyeOutlined, EditOutlined, DeleteOutlined, CopyOutlined, MoreOutlined, FormOutlined, CodeOutlined, PlusOutlined } from '@ant-design/icons';
5
+ import zhCN from 'antd/locale/zh_CN';
6
+ export { default as zhCN } from 'antd/locale/zh_CN';
5
7
  import dayjs from 'dayjs';
6
8
  import customParseFormat from 'dayjs/plugin/customParseFormat';
9
+ export { default as enUS } from 'antd/locale/en_US';
10
+ export { default as jaJP } from 'antd/locale/ja_JP';
11
+ export { default as koKR } from 'antd/locale/ko_KR';
7
12
 
8
13
  /* ─── 工具函数 ──────────────────────────────────────── */
9
14
  /**
@@ -270,7 +275,7 @@ function DynamicTable({ schema, data, loading, pagination, onView, onEdit, onDel
270
275
  return (jsx(Popconfirm, { title: (_b = (_a = action.confirm) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : '确定删除?', description: (_c = action.confirm) === null || _c === void 0 ? void 0 : _c.content, onConfirm: () => onDelete(record), okText: "\u786E\u5B9A", cancelText: "\u53D6\u6D88", okButtonProps: { danger: true }, children: jsx(Tooltip, { title: action.label, children: jsx(Button, { type: "link", size: "small", danger: true, icon: jsx(DeleteOutlined, {}) }) }) }, action.key));
271
276
  }
272
277
  return null;
273
- }), customActions.length > 0 && (jsx(Dropdown, { menu: { items: dropdownItems }, trigger: ['click'], placement: "bottomRight", children: jsx(Tooltip, { title: "\u5176\u5B83\u64CD\u4F5C", children: jsx(Button, { type: "link", size: "small", icon: jsx(MoreOutlined, {}) }) }) })), jsx(Tooltip, { title: "\u590D\u5236 JSON", children: jsx(Button, { type: "link", size: "small", icon: jsx(CopyOutlined, {}), onClick: () => copyJson(record) }) })] }));
278
+ }), jsx(Tooltip, { title: "\u590D\u5236 JSON", children: jsx(Button, { type: "link", size: "small", icon: jsx(CopyOutlined, {}), onClick: () => copyJson(record) }) }), customActions.length > 0 && (jsx(Dropdown, { menu: { items: dropdownItems }, trigger: ['click'], placement: "bottomRight", children: jsx(Tooltip, { title: "\u5176\u5B83\u64CD\u4F5C", children: jsx(Button, { type: "link", size: "small", icon: jsx(MoreOutlined, {}) }) }) }))] }));
274
279
  },
275
280
  });
276
281
  return (jsx(Table, { rowKey: (_a = schema.rowKey) !== null && _a !== void 0 ? _a : 'id', columns: columns, dataSource: data, loading: loading, scroll: { x: 'max-content' }, pagination: {
@@ -862,7 +867,7 @@ function extractListResponse(json) {
862
867
  }
863
868
  return { list: [], total: 0 };
864
869
  }
865
- const CrudPage = ({ schema, initialData = [], apiRequest: customApiRequest }) => {
870
+ const CrudPage = ({ schema, initialData = [], apiRequest: customApiRequest, locale = zhCN }) => {
866
871
  var _a;
867
872
  const rowKey = schema.rowKey || 'id';
868
873
  // 使用传入的apiRequest或默认的
@@ -1146,17 +1151,17 @@ const CrudPage = ({ schema, initialData = [], apiRequest: customApiRequest }) =>
1146
1151
  }, [
1147
1152
  request, modalState.mode, schema.api, fetchList, messageApi,
1148
1153
  ]);
1149
- return (jsxs("div", { style: { padding: 24, background: '#f5f6fa', minHeight: '100vh' }, children: [contextHolder, jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }, children: [jsx(Title, { level: 4, style: { margin: 0 }, children: schema.title }), schema.api.create && (jsx(Button, { type: "primary", icon: jsx(PlusOutlined, {}), onClick: () => setModalState({ open: true, mode: 'create', record: undefined }), children: schema.createButtonLabel || '新增' }))] }), jsx(DynamicFilter, { schema: schema, onSearch: handleSearch, onReset: () => handleSearch({}) }), jsx(DynamicTable, { schema: schema, data: data, loading: loading, pagination: {
1150
- current: page,
1151
- pageSize,
1152
- total,
1153
- onChange: handlePageChange,
1154
- }, onView: (record) => handleAction({ key: 'view', label: '查看', type: 'view' }, record), onEdit: (record) => handleAction({ key: 'edit', label: '编辑', type: 'edit' }, record), onDelete: (record) => handleDelete(record), onCustomAction: (actionKey, record) => {
1155
- var _a;
1156
- const action = (_a = schema.actions) === null || _a === void 0 ? void 0 : _a.find(a => a.key === actionKey);
1157
- if (action)
1158
- handleAction(action, record);
1159
- } }), jsx(DynamicForm, { schema: schema, visible: modalState.open, mode: modalState.mode, initialValues: modalState.record, onSubmit: handleFormOk, onCancel: () => setModalState({ open: false, mode: 'create' }) })] }));
1154
+ return (jsx(ConfigProvider, { locale: locale, children: jsxs("div", { style: { padding: 24, background: '#f5f6fa', minHeight: '100vh' }, children: [contextHolder, jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }, children: [jsx(Title, { level: 4, style: { margin: 0 }, children: schema.title }), schema.api.create && (jsx(Button, { type: "primary", icon: jsx(PlusOutlined, {}), onClick: () => setModalState({ open: true, mode: 'create', record: undefined }), children: schema.createButtonLabel || '新增' }))] }), jsx(DynamicFilter, { schema: schema, onSearch: handleSearch, onReset: () => handleSearch({}) }), jsx(DynamicTable, { schema: schema, data: data, loading: loading, pagination: {
1155
+ current: page,
1156
+ pageSize,
1157
+ total,
1158
+ onChange: handlePageChange,
1159
+ }, onView: (record) => handleAction({ key: 'view', label: '查看', type: 'view' }, record), onEdit: (record) => handleAction({ key: 'edit', label: '编辑', type: 'edit' }, record), onDelete: (record) => handleDelete(record), onCustomAction: (actionKey, record) => {
1160
+ var _a;
1161
+ const action = (_a = schema.actions) === null || _a === void 0 ? void 0 : _a.find(a => a.key === actionKey);
1162
+ if (action)
1163
+ handleAction(action, record);
1164
+ } }), jsx(DynamicForm, { schema: schema, visible: modalState.open, mode: modalState.mode, initialValues: modalState.record, onSubmit: handleFormOk, onCancel: () => setModalState({ open: false, mode: 'create' }) })] }) }));
1160
1165
  };
1161
1166
 
1162
1167
  export { BUILTIN_RULES, CrudPage, DynamicFilter, DynamicForm, DynamicTable, defaultWidgetForType, getAllRules, getEffectiveWidget, getFieldGroupPrefix, getNestedValue, getRuleByKey, keysToAntdRules, loadCustomRules, ruleConfigToAntdRule, saveCustomRules };