UNPKG

@aplus-frontend/ui

Version:

68 lines (67 loc) 2.37 kB
import { defineComponent as g, ref as h, onMounted as C, createElementBlock as l, openBlock as o, Fragment as n, unref as e, createTextVNode as u, toDisplayString as m, createBlock as d, mergeProps as V } from "vue"; import { isFunction as B, isNil as O, omit as q } from "lodash-unified"; import { Spin as T, CheckboxGroup as U } from "@aplus-frontend/antdv"; import "../../hooks/index.mjs"; import { getOptionValue as _, getOptionLabel as F } from "./helper.mjs"; import "../../config-provider/index.mjs"; import N from "../hooks/use-options.mjs"; import { useNamespace as A } from "../../config-provider/hooks/use-namespace.mjs"; import { useControllableValue as S } from "../../hooks/useControllableValue.mjs"; const I = /* @__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 } = N(t), { b: k, m: x } = A("field-checkbox"), i = h(!1); C(() => { B(t.request) && (i.value = !0, t.request().then((a) => y(a)).finally(() => { i.value = !1; })); }); const { value: r, updateValue: b } = S( t, v, { defaultValue: [] } ); return (a, j) => a.mode === "read" ? (o(), l(n, { key: 0 }, [ e(O)(e(r)) ? (o(), l(n, { key: 0 }, [ u(m(t.emptyText), 1) ], 64)) : (o(), l(n, { key: 1 }, [ u(m(e(p)?.filter((s) => e(r).indexOf(e(_)(s)) > -1).map((s) => e(F)(s)).join("、") || t.emptyText), 1) ], 64)) ], 64)) : (o(), l(n, { key: 1 }, [ i.value ? (o(), d(e(T), { key: 0, size: "small" })) : (o(), d(e(U), V({ key: 1 }, e(q)(t, ["onUpdate:value", "value", "request", "vertical"]), { options: e(p), value: e(r), class: [e(k)(), a.vertical ? e(x)("vertical") : null], "onUpdate:value": e(b) }), null, 16, ["options", "value", "class", "onUpdate:value"])) ], 64)); } }); export { I as default };