y-design-ssr
Version:
SSR component library of YUI with Vue3
123 lines (122 loc) • 3.59 kB
JavaScript
import { ref as m, reactive as B, defineComponent as F, computed as E, onMounted as I, createVNode as z } from "vue";
const g = (e, t) => t ? typeof t == "string" ? ` ${e}--${t}` : Array.isArray(t) ? t.reduce((a, r) => a + g(e, r), "") : Object.keys(t).reduce(
(a, r) => a + (t[r] ? g(e, r) : ""),
""
) : "", L = (e) => (t, a) => {
let r = t, u = a;
return r && typeof r != "string" && (u = r, r = ""), r = r ? `${e}__${r}` : e, `${r}${g(r, u)}`;
}, U = () => (e, t) => t ? `${g(`y-${e}`, t)}` : `y-${e}`, j = {
"pull-refresh": {
pulling: "下拉刷新...",
loosing: "释放刷新...",
loading: "数据加载中...",
success: "数据已更新",
failed: "数据跟新失败,请稍后再试"
},
"form-item": {
validateMessage: "请输入正确内容"
}
};
m("zh-CN");
B({
"zh-CN": j
});
const q = (e) => {
const t = `y-${e}`;
return [t, L(t), U()];
}, y = 1e3, w = 60 * y, S = 60 * w, T = 24 * S, [G] = q("count-down"), R = /* @__PURE__ */ F({
name: G,
props: {
time: {
type: [Number, String],
default: 0
},
format: {
type: String,
default: "HH:mm:ss"
},
/**
* @ignore
*/
autoStart: {
type: Boolean,
default: !0
},
millisecond: {
type: Boolean,
default: !1
}
},
emits: ["finish", "change"],
setup(e, {
slots: t,
emit: a,
expose: r
}) {
const u = m(), h = m(!1), s = m(Number(e.time)), $ = m(0), v = E(() => A(s.value));
I(() => {
e.autoStart && M();
});
const M = () => {
h.value = !0, $.value = s.value + Date.now(), D();
}, C = () => {
p(), s.value = Number(e.time), e.autoStart && M();
}, p = () => {
h.value = !1, window.cancelAnimationFrame(u.value);
}, D = () => {
h.value && (e.millisecond ? N() : b(s.value, x()) || N(), u.value = window.requestAnimationFrame(D));
}, N = () => {
if (s.value = x(), e.millisecond && s.value === 0 || !e.millisecond && Math.floor(s.value / 1e3) === 0) {
h.value = !1, a("finish");
return;
}
a("change", v.value);
}, x = () => Math.max($.value - Date.now(), 0), b = (o, n) => Math.floor(o / 1e3) === Math.floor(n / 1e3), A = (o) => {
const n = Math.floor(o / T), l = Math.floor(o % T / S), i = Math.floor(o % S / w), f = Math.floor(o % w / y), d = Math.floor(o % y);
return {
days: n,
hours: l,
minutes: i,
seconds: f,
milliseconds: d,
timestamp: o
};
}, _ = (o) => {
let n = o;
const {
days: l
} = v.value;
let {
hours: i,
minutes: f,
seconds: d,
milliseconds: O
} = v.value;
return n.indexOf("DD") === -1 ? i += l * 24 : n = n.replace("DD", c(l)), n.indexOf("HH") === -1 ? f += i * 60 : n = n.replace("HH", c(i)), n.indexOf("mm") === -1 ? d += f * 60 : n = n.replace("mm", c(f)), n.indexOf("ss") === -1 ? O += d * 1e3 : n = n.replace("ss", c(d)), n.indexOf("S") !== -1 && (n = n.replace(/S+/, (H) => c(O, H.length).slice(0, H.length))), n;
}, c = (o, n = 2) => {
let l = `${o}`;
for (; l.length < n; )
l = `0${l}`;
return l;
};
return r({
start: M,
reset: C,
suspend: p
}), () => {
var o;
return ((o = t.default) == null ? void 0 : o.call(t, v.value)) || z("div", null, [_(e.format)]);
};
}
});
function V(e) {
const t = e;
return t.install = (a) => {
const { name: r } = e;
r && a.component(r, e);
}, t;
}
const k = V(R);
export {
k as default
};