@ctsy/layui-vue
Version:
a component library for Vue 3 base on layui-vue
202 lines (201 loc) • 8.26 kB
JavaScript
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
import { defineComponent, useSlots, ref, computed, watch, openBlock, createElementBlock, toDisplayString, createCommentVNode, createElementVNode, normalizeClass, unref, renderSlot, Fragment, createTextVNode, renderList, withDirectives, isRef, vModelSelect, withKeys, vModelText } from "vue";
import { u as useI18n } from "../vue-i18n.esm-bundler.js";
var index = "";
const _hoisted_1 = { class: "layui-box layui-laypage layui-laypage-default" };
const _hoisted_2 = {
key: 0,
class: "layui-laypage-count"
};
const _hoisted_3 = {
key: 0,
class: "layui-laypage-curr"
};
const _hoisted_4 = ["onClick"];
const _hoisted_5 = {
key: 2,
class: "layui-laypage-limits"
};
const _hoisted_6 = ["value"];
const _hoisted_7 = {
key: 3,
href: "javascript:;",
class: "layui-laypage-refresh"
};
const _hoisted_8 = /* @__PURE__ */ createElementVNode("i", { class: "layui-icon layui-icon-refresh" }, null, -1);
const _hoisted_9 = [
_hoisted_8
];
const _hoisted_10 = {
key: 4,
class: "layui-laypage-skip"
};
const _hoisted_11 = /* @__PURE__ */ createTextVNode(" \u5230\u7B2C ");
const _hoisted_12 = /* @__PURE__ */ createTextVNode("\u9875 ");
const _hoisted_13 = ["disabled"];
const __default__ = {
name: "LayPage"
};
const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__), {
props: {
total: null,
limit: { default: 10 },
theme: { default: "green" },
modelValue: { default: 1 },
showPage: { type: [Boolean, String], default: false },
showSkip: { type: [Boolean, String], default: false },
showCount: { type: [Boolean, String], default: false },
showLimit: { type: [Boolean, String], default: true },
showInput: { type: [Boolean, String], default: false },
showRefresh: { type: [Boolean, String], default: false },
pages: { default: 10 },
limits: { default: () => [10, 20, 30, 40, 50] }
},
emits: ["jump", "limit"],
setup(__props, { emit }) {
const props = __props;
const slots = useSlots();
const { t } = useI18n();
const limits = ref(props.limits);
const pages = props.pages / 2;
const inlimit = computed({
get() {
return props.limit;
},
set(v) {
emit("limit", v);
}
});
const maxPage = ref(0);
const totalPage = computed(() => {
maxPage.value = Math.ceil(props.total / props.limit);
let r = [], start = maxPage.value <= props.pages ? 1 : currentPage.value > pages ? currentPage.value - pages : 1;
for (let i = start; ; i++) {
if (r.length >= props.pages || i > maxPage.value) {
break;
}
r.push(i);
}
return r;
});
const currentPage = ref(props.modelValue);
const currentPageShow = ref(currentPage.value);
const prev = function() {
if (currentPage.value === 1) {
return;
}
currentPage.value--;
};
const next = function() {
if (currentPage.value === maxPage.value) {
return;
}
currentPage.value++;
};
const jump = function(page) {
currentPage.value = page;
};
const jumpPage = function() {
currentPage.value = currentPageShow.value;
};
watch(inlimit, function() {
currentPage.value = 1;
});
watch(currentPage, function() {
currentPageShow.value = currentPage.value;
emit("jump", { current: currentPage.value });
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", _hoisted_1, [
__props.showCount ? (openBlock(), createElementBlock("span", _hoisted_2, "\u5171 " + toDisplayString(__props.total) + " \u6761 " + toDisplayString(maxPage.value) + " \u9875", 1)) : createCommentVNode("", true),
createElementVNode("a", {
href: "javascript:;",
class: normalizeClass(["layui-laypage-prev", [currentPage.value === 1 ? "layui-disabled" : ""]]),
onClick: _cache[0] || (_cache[0] = ($event) => prev())
}, [
unref(slots).prev ? renderSlot(_ctx.$slots, "prev", { key: 0 }) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
createTextVNode(toDisplayString(unref(t)("page.prev")), 1)
], 64))
], 2),
__props.showPage ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(unref(totalPage), (index2) => {
return openBlock(), createElementBlock(Fragment, { key: index2 }, [
index2 === currentPage.value ? (openBlock(), createElementBlock("span", _hoisted_3, [
createElementVNode("em", {
class: normalizeClass(["layui-laypage-em", [__props.theme ? "layui-bg-" + __props.theme : ""]])
}, null, 2),
createElementVNode("em", null, toDisplayString(index2), 1)
])) : (openBlock(), createElementBlock("a", {
key: 1,
href: "javascript:;",
onClick: ($event) => jump(index2)
}, toDisplayString(index2), 9, _hoisted_4))
], 64);
}), 128)) : createCommentVNode("", true),
createElementVNode("a", {
href: "javascript:;",
class: normalizeClass(["layui-laypage-next", [currentPage.value === maxPage.value ? "layui-disabled" : ""]]),
onClick: _cache[1] || (_cache[1] = ($event) => next())
}, [
unref(slots).next ? renderSlot(_ctx.$slots, "next", { key: 0 }) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
createTextVNode(toDisplayString(unref(t)("page.next")), 1)
], 64))
], 2),
__props.showLimit ? (openBlock(), createElementBlock("span", _hoisted_5, [
withDirectives(createElementVNode("select", {
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(inlimit) ? inlimit.value = $event : null)
}, [
(openBlock(true), createElementBlock(Fragment, null, renderList(limits.value, (val) => {
return openBlock(), createElementBlock("option", {
key: val,
value: val
}, toDisplayString(val) + " \u6761/\u9875 ", 9, _hoisted_6);
}), 128))
], 512), [
[vModelSelect, unref(inlimit)]
])
])) : createCommentVNode("", true),
__props.showRefresh ? (openBlock(), createElementBlock("a", _hoisted_7, _hoisted_9)) : createCommentVNode("", true),
__props.showSkip ? (openBlock(), createElementBlock("span", _hoisted_10, [
_hoisted_11,
withDirectives(createElementVNode("input", {
"onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => currentPageShow.value = $event),
onKeypress: _cache[4] || (_cache[4] = withKeys(($event) => jumpPage(), ["enter"])),
type: "number",
class: "layui-input layui-input-number"
}, null, 544), [
[vModelText, currentPageShow.value]
]),
_hoisted_12,
createElementVNode("button", {
type: "button",
class: "layui-laypage-btn",
onClick: _cache[5] || (_cache[5] = ($event) => jumpPage()),
disabled: currentPageShow.value > maxPage.value
}, " \u786E\u5B9A ", 8, _hoisted_13)
])) : createCommentVNode("", true)
]);
};
}
}));
_sfc_main.install = (app) => {
app.component(_sfc_main.name, _sfc_main);
};
export { _sfc_main as default };