ayongui
Version:
253 lines (252 loc) • 9.85 kB
JavaScript
import { j as a } from "../../../react/jsx-runtime.mjs";
import W, { useRef as Y, useState as u, useMemo as le, useEffect as I, useImperativeHandle as se } from "react";
import oe from "../base-calendar/index.mjs";
import n from "./index.module.less.mjs";
import ie from "../../config/style.module.less.mjs";
import "../icon/index.module.less.mjs";
import ce from "../icon/components/doubleright-frame/index.mjs";
import ue from "../icon/components/doubleleft-frame/index.mjs";
import "../icon/components/loading-frame/loading.module.less.mjs";
import de from "../icon/components/cendas-frame/index.mjs";
import me from "../icon/components/left-frame/index.mjs";
import he from "../icon/components/facright-frame/index.mjs";
import fe from "../icon/components/wrong-solid/index.mjs";
import pe from "../s-h-m/index.mjs";
let w = [], _ = [], B = [];
const p = [], z = {}, ve = {
day: "请选择日期",
week: "请选择周",
month: "请选择月份",
quarter: "请选择季度",
year: "请选择年份"
}, Ye = W.forwardRef((q, A) => {
const {
style: G,
className: J,
picker: r = "day",
yearsRange: K = [1970, 2099],
defaultValue: o = null,
disabled: N = !1,
value: s = null,
onChange: T = () => {
},
onClear: U = () => {
},
footerRender: O = null,
showTime: v = !1,
isRange: g = !1
} = q;
let y = "", i = "", c = "", x = "";
o instanceof Date && (i = o.toISOString().slice(0, 10), v ? (c = o.toTimeString().slice(0, 8), y = i + " " + c) : y = i), s instanceof Date && (i = s.toISOString().slice(0, 10), v ? (c = s.toTimeString().slice(0, 8), x = i + " " + c) : x = i);
const l = Y(null), [f, S] = u(y), [X, k] = u(!1), [d, b] = u(0), [m, Z] = u([]), [j, F] = u((/* @__PURE__ */ new Date()).getFullYear()), [H, $] = u(""), [ee, R] = u(!1), C = le(() => d < 0 ? m[0] || [] : d > m.length - 1 ? m[m.length - 1] || [] : m[d] || [], [d]), M = Y(null);
I(() => {
var e, t;
s && ((e = l.current) == null || e.handleItemClick(
null,
{
date: s.getDate().toString().padStart(2, "0"),
comprehensiveStr: x,
comprehensive: s,
isSelected: !0,
//判断value是否今年今天
isToday: i === (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)
},
0,
0,
!0
), $(c), S(x), (t = l.current) == null || t.setCountYYYMMM({
year: s.getFullYear(),
month: s.getMonth()
}));
}, [s]), I(() => {
var e;
if (o && ((e = l.current) == null || e.handleItemClick(
null,
{
date: o.getDate().toString().padStart(2, "0"),
comprehensiveStr: y,
comprehensive: o,
isSelected: !0,
isRangeSelected: !0,
isToday: !0
},
0,
0,
!0
)), r === "month" && (_ = [
{ value: "1月" },
{ value: "2月" },
{ value: "3月" },
{ value: "4月" },
{ value: "5月" },
{ value: "6月" },
{ value: "7月" },
{ value: "8月" },
{ value: "9月" },
{ value: "10月" },
{ value: "11月" },
{ value: "12月" }
]), r === "year") {
w = l.current.handleCreateDatePicker(K).years.slice(0, 58).map((t) => ({ value: t.label }));
for (let t = 0; t < w.length; t++)
t % 12 == 0 && p.push([]), p[p.length - 1].push(w[t]), z[w[t].value.replace("年", "")] = p.length - 1;
b(() => z[j]), Z(p);
}
r === "quarter" && (B = [{ value: "Q1" }, { value: "Q2" }, { value: "Q3" }, { value: "Q4" }]);
}, []);
const P = Y(null);
I(() => {
const e = (t) => {
M.current && !M.current.contains(t.target) && !P.current.contains(t.target) && k(!1);
};
return document.addEventListener("click", e), () => {
document.removeEventListener("click", e);
};
}, []);
const V = (e) => {
N || k(!0);
}, te = (e) => {
k(!1);
}, E = (e) => {
var t;
e == null || e.stopPropagation(), S(""), $(() => ""), U(), (t = l.current) == null || t.clearSetSelectedDates();
}, D = (e, t) => {
r === "week" ? (S(t), T(e, t)) : (v && (e.comprehensiveStr += " " + H), S(e.comprehensiveStr), T(e)), !g && k(!1);
}, ae = () => {
["month", "quarter", "day", "week"].includes(r) && F((e) => ++e), ["day", "week"].includes(r) && l.current.nextYear(), r === "year" && (d > m.length - 1 || b((e) => ++e));
}, re = () => {
if (["month", "quarter", "day", "week"].includes(r) && F((e) => --e), ["day", "week"].includes(r) && l.current.prevYear(), r === "year") {
if (d < 0)
return;
b((e) => --e);
}
}, ne = (e) => {
$(e), R(!1);
};
return se(A, () => ({
onWrong: E,
openDropdown: V,
closeDropdown: te
})), /* @__PURE__ */ a.jsxs("div", { className: g ? "" : n.warp, children: [
!g && /* @__PURE__ */ a.jsxs(
"main",
{
ref: M,
style: G,
className: `${n.main} ${f ? n.hoverMain : ""} ${N ? ie.disabled : n.mainHover} ${J} `,
onClick: V,
children: [
/* @__PURE__ */ a.jsx("input", { className: n.ssshhhmmInput, value: f, disabled: N, onChange: () => {
}, placeholder: ve[r] }),
/* @__PURE__ */ a.jsx(fe, { onClick: E, className: n.pickerWrong }),
/* @__PURE__ */ a.jsx(de, { className: n.pickerCollapse })
]
}
),
/* @__PURE__ */ a.jsx(
oe,
{
className: `${g ? "" : n.baseCalendarabsolute} ${n.baseCalendar} ${X ? n.baseCalendarShow : n.baseCalendarNone}`,
ref: l,
...q,
selectedMode: r,
onChange: D,
style: { width: "32px", height: "32px" },
defaultValue: o,
headerRender: ({ curMonth: e, yearOptions: t, monthOptions: h }) => {
var Q, L;
return /* @__PURE__ */ a.jsxs("div", { ref: P, className: n.tshanHien, style: { position: "relative", marginBottom: " 20px" }, children: [
v && /* @__PURE__ */ a.jsxs(a.Fragment, { children: [
/* @__PURE__ */ a.jsx("input", { className: n.input, value: H, onChange: () => {
}, onFocus: () => R(!0), placeholder: "选择几点钟" }),
/* @__PURE__ */ a.jsx(
pe,
{
onChange: ne,
value: c,
onCancel: () => R(!1),
className: `${n.SHM} ${ee && n.SHMShow}`,
defaultValue: c
}
)
] }),
/* @__PURE__ */ a.jsxs("main", { className: n.picker, children: [
/* @__PURE__ */ a.jsxs("div", { children: [
["day", "week", "quarter", "month", "year"].includes(r) && /* @__PURE__ */ a.jsx(ue, { onClick: re, className: n.icon }),
["day", "week"].includes(r) && /* @__PURE__ */ a.jsx(me, { onClick: () => l.current.prevMonth(), className: `${n.spacing} ${n.icon} ` })
] }),
/* @__PURE__ */ a.jsxs("div", { children: [
r === "year" && /* @__PURE__ */ a.jsx("span", { children: ((Q = C[0]) == null ? void 0 : Q.value) + "-" + ((L = C[C.length - 1]) == null ? void 0 : L.value) }),
["month", "quarter", "day", "week"].includes(r) && /* @__PURE__ */ a.jsxs("span", { children: [
" ",
j,
"年 "
] }),
" ",
r === "day" && /* @__PURE__ */ a.jsxs("span", { children: [
e + 1,
"月"
] })
] }),
/* @__PURE__ */ a.jsxs("div", { children: [
["day", "week"].includes(r) && /* @__PURE__ */ a.jsx(he, { onClick: () => l.current.nextMonth(), className: `${n.spacing} ${n.icon} ` }),
["day", "week", "quarter", "month", "year"].includes(r) && /* @__PURE__ */ a.jsx(ce, { onClick: ae, className: n.icon })
] })
] })
] });
},
dateRender: ["quarter", "month", "year"].includes(r) ? (e) => /* @__PURE__ */ a.jsxs(W.Fragment, { children: [
r === "year" && /* @__PURE__ */ a.jsx("main", { className: "block-12", children: C.map((t, h) => /* @__PURE__ */ a.jsx(
"div",
{
className: `block-chlid ${t.value === f ? "onSelect" : ""}`,
onClick: () => {
D({ comprehensiveStr: t.value });
},
children: t.value
},
h
)) }),
r === "month" && /* @__PURE__ */ a.jsx("main", { className: "block-12", children: _.map((t, h) => /* @__PURE__ */ a.jsx(
"div",
{
className: `block-chlid ${j + "年" + t.value === f ? "onSelect" : ""}`,
onClick: () => {
D({
comprehensiveStr: j + "年" + t.value
});
},
children: t.value
},
h
)) }),
r === "quarter" && /* @__PURE__ */ a.jsx("main", { className: "block-4", children: B.map((t, h) => /* @__PURE__ */ a.jsx(
"div",
{
className: `block-chlid ${t.value === f ? "onSelect" : ""}`,
onClick: () => {
D({ comprehensiveStr: t.value });
},
children: t.value
},
h
)) })
] }) : null,
footerRender: () => typeof O == "function" ? O() : r === "day" && /* @__PURE__ */ a.jsx(
"footer",
{
style: { position: "relative", display: "grid" },
className: n.footer,
onClick: (e) => {
l.current.setDateSelected((/* @__PURE__ */ new Date()).toISOString().slice(0, 10));
},
children: "今天"
}
)
}
)
] });
});
export {
Ye as default
};