@wetspace/pro-components
Version:
::: tip 基本介绍
56 lines (55 loc) • 2.54 kB
JavaScript
import { defineComponent as B, useSlots as x, shallowRef as p, getCurrentInstance as y, computed as v, onMounted as E, openBlock as i, createBlock as w, unref as u, mergeProps as M, withCtx as g, createElementBlock as S, renderSlot as m, createTextVNode as $, createCommentVNode as V, createElementVNode as b, toDisplayString as _ } from "vue";
import { ElButton as h, ElSpace as P } from "element-plus";
import { wetCountDownButtonProps as R } from "./types.mjs";
const W = { key: 0 }, j = { key: 0 }, F = /* @__PURE__ */ B({
name: "WetCountDownButton",
__name: "index",
props: R,
emits: ["click"],
setup(k, { emit: C }) {
const I = C, o = k, T = x(), s = p(!1), l = p(o.initCount), r = y(), n = v(() => o.uid || (r == null ? void 0 : r.uid) || (/* @__PURE__ */ new Date()).getTime()), D = v(() => o.disabled || s.value);
let d;
const f = (t = !0) => {
t && I("click"), s.value = !0;
const e = sessionStorage.getItem(`wet-deadlinetime-${n.value}`);
let a = e ? Number(e) : 0;
const c = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
a || (a = c + o.initCount, sessionStorage.setItem(`wet-deadlinetime-${n.value}`, `${a}`)), l.value = Number(a) - c, d = setInterval(() => {
const N = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
l.value = Number(a) - Number(N), l.value <= 0 && (clearInterval(d), s.value = !1, sessionStorage.setItem(`wet-deadlinetime-${n.value}`, ""));
}, 1e3);
};
return E(() => {
const t = sessionStorage.getItem(`wet-deadlinetime-${n.value}`), e = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
Number(t) - e > 0 ? f(!1) : (s.value = !1, sessionStorage.setItem(`wet-deadlinetime-${n.value}`, ""));
}), (t, e) => (i(), w(u(h), M(o, {
disabled: D.value,
onClick: e[0] || (e[0] = () => f())
}), {
default: g(() => [
s.value ? (i(), w(u(P), { key: 1 }, {
default: g(() => [
u(T).prefix ? (i(), S("span", j, [
m(t.$slots, "prefix")
])) : V("", !0),
b("span", null, _(l.value) + "s", 1),
b("span", null, [
m(t.$slots, "suffix", {}, () => [
e[2] || (e[2] = $("后获取"))
])
])
]),
_: 3
})) : (i(), S("span", W, [
m(t.$slots, "default", {}, () => [
e[1] || (e[1] = $("验证码"))
])
]))
]),
_: 3
}, 16, ["disabled"]));
}
});
export {
F as default
};