@aplus-frontend/ui
Version:
208 lines (207 loc) • 6.5 kB
JavaScript
import { defineComponent as z, 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 E, withCtx as p, createCommentVNode as N, createVNode 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 u from "dayjs";
import { InputGroup as G, Select as L, SelectOption as Y, DatePicker as Z } from "@aplus-frontend/antdv";
import { ApFieldDatePresetFormats as q, PRESET_FORMAT_MAP as b, PRESET_FORMAT_PICK_MAP as J, PRESET_FORMAT_TIME_MAP as Q } from "./constant.mjs";
import "../../hooks/index.mjs";
import { isNil as C, omit as X } from "lodash-unified";
import { formatDayWithTimezone as ee } from "./helper.mjs";
import { getTimeFormatToZone as oe } from "@aplus-frontend/utils";
import { useDefaultPlaceholder as te } from "../hooks/use-default-placeholder.mjs";
import { useDateTimezone as ae } from "../hooks/use-date-timezone.mjs";
import { useControllableValue as ne } from "../../hooks/useControllableValue.mjs";
const ye = /* @__PURE__ */ z({
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, 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: {},
onChange: {},
onOk: {},
format: { default: "Y-D" },
shownFormat: {},
formatBegins: { type: Boolean, default: !0 },
timezone: {}
},
emits: ["update:value"],
setup(S, { emit: T }) {
const e = S, O = T, { value: f, updateValue: h } = ne(
e,
O
), F = te("Date", e), { currentTimezone: d } = ae(e), l = r(
() => q.indexOf(e.format) > -1
), A = r(() => e.shownFormat ? e.shownFormat : l.value ? b[e.format] : e.format), s = r(
() => l.value ? b[e.format] : e.format
), c = r(() => {
if (C(t(f)))
return;
let o = u(t(f));
return e.timezone && (o = u(oe(t(f), d.value))), o;
}), _ = r(() => t(l) ? e.picker ?? J[e.format] : e.picker), R = r(() => {
const o = t(l) ? Q[e.format] : {};
return {
...X(e, [
"value",
"defaultValue",
"onChange",
"onOk",
"format",
"onUpdate:value",
"mode"
]),
placeholder: t(F),
...o
};
}), v = (o, n, a = !0) => ee(d.value)(o, n, a);
function M(o) {
if (C(o)) {
h(null);
return;
}
const n = u(o);
h(
v(
n,
t(l) ? t(s) : void 0,
e.formatBegins
)
);
}
function D(o, n) {
const a = u(o), m = o ? v(
a,
t(l) ? t(s) : void 0,
e.formatBegins
) : null;
e.onChange?.(m, n);
}
function V(o) {
const n = u(o), a = o ? v(
n,
t(l) ? t(s) : 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(s.value) : o.emptyText), 1)
], 64)) : (i(), y(t(G), {
key: 1,
compact: "",
style: E({
display: Array.isArray(e.timezone) && e.timezone.length ? "flex" : "block"
})
}, {
default: p(() => [
Array.isArray(e.timezone) && e.timezone.length ? (i(), y(t(L), {
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: p(() => [
(i(!0), B(g, null, P(e.timezone, (a) => (i(), y(t(Y), {
key: a?.value,
value: a?.value
}, {
default: p(() => [
k(w(a?.label ?? a?.value), 1)
]),
_: 2
}, 1032, ["value"]))), 128))
]),
_: 1
}, 8, ["value", "disabled"])) : N("", !0),
j(t(Z), U(R.value, {
value: c.value,
format: A.value,
picker: _.value,
"onUpdate:value": M,
onChange: D,
onOk: V
}), H({ _: 2 }, [
P(o.$slots, (a, m) => ({
name: m,
fn: p((x) => [
K(o.$slots, m, W($(x || {})))
])
}))
]), 1040, ["value", "format", "picker"])
]),
_: 3
}, 8, ["style"]));
}
});
export {
ye as default
};