comic-plus
Version:
<p align="center"> <img width="200px" src="./logo.png"/> </p>
148 lines (147 loc) • 5.34 kB
JavaScript
import { defineComponent, inject, computed, openBlock, createElementBlock, createElementVNode, Fragment, renderList, normalizeStyle, unref, toDisplayString, createCommentVNode, createBlock, createSlots, withCtx, renderSlot, createTextVNode, createVNode, Transition, withDirectives, vShow } from "vue";
import { SCHEDULE_PROVIDE } from "./type.mjs";
import _sfc_main$1 from "./card.vue.mjs";
import "../../../utils/config.mjs";
import { randomColor } from "../../../utils/tools.mjs";
import "@vueuse/core";
import "../../../icons/index.mjs";
import { Loading } from "../../../icons/components/components.mjs";
const _hoisted_1 = { class: "cu-schedule-content" };
const _hoisted_2 = { class: "cu-schedule-list--warpper" };
const _hoisted_3 = { class: "cu-schedule-list" };
const _hoisted_4 = {
key: 0,
class: "cu-schedule-list__time"
};
const _hoisted_5 = {
key: 1,
class: "cu-schedule-list__line"
};
const _hoisted_6 = {
key: 0,
class: "cu-schedule-empty"
};
const _hoisted_7 = { class: "loading-mask" };
const flag = 100 / 60;
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "content",
setup(__props) {
const { date, props, spacing } = inject(SCHEDULE_PROVIDE);
const timeList = computed(() => {
let result = [];
let i = props.start;
do {
if (i > 23) {
i -= 24;
}
result.push({
key: i,
timeTemp: date.value.setHours(i, 0, 0, 0)
});
i++;
if (i === 24) {
i = 0;
}
} while (!(i === props.end + 1));
return result;
});
function getNumber(t) {
let t1 = Math.floor(t);
let t2 = t % 1 * flag;
return t1 + t2;
}
const cardForArr = computed(() => {
let arr = props.schedules.map((v, index) => {
return {
...v,
_index: index,
color: props.cardColor ? v.color ?? randomColor() : void 0,
getTimes: v.time.split(props.separator).map((v2) => {
return getNumber(Number(v2.replace(/:/g, ".")));
})
};
}).sort((a, b) => a.getTimes[0] - b.getTimes[0]);
let chunkArr = [];
if (arr.length > 0) {
chunkArr = [
{
startTime: arr[0].getTimes[0],
endTime: arr[0].getTimes[1],
children: [arr[0]]
}
];
for (let i = 1; i < arr.length; i++) {
let item = arr[i];
let last = chunkArr[chunkArr.length - 1];
if (item.getTimes[0] < last.endTime) {
last.children.push(item);
last.endTime = Math.max(last.endTime, item.getTimes[1]);
} else {
chunkArr.push({
startTime: item.getTimes[0],
endTime: item.getTimes[1],
children: [item]
});
}
}
}
return chunkArr;
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", _hoisted_1, [
createElementVNode("div", _hoisted_2, [
createElementVNode("ul", _hoisted_3, [
(openBlock(true), createElementBlock(Fragment, null, renderList(timeList.value, (el) => {
return openBlock(), createElementBlock("li", {
class: "cu-schedule-list__li",
style: normalizeStyle({ height: unref(spacing) + "px" })
}, [
unref(props).showTime ? (openBlock(), createElementBlock("span", _hoisted_4, [
createElementVNode("span", null, toDisplayString((el.key < 10 ? "0" + el.key : el.key) + ":00"), 1)
])) : createCommentVNode("", true),
unref(props).showLine ? (openBlock(), createElementBlock("span", _hoisted_5)) : createCommentVNode("", true)
], 4);
}), 256))
]),
createElementVNode("div", {
class: "cu-schedule-cards--warpper",
style: normalizeStyle({ paddingLeft: unref(props).showTime ? void 0 : "0" })
}, [
(openBlock(true), createElementBlock(Fragment, null, renderList(cardForArr.value, (item, idx) => {
return openBlock(), createBlock(_sfc_main$1, {
data: item,
key: idx
}, createSlots({ _: 2 }, [
_ctx.$slots["card"] ? {
name: "card",
fn: withCtx(({ data }) => [
renderSlot(_ctx.$slots, "card", { data })
]),
key: "0"
} : void 0
]), 1032, ["data"]);
}), 128))
], 4)
]),
unref(props).showEmpty && cardForArr.value.length === 0 ? (openBlock(), createElementBlock("div", _hoisted_6, [
renderSlot(_ctx.$slots, "empty", { date: unref(date) }, () => [
createTextVNode(toDisplayString(unref(props).emptyText), 1)
])
])) : createCommentVNode("", true),
createVNode(Transition, { name: "cu-fade" }, {
default: withCtx(() => [
withDirectives(createElementVNode("div", _hoisted_7, [
createVNode(unref(Loading), { class: "is-loading" })
], 512), [
[vShow, unref(props).loading]
])
]),
_: 1
})
]);
};
}
});
export {
_sfc_main as default
};