“姨妈来了”逻辑修改

一、需求
之前:“姨妈来了”按钮打开后,修改第一天姨妈的日期以及天数,然后删除与其相关的姨妈信息,重新加入其他天的姨妈日期,这样就出现一个问题,之前保存的流量和痛感被重置了
修改后:保留之前的姨妈信息,修改第一天姨妈日期以及天数,在其他姨妈的表添加新增的日期
二、实现步骤
1.首先算出点击的日期与第一天日期相差多少天

differ = indexCalendar.differ(selectCalendar)

2.修改持续天数和第一天日期,记得当数据库有修改就得重新刷新获取数据库内容的数组

val newKeep = differ + replaceObjectList[index].menKeep!!
val findDate = replaceObjectList[index].menFirstDate
firstMenDao.modifyFirstKeepDay(newKeep,findDate)
firstMenDao.modifyMenFirstDateByDate(selectDay,findDate)
resetReplaceObjectList()
private fun resetReplaceObjectList() {
    replaceObjectList.clear()
    replaceObjectList = firstMenDao.getAllMenFirst() as MutableList<FirstMenses>
}

3.向普通姨妈表加入新增的日期,然后刷新获取普通姨妈表数据的数组

 //向普通姨妈表计入新的数据
    var tempYear = iSelectYear
    var tempMonth = iSelectMonth
    var tempDay = iSelectDay
    for(i in 1 .. differ){
        tempDay = iSelectDay + i
        val nearMonthDays: Int =
            CustomDateFormat.getDays(tempYear, tempMonth - 1);
        if(tempDay > nearMonthDays){
            tempDay -= nearMonthDays
            tempMonth = iSelectMonth + 1
            if(tempMonth == 13){
                tempMonth = 1
                tempYear += 1
            }
        }
        val tempDate = "$tempYear-$tempMonth-$tempDay"
        Timber.d("修改第一天后需要加入的日期:$tempDate")
        menDao.insert(
            Menses(null,replaceObjectList[index].menFirstId,
                tempDate,0,0))
    }
}
resetOtherObjectList()
private fun resetOtherObjectList(){
    otherObjectList.clear()
    otherObjectList = menDao.getAllMenses() as MutableList<Menses>
}
### 创建女性生理期追踪的日历功能 为了在 UniApp 中创建或集成女性生理期追踪的日历功能,可以基于 `uni-calendar` 组件并扩展其功能来满足特定需求。下面是一个简单的实现方案。 #### 导入必要的模块和组件 首先,在项目中引入所需的日历工具: ```javascript // 在页面的 script 部分导入 util 工具函数 import uniCalendarUtil from '@/uni_modules/uni-calendar/components/uni-calendar/util.js'; ``` 接着定义数据模型用于存储周期记录: ```javascript export default { data() { return { menstrualRecords: [], // 生理期日期数组 [{date: '2023-10-01', note: ''}] selectedDate: '', // 当前选中的日期字符串形式 YYYY-MM-DD } }, } ``` #### 构建界面布局 HTML 结构部分展示一个可交互的日历视图以及输入框让用户标记特殊日子的信息: ```html <template> <view class="container"> <!-- 日历插件 --> <uni-calendar ref="calendar" :selected="menstrualDates" @confirm="onConfirm"></uni-calendar> <!-- 添加新纪录按钮 --> <button type="primary" @click="addNewRecord">添加新的月经开始时间</button> <!-- 显示已有的记录列表 --> <ul v-if="menstrualRecords.length > 0"> <li v-for="(item, index) in menstrualRecords" :key="index">{{ item.date }} - {{ item.note }}</li> </ul> </view> </template> ``` 这里通过属性绑定的方式将已有记录映射到日历上显示出来,并监听确认事件更新状态[^1]。 #### 实现逻辑处理方法 编写 JavaScript 方法完成具体业务操作,比如保存新增加的数据项至本地缓存或是服务器端数据库;当用户点击某一天时触发相应的回调函数进行后续动作。 ```javascript methods: { onConfirm(event){ const { date } = event.detail; this.selectedDate = date; // 打开弹窗或其他方式提示填写备注信息... }, addNewRecord(){ if (!this.selectedDate) return alert('请选择有效日期'); let newEntry = { date: this.selectedDate, note: prompt(`请输入${this.selectedDate}这天的情况`) }; this.menstrualRecords.push(newEntry); // 更新日历高亮显示 this.$refs.calendar.updateSelected(this.menstrualRecords.map(item => item.date)); } } ``` 以上就是利用 `uni-calendar` 插件快速搭建起一套简易版经期跟踪系统的全部过程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值