@yidun/antd-super-table 0.0.6 → 0.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/README.md CHANGED
@@ -15,7 +15,7 @@ Antd Super Table 是一个基于 Ant Design Vue 的高级表格组件,提供
15
15
 
16
16
  ## 示例
17
17
 
18
- ![示例图片](./example.png)
18
+ ![示例图片](https://cdn.jsdelivr.net/npm/@yidun/antd-super-table@latest/example.png)
19
19
 
20
20
  ## 安装
21
21
 
@@ -99,25 +99,92 @@ const onRequest = async (options: { params: Record<string, any>; pageSize: numbe
99
99
 
100
100
  默认启用场景,场景相关的配置存储在localStorage中
101
101
 
102
- | 属性名 | 类型 | 默认值 | 说明 |
103
- | ---------------- | ------------ | ----------- | ----------------------------------- |
104
- | sceneType | string | '' | 场景对应的标识 |
105
- | enableScene | boolean | `true` | 是否启用场景管理 |
106
- | sceneStorageType | string | `local` | 场景存储位置,可选 `local` 或 `api` |
107
- | sceneRequestUrls | object | 内置API地址 | 场景存储的API地址配置 |
108
- | defaultScene | object/array | | 默认场景配置 |
109
- | maxSceneCount | number | `100` | 最大场景数量 |
102
+ | 属性名 | 类型 | 默认值 | 说明 |
103
+ | ---------------- | ------------ | ------- | ----------------------------------- |
104
+ | sceneType | string | '' | 场景对应的标识 |
105
+ | enableScene | boolean | `true` | 是否启用场景管理 |
106
+ | sceneStorageType | string | `local` | 场景存储位置,可选 `local` 或 `api` |
107
+ | sceneRequest | object | - | 场景请求函数配置(API模式时必填) |
108
+ | defaultScene | object/array | | 默认场景配置 |
109
+ | maxSceneCount | number | `100` | 最大场景数量 |
110
110
 
111
111
  ### 场景存储配置
112
112
 
113
- ```typescript
114
- // 场景API地址配置
115
- const sceneRequestUrls = {
116
- query: 'https://api.example.com/scene/query',
117
- create: 'https://api.example.com/scene/create',
118
- update: 'https://api.example.com/scene/update',
119
- delete: 'https://api.example.com/scene/delete',
113
+ #### 本地存储模式(默认)
114
+
115
+ ```vue
116
+ <template>
117
+ <SuperTable :form-items="formItems" :columns="columns" :request="onRequest" scene-storage-type="local" enable-scene />
118
+ </template>
119
+ ```
120
+
121
+ #### API存储模式
122
+
123
+ ```vue
124
+ <template>
125
+ <SuperTable
126
+ :form-items="formItems"
127
+ :columns="columns"
128
+ :request="onRequest"
129
+ scene-storage-type="api"
130
+ :scene-request="sceneRequest"
131
+ enable-scene
132
+ />
133
+ </template>
134
+
135
+ <script setup>
136
+ // 场景请求函数配置
137
+ const sceneRequest = {
138
+ // 查询场景列表
139
+ querySceneList: async (params: { type: string }) => {
140
+ const response = await fetch('/api/scene/query', {
141
+ method: 'POST',
142
+ headers: { 'Content-Type': 'application/json' },
143
+ body: JSON.stringify(params)
144
+ })
145
+ return response.json()
146
+ },
147
+
148
+ // 创建场景
149
+ createScene: async (params: any) => {
150
+ const response = await fetch('/api/scene/create', {
151
+ method: 'POST',
152
+ headers: { 'Content-Type': 'application/json' },
153
+ body: JSON.stringify(params)
154
+ })
155
+ return response.json()
156
+ },
157
+
158
+ // 更新场景
159
+ updateScene: async (params: any) => {
160
+ const response = await fetch('/api/scene/update', {
161
+ method: 'POST',
162
+ headers: { 'Content-Type': 'application/json' },
163
+ body: JSON.stringify(params)
164
+ })
165
+ return response.json()
166
+ },
167
+
168
+ // 删除场景
169
+ deleteScene: async (params: string[]) => {
170
+ const response = await fetch('/api/scene/delete', {
171
+ method: 'POST',
172
+ headers: { 'Content-Type': 'application/json' },
173
+ body: JSON.stringify(params)
174
+ })
175
+ return response.json()
176
+ }
120
177
  }
178
+ </script>
179
+ ```
180
+
181
+ #### 错误处理
182
+
183
+ 当 `sceneStorageType` 为 `'api'` 但没有提供 `sceneRequest` 时,组件会在控制台输出错误信息并禁用场景功能:
184
+
185
+ ```javascript
186
+ // 控制台错误信息
187
+ SuperTable: sceneStorageType 为 "api" 时,必须提供 sceneRequest 配置
121
188
  ```
122
189
 
123
190
  ## 查询条件配置
@@ -601,7 +668,7 @@ const onRowSortEnd = newData => {
601
668
  | sceneType | 场景类型 | `string` | `''` |
602
669
  | enableScene | 是否启用场景管理 | `boolean` | `true` |
603
670
  | sceneStorageType | 场景存储位置 | `'local' \| 'api'` | `'local'` |
604
- | sceneRequestUrls | 场景API地址配置 | `object` | 内置地址 |
671
+ | sceneRequest | 场景请求函数配置 | `SceneRequestConfig` | - |
605
672
  | defaultScene | 默认场景配置 | `DefaultSceneConfig \| DefaultSceneConfig[]` | - |
606
673
  | maxSceneCount | 最大场景数量 | `number` | `100` |
607
674
  | formItemColSpan | 查询条件列数 | `number` | `6` |
@@ -787,6 +854,33 @@ export interface SuperTableFormItem {
787
854
  ### 场景管理类型
788
855
 
789
856
  ```typescript
857
+ /** 场景请求函数配置 */
858
+ export interface SceneRequestConfig {
859
+ /** 查询场景列表 */
860
+ querySceneList: (params: { type: string }) => Promise<IResponse>
861
+
862
+ /** 创建场景 */
863
+ createScene: (params: any) => Promise<IResponse>
864
+
865
+ /** 更新场景 */
866
+ updateScene: (params: any) => Promise<IResponse>
867
+
868
+ /** 删除场景 */
869
+ deleteScene: (params: string[]) => Promise<IResponse>
870
+ }
871
+
872
+ /** 接口响应数据结构 */
873
+ export interface IResponse {
874
+ /** 状态码 */
875
+ code: number
876
+
877
+ /** 响应数据 */
878
+ data: any
879
+
880
+ /** 响应消息 */
881
+ msg: string
882
+ }
883
+
790
884
  /** 查询场景 */
791
885
  export interface SuperTableQueryScene {
792
886
  /** 场景唯一标识 */
@@ -886,13 +980,42 @@ export interface AntdTableProps extends TableProps {
886
980
  1. **依赖要求**:组件依赖于 Ant Design Vue,请确保项目中已安装相关依赖
887
981
  2. **TypeScript 支持**:TypeScript 项目需要在 `tsconfig.json` 中配置类型声明文件路径
888
982
  3. **自定义组件**:自定义组件需要通过 `component` 属性传入,并确保组件已全局注册或局部引入
889
- 4. **场景管理**:场景管理功能需要配置 `sceneType` 属性,并实现相关的存储接口
983
+ 4. **场景管理**:
984
+ - 场景管理功能需要配置 `sceneType` 属性
985
+ - 使用 `local` 存储模式时,场景数据保存在浏览器的 localStorage 中
986
+ - 使用 `api` 存储模式时,必须提供 `sceneRequest` 配置,否则会禁用场景功能并在控制台输出错误信息
890
987
  5. **性能优化**:组件内置了防抖、虚拟滚动等性能优化,大数据量场景下表现良好
891
988
  6. **响应式设计**:组件支持响应式布局,可根据屏幕尺寸自动调整
892
989
  7. **主题定制**:支持通过 CSS 变量或 Ant Design 主题系统进行样式定制
893
990
 
894
991
  ## 更新日志
895
992
 
993
+ ### v0.0.7
994
+
995
+ - 🔄 **重构场景管理API**:
996
+ - 将 `sceneRequestUrls` 重构为 `sceneRequest`
997
+ - 从传递URL字符串改为传递请求函数,提供更大的灵活性
998
+ - 支持自定义请求逻辑、错误处理和认证机制
999
+ - 🔧 **优化错误处理**:
1000
+ - 当 `sceneStorageType` 为 `'api'` 但未提供 `sceneRequest` 时,提供清晰的错误提示
1001
+ - 实现优雅降级,避免应用崩溃
1002
+ - 🗑️ **移除冗余代码**:
1003
+ - 删除 `apiSceneService` 中间层,直接使用 `sceneRequest`
1004
+ - 简化架构,提高代码可维护性
1005
+ - 📚 **完善文档**:
1006
+ - 更新API文档和类型定义
1007
+ - 添加详细的配置示例和错误处理说明
1008
+ - 提供本地存储和API存储两种模式的完整示例
1009
+ - 🖼️ **修复文档图片**:
1010
+ - 修复 npm 包中示例图片无法显示的问题
1011
+ - 使用 CDN 方式确保图片在不同平台都能正确显示
1012
+
1013
+ ### v0.0.6
1014
+
1015
+ - 🐛 修复场景管理相关问题
1016
+ - 🐛 修复表格列配置缓存问题
1017
+ - 💄 优化UI样式和交互体验
1018
+
896
1019
  ### v0.0.2
897
1020
 
898
1021
  - ✨ 新增表格拖拽排序功能
package/dist/config.d.ts CHANGED
@@ -28,10 +28,3 @@ export declare const SceneModalActionTypeEnum: {
28
28
  };
29
29
  /** 本地缓存需要保存的列配置字段 */
30
30
  export declare const cacheColumnKeys: string[];
31
- /** 场景管理接口地址 */
32
- export declare const sceneApiUrls: {
33
- query: string;
34
- create: string;
35
- update: string;
36
- delete: string;
37
- };