UNPKG

tk-eui-plus

Version:

433 lines (432 loc) 16.5 kB
import { defineComponent as se, ref as U, watch as q, resolveComponent as ie, openBlock as ue, createElementBlock as oe, createElementVNode as G, createVNode as Q, mergeProps as K, unref as W, isRef as X } from "vue"; var le = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function de(h) { return h && h.__esModule && Object.prototype.hasOwnProperty.call(h, "default") ? h.default : h; } var ee = { exports: {} }; (function(h, E) { (function(f, M) { h.exports = M(); })(le, function() { var f = 1e3, M = 6e4, m = 36e5, w = "millisecond", S = "second", v = "minute", _ = "hour", T = "day", u = "week", d = "month", R = "quarter", p = "year", N = "date", J = "Invalid Date", te = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, ne = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, ae = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(r) { var n = ["th", "st", "nd", "rd"], e = r % 100; return "[" + r + (n[(e - 20) % 10] || n[e] || n[0]) + "]"; } }, F = function(r, n, e) { var a = String(r); return !a || a.length >= n ? r : "" + Array(n + 1 - a.length).join(e) + r; }, re = { s: F, z: function(r) { var n = -r.utcOffset(), e = Math.abs(n), a = Math.floor(e / 60), t = e % 60; return (n <= 0 ? "+" : "-") + F(a, 2, "0") + ":" + F(t, 2, "0"); }, m: function r(n, e) { if (n.date() < e.date()) return -r(e, n); var a = 12 * (e.year() - n.year()) + (e.month() - n.month()), t = n.clone().add(a, d), s = e - t < 0, i = n.clone().add(a + (s ? -1 : 1), d); return +(-(a + (e - t) / (s ? t - i : i - t)) || 0); }, a: function(r) { return r < 0 ? Math.ceil(r) || 0 : Math.floor(r); }, p: function(r) { return { M: d, y: p, w: u, d: T, D: N, h: _, m: v, s: S, ms: w, Q: R }[r] || String(r || "").toLowerCase().replace(/s$/, ""); }, u: function(r) { return r === void 0; } }, H = "en", k = {}; k[H] = ae; var Z = "$isDayjsObject", B = function(r) { return r instanceof I || !(!r || !r[Z]); }, A = function r(n, e, a) { var t; if (!n) return H; if (typeof n == "string") { var s = n.toLowerCase(); k[s] && (t = s), e && (k[s] = e, t = s); var i = n.split("-"); if (!t && i.length > 1) return r(i[0]); } else { var l = n.name; k[l] = n, t = l; } return !a && t && (H = t), t || !a && H; }, D = function(r, n) { if (B(r)) return r.clone(); var e = typeof n == "object" ? n : {}; return e.date = r, e.args = arguments, new I(e); }, o = re; o.l = A, o.i = B, o.w = function(r, n) { return D(r, { locale: n.$L, utc: n.$u, x: n.$x, $offset: n.$offset }); }; var I = function() { function r(e) { this.$L = A(e.locale, null, !0), this.parse(e), this.$x = this.$x || e.x || {}, this[Z] = !0; } var n = r.prototype; return n.parse = function(e) { this.$d = function(a) { var t = a.date, s = a.utc; if (t === null) return /* @__PURE__ */ new Date(NaN); if (o.u(t)) return /* @__PURE__ */ new Date(); if (t instanceof Date) return new Date(t); if (typeof t == "string" && !/Z$/i.test(t)) { var i = t.match(te); if (i) { var l = i[2] - 1 || 0, c = (i[7] || "0").substring(0, 3); return s ? new Date(Date.UTC(i[1], l, i[3] || 1, i[4] || 0, i[5] || 0, i[6] || 0, c)) : new Date(i[1], l, i[3] || 1, i[4] || 0, i[5] || 0, i[6] || 0, c); } } return new Date(t); }(e), this.init(); }, n.init = function() { var e = this.$d; this.$y = e.getFullYear(), this.$M = e.getMonth(), this.$D = e.getDate(), this.$W = e.getDay(), this.$H = e.getHours(), this.$m = e.getMinutes(), this.$s = e.getSeconds(), this.$ms = e.getMilliseconds(); }, n.$utils = function() { return o; }, n.isValid = function() { return this.$d.toString() !== J; }, n.isSame = function(e, a) { var t = D(e); return this.startOf(a) <= t && t <= this.endOf(a); }, n.isAfter = function(e, a) { return D(e) < this.startOf(a); }, n.isBefore = function(e, a) { return this.endOf(a) < D(e); }, n.$g = function(e, a, t) { return o.u(e) ? this[a] : this.set(t, e); }, n.unix = function() { return Math.floor(this.valueOf() / 1e3); }, n.valueOf = function() { return this.$d.getTime(); }, n.startOf = function(e, a) { var t = this, s = !!o.u(a) || a, i = o.p(e), l = function(x, b) { var O = o.w(t.$u ? Date.UTC(t.$y, b, x) : new Date(t.$y, b, x), t); return s ? O : O.endOf(T); }, c = function(x, b) { return o.w(t.toDate()[x].apply(t.toDate("s"), (s ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(b)), t); }, g = this.$W, $ = this.$M, y = this.$D, Y = "set" + (this.$u ? "UTC" : ""); switch (i) { case p: return s ? l(1, 0) : l(31, 11); case d: return s ? l(1, $) : l(0, $ + 1); case u: var C = this.$locale().weekStart || 0, j = (g < C ? g + 7 : g) - C; return l(s ? y - j : y + (6 - j), $); case T: case N: return c(Y + "Hours", 0); case _: return c(Y + "Minutes", 1); case v: return c(Y + "Seconds", 2); case S: return c(Y + "Milliseconds", 3); default: return this.clone(); } }, n.endOf = function(e) { return this.startOf(e, !1); }, n.$set = function(e, a) { var t, s = o.p(e), i = "set" + (this.$u ? "UTC" : ""), l = (t = {}, t[T] = i + "Date", t[N] = i + "Date", t[d] = i + "Month", t[p] = i + "FullYear", t[_] = i + "Hours", t[v] = i + "Minutes", t[S] = i + "Seconds", t[w] = i + "Milliseconds", t)[s], c = s === T ? this.$D + (a - this.$W) : a; if (s === d || s === p) { var g = this.clone().set(N, 1); g.$d[l](c), g.init(), this.$d = g.set(N, Math.min(this.$D, g.daysInMonth())).$d; } else l && this.$d[l](c); return this.init(), this; }, n.set = function(e, a) { return this.clone().$set(e, a); }, n.get = function(e) { return this[o.p(e)](); }, n.add = function(e, a) { var t, s = this; e = Number(e); var i = o.p(a), l = function($) { var y = D(s); return o.w(y.date(y.date() + Math.round($ * e)), s); }; if (i === d) return this.set(d, this.$M + e); if (i === p) return this.set(p, this.$y + e); if (i === T) return l(1); if (i === u) return l(7); var c = (t = {}, t[v] = M, t[_] = m, t[S] = f, t)[i] || 1, g = this.$d.getTime() + e * c; return o.w(g, this); }, n.subtract = function(e, a) { return this.add(-1 * e, a); }, n.format = function(e) { var a = this, t = this.$locale(); if (!this.isValid()) return t.invalidDate || J; var s = e || "YYYY-MM-DDTHH:mm:ssZ", i = o.z(this), l = this.$H, c = this.$m, g = this.$M, $ = t.weekdays, y = t.months, Y = t.meridiem, C = function(b, O, V, P) { return b && (b[O] || b(a, s)) || V[O].slice(0, P); }, j = function(b) { return o.s(l % 12 || 12, b, "0"); }, x = Y || function(b, O, V) { var P = b < 12 ? "AM" : "PM"; return V ? P.toLowerCase() : P; }; return s.replace(ne, function(b, O) { return O || function(V) { switch (V) { case "YY": return String(a.$y).slice(-2); case "YYYY": return o.s(a.$y, 4, "0"); case "M": return g + 1; case "MM": return o.s(g + 1, 2, "0"); case "MMM": return C(t.monthsShort, g, y, 3); case "MMMM": return C(y, g); case "D": return a.$D; case "DD": return o.s(a.$D, 2, "0"); case "d": return String(a.$W); case "dd": return C(t.weekdaysMin, a.$W, $, 2); case "ddd": return C(t.weekdaysShort, a.$W, $, 3); case "dddd": return $[a.$W]; case "H": return String(l); case "HH": return o.s(l, 2, "0"); case "h": return j(1); case "hh": return j(2); case "a": return x(l, c, !0); case "A": return x(l, c, !1); case "m": return String(c); case "mm": return o.s(c, 2, "0"); case "s": return String(a.$s); case "ss": return o.s(a.$s, 2, "0"); case "SSS": return o.s(a.$ms, 3, "0"); case "Z": return i; } return null; }(b) || i.replace(":", ""); }); }, n.utcOffset = function() { return 15 * -Math.round(this.$d.getTimezoneOffset() / 15); }, n.diff = function(e, a, t) { var s, i = this, l = o.p(a), c = D(e), g = (c.utcOffset() - this.utcOffset()) * M, $ = this - c, y = function() { return o.m(i, c); }; switch (l) { case p: s = y() / 12; break; case d: s = y(); break; case R: s = y() / 3; break; case u: s = ($ - g) / 6048e5; break; case T: s = ($ - g) / 864e5; break; case _: s = $ / m; break; case v: s = $ / M; break; case S: s = $ / f; break; default: s = $; } return t ? s : o.a(s); }, n.daysInMonth = function() { return this.endOf(d).$D; }, n.$locale = function() { return k[this.$L]; }, n.locale = function(e, a) { if (!e) return this.$L; var t = this.clone(), s = A(e, a, !0); return s && (t.$L = s), t; }, n.clone = function() { return o.w(this.$d, this); }, n.toDate = function() { return new Date(this.valueOf()); }, n.toJSON = function() { return this.isValid() ? this.toISOString() : null; }, n.toISOString = function() { return this.$d.toISOString(); }, n.toString = function() { return this.$d.toUTCString(); }, r; }(), z = I.prototype; return D.prototype = z, [["$ms", w], ["$s", S], ["$m", v], ["$H", _], ["$W", T], ["$M", d], ["$y", p], ["$D", N]].forEach(function(r) { z[r[1]] = function(n) { return this.$g(n, r[0], r[1]); }; }), D.extend = function(r, n) { return r.$i || (r(n, I, D), r.$i = !0), D; }, D.locale = A, D.isDayjs = B, D.unix = function(r) { return D(1e3 * r); }, D.en = k[H], D.Ls = k, D.p = {}, D; }); })(ee); var ce = ee.exports; const L = /* @__PURE__ */ de(ce), fe = { style: { display: "flex" } }, he = { style: { "margin-right": "20px" } }, De = /* @__PURE__ */ se({ __name: "index", props: { //开始日期的占位符 startPlaceholder: { type: String, default: "请选择开始日期" }, //结束日期的占位符 endPlaceholder: { type: String, default: "请选择结束日期" }, //是否禁用选择今天之前的日期 disabledToday: { type: Boolean, default: !1 }, //可选的禁用日期的范围 checkDisabledDateRange: { type: String, default: "", validator: (h) => [ "", "lastOneWeek", //只能选择最近一周的数据 "lastOneMonth", //只能选择最近一个月的数据 "lastThreeMonth", //只能选择最近三个月的数据 "lastSixMonth", //只能选择最近半年的数据 "lastOneYear" //只能选择最近一年的数据 ].includes(h) }, //自定义禁用开始日期的范围 enterStartDisabledDateRange: { type: [String, Number], default: "" }, //自定义禁用结束日期的范围 enterEndDisabledDateRange: { type: [String, Number], default: "" } }, emits: ["startDateChange", "endDateChange"], setup(h, { emit: E }) { let f = h, M = E, m = U(null), w = U(null), S = U(!0), v = 1e3 * 60 * 60 * 24, _ = (u) => { if (f.disabledToday) return u.getTime() < Date.now() - v; if (!f.disabledToday && f.enterStartDisabledDateRange == "" && f.checkDisabledDateRange !== "") { let d = U(!1); switch (f.checkDisabledDateRange) { case "lastOneWeek": d.value = u.getTime() < Number(L(/* @__PURE__ */ new Date()).subtract(1, "week")) || u.getTime() > Date.now(); break; case "lastOneMonth": d.value = u.getTime() < Number(L(/* @__PURE__ */ new Date()).subtract(1, "month")) || u.getTime() > Date.now(); break; case "lastThreeMonth": d.value = u.getTime() < Number(L(/* @__PURE__ */ new Date()).subtract(3, "month")) || u.getTime() > Date.now(); break; case "lastOneYear": d.value = u.getTime() < Number(L(/* @__PURE__ */ new Date()).subtract(1, "year")) || u.getTime() > Date.now(); break; } return d.value; } if (!f.disabledToday && f.checkDisabledDateRange == "" && f.enterStartDisabledDateRange !== "") return u.getTime() < Number( L(/* @__PURE__ */ new Date()).subtract( Number(f.enterStartDisabledDateRange), "day" ) ) || u.getTime() > Date.now(); }, T = (u) => { if (m.value && f.disabledToday) return u.getTime() < m.value.getTime() + v; if (m.value && f.checkDisabledDateRange !== "") return u.getTime() < m.value.getTime() + v || u.getTime() > Date.now(); if (m.value && f.enterEndDisabledDateRange !== "") return u.getTime() < m.value.getTime() + v || u.getTime() > (/* @__PURE__ */ new Date()).getTime() + v * Number(f.enterEndDisabledDateRange); }; return q( () => m.value, (u) => { w.value = null, u ? (S.value = !1, M("startDateChange", u)) : S.value = !0; } ), q( () => w.value, (u) => { u || M("endDateChange", { startDate: m.value || "", endDate: u || "" }); } ), (u, d) => { const R = ie("el-date-picker"); return ue(), oe("div", fe, [ G("div", he, [ Q(R, K({ modelValue: W(m), "onUpdate:modelValue": d[0] || (d[0] = (p) => X(m) ? m.value = p : m = p), type: "date", placeholder: h.startPlaceholder, disabledDate: W(_) }, u.$attrs.startDateOptions, { class: "class_svg" }), null, 16, ["modelValue", "placeholder", "disabledDate"]) ]), G("div", null, [ Q(R, K({ modelValue: W(w), "onUpdate:modelValue": d[1] || (d[1] = (p) => X(w) ? w.value = p : w = p), type: "date", placeholder: h.endPlaceholder, disabled: W(S), disabledDate: W(T) }, u.$attrs.endDateOptions, { class: "class_svg" }), null, 16, ["modelValue", "placeholder", "disabled", "disabledDate"]) ]) ]); }; } }), ge = (h, E) => { const f = h.__vccOpts || h; for (const [M, m] of E) f[M] = m; return f; }, me = /* @__PURE__ */ ge(De, [["__scopeId", "data-v-8380fffa"]]), pe = { install(h) { h.component("tkChooseDate", me); } }; export { pe as default };