解决新建日程日期同步问题
This commit is contained in:
parent
a43d25b9f5
commit
f10dbc0ea5
|
|
@ -6,7 +6,7 @@
|
|||
}
|
||||
},
|
||||
|
||||
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/index/index",
|
||||
"style": {
|
||||
|
|
|
|||
|
|
@ -238,7 +238,8 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue';
|
||||
import { ref, computed } from 'vue';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
|
||||
// 表单数据
|
||||
const formData = ref({
|
||||
|
|
@ -394,15 +395,9 @@ const repeatText = computed(() => {
|
|||
});
|
||||
|
||||
// 初始化日期
|
||||
const initDates = () => {
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
const options = currentPage.options || currentPage.$route?.query || {};
|
||||
|
||||
let dateStr = '';
|
||||
if (options.date) {
|
||||
dateStr = options.date;
|
||||
} else {
|
||||
const initDates = (dateStr = '') => {
|
||||
// 如果没有传入日期参数,使用今天
|
||||
if (!dateStr) {
|
||||
const today = new Date();
|
||||
dateStr = today.toISOString().slice(0, 10);
|
||||
}
|
||||
|
|
@ -560,28 +555,17 @@ const handleSave = () => {
|
|||
reminder: formData.value.reminder
|
||||
};
|
||||
|
||||
// 通过 getCurrentPages 获取上一页实例并调用方法
|
||||
const pages = getCurrentPages();
|
||||
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);
|
||||
}
|
||||
// 使用全局存储传递数据,在首页的 onShow 中读取
|
||||
uni.setStorageSync('newEventData', eventData);
|
||||
|
||||
// 返回上一页
|
||||
uni.navigateBack();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
initDates();
|
||||
// 页面加载时接收参数
|
||||
onLoad((options) => {
|
||||
const dateStr = options?.date || '';
|
||||
initDates(dateStr);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<uv-calendar ref="calendar" mode="single" @confirm="handleConfirm" ></uv-calendar>
|
||||
<button @click="openCalendar">选择日期</button>
|
||||
<view style=" font-size: 12px; color: #666;">
|
||||
当前选择日期:{{ selectedDate }},事件数:{{ eventsInDay ? eventsInDay.length : 0 }}
|
||||
当前选择日期:{{ selectedDate }},日程数:{{ eventsInDay ? eventsInDay.length : 0 }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 滑动容器 -->
|
||||
|
|
@ -313,7 +313,7 @@ const resetToCenter = () => {
|
|||
|
||||
setTimeout(() => {
|
||||
isAnimating.value = false;
|
||||
}, 300); // 与 transition 时间一致(0.3s)
|
||||
}, 0); // 与 transition 时间一致(0.3s)
|
||||
};
|
||||
|
||||
// 滑动到前一天的位置(动画完成后更新日期)
|
||||
|
|
@ -341,7 +341,7 @@ const slideToPreviousDay = () => {
|
|||
|
||||
console.log(`日期切换:上一天,新日期:${selectedDate.value}`);
|
||||
}, 0); // 一帧的时间,确保 transition 已禁用
|
||||
}, 300); // 与 transition 时间一致(0.3s)
|
||||
}, 0); // 与 transition 时间一致(0.3s)
|
||||
};
|
||||
|
||||
// 滑动到后一天的位置(动画完成后更新日期)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user