UNPKG

@aplus-frontend/ui

Version:

92 lines (91 loc) 2.49 kB
import { defineComponent as B, ref as C, useSlots as S, onMounted as h, computed as U, unref as t, createVNode as s, Fragment as a, createBlock as i, createElementBlock as V, openBlock as u, resolveDynamicComponent as _, mergeProps as N, withCtx as q, renderSlot as z, normalizeProps as F, guardReactiveProps as P } from "vue"; import { Spin as T, Segmented as O } from "@aplus-frontend/antdv"; import { isFunction as f, isUndefined as R, isString as w, isNumber as A, omit as D } from "lodash-unified"; import "../../hooks/index.mjs"; import E from "../hooks/use-options.mjs"; import { useControllableValue as M } from "../../hooks/useControllableValue.mjs"; const K = /* @__PURE__ */ B({ name: "ApFieldSegmented", __name: "index", props: { mode: { default: "edit" }, class: {}, style: {}, prefixCls: {}, options: {}, block: { type: Boolean, default: void 0 }, disabled: { type: Boolean, default: void 0 }, size: {}, value: {}, motionName: {}, onChange: {}, "onUpdate:value": {}, vertical: { type: Boolean }, shape: {}, name: {}, emptyText: { default: "--" }, defaultValue: {}, request: {} }, emits: ["update:value"], setup(c, { emit: v }) { const o = c, { options: p, updateOptions: y } = E(o), g = v, { value: d, updateValue: b } = M(o, g), r = C(!1), k = S(); h(() => { f(o.request) && (r.value = !0, o.request().then((e) => y(e)).finally(() => { r.value = !1; })); }); const x = U(() => { const e = t(d); if (R(e)) return s(a, null, [o.emptyText]); const l = t(p)?.find((m) => m === e || m?.value === e); if (w(l) || A(l)) return s(a, null, [l]); const n = l?.label || k.label; return f(n) ? s(a, null, [n?.({ ...l })]) : s(a, null, [n || o.emptyText]); }); return (e, l) => r.value ? (u(), i(t(T), { key: 0, size: "small" })) : (u(), V(a, { key: 1 }, [e.mode === "read" ? (u(), i(_(x.value), { key: 0 })) : (u(), i(t(O), N({ key: 1 }, t(D)(o, ["onUpdate:value", "value", "defaultValue", "options"]), { value: t(d), options: t(p), "onUpdate:value": t(b) }), { label: q((n) => [z(e.$slots, "label", F(P(n)))]), _: 3 }, 16, ["value", "options", "onUpdate:value"]))], 64)); } }); export { K as default };