fix(admin): admin管理页面优化,增加排序过滤等

This commit is contained in:
sophie committed 2026-07-10 14:10:49 +08:00
1 parent 0939aeb0d8
commit fc843905d1
31 files changed
+1090 -671

No files matched your search

@@ -1,10 +1,8 @@
/**
* shared/composables/useReportLayoutStorage.ts
* 报表页面布局偏好 localStorage 持久化。
*/
/**
* useReportLayoutStorage.ts
* 用途:为报表页面提供统一的布局偏好持久化能力(按用户 + 表名隔离)
* 用途:报表页面布局偏好 localStorage 持久化(按用户 + 表名隔离)。
* 依赖:localStorage / sessionStorage 中的 hxops_user。
* 逻辑:ReportsPage / useReportsAdmin 读写列宽、显隐与排序偏好;v3 起聊天日志默认列宽收窄。
*/
const getCurrentAuthUser = () => {
@@ -24,10 +22,20 @@ const getCurrentIdentity = () => {
return user?.id ? `id_${user.id}` : `u_${user?.username || 'guest'}`;
};
/**
* 生成报表布局偏好的 storage key。
* @param table - 报表表名(如 chat_logs)
*/
const getReportLayoutStorageKey = (table: string) => {
return `hxops_report_layout_v2_${getCurrentIdentity()}_${table}`;
// v3:聊天日志默认列宽收窄(应用名/用户/姓名/Token),旧 v2 偏好不再沿用
return `hxops_report_layout_v3_${getCurrentIdentity()}_${table}`;
};
/**
* 读取指定报表表的布局偏好。
* @param table - 报表表名
* @returns 解析后的偏好,失败或不存在时返回 null
*/
export const loadReportLayoutPref = <T = any>(table: string): T | null => {
try {
const raw = localStorage.getItem(getReportLayoutStorageKey(table));
@@ -38,6 +46,11 @@ export const loadReportLayoutPref = <T = any>(table: string): T | null => {
}
};
/**
* 写入指定报表表的布局偏好。
* @param table - 报表表名
* @param payload - 可序列化的布局对象
*/
export const saveReportLayoutPref = (table: string, payload: unknown) => {
try {
localStorage.setItem(getReportLayoutStorageKey(table), JSON.stringify(payload));
@@ -45,4 +58,3 @@ export const saveReportLayoutPref = (table: string, payload: unknown) => {
// Ignore storage write failure to avoid blocking core report flow.
}
};
@@ -0,0 +1,66 @@
/**
* shared/composables/useTableSort.ts
* 用途:表格列排序状态(当前列、方向)与切换/排序辅助。
* 依赖:vue ref、table-sort 纯函数。
* 逻辑:业务 composable(如 useDepartmentsAdmin)注入本 hook,页面用 SortableTableHeader 展示。
*/
import { ref } from 'vue';
import {
nextSortState,
sortByKey,
type SortComparable,
type SortDir,
} from '@/shared/utils/table-sort';
export interface UseTableSortOptions<K extends string> {
/** 初始排序列 */
initialKey?: K;
/** 初始方向,默认 asc */
initialDir?: SortDir;
}
/**
* 管理表格排序状态,并提供按当前状态排序列表的方法。
* @param options.initialKey - 默认排序列
* @param options.initialDir - 默认方向
*/
export function useTableSort<K extends string>(options: UseTableSortOptions<K> = {}) {
const sortKey = ref(options.initialKey as K | undefined);
const sortDir = ref<SortDir>(options.initialDir ?? 'asc');
/**
* 切换表头排序:同列升/降切换,换列从升序开始。
* @param key - 点击的列键
*/
const toggleSort = (key: K): void => {
const next = nextSortState(sortKey.value, sortDir.value, key);
sortKey.value = next.sortKey;
sortDir.value = next.sortDir;
};
/**
* 按当前 sortKey / sortDir 对列表排序。
* @param items - 源列表
* @param getValue - 从行取比较值
* @param tieBreaker - 可选稳定次序
* @returns 新排序数组
*/
const sortItems = <T>(
items: readonly T[],
getValue: (item: T, key: K) => SortComparable,
tieBreaker?: (a: T, b: T) => number,
): T[] =>
sortByKey(items, {
sortKey: sortKey.value,
sortDir: sortDir.value,
getValue,
tieBreaker,
});
return {
sortKey,
sortDir,
toggleSort,
sortItems,
};
}