epic-designer-gold
Version:
基于vue3的设计器,可视化开发页面表单
125 lines (124 loc) • 2.93 kB
JavaScript
import { defineComponent as S, inject as g, h as b } from "vue";
/* empty css */
import { ElSelectV2 as D, ElSelect as L } from "element-plus";
const c = {
label: "label",
value: "value",
disabled: "disabled",
options: "options"
}, A = 100;
function i(e) {
return Array.isArray(e);
}
function T(e) {
return i(e) ? e.length > 0 : e != null && e !== "";
}
function V(e) {
return {
...c,
...e || {}
};
}
function m(e, n) {
const l = n.options || c.options, r = Array.from(/* @__PURE__ */ new Set([l, "children", "options"]));
for (const t of r) {
const a = e == null ? void 0 : e[t];
if (i(a) && a.length)
return a;
}
return [];
}
function y(e, n, l = []) {
return i(e) && e.forEach((r) => {
const t = m(r, n);
if (t.length) {
y(t, n, l);
return;
}
l.push(r);
}), l;
}
function h(e, n, l) {
if (!i(e))
return;
const r = l.value || c.value;
for (const t of e) {
const a = m(t, l);
if (a.length) {
const u = h(a, n, l);
if (u)
return u;
continue;
}
if ((t == null ? void 0 : t[r]) === n)
return t;
}
}
function O(e, n) {
return i(e) ? e.map((l) => {
const r = m(l, n);
return r.length ? {
...l,
options: O(r, n)
} : l;
}) : [];
}
function v(e, n) {
const l = n.label || c.label, r = n.value || c.value;
return {
...e,
label: e == null ? void 0 : e[l],
value: e == null ? void 0 : e[r]
};
}
function E(e) {
const n = Number(e);
return !Number.isFinite(n) || n < 0 ? A : n;
}
const _ = S({
emits: ["update:modelValue", "update:modelValueLabel", "update:selectFillData"],
setup(e, { emit: n, attrs: l }) {
const r = g("disabled", { value: !1 });
function t(a = null) {
var o;
const u = V(l.props), d = l.options;
if (i(a)) {
const s = a.map((f) => {
const p = h(d, f, u);
return p ? v(p, u) : {
label: f,
value: f
};
});
n("update:modelValueLabel", s);
} else {
const s = h(d, a, u);
s ? n("update:modelValueLabel", v(s, u)) : n("update:modelValueLabel", {
label: a,
value: a
});
}
n("update:modelValue", a), n("update:selectFillData", {
value: a,
field: ((o = l.componentSchema) == null ? void 0 : o.field) || "",
fillDataSource: l.fillDataSource,
fillDataParams: l.fillDataParams
});
}
return T(l.modelValue) && !l.disabled && !r.value && t(l.modelValue), () => {
const a = V(l.props), u = l.options, d = y(u, a).length >= E(l.virtualThreshold), o = {
...l,
key: String(l.multiple),
"onUpdate:modelValue": t,
disabled: r.value || l.disabled
};
return d ? b(D, {
...o,
options: O(u, a)
}) : b(L, o);
};
}
});
export {
_ as default
};