UNPKG

@zhsz/cool-design-crud

Version:

92 lines (91 loc) 2.53 kB
import { defineComponent, ref, createVNode, mergeProps } from "vue"; import "../../utils/test.mjs"; import { useCore, useTools } from "../../hooks/core.mjs"; import "clone-deep"; import "array.prototype.flat"; import "merge"; import "@formily/core"; import { omit, pickBy } from "lodash-es"; import "../../hooks/table.mjs"; import { Pagination } from "tdesign-vue-next"; import PaginationProps from "tdesign-vue-next/es/pagination/props"; const index = /* @__PURE__ */ defineComponent({ name: "cl-pagination", props: { ...PaginationProps }, components: { Pagination }, setup(props, { expose, slots }) { const { crud, mitt } = useCore(); const { style, browser } = useTools(); const total = ref(0); const currentPage = ref(1); const pageSize = ref(10); function onCurrentChange(index2) { crud.refresh({ page: index2 }); } function onSizeChange(size) { crud.refresh({ page: 1, size }); } function setPagination(res) { if (res) { currentPage.value = res.currentPage || res.page || 1; pageSize.value = res.pageSize || res.size || 20; total.value = res.total || 0; crud.params.size = pageSize.value; } } mitt.on("crud.refresh", ({ pagination }) => { setPagination(pagination); }); expose({ total, currentPage, pageSize, setPagination }); return () => { return createVNode("div", { "class": "cl-pagination" }, [createVNode(Pagination, mergeProps(omit(pickBy(props, (value) => value !== void 0), ["total", "current", "pageSize", "theme", "size", "onPageSizeChange", "onCurrentChange", "pageSizeOptions"]), { "total": total.value, "current": currentPage.value, "pageSize": pageSize.value, "theme": browser.isMini ? "simple" : "default", "size": style.size === "small" ? "small" : "medium", "onPageSizeChange": (size) => { var _a; onSizeChange(size); (_a = props.onPageSizeChange) == null ? void 0 : _a.call(props, size); }, "onCurrentChange": (index2) => { var _a; onCurrentChange(index2); (_a = props.onCurrentChange) == null ? void 0 : _a.call(props, index2); }, "pageSizeOptions": props.pageSizeOptions ? props.pageSizeOptions : [10, 20, 30, 40, 50, 100] }), slots)]); }; } }); export { index as default };