gaoluyang
2026-06-24 c0cb161bb52ce0fbdce5c66ec391d107c75e2452
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import type {
  VxeGridListeners,
  VxeGridPropTypes,
  VxeGridProps as VxeTableGridProps,
  VxeTablePropTypes,
  VxeUIExport,
} from 'vxe-table';
 
import type { Ref } from 'vue';
 
import type { ClassType, DeepPartial } from '..\..\..\..\types\src';
 
import type { BaseFormComponentType, VbenFormProps } from '..\..\..\..\@core\ui-kit\form-ui\src';
 
import type { VxeGridApi } from './api';
 
import { useVbenForm } from '..\..\..\..\@core\ui-kit\form-ui\src';
 
export interface VxePaginationInfo {
  currentPage: number;
  pageSize: number;
  total: number;
}
 
interface ToolbarConfigOptions extends VxeGridPropTypes.ToolbarConfig {
  /** 是否显示切换搜索表单的按钮 */
  search?: boolean;
}
 
export type VxeTableGridColumns<T = any> = VxeTableGridOptions<T>['columns'];
 
export interface VxeTableGridOptions<T = any> extends VxeTableGridProps<T> {
  /** 工具栏配置 */
  toolbarConfig?: ToolbarConfigOptions;
}
 
export interface SeparatorOptions {
  show?: boolean;
  backgroundColor?: string;
}
 
/**
 * 自定义存储适配器接口
 * 用户可接入任意后端(API、IndexedDB wrapper、第三方库等)
 */
export interface ViewedRowStorageAdapter {
  /** 读取所有已查看的 key 列表 */
  getKeys(): Promise<Array<number | string>>;
 
  /** 移除所有已查看数据 */
  removeKeys(): Promise<void>;
 
  /** 持久化已查看的 key 列表 */
  setKeys(keys: Array<number | string>): Promise<void>;
}
 
/**
 * 已读行持久化 — 公共基础字段
 */
interface ViewedRowPersistBase {
  /** 持久化数据的存活时间(毫秒) */
  ttl?: number;
  /** 最大缓存数量,超出时淘汰最早标记的 key(FIFO),默认 100 */
  maxSize?: number;
}
 
/**
 * 已读行持久化配置(按 type 区分的联合类型)
 *
 * - 'memory'          → 仅内存,不持久化
 * - 'localStorage'    → 使用 localStorage 整体存储,key 必传
 * - 'sessionStorage'  → 使用 sessionStorage 整体存储,key 必传
 * - 'indexedDB'       → 使用 IndexedDB 单条存储,key 必传
 * - 'custom'          → 用户自定义存储适配器,storage 必传
 */
export type ViewedRowPersistOptions =
  | ({
      /** IndexedDB 数据库名称,默认 'viewed-table-db' */
      dbName?: string;
      /** IndexedDB 数据库版本,默认 1 */
      dbVersion?: number;
      /** 存储 key / prefix(必传) */
      key: string;
      /** IndexedDB 对象存储名称,默认 'viewed-table-row' */
      storeName?: string;
      type: 'indexedDB';
    } & ViewedRowPersistBase)
  | ({
      /** 存储 key(必传) */
      key: string;
      type: 'localStorage' | 'sessionStorage';
    } & ViewedRowPersistBase)
  | ({
      /** 自定义存储适配器(必传) */
      storage: ViewedRowStorageAdapter;
      type: 'custom';
    } & ViewedRowPersistBase)
  | (ViewedRowPersistBase & {
      type: 'memory';
    });
 
/**
 * 已查看row设置
 */
export interface ViewedRowOptions<T = any> {
  /** 点击 CellOperation 中匹配的 code 时,自动将该行标记为已读 */
  actionCodes?: string | string[];
  /** 行唯一标识字段,默认取 gridOptions.rowConfig.keyField,最终兜底 'id' */
  keyField?: string;
  /** 已查看的行key列表 */
  viewedKeys?: Array<number | string> | Ref<Array<number | string>>;
  /**
   * 持久化配置
   * - 传 string:使用内置 localStorage,值为 storage key(向后兼容)
   * - 传 object:高级配置
   * - 不传:不持久化(等同于 memory)
   */
  persist?: string | ViewedRowPersistOptions;
  rowClassName?: VxeTablePropTypes.RowClassName<T>;
  rowStyle?: VxeTablePropTypes.RowStyle<T>;
}
 
export interface VxeGridProps<
  T extends Record<string, any> = any,
  D extends BaseFormComponentType = BaseFormComponentType,
  P extends Record<string, any> = Record<never, never>,
> {
  /**
   * 数据
   */
  tableData?: any[];
  /**
   * 标题
   */
  tableTitle?: string;
  /**
   * 标题帮助
   */
  tableTitleHelp?: string;
  /**
   * 组件class
   */
  class?: ClassType;
  /**
   * vxe-grid class
   */
  gridClass?: ClassType;
  /**
   * vxe-grid 配置
   */
  gridOptions?: DeepPartial<VxeTableGridOptions<T>>;
  /**
   * vxe-grid 事件
   */
  gridEvents?: DeepPartial<VxeGridListeners<T>>;
  /**
   * 表单配置
   */
  formOptions?: VbenFormProps<D, P>;
  /**
   * 显示搜索表单
   */
  showSearchForm?: boolean;
  /**
   * 搜索表单与表格主体之间的分隔条
   */
  separator?: boolean | SeparatorOptions;
  /**
   * 已读行功能
   */
  viewedRowOptions?: boolean | ViewedRowOptions<T>;
}
 
export type ExtendedVxeGridApi<
  D extends Record<string, any> = any,
  F extends BaseFormComponentType = BaseFormComponentType,
  P extends Record<string, any> = Record<never, never>,
> = VxeGridApi<D, F, P> & {
  useStore: <S = NoInfer<VxeGridProps<D, F, P>>>(
    selector?: (state: NoInfer<VxeGridProps<D, F, P>>) => S,
  ) => Readonly<Ref<S>>;
};
 
export interface SetupVxeTable {
  configVxeTable: (ui: VxeUIExport) => void;
  useVbenForm?: typeof useVbenForm;
}