comic-plus
Version:
<p align="center"> <img width="200px" src="./logo.png"/> </p>
138 lines (137 loc) • 5.49 kB
JavaScript
import { defineComponent, inject, ref, watch, openBlock, createElementBlock, Fragment, unref, createElementVNode, createVNode, withCtx, createTextVNode } from "vue";
import list from "./list.mjs";
import { CuButton } from "../../button/index.mjs";
import { TIMEPICKER_PROVIDE } from "./type.mjs";
const _hoisted_1 = { key: 0 };
const _hoisted_2 = { class: "rangetime-box" };
const _hoisted_3 = { class: "cu-time-picker__listbox" };
const _hoisted_4 = { class: "rangetime-box" };
const _hoisted_5 = { class: "cu-time-picker__listbox" };
const _hoisted_6 = {
key: 1,
class: "cu-time-picker__listbox"
};
const _hoisted_7 = { class: "cu-time-picker__footer" };
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "time-select",
setup(__props) {
const { props, show, confirm } = inject(TIMEPICKER_PROVIDE);
const currentTimes = ref([]);
const getValue = (value) => value ?? "00:00:00";
const setTimeValue = () => {
if (props.range) {
currentTimes.value = [getValue(props.modelValue[0]).split(":"), getValue(props.modelValue[1]).split(":")];
} else {
currentTimes.value = getValue(props.modelValue).split(":");
}
};
setTimeValue();
const sort = () => {
currentTimes.value = currentTimes.value.sort((a, b) => {
for (let i = 0; i < a.length; i++) {
let numA = parseInt(a[i], 10);
let numB = parseInt(b[i], 10);
if (numA !== numB) {
return numA - numB;
}
}
return 0;
});
};
function _confirm() {
if (props.range) {
sort();
let arr = [currentTimes.value[0].join(":"), currentTimes.value[1].join(":")];
confirm(arr);
} else {
confirm(currentTimes.value.join(":"));
}
}
watch(
() => show.value,
(val) => {
if (val) {
setTimeValue();
}
}
);
return (_ctx, _cache) => {
return openBlock(), createElementBlock(Fragment, null, [
unref(props).range ? (openBlock(), createElementBlock("div", _hoisted_1, [
createElementVNode("div", _hoisted_2, [
_cache[9] || (_cache[9] = createElementVNode("div", { class: "time-title" }, "开始时间", -1)),
createElementVNode("div", _hoisted_3, [
createVNode(unref(list), {
modelValue: currentTimes.value[0][0],
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => currentTimes.value[0][0] = $event),
time: 24
}, null, 8, ["modelValue"]),
createVNode(unref(list), {
modelValue: currentTimes.value[0][1],
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => currentTimes.value[0][1] = $event),
time: 60
}, null, 8, ["modelValue"]),
createVNode(unref(list), {
modelValue: currentTimes.value[0][2],
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => currentTimes.value[0][2] = $event),
time: 60
}, null, 8, ["modelValue"])
])
]),
createElementVNode("div", _hoisted_4, [
_cache[10] || (_cache[10] = createElementVNode("div", { class: "time-title" }, "结束时间", -1)),
createElementVNode("div", _hoisted_5, [
createVNode(unref(list), {
modelValue: currentTimes.value[1][0],
"onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => currentTimes.value[1][0] = $event),
time: 24
}, null, 8, ["modelValue"]),
createVNode(unref(list), {
modelValue: currentTimes.value[1][1],
"onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => currentTimes.value[1][1] = $event),
time: 60
}, null, 8, ["modelValue"]),
createVNode(unref(list), {
modelValue: currentTimes.value[1][2],
"onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => currentTimes.value[1][2] = $event),
time: 60
}, null, 8, ["modelValue"])
])
])
])) : (openBlock(), createElementBlock("div", _hoisted_6, [
createVNode(unref(list), {
modelValue: currentTimes.value[0],
"onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => currentTimes.value[0] = $event),
time: 24
}, null, 8, ["modelValue"]),
createVNode(unref(list), {
modelValue: currentTimes.value[1],
"onUpdate:modelValue": _cache[7] || (_cache[7] = ($event) => currentTimes.value[1] = $event),
time: 60
}, null, 8, ["modelValue"]),
createVNode(unref(list), {
modelValue: currentTimes.value[2],
"onUpdate:modelValue": _cache[8] || (_cache[8] = ($event) => currentTimes.value[2] = $event),
time: 60
}, null, 8, ["modelValue"])
])),
createElementVNode("div", _hoisted_7, [
createVNode(unref(CuButton), {
size: "small",
type: "primary",
text: "",
onClick: _confirm
}, {
default: withCtx(() => _cache[11] || (_cache[11] = [
createTextVNode("确认")
])),
_: 1
})
])
], 64);
};
}
});
export {
_sfc_main as default
};