Browse Source

feat: add `setExample` to `ListTable` to preserve pagination and other default parameters

dev
hechang27-sprt 6 months ago
parent
commit
95b1399eb3
  1. 18
      plugs/composables/useListTable.ts

18
plugs/composables/useListTable.ts

@ -1,8 +1,9 @@ @@ -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 { @@ -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) { @@ -64,14 +65,20 @@ export function useListTable(options: Options) {
size: initialPageSize || 10,
};
const example = reactive<any>({
const defaultExample = () => ({
...pageParams,
...initExample,
});
const example = reactive<any>(defaultExample());
const setExample = (params: Record<string, any>) => {
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) { @@ -86,6 +93,7 @@ export function useListTable(options: Options) {
rows: toReactive(rows),
example,
setRows,
setExample,
query,
};
}

Loading…
Cancel
Save