y-design-ssr
Version:
SSR component library of YUI with Vue3
201 lines (200 loc) • 4.75 kB
JavaScript
import { ref as $, reactive as M, defineComponent as S, computed as P, watchEffect as w, createVNode as c } from "vue";
const N = (e, t) => t ? typeof t == "string" ? ` ${e}--${t}` : Array.isArray(t) ? t.reduce((l, n) => l + N(e, n), "") : Object.keys(t).reduce(
(l, n) => l + (t[n] ? N(e, n) : ""),
""
) : "", C = (e) => (t, l) => {
let n = t, b = l;
return n && typeof n != "string" && (b = n, n = ""), n = n ? `${e}__${n}` : e, `${n}${N(n, b)}`;
}, V = () => (e, t) => t ? `${N(`y-${e}`, t)}` : `y-${e}`, _ = {
"pull-refresh": {
pulling: "下拉刷新...",
loosing: "释放刷新...",
loading: "数据加载中...",
success: "数据已更新",
failed: "数据跟新失败,请稍后再试"
},
"form-item": {
validateMessage: "请输入正确内容"
}
};
$("zh-CN");
M({
"zh-CN": _
});
const k = (e) => {
const t = `y-${e}`;
return [t, C(t), V()];
};
var B = /* @__PURE__ */ ((e) => (e.simple = "simple", e.multi = "multi", e))(B || {});
const h = (e, t, l) => ({
number: e,
text: t,
active: l
}), [z, f] = k("pagination"), I = {
modelValue: {
type: Number,
default: 1
},
mode: {
type: String,
default: B.multi
},
prevText: {
type: String,
default: "上一页"
},
nextText: {
type: String,
default: "下一页"
},
pageCount: {
type: Number,
default: 0
},
totalItems: {
type: Number,
default: 0
},
itemsPerPage: {
type: Number,
default: 10
},
showPageSize: {
type: Number,
default: 5
},
forceEllipses: {
type: Boolean,
default: !0
},
ellipsesWithInclusio: {
type: Boolean,
default: !0
},
showPrevButton: {
type: Boolean,
default: !0
},
showNextButton: {
type: Boolean,
default: !0
},
isBlockUpdate: {
type: Boolean,
default: !1
}
}, E = /* @__PURE__ */ S({
name: z,
props: I,
emits: ["change", "update:modelValue"],
setup(e, {
emit: t,
slots: l
}) {
const n = P(() => {
const {
pageCount: u,
totalItems: a,
itemsPerPage: o
} = e, p = Number(u) || Math.ceil(Number(a) / Number(o));
return Math.max(1, p);
}), b = P(() => {
const u = [], a = n.value, o = Number(e.showPageSize), {
modelValue: p,
forceEllipses: x,
ellipsesWithInclusio: d
} = e;
let i = 1, r = a;
const g = o < a;
g && (i = Math.max(p - Math.floor(o / 2), 1), r = i + o - 1, r > a && (r = a, i = r - o + 1));
for (let s = i; s <= r; s++) {
const m = h(s, s, s === p);
u.push(m);
}
if (g && o > 0 && x) {
if (i > 1) {
const s = h(i - 1, "...");
if (u.unshift(s), d) {
const m = h(1, "1");
u.unshift(m);
}
}
if (r < a) {
const s = h(r + 1, "...");
if (u.push(s), d) {
const m = h(a, a);
u.push(m);
}
}
}
return u;
}), y = (u, a) => {
const o = Math.min(Math.max(u, 1), n.value);
e.modelValue !== o && (!e.isBlockUpdate && t("update:modelValue", o), a && t("change", o));
};
return w(() => y(e.modelValue)), () => {
const {
mode: u,
modelValue: a,
showPrevButton: o,
showNextButton: p,
prevText: x,
nextText: d
} = e, i = l["prev-text"], r = a === 1, g = l["next-text"], s = a === n.value, m = l["simple-page"];
return c("nav", {
role: "navigation",
class: f()
}, [c("ul", {
class: f("items")
}, [o && c("li", {
class: [f("item", {
prevBtnDisabled: r,
prev: !0
})],
onClick: () => y(a - 1, !0)
}, [i ? i({
disabled: r,
text: x
}) : c("button", {
type: "button",
disabled: r
}, [x])]), u === "simple" ? c("li", {
class: f("page-desc")
}, [m ? m({
current: a,
total: n.value
}) : `${a}/${n.value}`]) : b.value.map((v) => c("li", {
class: [f("item", {
active: v.active,
page: !0
})],
onClick: () => y(v.number, !0)
}, [l.page ? l.page(v) : c("button", {
type: "button"
}, [v.text])])), p && c("li", {
class: [f("item", {
nextBtnDisabled: s,
next: !0
})],
onClick: () => y(a + 1, !0)
}, [g ? g({
disabled: s,
text: d
}) : c("button", {
type: "button",
disabled: s
}, [d])])])]);
};
}
});
function T(e) {
const t = e;
return t.install = (l) => {
const { name: n } = e;
n && l.component(n, e);
}, t;
}
const D = T(E);
export {
D as default
};