diff --git a/src/components/pageHome/ph-comp-calendar.vue b/src/components/pageHome/ph-comp-calendar.vue
index e5a2c246..b4781cdd 100644
--- a/src/components/pageHome/ph-comp-calendar.vue
+++ b/src/components/pageHome/ph-comp-calendar.vue
@@ -19,11 +19,17 @@
{{ text.text }}
-
+
-
+
-
+
import TItemBox, { type TItemBoxData } from "@comp/app/t-itemBox.vue";
import { timestampToDate } from "@utils/toolFunc.js";
-import { computed, onMounted, ref, shallowRef } from "vue";
+import { computed, onMounted, onUnmounted, ref, shallowRef, watch } from "vue";
import TCalendarBirth from "./ph-calendar-birth.vue";
import ToCalendar from "./ph-calendar-overlay.vue";
@@ -59,24 +65,38 @@ const btnText: Array = [
{ week: 6, text: "周六" },
];
const emits = defineEmits();
-const visible = 16;
+const ITEM_SIZE = 100;
+const GAP_SIZE = 8;
+const contentRef = ref(null);
const weekNow = ref(0);
const btnNow = ref(0);
const dateNow = ref("");
const page = ref(1);
const showItem = ref(false);
const selectedType = ref<"character" | "weapon">("character");
+const gridCols = ref(8);
+let resizeObserver: ResizeObserver | null = null;
+
const calendarTotal = computed>(() =>
AppCalendarData.filter(
(i) => i.dropDays.includes(btnNow.value) && i.itemType === selectedType.value,
),
);
-const length = computed(() => Math.ceil(calendarTotal.value.length / visible));
-const renderItems = computed>(() =>
- calendarTotal.value.slice((page.value - 1) * visible, page.value * visible),
-);
+const visible = computed(() => gridCols.value * 2);
+const length = computed(() => Math.ceil(calendarTotal.value.length / visible.value) || 1);
+const renderItems = computed>(() => {
+ const currentPage = Math.min(page.value, length.value);
+ return calendarTotal.value.slice((currentPage - 1) * visible.value, currentPage * visible.value);
+});
const selectedItem = shallowRef(renderItems.value[0]);
+const gridStyle = computed>(() => ({
+ gridTemplateColumns: `repeat(${gridCols.value}, ${ITEM_SIZE}px)`,
+}));
+
+watch(visible, () => {
+ page.value = 1;
+});
onMounted(() => {
const dayNow = new Date().getDay() === 0 ? 7 : new Date().getDay();
@@ -85,6 +105,25 @@ onMounted(() => {
weekNow.value = dayNow;
btnNow.value = dayNow;
emits("success");
+
+ if (contentRef.value) {
+ resizeObserver = new ResizeObserver((entries) => {
+ for (const entry of entries) {
+ const width = entry.contentRect.width;
+ const gridWidth = (width * 2) / 3;
+ const cols = Math.floor((gridWidth + GAP_SIZE) / (ITEM_SIZE + GAP_SIZE));
+ gridCols.value = Math.max(2, cols);
+ }
+ });
+ resizeObserver.observe(contentRef.value);
+ }
+});
+
+onUnmounted(() => {
+ if (resizeObserver) {
+ resizeObserver.disconnect();
+ resizeObserver = null;
+ }
});
function switchDay(day: number): void {
@@ -176,8 +215,8 @@ function getBoxData(item: TGApp.App.Calendar.Item): TItemBoxData {
.calendar-grid {
display: grid;
height: 100%;
+ flex: 1;
gap: 8px;
- grid-template-columns: repeat(8, 100px);
place-items: flex-start flex-start;
}