foggy-data-viewer 1.0.1-beta.26 → 1.0.1-beta.28

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
@@ -8,7 +8,7 @@
8
8
  - 📊 **动态列配置** - 基于 QM Schema + TableConfig 的灵活列配置
9
9
  - 🔍 **高级筛选** - 支持多种数据类型的筛选器(表头过滤 + 独立搜索工具栏)
10
10
  - 📈 **汇总行** - 自动计算选中行和全量汇总
11
- - 🎨 **自定义渲染** - 支持自定义格式化和渲染函数
11
+ - 🎨 **自定义渲染** - 支持 `column-*` 插槽、自定义格式化和渲染函数
12
12
  - 🔧 **组合组件** - 提供 SearchToolbar + DataTable 的组合组件
13
13
  - ✅ **高测试覆盖** - 核心组件覆盖率 90%+
14
14
  - 📦 **按需引入** - ES Module 支持
@@ -184,43 +184,119 @@ function buildTableColumns(
184
184
  - `showAll?: boolean` - 是否显示所有列
185
185
  - `customizations?: ColumnCustomization[]` - 列自定义配置
186
186
 
187
- **返回:**
188
- - `EnhancedColumnSchema[]` - 增强的列配置数组
189
-
190
- ## 类型定义
191
-
192
- ```typescript
193
- interface ColumnSchema {
194
- name: string
195
- type: string
196
- title: string
197
- }
198
-
199
- interface ColumnCustomization {
200
- name: string
201
- width?: number
202
- minWidth?: number
203
- fixed?: 'left' | 'right'
204
- formatter?: (value: any) => string
205
- render?: (params: any) => VNode
206
- filterComponent?: Component
207
- }
208
-
209
- interface TableConfig {
187
+ **返回:**
188
+ - `EnhancedColumnSchema[]` - 增强的列配置数组
189
+
190
+ ## 列内容自定义
191
+
192
+ ### `column-*` 插槽(推荐用于交互)
193
+
194
+ 当业务列需要渲染成链接、按钮,或点击后交给上游页面打开详情、编辑弹窗时,推荐使用 `#column-{field}` 插槽。插槽参数为 `{ row, value, column }`。
195
+
196
+ ```vue
197
+ <script setup lang="ts">
198
+ function openDetail(row: Record<string, unknown>) {
199
+ // 由业务系统决定跳转、弹窗或其他处理方式
200
+ }
201
+ </script>
202
+
203
+ <template>
204
+ <DataTableWithSearch
205
+ :columns="columns"
206
+ :data="data"
207
+ :total="total"
208
+ :loading="loading"
209
+ >
210
+ <template #column-name="{ row, value }">
211
+ <button type="button" class="link-cell" @click.stop="openDetail(row)">
212
+ {{ value || '-' }}
213
+ </button>
214
+ </template>
215
+ </DataTableWithSearch>
216
+ </template>
217
+ ```
218
+
219
+ `foggy-gen` 生成的 QueryTable wrapper 也会透传 `column-*` / `filter-*` 动态插槽,因此业务页可以直接在生成组件上写同样的插槽:
220
+
221
+ ```vue
222
+ <VehicleCapacityProfileManagementQueryTable>
223
+ <template #column-profileName="{ row, value }">
224
+ <button type="button" class="link-cell" @click.stop="openProfile(row)">
225
+ {{ value || '-' }}
226
+ </button>
227
+ </template>
228
+ </VehicleCapacityProfileManagementQueryTable>
229
+ ```
230
+
231
+ ### `render` 函数(适合纯展示)
232
+
233
+ 如果只是添加颜色、图标、标签等展示效果,也可以通过 `ColumnCustomization.render` 或生成组件的 `columnOverrides[field].render` 配置渲染函数:
234
+
235
+ ```typescript
236
+ import { h } from 'vue'
237
+ import { buildTableColumns } from 'foggy-data-viewer'
238
+
239
+ const columns = buildTableColumns(qmSchema, {
240
+ visibleColumns: ['name', 'status'],
241
+ customizations: [
242
+ {
243
+ name: 'status',
244
+ render: ({ value, column }) => h(
245
+ 'span',
246
+ { class: value === 'active' ? 'status-ok' : 'status-muted' },
247
+ `${column.title}: ${String(value ?? '-')}`
248
+ )
249
+ }
250
+ ]
251
+ })
252
+ ```
253
+
254
+ 选择原则:需要绑定业务事件时优先用 `column-*` 插槽;只改显示内容时使用 `render` 更轻。
255
+
256
+ ## 类型定义
257
+
258
+ ```typescript
259
+ import type { Component } from 'vue'
260
+
261
+ interface ColumnSchema {
262
+ name: string
263
+ type: string
264
+ title: string
265
+ }
266
+
267
+ interface CellRenderContext {
268
+ row: Record<string, unknown>
269
+ value: unknown
270
+ column: EnhancedColumnSchema
271
+ }
272
+
273
+ type CellRenderFn = (params: CellRenderContext) => unknown
274
+
275
+ interface ColumnCustomization {
276
+ name: string
277
+ width?: number
278
+ minWidth?: number
279
+ fixed?: 'left' | 'right'
280
+ formatter?: (value: unknown) => string
281
+ render?: CellRenderFn
282
+ filterComponent?: Component | unknown
283
+ }
284
+
285
+ interface TableConfig {
210
286
  visibleColumns?: string[]
211
287
  showAll?: boolean
212
288
  customizations?: ColumnCustomization[]
213
289
  }
214
290
 
215
291
  interface EnhancedColumnSchema extends ColumnSchema {
216
- width?: number
217
- minWidth?: number
218
- fixed?: 'left' | 'right'
219
- customFormatter?: (value: any) => string
220
- customRender?: (params: any) => VNode
221
- customFilterComponent?: Component
222
- }
223
- ```
292
+ width?: number
293
+ minWidth?: number
294
+ fixed?: 'left' | 'right'
295
+ customFormatter?: (value: unknown) => string
296
+ customRender?: CellRenderFn
297
+ customFilterComponent?: Component | unknown
298
+ }
299
+ ```
224
300
 
225
301
  ## 开发
226
302
 
@@ -1,4 +1,4 @@
1
- import type { QueryMetaResponse, ViewerQueryRequest, ViewerDataResponse, FilterOptionsResponse, ColumnSchema, FrontendMeta, MemberQueryRequest, MemberQueryResponse } from '@/types';
1
+ import type { QueryMetaResponse, ViewerQueryRequest, ViewerDataResponse, FilterOptionsResponse, ColumnSchema, FrontendMeta, MemberQueryRequest, MemberQueryResponse, OrderRequestDef } from '@/types';
2
2
  /**
3
3
  * 查询 payload(与 dataset.query_model 格式一致)
4
4
  */
@@ -14,10 +14,7 @@ export interface QueryPayload {
14
14
  field: string;
15
15
  agg?: string;
16
16
  }>;
17
- orderBy?: Array<{
18
- field: string;
19
- order: 'asc' | 'desc';
20
- }>;
17
+ orderBy?: OrderRequestDef[];
21
18
  calculatedFields?: Array<{
22
19
  name: string;
23
20
  expression: string;
@@ -3,7 +3,7 @@ import type { SliceRequestDef, MemberQueryRequest, MemberQueryResponse } from '@
3
3
  * QueryPanel - 传统查询区组件
4
4
  *
5
5
  * 根据 QuerySchema 渲染表格上方的查询表单区域。
6
- * 支持响应式 grid 布局、折叠/展开、查询/重置。
6
+ * 支持响应式 grid 布局、查询/重置。
7
7
  * 只处理 placement='form' 的查询字段。
8
8
  */
9
9
  export interface QueryFieldSchema {
@@ -74,7 +74,10 @@ declare const _default: import("vue").DefineComponent<Props, {
74
74
  }[];
75
75
  orderBy: {
76
76
  field: string;
77
- order: "asc" | "desc";
77
+ dir?: import("@/types").SortDirection;
78
+ order?: import("@/types").SortDirection;
79
+ nullLast?: boolean;
80
+ nullFirst?: boolean;
78
81
  }[];
79
82
  };
80
83
  pageSize?: number;
package/dist/index.d.ts CHANGED
@@ -26,4 +26,4 @@ export { saveQuery, listSavedQueries, getSavedQuery, updateSavedQuery, deleteSav
26
26
  export type { SavedQueryDef, SaveQueryRequest, QueryVisibility } from './api/savedQuery';
27
27
  export { listPresets, getDefaultListPreset, createListPreset, getListPreset, updateListPreset, deleteListPreset, setDefaultListPreset, clearDefaultListPreset } from './api/listPreset';
28
28
  export type { ListPresetScope, SaveListPresetRequest, UpdateListPresetRequest } from './api/listPreset';
29
- export type { ColumnSchema, EnhancedColumnSchema, TableConfig, TableSchema, CellCopyConfig, QueryMode, ColumnCustomization, QueryMetaResponse, ViewerQueryRequest, ViewerDataResponse, SliceRequestDef, OrderRequestDef, FilterOption, FetchDataParams, FetchDataResult, FetchDataFn, DictItem, PaginationState, SortState, QueryHooks, QueryHookContext, QueryTrigger, QueryHookName, BeforeQueryHookFn, AfterQueryHookFn, ErrorQueryHookFn, MaybePromise, PivotAxisField, PivotAxisPage, PivotAxisPageScope, PivotAxisRole, PivotHeaderNode, PivotHeaderRole, PivotMetric, PivotRawAxisMember, PivotRawCell, PivotRawPayload, PivotShape, PivotViewMode, PivotViewModel, ListPresetVisibility, ListPresetPlacement, ListPresetConfig, ColumnViewSetting, QueryConditionPreset, ListViewState, ListPresetDef, FrontendMeta, FieldMeta, FieldCategory, MemberLookupMeta, UiHintsMeta, DefaultsMeta, CapabilitiesMeta, ParamsMeta, MemberQueryRequest, MemberOption, MemberQueryResponse } from './types';
29
+ export type { ColumnSchema, EnhancedColumnSchema, TableConfig, TableSchema, CellRenderContext, CellRenderFn, CellCopyConfig, QueryMode, ColumnCustomization, QueryMetaResponse, ViewerQueryRequest, ViewerDataResponse, SliceRequestDef, OrderRequestDef, FilterOption, FetchDataParams, FetchDataResult, FetchDataFn, DictItem, PaginationState, SortState, QueryHooks, QueryHookContext, QueryTrigger, QueryHookName, BeforeQueryHookFn, AfterQueryHookFn, ErrorQueryHookFn, MaybePromise, PivotAxisField, PivotAxisPage, PivotAxisPageScope, PivotAxisRole, PivotHeaderNode, PivotHeaderRole, PivotMetric, PivotRawAxisMember, PivotRawCell, PivotRawPayload, PivotShape, PivotViewMode, PivotViewModel, ListPresetVisibility, ListPresetPlacement, ListPresetConfig, ColumnViewSetting, QueryConditionPreset, ListViewState, ListPresetDef, FrontendMeta, FieldMeta, FieldCategory, MemberLookupMeta, UiHintsMeta, DefaultsMeta, CapabilitiesMeta, ParamsMeta, MemberQueryRequest, MemberOption, MemberQueryResponse } from './types';