From 95b1399eb3ea2426c564032004fc8ce8197b2349 Mon Sep 17 00:00:00 2001 From: hechang27-sprt Date: Sat, 27 Dec 2025 10:41:52 +0800 Subject: [PATCH] feat: add `setExample` to `ListTable` to preserve pagination and other default parameters --- plugs/composables/useListTable.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugs/composables/useListTable.ts b/plugs/composables/useListTable.ts index 153355b..4c8e725 100644 --- a/plugs/composables/useListTable.ts +++ b/plugs/composables/useListTable.ts @@ -1,8 +1,9 @@ import { toReactive } from "@vueuse/core"; -import { reactive, ref, toRaw, shallowRef, watchEffect } from "vue"; +import { reactive, ref, shallowRef, watchEffect } from "vue"; import * as Element from "../element"; import { useI18n } from "vue3-i18n"; import { PageResponse } from "../http"; +import { clearAndAssign, deepCopy } from "noob-mengyxu/utils"; const { showMessage } = Element; @@ -12,8 +13,8 @@ export interface TableColumn { i18n?: string; type?: string; width?: string | number; - fixed?: boolean | 'left' | 'right'; - align?: 'left' | 'center' | 'right'; + fixed?: boolean | "left" | "right"; + align?: "left" | "center" | "right"; slot?: boolean; dict?: string; timestamp?: boolean; @@ -64,14 +65,20 @@ export function useListTable(options: Options) { size: initialPageSize || 10, }; - const example = reactive({ + const defaultExample = () => ({ ...pageParams, ...initExample, }); + const example = reactive(defaultExample()); + + const setExample = (params: Record) => { + clearAndAssign(params, { ...defaultExample(), ...params }); + }; + const query = async () => { try { - const resp = await options.query(toRaw(example)); + const resp = await options.query(deepCopy(example)); setRows(resp); } catch (error) { showMessage("error", t("common.errors.listTableQueryError")); @@ -86,6 +93,7 @@ export function useListTable(options: Options) { rows: toReactive(rows), example, setRows, + setExample, query, }; }