@aplus-frontend/ui
Version:
79 lines (78 loc) • 2.54 kB
JavaScript
import { defineComponent as g, ref as C, onMounted as V, createElementBlock as l, openBlock as o, Fragment as i, unref as e, createTextVNode as u, toDisplayString as m, createBlock as d, mergeProps as B } from "vue";
import { Spin as O, CheckboxGroup as T } from "@aplus-frontend/antdv";
import { isFunction as q, isNil as U, omit as _ } from "lodash-unified";
import "../../config-provider/index.mjs";
import "../../hooks/index.mjs";
import F from "../hooks/use-options.mjs";
import N from "../style/index.mjs";
import { getOptionValue as S, getOptionLabel as A } from "./helper.mjs";
import { useNamespace as j } from "../../config-provider/hooks/use-namespace.mjs";
import { useControllableValue as z } from "../../hooks/useControllableValue.mjs";
const Q = /* @__PURE__ */ g({
name: "ApFieldCheckbox",
inheritAttrs: !1,
__name: "index",
props: {
mode: { default: "edit" },
class: {},
style: {},
defaultValue: {},
value: {},
onChange: {},
"onUpdate:value": {},
name: {},
prefixCls: {},
options: { default: () => [] },
disabled: { type: Boolean, default: void 0 },
id: {},
emptyText: { default: "--" },
request: {},
vertical: { type: Boolean }
},
emits: ["update:value"],
setup(c, { emit: f }) {
const v = f, t = c, { options: p, updateOptions: y } = F(t), { b: k, m: x } = j("field-checkbox"), h = N("field"), n = C(!1);
V(() => {
q(t.request) && (n.value = !0, t.request().then((a) => y(a)).finally(() => {
n.value = !1;
}));
});
const { value: r, updateValue: b } = z(
t,
v,
{
defaultValue: []
}
);
return (a, D) => a.mode === "read" ? (o(), l(i, { key: 0 }, [
e(U)(e(r)) ? (o(), l(i, { key: 0 }, [
u(m(t.emptyText), 1)
], 64)) : (o(), l(i, { key: 1 }, [
u(m(e(p)?.filter((s) => e(r).indexOf(e(S)(s)) > -1).map((s) => e(A)(s)).join("、") || t.emptyText), 1)
], 64))
], 64)) : (o(), l(i, { key: 1 }, [
n.value ? (o(), d(e(O), {
key: 0,
size: "small"
})) : (o(), d(e(T), B(
{ key: 1 },
e(_)(t, [
"onUpdate:value",
"value",
"request",
"vertical",
"emptyText"
]),
{
options: e(p),
value: e(r),
class: [e(k)(), a.vertical ? e(x)("vertical") : null, e(h)],
"onUpdate:value": e(b)
}
), null, 16, ["options", "value", "class", "onUpdate:value"]))
], 64));
}
});
export {
Q as default
};