UNPKG

@wetspace/pro-components

Version:
70 lines (69 loc) 1.75 kB
import { shallowRef as p, ref as g, computed as f, onMounted as h, watch as S } from "vue"; import { useDebounceFn as m } from "../../../node_modules/.pnpm/@vueuse_shared@10.11.1_vue@3.5.12_typescript@5.4.2_/node_modules/@vueuse/shared/index.mjs"; const q = (t, d) => { const n = p(!1), o = g({ success: !0, data: [], total: 1 }), u = g({ pageSize: 10, currentPage: 1 }), i = async () => { const e = t.data || []; if (t.pagination) { const { pageSize: a, currentPage: v } = u.value, s = (v - 1) * a; return { success: !0, total: e.length, data: s + a >= e.length ? e.slice(s, e.length) : e.slice(s, s + a) }; } else return { total: e.length, data: e }; }, r = f(() => { if (t.pagination) { const e = { pageSizes: [10, 20, 50], layout: "total,sizes,prev,pager,next,jumper", background: !0, position: "center" }; return typeof t.pagination == "boolean" ? e : { ...e, ...t.pagination }; } else return !1; }), l = f(() => t.request ? t.request : i), c = m(async () => { if (!n.value) { n.value = !0; try { const e = await l.value(d.value, u.value); e.success && (o.value = e); } catch (e) { console.error(e); } n.value = !1; } }, 200); return h(() => { r.value && (u.value.pageSize = r.value.pageSizes[0]), c(); }), S(() => t.data, async (e) => { if (e) { const a = await i(); o.value = a; } }, { deep: !0 }), { dataSource: o, requestApi: l, paginationInfo: u, $pagination: r, loading: n, runReuestApi: c }; }; export { q as default };