UNPKG

@aplus-frontend/ui

Version:

214 lines (213 loc) 6.74 kB
import { defineComponent as E, computed as r, unref as t, createElementBlock as B, createBlock as y, openBlock as i, Fragment as g, createTextVNode as k, toDisplayString as w, normalizeStyle as N, withCtx as s, createVNode as b, createCommentVNode as j, isRef as I, renderList as P, mergeProps as U, createSlots as H, renderSlot as K, normalizeProps as W, guardReactiveProps as $ } from "vue"; import { InputGroup as G, FormItemRest as L, Select as Y, SelectOption as Z, DatePicker as q } from "@aplus-frontend/antdv"; import { getTimeFormatToZone as J } from "@aplus-frontend/utils"; import u from "dayjs"; import { isNil as C, omit as Q } from "lodash-unified"; import "../../hooks/index.mjs"; import { useDateTimezone as X } from "../hooks/use-date-timezone.mjs"; import { useDefaultPlaceholder as ee } from "../hooks/use-default-placeholder.mjs"; import { ApFieldDatePresetFormats as oe, PRESET_FORMAT_MAP as O, PRESET_FORMAT_PICK_MAP as te, PRESET_FORMAT_TIME_MAP as ae } from "./constant.mjs"; import { formatDayWithTimezone as ne } from "./helper.mjs"; import { useControllableValue as le } from "../../hooks/useControllableValue.mjs"; const he = /* @__PURE__ */ E({ name: "ApFieldDate", __name: "index", props: { mode: { default: "edit" }, class: {}, style: {}, dropdownClassName: {}, dropdownAlign: {}, popupStyle: {}, transitionName: {}, placeholder: {}, allowClear: { type: Boolean, default: !0 }, autofocus: { type: Boolean, default: void 0 }, disabled: { type: Boolean, default: void 0 }, tabindex: {}, open: { type: Boolean, default: void 0 }, defaultOpen: { type: Boolean, default: void 0 }, inputReadOnly: { type: Boolean, default: void 0 }, id: {}, presets: {}, suffixIcon: { type: [Object, String, Number, Boolean, null, Array], default: void 0 }, clearIcon: { type: [Object, String, Number, Boolean, null, Array], default: void 0 }, getPopupContainer: {}, panelRender: {}, inputRender: {}, onOpenChange: {}, onPanelChange: {}, onFocus: {}, onBlur: {}, onMousedown: {}, onMouseup: {}, onMouseenter: {}, onMouseleave: {}, onClick: {}, onContextmenu: {}, onKeydown: {}, role: {}, name: {}, autocomplete: {}, direction: {}, showToday: { type: Boolean, default: void 0 }, showTime: { type: [Boolean, Object], default: void 0 }, picker: {}, prefixCls: {}, defaultPickerValue: {}, disabledDate: {}, showWeek: { type: Boolean }, dateRender: {}, monthCellRender: {}, renderExtraFooter: {}, onSelect: {}, locale: {}, size: {}, bordered: { type: Boolean, default: void 0 }, variant: {}, showNow: { type: Boolean, default: void 0 }, disabledTime: {}, defaultOpenValue: {}, showHour: { type: Boolean, default: void 0 }, showMinute: { type: Boolean, default: void 0 }, showSecond: { type: Boolean, default: void 0 }, use12Hours: { type: Boolean, default: void 0 }, hourStep: {}, minuteStep: {}, secondStep: {}, hideDisabledOptions: { type: Boolean, default: void 0 }, disabledHours: {}, disabledMinutes: {}, disabledSeconds: {}, valueFormat: {}, emptyText: { default: "--" }, value: {}, defaultValue: {}, "onUpdate:value": {}, onChange: {}, onOk: {}, format: { default: "Y-D" }, shownFormat: {}, formatBegins: { type: Boolean, default: !0 }, timezone: {} }, emits: ["update:value"], setup(S, { emit: T }) { const e = S, F = T, { value: f, updateValue: h } = le( e, F ), _ = ee("Date", e), { currentTimezone: d } = X(e), l = r( () => oe.indexOf(e.format) > -1 ), A = r(() => e.shownFormat ? e.shownFormat : l.value ? O[e.format] : e.format), m = r( () => l.value ? O[e.format] : e.format ), c = r(() => { if (C(t(f))) return; let o = u(t(f)); return e.timezone && (o = u(J(t(f), d.value))), o; }), R = r(() => t(l) ? e.picker ?? te[e.format] : e.picker), M = r(() => { const o = t(l) ? ae[e.format] : {}; return { ...Q(e, [ "value", "defaultValue", "onChange", "onOk", "format", "onUpdate:value", "mode" ]), placeholder: t(_), ...o }; }), v = (o, n, a = !0) => ne(d.value)(o, n, a); function D(o) { if (C(o)) { h(null); return; } const n = u(o); h( v( n, t(l) ? t(m) : void 0, e.formatBegins ) ); } function V(o, n) { const a = u(o), p = o ? v( a, t(l) ? t(m) : void 0, e.formatBegins ) : null; e.onChange?.(p, n); } function x(o) { const n = u(o), a = o ? v( n, t(l) ? t(m) : void 0, e.formatBegins ) : null; e.onOk?.(a); } return (o, n) => o.mode === "read" ? (i(), B(g, { key: 0 }, [ k(w(c.value ? t(u)(c.value).format(m.value) : o.emptyText), 1) ], 64)) : (i(), y(t(G), { key: 1, compact: "", style: N({ display: Array.isArray(e.timezone) && e.timezone.length ? "flex" : "block" }) }, { default: s(() => [ b(t(L), null, { default: s(() => [ Array.isArray(e.timezone) && e.timezone.length ? (i(), y(t(Y), { key: 0, value: t(d), "onUpdate:value": n[0] || (n[0] = (a) => I(d) ? d.value = a : null), "default-active-first-option": "", "dropdown-match-select-width": !1, style: { "max-width": "50%" }, disabled: o.disabled }, { default: s(() => [ (i(!0), B(g, null, P(e.timezone, (a) => (i(), y(t(Z), { key: a?.value, value: a?.value }, { default: s(() => [ k(w(a?.label ?? a?.value), 1) ]), _: 2 }, 1032, ["value"]))), 128)) ]), _: 1 }, 8, ["value", "disabled"])) : j("", !0) ]), _: 1 }), b(t(q), U(M.value, { value: c.value, format: A.value, picker: R.value, "onUpdate:value": D, onChange: V, onOk: x }), H({ _: 2 }, [ P(o.$slots, (a, p) => ({ name: p, fn: s((z) => [ K(o.$slots, p, W($(z || {}))) ]) })) ]), 1040, ["value", "format", "picker"]) ]), _: 3 }, 8, ["style"])); } }); export { he as default };