tms-vue3-ui
Version:
Vue3基础UI库,提供JSONSchema编辑器,支持基于JSONSchema生成表单。
188 lines (187 loc) • 6.27 kB
JavaScript
import { defineComponent as j, ref as _, reactive as B, onMounted as z, nextTick as O, openBlock as l, createElementBlock as n, Fragment as M, createElementVNode as r, normalizeClass as I, unref as a, renderList as P, withDirectives as R, vModelDynamic as $, createCommentVNode as y, vModelText as G, createTextVNode as J, toDisplayString as L, toRaw as K, createApp as Q } from "vue";
const W = ["placeholder", "type", "onUpdate:modelValue"], X = ["onClick"], Y = {
key: 0,
class: "tvu-register__captcha"
}, Z = ["placeholder"], ee = {
key: 1,
class: "tvu-register__error--tip"
}, te = {
key: 2,
class: "tvu-register__button"
}, oe = {
key: 3,
class: "tvu-register__tip"
}, se = {
key: 0,
class: "tvu-register__modal"
}, m = /* @__PURE__ */ j({
__name: "Register",
props: {
schema: Array,
registerTip: Object,
errorTip: { type: Boolean, default: !1 },
fnCaptcha: Function,
fnRegister: Function,
onSuccess: { type: Function, default: () => {
} },
onFail: { type: Function, default: () => {
} },
asDialog: { type: Boolean, default: !1 },
onClose: { type: Function },
closeAfterSuccess: { type: Boolean, default: !1 }
},
setup(g) {
const h = g, c = _(null), p = _(null);
let { schema: d, registerTip: b, fnRegister: F, fnCaptcha: T, onSuccess: N, onFail: E, errorTip: U, asDialog: k, onClose: S } = h;
const i = B({}), x = _(null);
let f = B({ password: !1, password2: !1 });
const u = _(), D = _([]), v = _();
d && d.length && d.forEach((e) => {
e.type === "captcha" ? v.value = e : D.value.push(e);
});
const C = () => {
i[v.value.key] = "", p != null && p.value && typeof T == "function" && T().then((e) => {
let { code: t, captcha: s, msg: o } = e;
t !== 0 ? (u.value = o || "获取验证码失败", p.value.innerHTML = "获取失败") : (u.value = "", p.value.innerHTML = s);
});
}, q = (e) => {
f[e] = !f[e];
const t = K(x.value);
e == "password" ? f[e] ? t[0].previousSibling.type = "text" : t[0].previousSibling.type = "password" : f[e] ? t[1].previousSibling.type = "text" : t[1].previousSibling.type = "password";
}, H = () => {
if (Array.isArray(d) && d.length) {
if (d.map((s) => s.key).filter((s) => !i[s]).length)
return u.value = "缺少必填信息", E({ msg: "缺少必填信息" });
typeof F == "function" && F(i).then((s) => {
let { code: o, msg: w } = s;
if (o !== 0)
return C(), u.value = w || "登录失败", E(s);
u.value = "", N(s), closeAfterSuccess && A();
});
}
}, A = () => {
var e, t;
typeof S == "function" ? S() : (t = (e = c.value.parentElement) == null ? void 0 : e.parentElement) == null || t.removeChild(c.value.parentElement);
};
return z(() => {
O(() => C());
}), (e, t) => {
var s;
return l(), n(
M,
null,
[
r(
"div",
{
ref_key: "el",
ref: c,
class: I(["tvu-register__form", { "tvu-register__form--modal": a(k) }])
},
[
(l(!0), n(
M,
null,
P(D.value, (o, w) => (l(), n("div", {
class: "tvu-register__input",
key: w
}, [
R(r("input", {
placeholder: o.placeholder,
type: o.type,
"onUpdate:modelValue": (V) => i[o.key] = V,
required: ""
}, null, 8, W), [
[$, i[o.key]]
]),
o.type == "password" ? (l(), n("span", {
key: 0,
ref_for: !0,
ref_key: "passwordEle",
ref: x,
onClick: (V) => q(o.key),
class: I({ "tvu-register__password--close": !a(f)[o.key], "tvu-register__password--open": a(f)[o.key] })
}, null, 10, X)) : y("v-if", !0)
]))),
128
/* KEYED_FRAGMENT */
)),
v.value ? (l(), n("div", Y, [
R(r("input", {
placeholder: v.value.placeholder,
"onUpdate:modelValue": t[0] || (t[0] = (o) => i[v.value.key] = o),
required: ""
}, null, 8, Z), [
[G, i[v.value.key]]
]),
r(
"div",
{
ref_key: "elCaptcha",
ref: p
},
null,
512
/* NEED_PATCH */
),
r("button", { onClick: C })
])) : y("v-if", !0),
a(U) && u.value ? (l(), n("div", ee, [
t[1] || (t[1] = r(
"i",
null,
null,
-1
/* HOISTED */
)),
J(
L(u.value),
1
/* TEXT */
)
])) : y("v-if", !0),
r("div", { class: "tvu-register__button" }, [
r("button", { onClick: H }, "注册")
]),
a(k) ? (l(), n("div", te, [
r("button", { onClick: A }, "关闭")
])) : y("v-if", !0),
a(b) ? (l(), n(
"div",
oe,
L((s = a(b)) == null ? void 0 : s.text),
1
/* TEXT */
)) : y("v-if", !0)
],
2
/* CLASS */
),
a(k) ? (l(), n("div", se)) : y("v-if", !0)
],
64
/* STABLE_FRAGMENT */
);
};
}
});
function le(g) {
const h = document.createElement("div");
document.body.appendChild(h);
let c = Q(m, {
asDialog: !0,
...g,
onClose: () => {
c.unmount(), document.body.removeChild(h);
}
});
c.mount(h);
}
function ne(g) {
g.component("tms-regiser", m);
}
m.install = ne;
m.open = le;
export {
m as default
};