解决新建日程日期同步问题

This commit is contained in:
WindowBird 2025-11-03 10:52:56 +08:00
parent a43d25b9f5
commit f10dbc0ea5
3 changed files with 15 additions and 31 deletions

View File

@ -6,7 +6,7 @@
} }
}, },
"pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages "pages": [
{ {
"path": "pages/index/index", "path": "pages/index/index",
"style": { "style": {

View File

@ -238,7 +238,8 @@
</template> </template>
<script setup> <script setup>
import { ref, computed, onMounted } from 'vue'; import { ref, computed } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
// //
const formData = ref({ const formData = ref({
@ -394,15 +395,9 @@ const repeatText = computed(() => {
}); });
// //
const initDates = () => { const initDates = (dateStr = '') => {
const pages = getCurrentPages(); // 使
const currentPage = pages[pages.length - 1]; if (!dateStr) {
const options = currentPage.options || currentPage.$route?.query || {};
let dateStr = '';
if (options.date) {
dateStr = options.date;
} else {
const today = new Date(); const today = new Date();
dateStr = today.toISOString().slice(0, 10); dateStr = today.toISOString().slice(0, 10);
} }
@ -560,28 +555,17 @@ const handleSave = () => {
reminder: formData.value.reminder reminder: formData.value.reminder
}; };
// getCurrentPages // 使 onShow
const pages = getCurrentPages(); uni.setStorageSync('newEventData', eventData);
if (pages.length > 1) {
const prevPage = pages[pages.length - 2];
// addEvent
if (prevPage && typeof prevPage.addEvent === 'function') {
prevPage.addEvent(eventData);
} else {
// 使 onShow
uni.setStorageSync('newEventData', eventData);
}
} else {
// 使
uni.setStorageSync('newEventData', eventData);
}
// //
uni.navigateBack(); uni.navigateBack();
}; };
onMounted(() => { //
initDates(); onLoad((options) => {
const dateStr = options?.date || '';
initDates(dateStr);
}); });
</script> </script>

View File

@ -7,7 +7,7 @@
<uv-calendar ref="calendar" mode="single" @confirm="handleConfirm" ></uv-calendar> <uv-calendar ref="calendar" mode="single" @confirm="handleConfirm" ></uv-calendar>
<button @click="openCalendar">选择日期</button> <button @click="openCalendar">选择日期</button>
<view style=" font-size: 12px; color: #666;"> <view style=" font-size: 12px; color: #666;">
当前选择日期{{ selectedDate }}事件{{ eventsInDay ? eventsInDay.length : 0 }} 当前选择日期{{ selectedDate }}日程{{ eventsInDay ? eventsInDay.length : 0 }}
</view> </view>
</view> </view>
<!-- 滑动容器 --> <!-- 滑动容器 -->
@ -313,7 +313,7 @@ const resetToCenter = () => {
setTimeout(() => { setTimeout(() => {
isAnimating.value = false; isAnimating.value = false;
}, 300); // transition 0.3s }, 0); // transition 0.3s
}; };
// //
@ -341,7 +341,7 @@ const slideToPreviousDay = () => {
console.log(`日期切换:上一天,新日期:${selectedDate.value}`); console.log(`日期切换:上一天,新日期:${selectedDate.value}`);
}, 0); // transition }, 0); // transition
}, 300); // transition 0.3s }, 0); // transition 0.3s
}; };
// //