UNPKG

@zhsz/cool-design-crud

Version:

92 lines (91 loc) 2.71 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const vue = require("vue"); require("../../utils/test.js"); const core = require("../../hooks/core.js"); require("clone-deep"); require("array.prototype.flat"); require("merge"); require("@formily/core"); const lodashEs = require("lodash-es"); require("../../hooks/table.js"); const tdesignVueNext = require("tdesign-vue-next"); const PaginationProps = require("tdesign-vue-next/es/pagination/props"); const index = /* @__PURE__ */ vue.defineComponent({ name: "cl-pagination", props: { ...PaginationProps }, components: { Pagination: tdesignVueNext.Pagination }, setup(props, { expose, slots }) { const { crud, mitt } = core.useCore(); const { style, browser } = core.useTools(); const total = vue.ref(0); const currentPage = vue.ref(1); const pageSize = vue.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 vue.createVNode("div", { "class": "cl-pagination" }, [vue.createVNode(tdesignVueNext.Pagination, vue.mergeProps(lodashEs.omit(lodashEs.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)]); }; } }); exports.default = index;