import { defineComponent as E, inject as X, ref as w, createVNode as n, Fragment as T, mergeProps as c, renderSlot as R, isVNode as L, provide as p, toRefs as H } from "vue"; import { a as D, h as u, F as k, P as _, A as z, b as J, u as K, C as Q, D as F, T as O, c as G, R as W, d as Z, e as ee, f as te, S as ae, g as le, j as ne, k as re, l as oe, m as ue, n as Y, o as ie, p as de, q as ce } from "./vendor-BQjPAPzR.js"; import { X as I } from "./datetime-picker-CcyYpp0V.js"; import { c as me, w as se } from "./utils-CTHIEenF.js"; const fe = ["input", "picker", "cascader", "area", "radio", "checkbox", "date-picker", "time-picker", "datetime-picker", "date-range-picker", "time-range-picker", "datetime-range-picker", "switch", "rate", "slider", "stepper", "text", "html", "slot", "input-slot"], M = ["picker", "cascader", "area", "date-picker", "time-picker", "datetime-picker", "date-range-picker", "time-range-picker", "datetime-range-picker"], B = { change: ["rate", "switch", "stepper", "slider", "radio", "checkbox"], blur: ["input", "stepper"], focus: ["input", "stepper"], click: ["input", "switch"], confirm: [], cancel: [], "drag-end": ["slider"], "drag-start": ["slider"], plus: ["stepper"], minus: ["stepper"], finish: [], "click-tab": [], overlimit: [] }, Ve = (e, t, b) => { const r = ["picker", "area", "cascader", "date-picker", "time-picker", "datetime-picker", "date-range-picker", "time-range-picker", "datetime-range-picker"].includes(e), P = ["input"].includes(e); if (r) return b || `请选择${t}`; if (P) return b || `请输入${t}`; if (b) return b; }, ge = (e, t = [], b) => { let r = []; const P = { required: !0, message: `${b}不能为空`, trigger: ["onBlur", "onChange", "onSubmit"] }; if (t && D(t)) { const V = t.find((q) => u(q, "required")); e && !V && r.push(P), r = r.concat(t); } return r; }, he = (e) => M.includes(e) ? "arrow" : ""; function be(e) { return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !L(e); } const $e = /* @__PURE__ */ E({ props: { formValue: { type: Object }, type: { type: String, required: !0 }, label: { type: String, default: "" }, name: { type: String, required: !0 }, options: { type: Array, default: () => [] }, required: { type: Boolean, default: !1 }, readonly: { type: Boolean, default: !1 }, itemAttrs: { type: Object, default: () => ({}) }, popup: { type: Object, default: () => ({}) }, orgAttrs: { type: Object, default: () => ({}) }, config: { type: Object, default: () => ({}) } }, setup(e, {}) { const { name: t, itemAttrs: b, orgAttrs: r, config: P } = e, { formSlots: V, rules: q, onEvents: m } = X("x-form"), S = w(!1), f = () => { let a = {}; const l = e.name; return B.change.includes(e.type) && (a.onChange = (...o) => m("change", l, ...o)), B.blur.includes(e.type) && (a.onBlur = (o) => m("blur", l, o)), B.focus.includes(e.type) && (a.onFocus = (o) => m("focus", l, o)), B.click.includes(e.type) && (a.onClick = (o) => m("click", l, o)), a; }, h = () => { let a = {}; const l = e.name, o = (d) => b && u(b, "slots") && u(b.slots, d), i = (d, s) => { if (Y(b.slots[d])) return b.slots[d](s); throw new Error(`slots.${d} is not a function`); }; return (e.label || u(V, `${l}.label`) || o("label")) && (a.label = () => u(V, `${l}.label`) ? R(V, `${l}.label`) : o("label") ? i("label") : e.label), (u(V, `${l}.left-icon`) || o("left-icon")) && (a["left-icon"] = () => u(V, `${l}.left-icon`) ? R(V, `${l}.left-icon`) : i("left-icon")), (u(V, `${l}.right-icon`) || o("right-icon")) && (a["right-icon"] = () => u(V, `${l}.right-icon`) ? R(V, `${l}.right-icon`) : i("right-icon")), (u(V, `${l}.error-message`) || o("error-message")) && (a["error-message"] = ({ message: d }) => u(V, `${l}.error-message`) ? R(V, `${l}.error-message`, { message: d }) : i("error-message", { message: d })), (u(V, `${l}.button`) || o("button")) && (a.button = () => u(V, `${l}.button`) ? R(V, `${l}.button`) : i("button")), (u(V, `${l}.extra`) || o("extra")) && (a.extra = () => u(V, `${l}.extra`) ? R(V, `${l}.extra`) : i("extra")), a; }, y = () => u(r, "slots") ? r.slots : {}, $ = (a = {}) => { const l = u(b, "rules") && D(b.rules) ? b.rules : [], o = u(P, "rules") ? P.rules : [], i = u(q, t) ? q[t] : [], d = [...l, ...o, ...i], s = { placeholder: Ve(e.type, e.label, b == null ? void 0 : b.placeholder), required: e.required, rules: ge(e.required, d, e.label), label: e.label, name: t }; return u(P, "hiddenLabel") && ue(P.hiddenLabel) && P.hiddenLabel && (s.class = "xform-hidden-label"), Object.assign(s, b), M.includes(e.type) && Object.assign(s, { "right-icon": he(e.type), readonly: !0, onClickRightIcon: () => { e.readonly || (S.value = !0); } }), Object.assign(s, a); }, x = () => `请选择${e.label}`, U = () => { v(), m("cancel", t); }, v = () => S.value = !1, A = { input: () => n(k, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (a) => e.formValue[t] = a }, f(), $()), h()), picker: () => n(T, null, [n(k, c({ modelValue: e.formValue[`${t}Text`], "onUpdate:modelValue": (a) => e.formValue[`${t}Text`] = a }, $()), h()), j(n(_, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (a) => e.formValue[t] = a, title: x(), columns: e.options }, f(), r, { onConfirm: (...a) => { const [{ selectedOptions: l }] = a; e.formValue[`${t}Text`] = l.map((o) => o.text).join("/"), v(), m("confirm", t, ...a); }, onChange: (...a) => m("change", t, ...a), onCancel: U }), y()))]), area: () => n(T, null, [n(k, c({ modelValue: e.formValue[`${t}Text`], "onUpdate:modelValue": (a) => e.formValue[`${t}Text`] = a }, $()), h()), j(n(z, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (a) => e.formValue[t] = a, title: x(), areaList: J }, f(), r, { onConfirm: (...a) => { const [{ selectedOptions: l }] = a; e.formValue[`${t}Text`] = l.map((o) => o.text).join("/"), v(), m("confirm", t, ...a); }, onChange: (...a) => m("change", t, ...a), onCancel: U }), y()))]), cascader: () => { const a = K(); return n(T, null, [n(k, c({ modelValue: e.formValue[`${t}Text`], "onUpdate:modelValue": (l) => e.formValue[`${t}Text`] = l }, $()), h()), j(n(Q, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (l) => e.formValue[t] = l, title: x(), options: r && u(r, "useVantAreaData") ? a : e.options }, f(), r, { onFinish: (...l) => { const [{ selectedOptions: o }] = l; e.formValue[`${t}Text`] = o.map((i) => i.text).join("/"), v(), m("finish", t, ...l); }, onChange: (...l) => m("change", t, ...l), onClickTab: (...l) => m("click-tab", t, ...l), onClose: U }), y()))]); }, "date-picker": () => { const a = (/* @__PURE__ */ new Date()).getFullYear(); return n(T, null, [n(k, c({ modelValue: e.formValue[`${t}Text`], "onUpdate:modelValue": (l) => e.formValue[`${t}Text`] = l }, $()), h()), j(n(F, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (l) => e.formValue[t] = l, title: x() }, f(), r, { minDate: u(r, "minDate") ? r.minDate : new Date(a - 20, 1, 1), maxDate: u(r, "maxDate") ? r.maxDate : new Date(a + 10, 12, 31), onConfirm: (...l) => { e.formValue[`${t}Text`] = e.formValue[t].join("-"), v(), m("confirm", t, ...l); }, onChange: (...l) => m("change", t, ...l), onCancel: U }), y()))]); }, "time-picker": () => n(T, null, [n(k, c({ modelValue: e.formValue[`${t}Text`], "onUpdate:modelValue": (a) => e.formValue[`${t}Text`] = a }, $()), h()), j(n(O, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (a) => e.formValue[t] = a, title: x() }, f(), r, { onConfirm: (...a) => { e.formValue[`${t}Text`] = e.formValue[t].join(":"), v(), m("confirm", t, ...a); }, onChange: (...a) => m("change", t, ...a), onCancel: U }), y()))]), "datetime-picker": () => { const a = (/* @__PURE__ */ new Date()).getFullYear(), l = r, o = (d) => { let s = [{}, {}]; if (u(d, "groupProps") && D(d.groupProps)) { const [g, C] = d.groupProps; g && (s[0] = { ...g, minDate: g.minDate || new Date(a - 20, 1, 1), maxDate: g.maxDate || new Date(a + 10, 12, 31) }), C && (s[1] = C); } return s; }, i = () => { switch (u(r, "showType") && ["group", "single"].includes(r.showType) ? r.showType : "group") { case "group": const s = w({ date: D(e.formValue[t]) && e.formValue[t].length > 0 ? e.formValue[t][0] : [], time: D(e.formValue[t]) && e.formValue[t].length > 1 ? e.formValue[t][1] : [] }); return n(G, c({ title: x() }, f(), l, { tabs: u(l, "tabs") ? l.tabs : ["选择日期", "选择时间"], onConfirm: (...g) => { e.formValue[t] = [s.value.date, s.value.time], e.formValue[`${t}Text`] = `${s.value.date.join("-")} ${s.value.time.join(":")}`, v(), m("confirm", t, ...g); }, onChange: (...g) => m("change", t, ...g), onCancel: U }), { default: () => [n(F, c({ modelValue: s.value.date, "onUpdate:modelValue": (g) => s.value.date = g }, o(l)[0]), null), n(O, c({ modelValue: s.value.time, "onUpdate:modelValue": (g) => s.value.time = g }, o(l)[1]), null)], ...y() }); case "single": return n(I, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (g) => e.formValue[t] = g, title: x() }, f(), u(l, "groupProps") ? l.groupProps : {}, { onConfirm: (...g) => { const [{ selectedValues: C }] = g; e.formValue[t] = C; const N = `${C.slice(0, 3).join("-")} ${C.slice(3).join(":")}`; e.formValue[`${t}Text`] = N, v(), m("confirm", t, ...g); }, onChange: (...g) => m("change", t, ...g), onCancel: U }), y()); } }; return n(T, null, [n(k, c({ modelValue: e.formValue[`${t}Text`], "onUpdate:modelValue": (d) => e.formValue[`${t}Text`] = d }, $()), h()), j(i())]); }, "date-range-picker": () => { const a = (/* @__PURE__ */ new Date()).getFullYear(), l = w({ start: D(e.formValue[t]) && e.formValue[t].length > 0 ? e.formValue[t][0] : [], end: D(e.formValue[t]) && e.formValue[t].length > 1 ? e.formValue[t][1] : [] }), o = r, i = (d) => { let s = [{}, {}]; if (u(d, "groupProps") && D(d.groupProps)) { const [g, C] = d.groupProps || []; g && (s[0] = g, s[0].minDate = g.minDate || new Date(a - 20, 1, 1), s[0].maxDate = g.maxDate || new Date(a + 10, 1, 1)), C && (s[1] = C, s[1].minDate = g.minDate || new Date(a - 20, 1, 1), s[1].maxDate = g.maxDate || new Date(a + 10, 1, 1)); } return s; }; return n(T, null, [n(k, c({ modelValue: e.formValue[`${t}Text`], "onUpdate:modelValue": (d) => e.formValue[`${t}Text`] = d }, $()), h()), j(n(G, c({ title: x() }, f(), o, { tabs: u(o, "tabs") ? o.tabs : ["开始日期", "结束日期"], onConfirm: (...d) => { e.formValue[t] = [l.value.start, l.value.end], e.formValue[`${t}Text`] = `${l.value.start.join("-")} 至 ${l.value.end.join("-")}`, v(), m("confirm", t, ...d); }, onChange: (...d) => m("change", t, ...d), onCancel: v }), { default: () => [n(F, c({ modelValue: l.value.start, "onUpdate:modelValue": (d) => l.value.start = d }, i(o)[0]), null), n(F, c({ modelValue: l.value.end, "onUpdate:modelValue": (d) => l.value.end = d }, i(o)[1]), null)], ...y() }))]); }, "time-range-picker": () => { const a = w({ start: D(e.formValue[t]) && e.formValue[t].length > 0 ? e.formValue[t][0] : [], end: D(e.formValue[t]) && e.formValue[t].length > 1 ? e.formValue[t][1] : [] }), l = r, o = (i) => { let d = {}, s = {}; if (u(i, "groupProps") && D(i.groupProps)) { const [g, C] = i.groupProps; g && (d = g), C && (s = C); } return [d, s]; }; return n(T, null, [n(k, c({ modelValue: e.formValue[`${t}Text`], "onUpdate:modelValue": (i) => e.formValue[`${t}Text`] = i }, $()), h()), j(n(G, c({ title: x() }, f(), l, { tabs: u(l, "tabs") ? l.tabs : ["开始时间", "结束时间"], onConfirm: (...i) => { v(), e.formValue[t] = [a.value.start, a.value.end], e.formValue[`${t}Text`] = `${a.value.start.join(":")} 至 ${a.value.end.join(":")}`, m("confirm", t, ...i); }, onChange: (...i) => m("change", t, ...i), onCancel: v }), { default: () => [n(O, c({ modelValue: a.value.start, "onUpdate:modelValue": (i) => a.value.start = i }, o(l)[0]), null), n(O, c({ modelValue: a.value.end, "onUpdate:modelValue": (i) => a.value.end = i }, o(l)[1]), null)], ...y() }))]); }, "datetime-range-picker": () => { const a = w({ start: D(e.formValue[t]) && e.formValue[t].length > 0 ? e.formValue[t][0] : [], end: D(e.formValue[t]) && e.formValue[t].length > 1 ? e.formValue[t][1] : [] }), l = r, o = (i) => { let d = {}, s = {}; if (u(i, "groupProps") && D(i.groupProps)) { const [g, C] = i.groupProps; g && (d = g), C && (s = C); } return [d, s]; }; return n(T, null, [n(k, c({ modelValue: e.formValue[`${t}Text`], "onUpdate:modelValue": (i) => e.formValue[`${t}Text`] = i }, $()), h()), j(n(G, c({ title: x() }, f(), l, { tabs: u(l, "tabs") ? l.tabs : ["开始时间", "结束时间"], onConfirm: (...i) => { const { start: d, end: s } = a.value; e.formValue[t] = [a.value.start, a.value.end]; const g = `${d.slice(0, 3).join("-")} ${d.slice(3).join(":")}`, C = `${s.slice(0, 3).join("-")} ${s.slice(3).join(":")}`; e.formValue[`${t}Text`] = `${g} 至 ${C}`, v(), m("confirm", t, ...i); }, onChange: (...i) => m("change", t, ...i), onCancel: v }), { default: () => [n(I, c({ modelValue: a.value.start, "onUpdate:modelValue": (i) => a.value.start = i }, o(l)[0]), null), n(I, c({ modelValue: a.value.end, "onUpdate:modelValue": (i) => a.value.end = i }, o(l)[1]), null)], ...y() }))]); }, // 'calender': () => { // return <> // // (showPopup.value = val)} // title={`请选择${label}`} // {...eventsCollector()} // {...(orgAttrs as CompAttrsPropsMap['calender'])} // show={showPopup.value} // onConfirm={(...args: any) => { // // console.log('calender', args); // props.formValue[`${name}Text`] = props.formValue[name].map((item: any) => dayjs(item).format('YYYY-MM-DD')).join('、') // closePopup() // onEvents('confirm', name, ...args) // }} // onChange={(...args: any) => { // onEvents('change', name, ...args) // }} // onPanelChange={(...args: any) => onEvents('panel-change', name, ...args)} // onSelect={(...args: any) => onEvents('select', name, ...args)} // onOpen={(...args: any) => onEvents('open', name, ...args)} // onClose={(...args: any) => onEvents('close', name, ...args)} // onOpened={(...args: any) => onEvents('opened', name, ...args)} // onClosed={(...args: any) => onEvents('closed', name, ...args)} // onUnselect={(...args: any) => onEvents('unselec', name, ...args)} // onMonthShow={(...args: any) => onEvents('month-show', name, ...args)} // onOverRange={(...args: any) => onEvents('over-range', name, ...args)} // onClickDisabledDate={(...args: any) => onEvents('click-disabled-date', name, ...args)} // onClickSubtitle={(...args: any) => onEvents('click-subtitle', name, ...args)} // onCancel={onCancel} // v-slots={handlerCompSlots()} // />, // // }, radio: () => n(k, $(), { input: () => n(W, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (a) => e.formValue[t] = a }, f(), r, { class: { "readonly-radio": e.readonly }, disabled: e.readonly || u(r, "disabled") && !!r.disabled }), { default: () => { var a; return [(a = e.options) == null ? void 0 : a.map((l) => n(Z, c({ key: l.value }, l.attrs, { name: l.value, onClick: (...o) => { m("child-click", t, ...o); } }), { default: () => [l.text] }))]; }, ...y() }) }), checkbox: () => n(k, $(), { ...h(), input: () => n(ee, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (a) => e.formValue[t] = a }, f(), r, { class: { "readonly-checkbox": e.readonly }, disabled: e.readonly || u(r, "disabled") && !!r.disabled }), { default: () => { var a; return [(a = e.options) == null ? void 0 : a.map((l) => n(te, c({ key: l.value }, l.attrs, { name: l.value, onClick: (...o) => { m("child-click", t, ...o); }, onChange: (...o) => { m("child-change", t, ...o); } }), { default: () => [l.text] }))]; }, ...y() }) }), switch: () => n(k, $(), { ...h(), input: () => n(ae, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (a) => e.formValue[t] = a }, f(), r, { class: { "readonly-switch": e.readonly }, disabled: e.readonly || u(r, "disabled") && !!r.disabled }), y()) }), rate: () => n(k, $(), { ...h(), input: () => n(le, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (a) => e.formValue[t] = a }, f(), r, { readonly: e.readonly || u(r, "readonly") && !!r.readonly }), y()) }), slider: () => n(k, $(), { ...h(), input: () => n(ne, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (a) => e.formValue[t] = a }, f(), r, { class: { "readonly-slider": e.readonly }, disabled: e.readonly || u(r, "disabled") && !!r.disabled, onDragStart: (...a) => { m("drag-start", t, ...a); }, onDragEnd: (...a) => { m("drag-end", t, ...a); } }), y()) }), stepper: () => n(k, $(), { ...h(), input: () => n(re, c({ modelValue: e.formValue[t], "onUpdate:modelValue": (a) => e.formValue[t] = a }, f(), r, { class: { "readonly-stepper": e.readonly }, disabled: e.readonly || u(r, "disabled") && !!r.disabled, onPlus: (...a) => { m("plus", t, ...a); }, onMinus: (...a) => { m("minus", t, ...a); }, onOverlimit: (...a) => { m("overlimit", t, ...a); } }), y()) }), text: () => n(k, $(), { ...h(), input: () => n(T, null, [e.formValue[t]]) }), html: () => n(k, $(), { ...h(), input: () => n("div", c({ innerHTML: e.formValue[t] }, r), null) }), "input-slot": () => n(k, $(), { ...h(), input: () => n(T, null, [u(V, t) ? R(V, t) : n(T, null, null)]) }), slot: () => n(T, null, [u(V, t) ? R(V, t) : n(T, null, null)]) }, j = (a, l = {}) => n(oe, c({ show: S.value, "onUpdate:show": (o) => S.value = o, "destroy-on-close": !0, round: !0, position: "bottom" }, l, e.popup), be(a) ? a : { default: () => [a] }); return () => n(T, null, [A[e.type]()]); } }); function ye(e) { return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !L(e); } const [ve] = me("form"), xe = Object.assign({}, ie, { model: { type: Object, required: !0, default: () => ({}) }, items: { type: Array, required: !0, default: () => [] }, rules: { type: Object, default: () => ({}) }, inset: { type: Boolean, default: !1 } }), ke = /* @__PURE__ */ E({ name: ve, props: xe, emits: ["submit", "failed", "confirm", "cancel", "change", "blur", "focus", "click", "drag-start", "drag-end", "plus", "minus", "overlimit", "finish", "click-tab", "child-click", "child-change"], setup(e, { slots: t, attrs: b, emit: r, expose: P }) { const V = w(), q = (...f) => r("submit", ...f), m = (...f) => r("failed", ...f); p("x-form", { formSlots: t, rules: e.rules, onEvents: (f, ...h) => { r(f, ...h); } }), P({ submit: () => V.value.submit(), getValues: () => V.value.getValues(), validate: async (f) => { var h; return await ((h = V.value) == null ? void 0 : h.validate(f)); }, resetValidation: (f) => V.value.resetValidation(f), getValidationStatus: () => V.value.getValidationStatus(), scrollToField: (f, h) => V.value.scrollToField(f, h) }); const S = (f) => { const { itemProps: h, name: y } = f, $ = u(e.rules, y) ? !!e.rules[y].find((v) => u(v, "required") && v.required) : !1, x = u(f, "required") ? !!f.required : !1; return (h && u(h, "required") ? !!h.required : !1) || x || $ || !!e.required; }; return { formRef: V, ...H(e), attrs: b, getRequired: S, onSubmit: q, onFailed: m }; }, render() { let e; const { formRef: t, items: b, model: r, rules: P, required: V, readonly: q, onSubmit: m, onFailed: S, attrs: f, inset: h, getRequired: y, ...$ } = this; return n(de, c({ ref: "formRef", onSubmit: m, onFailed: S, required: V, readonly: q }, $, f), { default: () => [n(ce, { inset: h }, ye(e = b.map((x, U) => { const { vif: v, type: A, name: j, label: a, itemProps: l, popup: o } = x; if (!fe.includes(A)) throw new Error(`${A} 类型组件暂不支持`); return (u(x, "vif") ? Y(v) ? v(r) : v : !0) ? n($e, { key: j + U, formValue: r, type: A, name: j, label: a, options: x.options, config: x, required: y(x), readonly: q, popup: o, itemAttrs: l, orgAttrs: x.attrs }, null) : null; })) ? e : { default: () => [e] })] }); } }), je = se(ke); export { je as X };