199 lines
7.9 KiB
JavaScript
199 lines
7.9 KiB
JavaScript
|
|
"use strict";
|
||
|
|
const common_vendor = require("../../../../common/vendor.js");
|
||
|
|
require("../../../adapter-vue.js");
|
||
|
|
const TUIKit_utils_env = require("../../../utils/env.js");
|
||
|
|
if (!Math) {
|
||
|
|
DatePickerPanel();
|
||
|
|
}
|
||
|
|
const DatePickerPanel = () => "./date-picker-panel.js";
|
||
|
|
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||
|
|
__name: "index",
|
||
|
|
props: {
|
||
|
|
type: {
|
||
|
|
type: String,
|
||
|
|
default: "range"
|
||
|
|
// "single" / "range"
|
||
|
|
},
|
||
|
|
rangeTableType: {
|
||
|
|
type: String,
|
||
|
|
default: "one"
|
||
|
|
// "one"/ "two"
|
||
|
|
},
|
||
|
|
startPlaceholder: {
|
||
|
|
type: String,
|
||
|
|
default: () => common_vendor.Wt.t("开始时间")
|
||
|
|
},
|
||
|
|
endPlaceholder: {
|
||
|
|
type: String,
|
||
|
|
default: () => common_vendor.Wt.t("开始时间")
|
||
|
|
},
|
||
|
|
popupPosition: {
|
||
|
|
type: String,
|
||
|
|
default: "bottom"
|
||
|
|
// "top" / "bottom"
|
||
|
|
},
|
||
|
|
// Default single-select date
|
||
|
|
defaultSingleDate: {
|
||
|
|
type: common_vendor.dayjs_minExports.Dayjs,
|
||
|
|
default: null,
|
||
|
|
required: false
|
||
|
|
}
|
||
|
|
},
|
||
|
|
emits: ["pick", "change"],
|
||
|
|
setup(__props, { emit: __emit }) {
|
||
|
|
common_vendor.dayjs.extend(common_vendor.localeData);
|
||
|
|
common_vendor.dayjs.extend(common_vendor.isSameOrAfter);
|
||
|
|
common_vendor.dayjs.extend(common_vendor.isSameOrBefore);
|
||
|
|
common_vendor.dayjs.locale("zh-cn");
|
||
|
|
const emit = __emit;
|
||
|
|
const props = __props;
|
||
|
|
const isDatePanelShow = common_vendor.ref(false);
|
||
|
|
const dateValue = common_vendor.ref(props.type === "single" ? props == null ? void 0 : props.defaultSingleDate : null);
|
||
|
|
const startValue = common_vendor.ref(props.type === "single" ? props == null ? void 0 : props.defaultSingleDate : null);
|
||
|
|
const endValue = common_vendor.ref(props.type === "single" ? props == null ? void 0 : props.defaultSingleDate : null);
|
||
|
|
const startFormatDate = common_vendor.computed(() => {
|
||
|
|
var _a;
|
||
|
|
return (_a = startValue == null ? void 0 : startValue.value) == null ? void 0 : _a.format("YYYY/MM/DD");
|
||
|
|
});
|
||
|
|
const endFormatDate = common_vendor.computed(() => {
|
||
|
|
var _a;
|
||
|
|
return (_a = endValue == null ? void 0 : endValue.value) == null ? void 0 : _a.format("YYYY/MM/DD");
|
||
|
|
});
|
||
|
|
const startPlaceholderVal = props.startPlaceholder;
|
||
|
|
const endPlaceholderVal = props.endPlaceholder;
|
||
|
|
const leftCurrentPanelValue = common_vendor.ref();
|
||
|
|
const rightCurrentPanelValue = common_vendor.ref();
|
||
|
|
const setDatePanelDisplay = (show) => {
|
||
|
|
isDatePanelShow.value = show;
|
||
|
|
};
|
||
|
|
const n = (classNameList) => {
|
||
|
|
const resultClassList = [];
|
||
|
|
classNameList.forEach((className) => {
|
||
|
|
if (className) {
|
||
|
|
resultClassList.push("tui-date-picker-" + className);
|
||
|
|
!TUIKit_utils_env.isPC && resultClassList.push("tui-date-picker-h5-" + className);
|
||
|
|
} else {
|
||
|
|
resultClassList.push("tui-date-picker");
|
||
|
|
!TUIKit_utils_env.isPC && resultClassList.push("tui-date-picker-h5");
|
||
|
|
}
|
||
|
|
});
|
||
|
|
return resultClassList;
|
||
|
|
};
|
||
|
|
const handlePick = (cell) => {
|
||
|
|
var _a, _b, _c;
|
||
|
|
switch (props.type) {
|
||
|
|
case "single":
|
||
|
|
startValue.value = cell.date;
|
||
|
|
endValue.value = cell.date;
|
||
|
|
dateValue.value = cell.date;
|
||
|
|
emit("change", cell);
|
||
|
|
emit("pick", dateValue.value);
|
||
|
|
setTimeout(() => {
|
||
|
|
setDatePanelDisplay(false);
|
||
|
|
}, 300);
|
||
|
|
break;
|
||
|
|
case "range":
|
||
|
|
if (!(startValue == null ? void 0 : startValue.value)) {
|
||
|
|
startValue.value = cell.date;
|
||
|
|
} else if (!(endValue == null ? void 0 : endValue.value)) {
|
||
|
|
if ((_a = startValue == null ? void 0 : startValue.value) == null ? void 0 : _a.isSameOrBefore(cell.date, "day")) {
|
||
|
|
endValue.value = cell.date;
|
||
|
|
} else {
|
||
|
|
endValue.value = startValue.value;
|
||
|
|
startValue.value = cell.date;
|
||
|
|
}
|
||
|
|
emit("pick", {
|
||
|
|
startDate: (_b = startValue == null ? void 0 : startValue.value) == null ? void 0 : _b.startOf("date"),
|
||
|
|
endDate: (_c = endValue == null ? void 0 : endValue.value) == null ? void 0 : _c.endOf("date")
|
||
|
|
});
|
||
|
|
setTimeout(() => {
|
||
|
|
setDatePanelDisplay(false);
|
||
|
|
}, 200);
|
||
|
|
} else {
|
||
|
|
startValue.value = cell.date;
|
||
|
|
endValue.value = null;
|
||
|
|
}
|
||
|
|
emit("change", {
|
||
|
|
startDate: startValue.value,
|
||
|
|
endDate: endValue.value,
|
||
|
|
leftCurrentPanel: leftCurrentPanelValue.value,
|
||
|
|
rightCurrentPanel: leftCurrentPanelValue.value
|
||
|
|
});
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
const handleLeftPanelChange = (value) => {
|
||
|
|
leftCurrentPanelValue.value = value;
|
||
|
|
emit("change", {
|
||
|
|
startDate: startValue.value,
|
||
|
|
endDate: endValue.value,
|
||
|
|
leftCurrentPanel: leftCurrentPanelValue.value,
|
||
|
|
rightCurrentPanel: leftCurrentPanelValue.value
|
||
|
|
});
|
||
|
|
};
|
||
|
|
const handleRightPanelChange = (value) => {
|
||
|
|
rightCurrentPanelValue.value = value;
|
||
|
|
emit("change", {
|
||
|
|
startDate: startValue.value,
|
||
|
|
endDate: endValue.value,
|
||
|
|
leftCurrentPanel: leftCurrentPanelValue.value,
|
||
|
|
rightCurrentPanel: leftCurrentPanelValue.value
|
||
|
|
});
|
||
|
|
};
|
||
|
|
return (_ctx, _cache) => {
|
||
|
|
return common_vendor.e({
|
||
|
|
a: common_vendor.unref(startPlaceholderVal),
|
||
|
|
b: common_vendor.n(n(["input-start"])),
|
||
|
|
c: common_vendor.unref(TUIKit_utils_env.isUniFrameWork),
|
||
|
|
d: common_vendor.unref(startFormatDate),
|
||
|
|
e: common_vendor.o$1(($event) => common_vendor.isRef(startFormatDate) ? startFormatDate.value = $event.detail.value : null),
|
||
|
|
f: __props.type !== "single"
|
||
|
|
}, __props.type !== "single" ? {} : {}, {
|
||
|
|
g: __props.type !== "single"
|
||
|
|
}, __props.type !== "single" ? {
|
||
|
|
h: common_vendor.unref(endPlaceholderVal),
|
||
|
|
i: common_vendor.n(n(["input-end"])),
|
||
|
|
j: common_vendor.unref(TUIKit_utils_env.isUniFrameWork),
|
||
|
|
k: common_vendor.unref(endFormatDate),
|
||
|
|
l: common_vendor.o$1(($event) => common_vendor.isRef(endFormatDate) ? endFormatDate.value = $event.detail.value : null)
|
||
|
|
} : {}, {
|
||
|
|
m: common_vendor.n(n(["input"])),
|
||
|
|
n: common_vendor.n(common_vendor.unref(isDatePanelShow) && n(["input-active"])),
|
||
|
|
o: common_vendor.o$1(($event) => setDatePanelDisplay(!common_vendor.unref(isDatePanelShow))),
|
||
|
|
p: common_vendor.unref(isDatePanelShow)
|
||
|
|
}, common_vendor.unref(isDatePanelShow) ? common_vendor.e({
|
||
|
|
q: common_vendor.o$1(handlePick),
|
||
|
|
r: common_vendor.o$1(handleLeftPanelChange),
|
||
|
|
s: common_vendor.p({
|
||
|
|
type: props.type,
|
||
|
|
rangeType: "left",
|
||
|
|
date: common_vendor.unref(dateValue),
|
||
|
|
startDate: common_vendor.unref(startValue),
|
||
|
|
endDate: common_vendor.unref(endValue),
|
||
|
|
currentOtherPanelValue: common_vendor.unref(rightCurrentPanelValue)
|
||
|
|
}),
|
||
|
|
t: props.type === "range" && common_vendor.unref(TUIKit_utils_env.isPC) && __props.rangeTableType === "two"
|
||
|
|
}, props.type === "range" && common_vendor.unref(TUIKit_utils_env.isPC) && __props.rangeTableType === "two" ? {
|
||
|
|
v: common_vendor.o$1(handlePick),
|
||
|
|
w: common_vendor.o$1(handleRightPanelChange),
|
||
|
|
x: common_vendor.p({
|
||
|
|
type: props.type,
|
||
|
|
rangeType: "right",
|
||
|
|
date: common_vendor.unref(dateValue),
|
||
|
|
startDate: common_vendor.unref(startValue),
|
||
|
|
endDate: common_vendor.unref(endValue),
|
||
|
|
currentOtherPanelValue: common_vendor.unref(leftCurrentPanelValue)
|
||
|
|
})
|
||
|
|
} : {}, {
|
||
|
|
y: common_vendor.n(n(["dialog-container", "dialog-container-" + __props.rangeTableType, "dialog-container-" + __props.popupPosition])),
|
||
|
|
z: common_vendor.n(n(["dialog"]))
|
||
|
|
}) : {}, {
|
||
|
|
A: common_vendor.n(n([""]))
|
||
|
|
});
|
||
|
|
};
|
||
|
|
}
|
||
|
|
});
|
||
|
|
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-eb57fa2c"]]);
|
||
|
|
wx.createComponent(Component);
|
||
|
|
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/common/DatePicker/index.js.map
|