UNPKG

tdesign-pro-component

Version:

ProComponents tdesign-vue-next + Vue3 + TS

359 lines (358 loc) 8.36 kB
import "lodash-es"; import { g as V, b as I, w as x } from "./utils-CIySOLoe.js"; import { defineComponent as y, ref as f, watch as c, createVNode as o, isVNode as b, mergeProps as m, computed as _, onMounted as A, Fragment as T } from "vue"; import { RadioGroup as N, Space as j, Radio as $, RadioButton as k, FormItem as w } from "tdesign-vue-next"; function h(e) { return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !b(e); } const S = /* @__PURE__ */ y({ name: "DefaultRadio", props: { data: { type: Array }, direction: { type: String, default: "horizontal" }, onChange: { type: Function }, modelValue: { type: [String, Number, Boolean] }, readonly: { type: Boolean }, disabled: { type: Boolean } }, emits: ["update:modelValue", "change"], setup(e, { emit: n }) { const l = f(e.modelValue || ""); c(() => e.modelValue, (a) => { a !== l.value && (l.value = a); }); const u = (a) => { e.readonly || (n("update:modelValue", a), n("change", a)); }; return () => { let a; return o(N, { modelValue: l.value, "onUpdate:modelValue": (t) => l.value = t, onChange: u }, { default: () => [o(j, { direction: e.direction }, h(a = //@ts-ignore e.data.map((t) => { let r; return o($, { disabled: e.disabled || t.disabled, key: t.value, value: t.value }, h(r = t.render(t)) ? r : { default: () => [r] }); })) ? a : { default: () => [a] })] }); }; } }); function s(e) { return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !b(e); } const B = /* @__PURE__ */ y({ name: "ButtonRadio", props: { data: { type: Array }, vertical: { type: String, default: "row" }, onChange: { type: Function }, modelValue: { type: [String, Number, Boolean] }, readonly: { type: Boolean }, disabled: { type: Boolean } }, setup(e, { emit: n }) { const l = f(e.modelValue || ""); function u(a) { e.readonly || (n("change", a), l.value = a); } return c(() => e.modelValue, (a) => { l.value = a; }), c(l, (a) => { n("update:modelValue", a); }), () => { let a; return o(N, { readonly: e.readonly, value: l.value, onChange: u }, s(a = //@ts-ignore e.data.map((t) => { let r; return o(k, m({ disabled: e.disabled || t.disabled }, e, { value: t.value }), s(r = t.render(t)) ? r : { default: () => [r] }); })) ? a : { default: () => [a] }); }; } }), C = /* @__PURE__ */ y({ name: "TagItem", props: { data: Object, currentIndex: [String, Boolean, Number], fill: Boolean, updateColor: Boolean, disabled: Boolean }, setup(e, { slots: n }) { const l = _(() => e.disabled ? e.currentIndex === e.data.value ? "tag-item tag-item-disabled-active" : "tag-item tag-item-disabled" : e.currentIndex === e.data.value ? `tag-item tag-item-active ${e.fill ? "tag-item-active-fill" : ""} ${e.updateColor ? "tag-item-color-active" : ""}` : "tag-item"); return () => o("div", { class: l.value }, [n.default && (n == null ? void 0 : n.default())]); } }); function D(e) { return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !b(e); } const R = /* @__PURE__ */ y({ name: "TagRadio", props: { data: { type: Array }, direction: { type: String, default: "horizontal" }, onChange: { type: Function }, modelValue: { type: [String] }, gap: { type: String, default: "24px" }, updateColor: { type: Boolean, default: !1 }, fill: { type: Boolean, default: !1 }, readonly: { type: Boolean, default: !1 }, disabled: { type: Boolean, default: !1 } }, components: { TagItem: C }, emits: ["update:modelValue", "change"], setup(e, { emit: n }) { const l = f(e.modelValue || ""); function u(a, t) { e.readonly || e.disabled || t.disabled || (n("change", a), l.value = a); } return c(() => e.modelValue, (a) => { l.value = a; }), c(l, (a) => { n("update:modelValue", a); }), () => o(j, { direction: e.direction }, { default: () => [e.data && e.data.map((a) => { let t; return o(C, { disabled: e.disabled || a.disabled, fill: e.fill, updateColor: e.updateColor, currentIndex: l.value, key: a.value, onClick: () => u(a.value, a), data: a }, D(t = a.render(a)) ? t : { default: () => [t] }); })] }); } }), U = /* @__PURE__ */ y({ name: "ProFormRadio", props: { // about pro data: { type: [Array, Function], default: () => [] }, theme: { type: String, default: "radio" }, labelName: { type: String, default: "label" }, valueName: { type: String, default: "value" }, direction: { type: String, default: "horizontal" }, loadingText: { type: String, default: "数据加载中,请稍后..." }, // about form name: { required: !0, type: String }, label: [String, Function, Object], rules: Array, formItemProps: Object, // about input modelValue: { type: [String, Number, Boolean] }, radioProps: { type: [Object] }, readonly: { type: Boolean, default: !1 }, disabled: { type: Boolean, default: !1 } }, components: { DefaultRadio: S, ButtonRadio: B, TagRadio: R }, emits: ["update:modelValue", "change"], setup(e, { emit: n, slots: l }) { const u = f([]), a = f(!1), t = f(e.modelValue || "2222"), r = V("label", l, e), O = V("loadingText", l, e); A(() => { v(); }); function v() { a.value = !0, I(e.data, e.labelName, e.valueName).then((d) => { u.value = d.map((i) => ({ ...i, //@ts-ignore render: (F) => i.render ? i.render(F) : l[`option-${i[e.valueName]}`] ? l[`option-${i[e.valueName]}`]({ option: i }) : i[e.labelName] })); }).finally(() => { a.value = !1; }); } function g(d) { n("change", d), n("update:modelValue", d); } c(() => e.modelValue, (d) => { t.value = d; }), c(() => e.data, (d) => { Array.isArray(d) && v(); }, { deep: !0 }); function P() { switch (e.theme) { case "radio": default: return o(T, null, [o(S, m({ direction: e.direction, onChange: g }, e.radioProps, { readonly: e.readonly, disabled: e.disabled, vertical: e.vertical, modelValue: t.value, "onUpdate:modelValue": (d) => t.value = d, data: u.value }), null)]); case "button": return o(B, m({ onChange: g }, e.radioProps, { readonly: e.readonly, disabled: e.disabled, vertical: e.vertical, modelValue: t.value, "onUpdate:modelValue": (d) => t.value = d, data: u.value }), null); case "tag": return o(R, m({ direction: e.direction, onChange: g }, e.radioProps, { readonly: e.readonly, disabled: e.disabled, vertical: e.vertical, modelValue: t.value, "onUpdate:modelValue": (d) => t.value = d, data: u.value }), null); } } return () => o(w, m({ rules: e.rules, name: e.name }, e.formItemProps), { default: () => a.value ? O() : P(), label: r() ? r() : null }); } }), L = x(U); export { L as P };