|
|
2 周之前 | |
|---|---|---|
| src | 2 周之前 | |
| .eslintrc-auto-import.json | 1 月之前 | |
| .gitignore | 1 月之前 | |
| README.md | 1 月之前 | |
| index.html | 3 周之前 | |
| package.json | 3 周之前 | |
| shims-uni.d.ts | 1 月之前 | |
| tailwind.config.js | 3 周之前 | |
| tsconfig.json | 1 月之前 | |
| vite.config.js | 3 周之前 |
这是一个基于 uni-app 的学习应用项目,使用 Vite 作为构建工具。
修改时间: 2024年 修改内容: 为 uni-calendar 组件新增了多项实用功能,提升组件的灵活性和可定制性
sundayFirst (Boolean, 默认: false)用法:
<uni-calendar :sunday-first="true" /> <!-- 周日在前 -->
<uni-calendar :sunday-first="false" /> <!-- 周日在后 -->
displayMode (String, 默认: 'month')preWeek(): 切换到上一周nextWeek(): 切换到下一周setWeekNumber(weekNumber): 设置指定周数change-week: 周数变化时触发上一周 下一周 第3周 ```
highlightToday (Boolean, 默认: true)用法:
<uni-calendar :highlight-today="false" /> <!-- 不高亮今天 -->
showToolbar (Boolean, 默认: true)vue
<uni-calendar :show-toolbar="false" /> <!-- 隐藏工具栏 -->
calendar-item用法:
<!-- 自定义整个日期项 -->
<uni-calendar>
<template #calendar-item="{ weeks, calendar, selected, lunar, highlightToday, weekIndex, weeksIndex }">
<view class="enhanced-calendar-item" :class="{ 'not-current-month': !weeks.isCurrentMonth }">
<text class="date-number">{{ weeks.date }}</text>
<view class="date-indicators">
<view v-if="weeks.extraInfo" class="indicator-dot"></view>
<view v-if="weeks.isDay" class="today-badge">今</view>
<view v-if="!weeks.isCurrentMonth" class="month-badge">非本月</view>
</view>
</view>
</template>
</uni-calendar>
每个日期项(weeks)包含以下属性:
fullDate: 完整日期字符串 (如: "2024-01-15")year: 年份month: 月份date: 日期数字isDay: 是否为今天disable: 是否禁用isCurrentMonth: 是否为当前月份 (true: 本月, false: 上月/下月)isWeekModeDisabled: 按周模式下的置灰标识beforeMultiple: 多选开始标识afterMultiple: 多选结束标识multiple: 多选中间标识lunar: 农历信息extraInfo: 额外信息(打点数据)src/uni_modules/uni-calendar/components/uni-calendar/uni-calendar.vuefilteredWeeks 处理按周显示优化星期标题显示逻辑
src/uni_modules/uni-calendar/components/uni-calendar/util.js
新增 sundayFirst 参数支持
修改 _getWeek 方法支持周日位置控制
优化日期计算逻辑
src/uni_modules/uni-calendar/components/uni-calendar/uni-calendar-item.vue
新增 highlightToday 参数支持
添加插槽支持自定义日期样式
优化今天高亮显示逻辑
<uni-calendar
:sunday-first="false" <!-- 周日位置控制 -->
display-mode="month" <!-- 显示模式 -->
:week-number="1" <!-- 按周显示时的周数 -->
:highlight-today="true" <!-- 是否高亮今天 -->
:show-toolbar="true" <!-- 是否显示工具栏 -->
:insert="true" <!-- 插入模式 -->
:lunar="false" <!-- 显示农历 -->
:range="false" <!-- 范围选择 -->
:selected="[]" <!-- 打点信息 -->
:start-date="" <!-- 开始日期 -->
:end-date="" <!-- 结束日期 -->
:show-month="true" <!-- 显示月份背景 -->
:clear-date="true" <!-- 清空日期 -->
:readonly="false" <!-- 只读模式 -->
>
<template #calendar-item="{ weeks, calendar, selected, lunar, highlightToday, weekIndex, weeksIndex }">
<!-- 自定义整个日期项 -->
</template>
</uni-calendar>
Calendar 工具类提供两个实用的日期范围获取方法:
import Calendar from './util.js'
const calendar = new Calendar()
const monthRange = calendar.getCurrentMonthRange('2024-10-15')
// 返回: {startDate: '2024-10-01', endDate: '2024-10-31', totalDays: 31, totalWeeks: 5}
// 获取当前日期所在的周
const currentWeek = calendar.getCurrentWeekRange('2024-10-15')
// 返回: {startDate: '2024-10-13', endDate: '2024-10-19', totalDays: 7, currentWeek: 3, totalWeeks: 5}
// 获取指定周数
const week2 = calendar.getCurrentWeekRange('2024-10-15', 2)
// 返回: {startDate: '2024-10-06', endDate: '2024-10-12', totalDays: 7, currentWeek: 2, totalWeeks: 5}
参数说明:
date: 日期字符串,可选,默认为当前日期weekNumber: 周数,从1开始,可选,不传时自动计算指定日期所在的周返回值说明:
startDate: 开始日期endDate: 结束日期totalDays: 总天数totalWeeks: 总周数(实际包含本月日期的周数)currentWeek: 当前周数(仅周范围方法)src/
├── uni_modules/ # uni-app 模块
│ └── uni-calendar/ # 日历组件
├── pagesStudy/ # 学习相关页面
├── components/ # 公共组件
└── ...