@fe-free/core 6.0.6 → 6.0.7
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/CHANGELOG.md +8 -0
- package/README.md +172 -0
- package/package.json +4 -4
- package/src/index.ts +6 -6
- package/src/tabs/index.tsx +8 -10
package/CHANGELOG.md
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# @fe-free/core
|
|
2
|
+
|
|
3
|
+
基于 React + Antd + @ant-design/pro-components 的业务核心组件与工具库,提供 CRUD、表单、布局、路由、上传、树等能力。
|
|
4
|
+
|
|
5
|
+
## 安装与依赖
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @fe-free/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**样式**:库内已引入 `style.scss`。`tailwind.css`(core 组件依赖的 Tailwind 样式)需在**项目入口**单独引入一次,否则相关组件样式可能不生效。例如在应用根入口(如 `main.tsx` 或 `App.tsx`)中:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import '@fe-free/core/src/tailwind.css';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
(若使用构建产物路径不同,请按实际路径调整。)
|
|
18
|
+
|
|
19
|
+
## 技术栈与约定
|
|
20
|
+
|
|
21
|
+
- **技术栈**:React、TypeScript、Antd、@ant-design/pro-components、Tailwindcss、react-router-dom
|
|
22
|
+
- **目录命名**:小写 + 下划线连接(如 `page_layout`、`use_global_request`)
|
|
23
|
+
- **导出方式**:使用具名导出 `export { X }` / `export type { X }`,不使用 `export default`
|
|
24
|
+
|
|
25
|
+
## 模块概览
|
|
26
|
+
|
|
27
|
+
### 应用壳与路由
|
|
28
|
+
|
|
29
|
+
| 导出 | 说明 |
|
|
30
|
+
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
31
|
+
| `CoreApp` | 应用根组件:ConfigProvider + ProConfigProvider + Router + i18n + 可选更新检测,需传入 `basename`、`children` |
|
|
32
|
+
| `routeTool` | 路由工具:`setNavigate`/`setBaseName`(由 CoreApp 内部设置)、`navigateTo`、`setSearchParams`、`changeSearchParams`、`generateUrl` |
|
|
33
|
+
|
|
34
|
+
**使用示例**:入口用 `<CoreApp basename="/app">{children}</CoreApp>` 包裹;非 React 上下文中可用 `routeTool.getNavigate()`、`routeTool.setSearchParams({ tab: '1' })` 等。
|
|
35
|
+
|
|
36
|
+
### CRUD 与表格
|
|
37
|
+
|
|
38
|
+
| 导出 | 说明 |
|
|
39
|
+
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
40
|
+
| `CRUD` | 增删改查容器:`actions`(create/read/read_detail/update/delete/batch_delete)、`tableProps`(ProTable 配置,需含 `rowKey`)、详情/新建/编辑弹窗、删除/批量删除 |
|
|
41
|
+
| `OperateDelete` / `useDelete` | 删除操作按钮与逻辑 |
|
|
42
|
+
| `CRUDOfList` / `CRUDOfPure` | 列表型/纯表单型 CRUD 变体 |
|
|
43
|
+
|
|
44
|
+
表格通过 `tableProps` 传入,类型兼容 ProTable(`columns`、`request` 等),默认 `search: false`,需搜索时在列上设置 `search: true`。
|
|
45
|
+
|
|
46
|
+
### 布局与 Tab
|
|
47
|
+
|
|
48
|
+
| 导出 | 说明 |
|
|
49
|
+
| ---------------- | ------------------------------------------------------------------------------------------------ |
|
|
50
|
+
| `PageLayout` | 三区布局:`start` / `children` / `end`,`direction` 为 horizontal(默认)或 vertical |
|
|
51
|
+
| `PageLayoutTabs` | 上 Tab + 下内容区,Tab 与 URL searchParams 同步(`tabsProps.items`:`key`、`label`、`children`) |
|
|
52
|
+
| `Tabs` | 对 antd Tabs 的封装,可选 `withSearchParams` 与 `tabKey` 同步到 URL |
|
|
53
|
+
|
|
54
|
+
### ProForm / ProTable 扩展
|
|
55
|
+
|
|
56
|
+
| 导出 | 说明 |
|
|
57
|
+
| --------------------------------------------------------------------------------- | ----------------------------------------------- |
|
|
58
|
+
| `ProFormJSON` / `ProFormJavascript` / `ProFormEditor` | JSON/JS/富文本编辑 |
|
|
59
|
+
| `ProFormRecord` / `ProFormRecordArray` | 键值对/键值对数组 |
|
|
60
|
+
| `ProFormSwitchNumber` / `ProFormSwitchOptions` / `SwitchNumber` / `SwitchOptions` | 开关数值/选项 |
|
|
61
|
+
| `ProFormListBoolean` / `ProFormListNumber` / `ProFormListText` 等 | 列表型表单项 |
|
|
62
|
+
| `ProFormListHelper` / `ProFormListModalHelper` | 列表辅助 |
|
|
63
|
+
| `ProFormImageUpload` / `ProFormUpload` / `ProFormUploadDragger` 等 | 上传表单项 |
|
|
64
|
+
| `proFormSelectSearchProps` | 下拉搜索 + 拼音过滤的 `fieldProps` |
|
|
65
|
+
| `customValueTypeMap` / `CustomValueTypeEnum` | Pro 表格/表单自定义 valueType(CoreApp 已集成) |
|
|
66
|
+
|
|
67
|
+
### 树与文件树
|
|
68
|
+
|
|
69
|
+
| 导出 | 说明 |
|
|
70
|
+
| ---------------- | ------------------------ |
|
|
71
|
+
| `Tree` | 树组件(见 `TreeProps`) |
|
|
72
|
+
| `FileTree` | 文件树展示 |
|
|
73
|
+
| `flatToTreeData` | 扁平数据转树结构 |
|
|
74
|
+
|
|
75
|
+
### 列表与滚动
|
|
76
|
+
|
|
77
|
+
| 导出 | 说明 |
|
|
78
|
+
| ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |
|
|
79
|
+
| `InfiniteList` | 无限滚动列表:`request`(分页接口)、`renderItem`、`pageSize`、`gridClassName`(内部使用 `useGlobalInfiniteScroll`) |
|
|
80
|
+
| `ScrollFixed` / `useScrollFixed` / `getScrollbarWidth` | 滚动固定与滚动条宽度 |
|
|
81
|
+
|
|
82
|
+
### ahooks / Hooks
|
|
83
|
+
|
|
84
|
+
| 导出 | 说明 |
|
|
85
|
+
| ------------------------- | ------------------------------------------------------- |
|
|
86
|
+
| `useGlobalInfiniteScroll` | 全局无限滚动 hook,供 InfiniteList 或自定义无限列表使用 |
|
|
87
|
+
| `useGlobalRequest` | 全局请求 hook |
|
|
88
|
+
| `useLocalforageState` | 基于 localforage 的本地持久化 state |
|
|
89
|
+
|
|
90
|
+
### 上传与文件
|
|
91
|
+
|
|
92
|
+
| 导出 | 说明 |
|
|
93
|
+
| ---------------------------------------------------------- | ------------- |
|
|
94
|
+
| `Upload` / `UploadDragger` | 上传组件 |
|
|
95
|
+
| `ImageUpload` / `ImageUploadDragger` / `AvatarImageUpload` | 图片/头像上传 |
|
|
96
|
+
| `FileCard` | 文件卡片展示 |
|
|
97
|
+
|
|
98
|
+
### 编辑器与展示
|
|
99
|
+
|
|
100
|
+
| 导出 | 说明 |
|
|
101
|
+
| --------------------------------------------- | -------------------- |
|
|
102
|
+
| `Editor` | 代码编辑器 |
|
|
103
|
+
| `EditorJSON` / `EditorLogs` / `EditorMention` | JSON/日志/提及编辑器 |
|
|
104
|
+
| `DataViewer` | 数据查看 |
|
|
105
|
+
| `Markdown` / `CustomMarkdown` | Markdown 渲染 |
|
|
106
|
+
|
|
107
|
+
### 其它
|
|
108
|
+
|
|
109
|
+
| 导出 | 说明 |
|
|
110
|
+
| ----------------------------------- | ---------------------- |
|
|
111
|
+
| `LoadingButton` | 带 loading 的按钮 |
|
|
112
|
+
| `Copy` | 复制到剪贴板 |
|
|
113
|
+
| `Record` / `RecordArray` | 键值对/键值对数组展示 |
|
|
114
|
+
| `NumberSlider` / `PercentageSlider` | 数字/百分比滑块 |
|
|
115
|
+
| `RequestError` / `initErrorHandle` | 请求错误与全局错误处理 |
|
|
116
|
+
| `downloadInterceptor` | 下载拦截 |
|
|
117
|
+
|
|
118
|
+
### 主题
|
|
119
|
+
|
|
120
|
+
| 导出 | 说明 |
|
|
121
|
+
| ---------------- | -------- |
|
|
122
|
+
| `themeVariables` | 主题变量 |
|
|
123
|
+
|
|
124
|
+
### Tailwind Token 参考(tailwind.css)
|
|
125
|
+
|
|
126
|
+
`tailwind.css` 通过 `@theme` 定义了以下 CSS 变量,引入后可在项目中使用对应 Tailwind 类名(如 `text-primary`、`bg-theme03`、`text-text-color-03` 等)。完整定义见 `packages/core/src/tailwind.css`。
|
|
127
|
+
|
|
128
|
+
| 类别 | 变量名 | 说明/用途 |
|
|
129
|
+
| ------------- | ----------------------- | --------- |
|
|
130
|
+
| **主色** | `--color-primary` | 主色 |
|
|
131
|
+
| | `--color-theme09` | 主色深 |
|
|
132
|
+
| | `--color-theme08` | 主色 |
|
|
133
|
+
| | `--color-theme05` | 主色中 |
|
|
134
|
+
| | `--color-theme03` | 主色浅 |
|
|
135
|
+
| | `--color-theme02` | 主色最浅 |
|
|
136
|
+
| **语义色·红** | `--color-red09` | 红深 |
|
|
137
|
+
| | `--color-red08` | 红 |
|
|
138
|
+
| | `--color-red05` | 红中 |
|
|
139
|
+
| | `--color-red03` | 红浅 |
|
|
140
|
+
| **语义色·绿** | `--color-green09` | 绿深 |
|
|
141
|
+
| | `--color-green08` | 绿 |
|
|
142
|
+
| | `--color-green05` | 绿中 |
|
|
143
|
+
| | `--color-green03` | 绿浅 |
|
|
144
|
+
| **语义色·黄** | `--color-yellow09` | 黄深 |
|
|
145
|
+
| | `--color-yellow08` | 黄 |
|
|
146
|
+
| | `--color-yellow05` | 黄中 |
|
|
147
|
+
| | `--color-yellow03` | 黄浅 |
|
|
148
|
+
| **文字** | `--text-color-01` | 文字最深 |
|
|
149
|
+
| | `--text-color-02` | 文字 |
|
|
150
|
+
| | `--text-color-03` | 文字次要 |
|
|
151
|
+
| | `--text-color-04` | 文字最浅 |
|
|
152
|
+
| **边框** | `--border-color-01` | 边框浅 |
|
|
153
|
+
| | `--border-color-02` | 边框中 |
|
|
154
|
+
| | `--border-color-03` | 边框深 |
|
|
155
|
+
| **背景** | `--background-color-01` | 背景最浅 |
|
|
156
|
+
| | `--background-color-02` | 背景浅 |
|
|
157
|
+
| | `--background-color-03` | 背景中 |
|
|
158
|
+
| | `--background-color-04` | 背景深 |
|
|
159
|
+
|
|
160
|
+
使用示例:`className="text-primary"`、`className="bg-theme03"`、`className="text-text-color-03"`。与 Antd 主题变量(`themeVariables`)配合时,可保持整站色彩一致。
|
|
161
|
+
|
|
162
|
+
当你在本仓库或引用 `@fe-free/core` 的项目中编写代码时,可参考以下约定:
|
|
163
|
+
|
|
164
|
+
1. **应用入口**:使用 `<CoreApp basename="...">` 包裹路由,以保证路由、i18n、Pro 组件 valueType 等生效。
|
|
165
|
+
2. **CRUD 页**:优先使用 `CRUD` + `tableProps`(含 `rowKey`、`columns`、`request`),通过 `actions`、`detailForm`、`requestCreateByValues`、`requestUpdateByValues`、`requestDeleteByRecord` 等接业务接口。
|
|
166
|
+
3. **带 Tab 的页面**:用 `PageLayoutTabs` 或 `Tabs` + `withSearchParams`,Tab 与 URL 同步,便于分享与刷新保持状态。
|
|
167
|
+
4. **表单**:在 ProForm 中需要 JSON/键值对/列表/上传时,使用本库的 `ProForm*` 组件;下拉搜索用 `proFormSelectSearchProps`。
|
|
168
|
+
5. **路由跳转/参数**:使用 `routeTool.navigateTo`、`routeTool.setSearchParams`、`routeTool.changeSearchParams`,不要直接操作 `window.location`(除非确需整页跳转)。
|
|
169
|
+
6. **命名与导出**:新模块目录用小写+下划线;对外一律具名导出 `export { X }` / `export type { X }`。
|
|
170
|
+
7. **样式**:库内已引入 `style.scss`;**`tailwind.css` 需在项目入口单独 `import '@fe-free/core/src/tailwind.css'`**,否则 core 组件所需的 Tailwind 类可能不生效。组件类名多带 `fec-` 前缀,避免与业务样式冲突。
|
|
171
|
+
|
|
172
|
+
更多细节以 `src/index.ts` 的导出和各自模块的 TypeScript 类型为准。
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/core",
|
|
3
|
-
"version": "6.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "6.0.7",
|
|
4
|
+
"description": "React 业务核心组件库:CRUD、ProForm 扩展、布局、路由、树、上传等(Antd + ProComponents)",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
7
7
|
"main": "./src/index.ts",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"i18next-icu": "^2.4.1",
|
|
53
53
|
"react": "^19.2.0",
|
|
54
54
|
"react-i18next": "^16.4.0",
|
|
55
|
-
"@fe-free/icons": "6.0.
|
|
56
|
-
"@fe-free/tool": "6.0.
|
|
55
|
+
"@fe-free/icons": "6.0.7",
|
|
56
|
+
"@fe-free/tool": "6.0.7"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"i18n-extract": "rm -rf ./src/locales/zh-CN && npx i18next-cli extract"
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { LoadingButton } from './button';
|
|
|
7
7
|
export { Copy } from './copy';
|
|
8
8
|
export type { CopyProps } from './copy';
|
|
9
9
|
export { CoreApp } from './core_app';
|
|
10
|
-
export { CRUD,
|
|
10
|
+
export { CRUD, OperateDelete, useDelete } from './crud';
|
|
11
11
|
export type { CRUDDetailProps, CRUDProps, CRUDRef } from './crud';
|
|
12
12
|
export { CRUDOfList } from './crud_of_list';
|
|
13
13
|
export type { CRUDOfListProps } from './crud_of_list';
|
|
@@ -32,8 +32,8 @@ export {
|
|
|
32
32
|
ProFormEditor,
|
|
33
33
|
ProFormImageUpload,
|
|
34
34
|
ProFormImageUploadDragger,
|
|
35
|
-
ProFormJSON,
|
|
36
35
|
ProFormJavascript,
|
|
36
|
+
ProFormJSON,
|
|
37
37
|
ProFormListBoolean,
|
|
38
38
|
ProFormListHelper,
|
|
39
39
|
ProFormListModalHelper,
|
|
@@ -41,15 +41,15 @@ export {
|
|
|
41
41
|
ProFormListText,
|
|
42
42
|
ProFormRecord,
|
|
43
43
|
ProFormRecordArray,
|
|
44
|
+
proFormSelectSearchProps,
|
|
44
45
|
ProFormSwitchNumber,
|
|
45
46
|
ProFormSwitchOptions,
|
|
46
47
|
ProFormUpload,
|
|
47
48
|
ProFormUploadDragger,
|
|
48
49
|
SwitchNumber,
|
|
49
50
|
SwitchOptions,
|
|
50
|
-
proFormSelectSearchProps,
|
|
51
51
|
} from './form';
|
|
52
|
-
export {
|
|
52
|
+
export { initErrorHandle, RequestError } from './global/error';
|
|
53
53
|
export { downloadInterceptor } from './global/interceptors';
|
|
54
54
|
export { InfiniteList } from './infinite_list';
|
|
55
55
|
export type { InfiniteListProps } from './infinite_list';
|
|
@@ -60,13 +60,13 @@ export type { PageLayoutProps, PageLayoutTabsProps } from './page_layout';
|
|
|
60
60
|
export { Record, RecordArray } from './record';
|
|
61
61
|
export type { RecordArrayProps, RecordProps } from './record';
|
|
62
62
|
export { routeTool } from './route';
|
|
63
|
-
export {
|
|
63
|
+
export { getScrollbarWidth, ScrollFixed, useScrollFixed } from './scroll';
|
|
64
64
|
export { NumberSlider, PercentageSlider } from './slider';
|
|
65
65
|
export type { NumberSliderProps, PercentageSliderProps } from './slider';
|
|
66
66
|
export { Tabs } from './tabs';
|
|
67
67
|
export type { TabsProps } from './tabs';
|
|
68
68
|
export { themeVariables } from './theme';
|
|
69
|
-
export { FileTree,
|
|
69
|
+
export { FileTree, flatToTreeData, Tree } from './tree';
|
|
70
70
|
export type { FileTreeProps, TreeProps } from './tree';
|
|
71
71
|
export {
|
|
72
72
|
AvatarImageUpload,
|
package/src/tabs/index.tsx
CHANGED
|
@@ -2,28 +2,26 @@ import type { TabsProps as AntdTabsProps } from 'antd';
|
|
|
2
2
|
import { Tabs as AntdTabs } from 'antd';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { useSearchParams } from 'react-router-dom';
|
|
5
|
+
|
|
5
6
|
import { routeTool } from '../route';
|
|
7
|
+
|
|
6
8
|
import './style.scss';
|
|
7
9
|
|
|
8
|
-
interface TabsProps
|
|
10
|
+
interface TabsProps {
|
|
9
11
|
/** 自动时设置和同步 searchParams tab */
|
|
10
12
|
withSearchParams?: boolean;
|
|
11
13
|
/** 设置 searchParams 的类型,默认 set */
|
|
12
14
|
searchParamsType?: 'set' | 'change';
|
|
13
15
|
/** 默认 tab */
|
|
14
16
|
tabKey?: string;
|
|
17
|
+
|
|
18
|
+
tabProps?: AntdTabsProps;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
function Tabs(props: TabsProps) {
|
|
18
|
-
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
tabKey = 'tab',
|
|
22
|
-
activeKey,
|
|
23
|
-
onChange,
|
|
24
|
-
className,
|
|
25
|
-
...rest
|
|
26
|
-
} = props;
|
|
22
|
+
const { withSearchParams, searchParamsType = 'set', tabKey = 'tab', tabProps } = props;
|
|
23
|
+
const { className, activeKey, onChange, ...rest } = tabProps || {};
|
|
24
|
+
|
|
27
25
|
const [searchParams] = useSearchParams();
|
|
28
26
|
const tab = searchParams.get(tabKey) || undefined;
|
|
29
27
|
|