style: 优化 vxe-table 类型组织结构,将 viewed-row 功能域相关类型进行模块化拆分,由全局类型声明调整为功能目录内聚管理,避免公共 types 文件持续膨胀。 (#8204)
This commit is contained in:
@@ -7,7 +7,7 @@ import type {
|
||||
} from '@vben-core/form-ui';
|
||||
|
||||
import type { VxeGridProps } from './types';
|
||||
import type { ViewedRowHelper } from './use-viewed-row';
|
||||
import type { ViewedRowHelper } from './viewed-row';
|
||||
|
||||
import { toRaw } from 'vue';
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import type {
|
||||
VxeGridListeners,
|
||||
VxeGridPropTypes,
|
||||
VxeGridProps as VxeTableGridProps,
|
||||
VxeTablePropTypes,
|
||||
VxeUIExport,
|
||||
} from 'vxe-table';
|
||||
|
||||
@@ -17,6 +16,7 @@ import type {
|
||||
} from '@vben-core/form-ui';
|
||||
|
||||
import type { VxeGridApi } from './api';
|
||||
import type { ViewedRowOptions } from './viewed-row';
|
||||
|
||||
import { useVbenForm } from '@vben-core/form-ui';
|
||||
|
||||
@@ -43,87 +43,6 @@ export interface SeparatorOptions {
|
||||
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,
|
||||
|
||||
@@ -44,7 +44,7 @@ import { VxeGrid, VxeUI } from 'vxe-table';
|
||||
|
||||
import { extendProxyOptions } from './extends';
|
||||
import { useTableForm } from './init';
|
||||
import { applyViewedRowOptions, useViewedRow } from './use-viewed-row';
|
||||
import { applyViewedRowOptions, useViewedRow } from './viewed-row';
|
||||
|
||||
import 'vxe-table/styles/cssvar.scss';
|
||||
import 'vxe-pc-ui/styles/cssvar.scss';
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
export type {
|
||||
ViewedRowOptions,
|
||||
ViewedRowPersistOptions,
|
||||
ViewedRowStorageAdapter,
|
||||
} from './types';
|
||||
|
||||
export { applyViewedRowOptions, useViewedRow } from './use-viewed-row';
|
||||
export type { ViewedRowHelper } from './use-viewed-row';
|
||||
84
packages/effects/plugins/src/vxe-table/viewed-row/types.ts
Normal file
84
packages/effects/plugins/src/vxe-table/viewed-row/types.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import type { VxeTablePropTypes } from 'vxe-table';
|
||||
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
/**
|
||||
* 自定义存储适配器接口
|
||||
* 用户可接入任意后端(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>;
|
||||
}
|
||||
Reference in New Issue
Block a user