UNPKG

tass-ui

Version:

A high quality UI Toolkit built on Vue.js3+.

97 lines (96 loc) 3.36 kB
import { defineComponent, computed, useAttrs, ref, openBlock, createElementBlock, createElementVNode, normalizeClass, unref, createCommentVNode, Fragment, renderList, toDisplayString } from "vue"; import "../../../theme-chalk/src/pagination.scss.mjs"; const _hoisted_1 = { class: "tas-pagination" }; const _hoisted_2 = { key: 0 }; const _hoisted_3 = ["onClick"]; const _hoisted_4 = { key: 1 }; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "pagination", props: { //数据总条数 total: { type: Number, default: 80 }, //每页数据条数 pagesize: { type: Number, default: 8 } }, emits: ["change-page"], setup(__props, { emit }) { const props = __props; let pages = computed(() => Math.ceil(props.total / props.pagesize)); const attrs = useAttrs(); const currentPage = ref(attrs.page || 1); const list = computed(() => { const result = []; if (pages.value <= 5) { for (let i = 1; i <= pages.value; i++) { result.push(i); } } else { if (currentPage.value <= 2) { for (let i = 1; i <= 5; i++) { result.push(i); } } else if (currentPage.value >= pages.value - 1) { for (let i = pages.value - 4; i <= pages.value; i++) { result.push(i); } } else { for (let i = currentPage.value - 2; i <= currentPage.value + 2; i++) { result.push(i); } } } return result; }); const changePage = (type) => { if (type === false) { if (currentPage.value === 1) return; if (currentPage.value > 1) { currentPage.value -= 1; } } else if (type === true) { if (currentPage.value === pages.value) return; if (currentPage.value < pages.value) { currentPage.value += 1; } } else { currentPage.value = type; } emit("change-page", currentPage.value); }; return (_ctx, _cache) => { return openBlock(), createElementBlock("div", _hoisted_1, [ createElementVNode("a", { onClick: _cache[0] || (_cache[0] = ($event) => changePage(false)), href: "javascript:;", class: normalizeClass({ disabled: unref(currentPage) === 1 }) }, "上一页", 2), unref(currentPage) > 3 ? (openBlock(), createElementBlock("span", _hoisted_2, "...")) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(unref(list), (item) => { return openBlock(), createElementBlock("a", { onClick: ($event) => changePage(item), href: "javascript:;", class: normalizeClass({ active: unref(currentPage) === item }), key: item }, toDisplayString(item), 11, _hoisted_3); }), 128)), unref(currentPage) < unref(pages) - 2 ? (openBlock(), createElementBlock("span", _hoisted_4, "...")) : createCommentVNode("", true), createElementVNode("a", { onClick: _cache[1] || (_cache[1] = ($event) => changePage(true)), href: "javascript:;", class: normalizeClass({ disabled: unref(currentPage) === unref(pages) }) }, "下一页", 2) ]); }; } }); export { _sfc_main as default };