From 7c270da26650af8488ea4bb652c9f91e4b978734 Mon Sep 17 00:00:00 2001
From: likecodeboys <1239288387@qq.com>
Date: Mon, 30 Jun 2025 19:14:28 +0800
Subject: [PATCH 01/13] =?UTF-8?q?feat:=20=E9=9B=8F=E5=BD=A2=E5=AE=8C?=
=?UTF-8?q?=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
example/app.mpx | 3 +-
example/common/config.ts | 3 +-
example/pages/calendar-modal/README.md | 27 ++
example/pages/calendar-modal/index.mpx | 43 +++
.../calendar-modal/calendar-modal.ts | 323 ++++++++++++++++++
.../src/components/calendar-modal/index.mpx | 173 ++++++++++
.../src/components/calendar-modal/utils.ts | 97 ++++++
7 files changed, 667 insertions(+), 2 deletions(-)
create mode 100644 example/pages/calendar-modal/README.md
create mode 100644 example/pages/calendar-modal/index.mpx
create mode 100644 packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
create mode 100644 packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
create mode 100644 packages/mpx-cube-ui/src/components/calendar-modal/utils.ts
diff --git a/example/app.mpx b/example/app.mpx
index 407c8ab5..02091768 100644
--- a/example/app.mpx
+++ b/example/app.mpx
@@ -47,7 +47,8 @@
"./pages/float-ball/index",
"./pages/rate/index",
"./pages/switch/index",
- "./pages/loading/index"
+ "./pages/loading/index",
+ "./pages/calendar-modal/index"
]
}
diff --git a/example/common/config.ts b/example/common/config.ts
index 46ce2e1c..85405d7b 100644
--- a/example/common/config.ts
+++ b/example/common/config.ts
@@ -84,7 +84,8 @@ export default {
'picker-popup',
'cascade-picker-popup',
'date-picker-popup',
- 'time-picker-popup'
+ 'time-picker-popup',
+ 'calendar-modal'
]
}
],
diff --git a/example/pages/calendar-modal/README.md b/example/pages/calendar-modal/README.md
new file mode 100644
index 00000000..2d08f024
--- /dev/null
+++ b/example/pages/calendar-modal/README.md
@@ -0,0 +1,27 @@
+## cube-calendar
+
+
+
+### 介绍
+
+加载,提供了可自定义大小的加载动画。
+
+
+
+### 示例
+
+
+
+### 基础用法
+
+默认大小为`24px`,可通过`size`属性配置
+
+
+
+
+```vue
+
+```
+
+
+
diff --git a/example/pages/calendar-modal/index.mpx b/example/pages/calendar-modal/index.mpx
new file mode 100644
index 00000000..dac6c5b7
--- /dev/null
+++ b/example/pages/calendar-modal/index.mpx
@@ -0,0 +1,43 @@
+
+
+
+ 日历组件
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
new file mode 100644
index 00000000..09e858c9
--- /dev/null
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
@@ -0,0 +1,323 @@
+import { createComponent, set } from '@mpxjs/core'
+import {
+ getWeekInMonth,
+ getWeeksCountInMonth,
+ getRangeDaysCount,
+ getDaysCountInMonth,
+ getDayInWeek,
+ getDateObj
+} from './utils'
+
+const EVENT_SELECT = 'select'
+const EVENT_CANCEL = 'cancel'
+
+createComponent({
+ options: {
+ multipleSlots: true,
+ styleIsolation: 'shared'
+ },
+ properties: {
+ min: {
+ type: Object, // todo 修改
+ value: () => new Date(2016, 2, 12)
+ },
+ // 可选日期的最大时间
+ max: {
+ type: Object,
+ value: new Date(2017, 4, 2)
+ },
+ // 可选的最大范围,0 为不限制
+ maxRange: {
+ type: Number,
+ value: 30
+ },
+ // 选择开始、结束时间时展示tip
+ showTip: {
+ type: Boolean,
+ value: true
+ },
+ // 是否滚动到底部
+ scrollToEnd: {
+ type: Boolean,
+ value: true
+ },
+ // 日期默认值,区间选择Array格式
+ defaultDate: {
+ type: Array,
+ value: []
+ },
+ height: {
+ type: String,
+ value: '300px'
+ }
+ },
+ data: {
+ scrollEvents: ['scroll'],
+ days: ['日', '一', '二', '三', '四', '五', '六'],
+ dateList: [] as any[],
+ selectDateSet: [] as any[], // 记录已选起始和结束的时间
+ dateClass: '',
+ errTipTxt: '最多选择30天',
+ angleOffset: {},
+ isVisible: true,
+ testData: [] as any[]
+ },
+ watch: {
+ selectDateSet(v) {
+ const startDate = v[0] && v[0].date
+ const endDate = v.length > 1 ? v[v.length - 1].data : null
+ this.$emit(
+ 'dateChange',
+ {
+ len: v.length,
+ startDate,
+ endDate
+ })
+ }
+ },
+ lifetimes: {
+ ready() {
+ this.getRangeDateArray()
+ this.reset(this.defaultDate)
+ }
+ },
+ methods: {
+ // @vuese
+ // 显示
+ show() {
+ if (this.isVisible) return
+ this.$nextTick(() => {
+ this.isVisible = true
+ })
+ },
+ // @vuese
+ // 隐藏
+ hide() {
+ this.isVisible = false
+ },
+ maskClick() {
+ this.cancel()
+ },
+ cancel() {
+ // 点击取消时触发
+ this.triggerEvent(EVENT_CANCEL)
+ this.hide()
+ },
+ itemClick(item, index) {
+ // 点击某项时触发
+ this.triggerEvent(EVENT_SELECT, { item, index })
+ this.hide()
+ },
+ selectDate(item, index, event) {
+ let selectDaysCount = 0
+ if (item.disable || !+item.date) return
+
+ this.resetDateRender(item)
+ // this.dateList[1].dateArr[0][3].active = true
+ console.log('this.dateList[1].dateArr[0][3].active', this.dateList[1].dateArr[0][3])
+ // set(this.dateList[1].dateArr[0][3], 'active', 'true')
+ this.$forceUpdate({
+ [`dateList[${1}].dateArr[0][3].active`]: true
+ })
+ console.log('this.dateList[1].dateArr[0][3].active', this.dateList[1].dateArr[0][3])
+ // 选择开始时间
+ if (!this.selectDateSet.length) {
+ this.selectDateSet.push(item as never)
+ // this.$emit('select', 'start', item)
+ } else {
+ // 选择结束时间
+ selectDaysCount = getRangeDaysCount(+(this.selectDateSet[0] as any).date, +item.date)
+
+ if (this.maxRange && selectDaysCount > this.maxRange) {
+ // this.showErrToast(`最多选择${this.maxRange}天`)
+ return
+ }
+ if (selectDaysCount > 0) {
+ this.renderSelectedRangeDate(this.selectDateSet[0], item)
+ }
+ // this.$emit('select', 'end', item)
+ }
+ if (+item.date) {
+ item.active = !item.active
+ console.log('iem.date', item.active, item)
+ }
+ },
+ reset(dateRange) {
+ if (dateRange && dateRange.length === 2) {
+ this.clear()
+ const startDateObj = getDateObj(dateRange[0])
+ const endDateObj = getDateObj(dateRange[1])
+ this.selectDateSet.push(startDateObj)
+ this.renderSelectedRangeDate(startDateObj, endDateObj)
+ // this.$set(this.selectDateSet[0], 'active', true)
+ set(this.selectDateSet[0], 'active', true)
+ // this.$set(this.selectDateSet[this.selectDateSet.length - 1], 'active', true)
+ set(this.selectDateSet[this.selectDateSet.length - 1], 'active', true)
+ }
+ },
+ resetDateRender(item) {
+ if (this.selectDateSet.length && (this.selectDateSet.length >= 2 || +item.date <= +(this.selectDateSet[0] as any).date)) {
+ for (let i = 0; i < this.selectDateSet.length; i++) {
+ // this.$set(this.selectDateSet[i], 'dateClass', '')
+ set(this.selectDateSet[i], 'dateClass', '')
+ // 遍历重置样式后,清空数组
+ if (i === this.selectDateSet.length - 1) {
+ this.selectDateSet.length = 0
+ }
+ }
+ }
+ },
+ getMonthDateGroup(year, month) {
+ let monthGroupIndex
+ let monthGroupData = '' as any
+
+ monthGroupData = this.dateList.find((item :any, index) => {
+ if (item.year === year && item.month === month) {
+ monthGroupIndex = index
+ return item
+ }
+ return ''
+ })
+ return {
+ data: monthGroupData,
+ index: monthGroupIndex
+ }
+ },
+ renderSelectedRangeDate(startDateObj, endDateObj) {
+ let startDateWeekInMonth = startDateObj.weekInMonth
+ let endDateWeekInMonth = endDateObj.weekInMonth
+ let startDateInWeek = startDateObj.dayInWeek
+ const startMonthIndex = this.getMonthDateGroup(startDateObj.year, startDateObj.month).index
+ const endMonthIndex = this.getMonthDateGroup(endDateObj.year, endDateObj.month).index
+ let monthDateGroup
+ for (let currentMonthIndex = startMonthIndex; currentMonthIndex <= endMonthIndex; currentMonthIndex++) {
+ monthDateGroup = this.dateList[currentMonthIndex]
+
+ if (currentMonthIndex !== startMonthIndex) {
+ startDateInWeek = 0
+ startDateWeekInMonth = 0
+ } else {
+ startDateWeekInMonth = startDateObj.weekInMonth
+ startDateInWeek = startDateObj.dayInWeek
+ }
+ endDateWeekInMonth = currentMonthIndex !== endMonthIndex
+ ? monthDateGroup.dateArr.length - 1 // 取该月最后一周
+ : endDateObj.weekInMonth
+
+ this.renderDateInOneMonth(startDateInWeek, monthDateGroup, startDateWeekInMonth, endDateWeekInMonth, endDateObj.date)
+ }
+ this.selectDateSet.length && this.selectDateSet.shift()
+ },
+ renderDateInOneMonth(startDateInWeek, monthDateGroup, startDateWeekInMonth, endDateWeekInMonth, endDate) {
+ console.log('startDateInWeek', startDateInWeek, monthDateGroup, startDateWeekInMonth, endDateWeekInMonth, endDate)
+ let day = startDateInWeek
+ const rangeArr = []
+ let weekDateGroup
+ let dateClass
+ const endDateTimestamp = endDate.setHours(0, 0, 0, 0)
+ for (let week = startDateWeekInMonth; week <= endDateWeekInMonth; week++) {
+ weekDateGroup = monthDateGroup.dateArr[week]
+
+ for (day; day <= 7; day++) {
+ if (day === 7) {
+ day = 0
+ break
+ }
+
+ // 渲染开始日期样式
+ if (+weekDateGroup[day].date === (this.selectDateSet[0] as any).date.setHours(0, 0, 0, 0)) {
+ // this.setData(weekDateGroup[day], 'dateClass', 'start-date')
+ weekDateGroup[day].dateClass = 'start-date'
+ }
+ dateClass = weekDateGroup[day].dateClass && +weekDateGroup[day].date
+ ? `${weekDateGroup[day].dateClass} transition-date`
+ : 'transition-date'
+ // this.$set(weekDateGroup[day], 'dateClass', dateClass)
+ set(weekDateGroup[day], 'dateClass', dateClass)
+ console.log('dateClass', dateClass)
+ console.log('weekDateGroup[day]', weekDateGroup[day])
+ rangeArr.push(weekDateGroup[day] as never)
+
+ if (+weekDateGroup[day].date >= endDateTimestamp) {
+ break
+ }
+ }
+ }
+ this.selectDateSet = [...this.selectDateSet, ...rangeArr]
+
+ // 渲染结束日期样式
+ if (this.selectDateSet.length >= 2 && +weekDateGroup[day].date === +(this.selectDateSet[this.selectDateSet.length - 1] as any).date) {
+ // this.$set(weekDateGroup[day], 'dateClass', weekDateGroup[day].dateClass ? `${weekDateGroup[day].dateClass} end-date` : 'end-date')
+ set(weekDateGroup[day], 'dateClass', weekDateGroup[day].dateClass ? `${weekDateGroup[day].dateClass} end-date` : 'end-date')
+ }
+ },
+ getRangeDateArray() {
+ // TODO: 校验传入的日期格式
+ const minYear = this.min.getFullYear()
+ const maxYear = this.max.getFullYear()
+ const minMonth = this.min.getMonth() + 1
+ const maxMonth = this.max.getMonth() + 1
+
+ if (+this.min >= +this.max) {
+ console.warn('传入props错误:时间的max值应大于min值!')
+ return
+ }
+
+ for (let year = minYear; year <= maxYear; year++) {
+ const monthLowerLimit = year === minYear ? minMonth : 1
+ const monthUpperLimit = year === maxYear ? maxMonth : 12
+ for (let month = monthLowerLimit; month <= monthUpperLimit; month++) {
+ this.dateList.push(this.getCurrentMonthDaysArray(year, month) as never)
+ }
+ }
+ this.testData = this.dateList
+ },
+ getCurrentMonthDaysArray(year, month) {
+ const days = getDaysCountInMonth(year, month)
+ const weeksCountInMonth = getWeeksCountInMonth(year, month)
+
+ // 根据周数,初始化二维数组
+ const daysArray = [] as any[]
+ for (let i = 0; i < weeksCountInMonth; i++) {
+ daysArray[i] = []
+ }
+
+ // 当月日历面板中的排列
+ for (let day = 1; day <= days; day++) {
+ const currentWeekInMonth = getWeekInMonth(year, month, day)
+ daysArray[currentWeekInMonth - 1].push({
+ day,
+ month: month,
+ year: year,
+ date: new Date(year, month - 1, day),
+ dayInWeek: getDayInWeek(year, month, day),
+ weekInMonth: currentWeekInMonth - 1,
+ active: false,
+ disable: +new Date(year, month - 1, day) < +this.min || +new Date(year, month - 1, day) > +this.max
+ })
+ }
+
+ this.fillDaysInMonth(year, month, days, weeksCountInMonth, daysArray)
+
+ return {
+ title: `${year}年${month}月`,
+ dayCount: days,
+ year: year,
+ month: month,
+ dateArr: [...daysArray]
+ }
+ },
+ fillDaysInMonth(year, month, days, weeksCountInMonth, daysArray) {
+ const firstDayInWeek = getDayInWeek(year, month, 1)
+ const lastDayInWeek = getDayInWeek(year, month, days)
+ if (firstDayInWeek !== 0) {
+ const fillArr = [...new Array(firstDayInWeek).fill({ date: '' })]
+ daysArray[0] = [...fillArr, ...daysArray[0]]
+ }
+ if (lastDayInWeek !== 6) {
+ const fillArr = [...new Array(6 - lastDayInWeek).fill({ date: '' })]
+ daysArray[weeksCountInMonth - 1] = [...daysArray[weeksCountInMonth - 1], ...fillArr]
+ }
+ }
+ }
+})
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
new file mode 100644
index 00000000..7c7de280
--- /dev/null
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
@@ -0,0 +1,173 @@
+
+
+
+
+ 选择日期
+
+
+
+
+
+ {{item}}
+
+
+
+
+
+
+ {{item.active}}
+
+
+
+ {{item.day}}
+
+
+
+
+
+
+
+ 完成
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/utils.ts b/packages/mpx-cube-ui/src/components/calendar-modal/utils.ts
new file mode 100644
index 00000000..24dd32ae
--- /dev/null
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/utils.ts
@@ -0,0 +1,97 @@
+/**
+ * 获得某天在当月是第几周
+ * @param a
+ * @param b
+ * @param c
+ * @returns {number}
+ */
+function getWeekInMonth(a, b, c) {
+ const date = new Date(a, parseInt(b) - 1, c)
+ const w = date.getDay()
+ const d = date.getDate()
+ return Math.ceil((d + 6 - w) / 7)
+}
+
+/**
+ * 获取本月有几周
+ * @param year
+ * @param month
+ * @returns {number}
+ */
+function getWeeksCountInMonth(year, month) {
+ const firstDayInWeek = getDayInWeek(year, month, 1)
+ const daysCountInMonth = getDaysCountInMonth(year, month)
+ let weekCount
+
+ if (daysCountInMonth === 31 && (firstDayInWeek === 5 || firstDayInWeek === 6)) {
+ weekCount = 6
+ } else if (daysCountInMonth === 30 && firstDayInWeek === 6) {
+ weekCount = 6
+ } else if (daysCountInMonth === 28 && firstDayInWeek === 0) {
+ weekCount = 4
+ } else {
+ weekCount = 5
+ }
+ return weekCount
+}
+
+/**
+ * 计算时间差(天数)
+ * @param startDate
+ * @param endDate
+ * @returns {number}
+ */
+function getRangeDaysCount(startDate, endDate) {
+ // TODO:
+ return Math.floor((endDate - startDate) / (24 * 3600 * 1000) + 1)
+}
+
+/**
+ * 计算一个月有几天
+ * @param year
+ * @param month
+ * @returns {number}
+ */
+function getDaysCountInMonth(year, month) {
+ return new Date(year, month, 0).getDate()
+}
+
+/**
+ * 计算某天是周几
+ * @param year
+ * @param month
+ * @param day
+ * @returns {number}
+ */
+function getDayInWeek(year, month, day) {
+ return new Date(`${year}/${month}/${day}`).getDay()
+}
+
+/**
+ * 获取日期对象
+ * @param date
+ * @returns {{date: *, month: number, year: number, day: number, dayInWeek: number, weekInMonth: number}}
+ */
+function getDateObj(date) {
+ const month = date.getMonth() + 1
+ const year = date.getFullYear()
+ const day = date.getDate()
+
+ return {
+ date,
+ month,
+ year,
+ day,
+ dayInWeek: getDayInWeek(year, month, day),
+ weekInMonth: getWeekInMonth(year, month, day) - 1
+ }
+}
+
+export {
+ getWeekInMonth,
+ getWeeksCountInMonth,
+ getRangeDaysCount,
+ getDaysCountInMonth,
+ getDayInWeek,
+ getDateObj
+}
From ffd4058ab1189476ae0e592fb44d06ad30655e73 Mon Sep 17 00:00:00 2001
From: likecodeboys <1239288387@qq.com>
Date: Wed, 2 Jul 2025 14:18:10 +0800
Subject: [PATCH 02/13] feat: update
---
.../calendar-modal/calendar-modal.ts | 47 +++++++++----------
.../src/components/calendar-modal/index.mpx | 9 ++--
2 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
index 09e858c9..960daf12 100644
--- a/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
@@ -1,4 +1,4 @@
-import { createComponent, set } from '@mpxjs/core'
+import { createComponent } from '@mpxjs/core'
import {
getWeekInMonth,
getWeeksCountInMonth,
@@ -24,7 +24,7 @@ createComponent({
// 可选日期的最大时间
max: {
type: Object,
- value: new Date(2017, 4, 2)
+ value: new Date(2016, 2, 14)
},
// 可选的最大范围,0 为不限制
maxRange: {
@@ -73,6 +73,12 @@ createComponent({
startDate,
endDate
})
+ },
+ dateList: {
+ handler(newVal, oldVal) {
+ console.log(1)
+ },
+ deep: true // 开启深度监听
}
},
lifetimes: {
@@ -113,16 +119,9 @@ createComponent({
if (item.disable || !+item.date) return
this.resetDateRender(item)
- // this.dateList[1].dateArr[0][3].active = true
- console.log('this.dateList[1].dateArr[0][3].active', this.dateList[1].dateArr[0][3])
- // set(this.dateList[1].dateArr[0][3], 'active', 'true')
- this.$forceUpdate({
- [`dateList[${1}].dateArr[0][3].active`]: true
- })
- console.log('this.dateList[1].dateArr[0][3].active', this.dateList[1].dateArr[0][3])
// 选择开始时间
if (!this.selectDateSet.length) {
- this.selectDateSet.push(item as never)
+ this.selectDateSet.push(item)
// this.$emit('select', 'start', item)
} else {
// 选择结束时间
@@ -139,7 +138,8 @@ createComponent({
}
if (+item.date) {
item.active = !item.active
- console.log('iem.date', item.active, item)
+ console.log('date', item)
+ console.log('date', this.dateList)
}
},
reset(dateRange) {
@@ -149,17 +149,17 @@ createComponent({
const endDateObj = getDateObj(dateRange[1])
this.selectDateSet.push(startDateObj)
this.renderSelectedRangeDate(startDateObj, endDateObj)
- // this.$set(this.selectDateSet[0], 'active', true)
- set(this.selectDateSet[0], 'active', true)
- // this.$set(this.selectDateSet[this.selectDateSet.length - 1], 'active', true)
- set(this.selectDateSet[this.selectDateSet.length - 1], 'active', true)
+ this.$set(this.selectDateSet[0], 'active', true)
+ // set(this.selectDateSet[0], 'active', true)
+ this.$set(this.selectDateSet[this.selectDateSet.length - 1], 'active', true)
+ // set(this.selectDateSet[this.selectDateSet.length - 1], 'active', true)
}
},
resetDateRender(item) {
if (this.selectDateSet.length && (this.selectDateSet.length >= 2 || +item.date <= +(this.selectDateSet[0] as any).date)) {
for (let i = 0; i < this.selectDateSet.length; i++) {
- // this.$set(this.selectDateSet[i], 'dateClass', '')
- set(this.selectDateSet[i], 'dateClass', '')
+ this.$set(this.selectDateSet[i], 'dateClass', '')
+ // set(this.selectDateSet[i], 'dateClass', '')
// 遍历重置样式后,清空数组
if (i === this.selectDateSet.length - 1) {
this.selectDateSet.length = 0
@@ -227,15 +227,14 @@ createComponent({
// 渲染开始日期样式
if (+weekDateGroup[day].date === (this.selectDateSet[0] as any).date.setHours(0, 0, 0, 0)) {
// this.setData(weekDateGroup[day], 'dateClass', 'start-date')
- weekDateGroup[day].dateClass = 'start-date'
+ this.$set(weekDateGroup[day], 'dateClass', 'start-date')
}
dateClass = weekDateGroup[day].dateClass && +weekDateGroup[day].date
? `${weekDateGroup[day].dateClass} transition-date`
: 'transition-date'
- // this.$set(weekDateGroup[day], 'dateClass', dateClass)
- set(weekDateGroup[day], 'dateClass', dateClass)
- console.log('dateClass', dateClass)
- console.log('weekDateGroup[day]', weekDateGroup[day])
+ this.$set(weekDateGroup[day], 'dateClass', dateClass)
+ console.log('groupDay', weekDateGroup[day])
+ // set(weekDateGroup[day], 'dateClass', dateClass)
rangeArr.push(weekDateGroup[day] as never)
if (+weekDateGroup[day].date >= endDateTimestamp) {
@@ -247,8 +246,8 @@ createComponent({
// 渲染结束日期样式
if (this.selectDateSet.length >= 2 && +weekDateGroup[day].date === +(this.selectDateSet[this.selectDateSet.length - 1] as any).date) {
- // this.$set(weekDateGroup[day], 'dateClass', weekDateGroup[day].dateClass ? `${weekDateGroup[day].dateClass} end-date` : 'end-date')
- set(weekDateGroup[day], 'dateClass', weekDateGroup[day].dateClass ? `${weekDateGroup[day].dateClass} end-date` : 'end-date')
+ this.$set(weekDateGroup[day], 'dateClass', weekDateGroup[day].dateClass ? `${weekDateGroup[day].dateClass} end-date` : 'end-date')
+ // set(weekDateGroup[day], 'dateClass', weekDateGroup[day].dateClass ? `${weekDateGroup[day].dateClass} end-date` : 'end-date')
}
},
getRangeDateArray() {
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
index 7c7de280..52dd88ba 100644
--- a/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
@@ -17,7 +17,7 @@
- {{item}}
+ {{item}}
- {{item.active}}
+
+ {{dateList[0].dateArr[1]}}
完成
@@ -152,7 +153,7 @@
display flex
justify-content center
align-items center
- width 25px
+ width 50px
height 25px
border-radius 6px
.date-left,
From d7f145f6844fed183b54efd6313f7acd5689a5ff Mon Sep 17 00:00:00 2001
From: likecodeboys <1239288387@qq.com>
Date: Fri, 1 Aug 2025 17:15:45 +0800
Subject: [PATCH 03/13] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../calendar-modal/customize-calendar.mpx | 84 +++++
example/pages/calendar-modal/index.mpx | 16 +-
.../pages/calendar-modal/normal-calendar.mpx | 61 ++++
.../theme/components/calendar-modal.styl | 0
.../stylus/theme/components/calendar.styl | 28 ++
.../calendar-modal/calendar-modal.ts | 317 +++--------------
.../src/components/calendar-modal/index.mpx | 174 ++--------
.../src/components/calendar/calendar.ts | 321 ++++++++++++++++++
.../src/components/calendar/index.mpx | 186 ++++++++++
.../{calendar-modal => calendar}/utils.ts | 0
10 files changed, 761 insertions(+), 426 deletions(-)
create mode 100644 example/pages/calendar-modal/customize-calendar.mpx
create mode 100644 example/pages/calendar-modal/normal-calendar.mpx
create mode 100644 packages/mpx-cube-ui/src/common/stylus/theme/components/calendar-modal.styl
create mode 100644 packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl
create mode 100644 packages/mpx-cube-ui/src/components/calendar/calendar.ts
create mode 100644 packages/mpx-cube-ui/src/components/calendar/index.mpx
rename packages/mpx-cube-ui/src/components/{calendar-modal => calendar}/utils.ts (100%)
diff --git a/example/pages/calendar-modal/customize-calendar.mpx b/example/pages/calendar-modal/customize-calendar.mpx
new file mode 100644
index 00000000..d8cac981
--- /dev/null
+++ b/example/pages/calendar-modal/customize-calendar.mpx
@@ -0,0 +1,84 @@
+
+
+ 自定义日历组件
+ 起始时间:{{toastText[0]}}
+ 结束时间:{{toastText[1]}}
+
+
+
+
+
+
+
+
+
diff --git a/example/pages/calendar-modal/index.mpx b/example/pages/calendar-modal/index.mpx
index dac6c5b7..d3fbd9f5 100644
--- a/example/pages/calendar-modal/index.mpx
+++ b/example/pages/calendar-modal/index.mpx
@@ -1,12 +1,8 @@
- 日历组件
-
+
+
@@ -18,11 +14,6 @@
data: {
},
methods: {
- onSelect(selectData) {
- const { item } = selectData.detail
- this.selectContent = `Clicked: ${item.content}`
- this.$refs.selectToast.show()
- },
showCalendarModal() {
this.$refs.calendarModal.show()
}
@@ -37,7 +28,8 @@
{
"usingComponents": {
"base-container": "../../components/base-container/index.mpx",
- "cube-calendar-modal": "@mpxjs/mpx-cube-ui/src/components/calendar-modal/index"
+ "customize-calendar": "./customize-calendar.mpx",
+ "normal-calendar": "./normal-calendar.mpx"
}
}
diff --git a/example/pages/calendar-modal/normal-calendar.mpx b/example/pages/calendar-modal/normal-calendar.mpx
new file mode 100644
index 00000000..f91c33a2
--- /dev/null
+++ b/example/pages/calendar-modal/normal-calendar.mpx
@@ -0,0 +1,61 @@
+
+
+ 常规日历组件
+ 起始时间:{{toastText[0]}}
+ 结束时间:{{toastText[1]}}
+
+
+
+
+
+
+
+
+
diff --git a/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar-modal.styl b/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar-modal.styl
new file mode 100644
index 00000000..e69de29b
diff --git a/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl b/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl
new file mode 100644
index 00000000..64a63452
--- /dev/null
+++ b/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl
@@ -0,0 +1,28 @@
+// @type
+$calendar-inner-padding := 0 10px 10px 0 // 容器内边距
+$calendar-inner-border-radius := 10px 10px 0 0 // 容器圆角
+$calendar-height := 320px // 容器高度
+$calendar-days-li-lh := 23px // 日期文案行高
+$calendar-days-li-padding := 10px 0 // 日期文案内边距
+$calendar-title-margin := 23px // 标题外边距
+$calendar-title-size := 22px // 标题字体大小
+
+$calendar-render-wrapper-padding := 10px 0 10px 0 // 日期容器内边距
+
+
+$calendar-date-header-padding-top := 10px // 日期标题top内边距
+$calendar-date-header-padding-bottom := 10px // 日期标题bottom内边距
+$calendar-date-header-margin-bottom := 6px // 日期标题bottom外边距
+$calendar-date-header-size := 16px // 日期方格标题字体大小
+$calendar-date-li-min-height := 25px // 日期方格最小高度
+$calendar-date-li-margin-bottom := 8px // 日期方格底步外边距
+$calendar-date-li-size := 14px // 日期元素字体大小
+
+$calendar-date-start-border-radius := 6px 0 0 6px // 日期元素开始时圆角
+$calendar-date-end-border-radius := 0 6px 6px 0 // 日期元素结束时圆角
+$calendar-date-width := 50px // 日期元素宽度
+$calendar-date-min-height := 25px // 日期元素最小高度
+$calendar-date-border-radius := 6px // 日期元素圆角
+
+
+
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
index 960daf12..aff21d2b 100644
--- a/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
@@ -1,41 +1,28 @@
import { createComponent } from '@mpxjs/core'
-import {
- getWeekInMonth,
- getWeeksCountInMonth,
- getRangeDaysCount,
- getDaysCountInMonth,
- getDayInWeek,
- getDateObj
-} from './utils'
-
-const EVENT_SELECT = 'select'
-const EVENT_CANCEL = 'cancel'
+import { visibilityMixin } from '../../common/mixins'
+const EVENT_MASK_CLOSE = 'maskClose'
createComponent({
+ mixins: [visibilityMixin],
options: {
multipleSlots: true,
styleIsolation: 'shared'
},
properties: {
min: {
- type: Object, // todo 修改
- value: () => new Date(2016, 2, 12)
+ type: Number,
+ value: +new Date(2016, 2, 12)
},
// 可选日期的最大时间
max: {
- type: Object,
- value: new Date(2016, 2, 14)
+ type: Number,
+ value: +new Date(2016, 4, 14)
},
// 可选的最大范围,0 为不限制
maxRange: {
type: Number,
value: 30
},
- // 选择开始、结束时间时展示tip
- showTip: {
- type: Boolean,
- value: true
- },
// 是否滚动到底部
scrollToEnd: {
type: Boolean,
@@ -49,274 +36,50 @@ createComponent({
height: {
type: String,
value: '300px'
- }
- },
- data: {
- scrollEvents: ['scroll'],
- days: ['日', '一', '二', '三', '四', '五', '六'],
- dateList: [] as any[],
- selectDateSet: [] as any[], // 记录已选起始和结束的时间
- dateClass: '',
- errTipTxt: '最多选择30天',
- angleOffset: {},
- isVisible: true,
- testData: [] as any[]
- },
- watch: {
- selectDateSet(v) {
- const startDate = v[0] && v[0].date
- const endDate = v.length > 1 ? v[v.length - 1].data : null
- this.$emit(
- 'dateChange',
- {
- len: v.length,
- startDate,
- endDate
- })
},
- dateList: {
- handler(newVal, oldVal) {
- console.log(1)
- },
- deep: true // 开启深度监听
+ maskClosable: {
+ type: Boolean,
+ value: true
+ },
+ isCustomizeShow: {
+ type: Boolean,
+ value: false
+ },
+ customizeShowFunction: {
+ type: Object,
+ value: function (day, disable) {
+ return `
${day}
`
+ }
+ },
+ title: {
+ type: String,
+ value: '选择日期'
+ },
+ buttonText: {
+ type: String,
+ value: '完成'
}
},
- lifetimes: {
- ready() {
- this.getRangeDateArray()
- this.reset(this.defaultDate)
- }
+ data: {
+ isVisible: false,
+ lastValue: [] as any[]
},
methods: {
- // @vuese
- // 显示
- show() {
- if (this.isVisible) return
- this.$nextTick(() => {
- this.isVisible = true
- })
- },
- // @vuese
- // 隐藏
- hide() {
- this.isVisible = false
- },
maskClick() {
- this.cancel()
+ this.triggerEvent(EVENT_MASK_CLOSE)
+ this.hide()
},
cancel() {
- // 点击取消时触发
- this.triggerEvent(EVENT_CANCEL)
+ if (!this.lastValue.length) {
+ this.lastValue = this.defaultDate
+ }
this.hide()
},
- itemClick(item, index) {
- // 点击某项时触发
- this.triggerEvent(EVENT_SELECT, { item, index })
+ confirm() {
+ const dateRange = this.$refs.calendar.getSelectDate()
+ this.lastValue = [dateRange[0].date, dateRange[1].date]
+ this.$emit('confirm', dateRange)
this.hide()
- },
- selectDate(item, index, event) {
- let selectDaysCount = 0
- if (item.disable || !+item.date) return
-
- this.resetDateRender(item)
- // 选择开始时间
- if (!this.selectDateSet.length) {
- this.selectDateSet.push(item)
- // this.$emit('select', 'start', item)
- } else {
- // 选择结束时间
- selectDaysCount = getRangeDaysCount(+(this.selectDateSet[0] as any).date, +item.date)
-
- if (this.maxRange && selectDaysCount > this.maxRange) {
- // this.showErrToast(`最多选择${this.maxRange}天`)
- return
- }
- if (selectDaysCount > 0) {
- this.renderSelectedRangeDate(this.selectDateSet[0], item)
- }
- // this.$emit('select', 'end', item)
- }
- if (+item.date) {
- item.active = !item.active
- console.log('date', item)
- console.log('date', this.dateList)
- }
- },
- reset(dateRange) {
- if (dateRange && dateRange.length === 2) {
- this.clear()
- const startDateObj = getDateObj(dateRange[0])
- const endDateObj = getDateObj(dateRange[1])
- this.selectDateSet.push(startDateObj)
- this.renderSelectedRangeDate(startDateObj, endDateObj)
- this.$set(this.selectDateSet[0], 'active', true)
- // set(this.selectDateSet[0], 'active', true)
- this.$set(this.selectDateSet[this.selectDateSet.length - 1], 'active', true)
- // set(this.selectDateSet[this.selectDateSet.length - 1], 'active', true)
- }
- },
- resetDateRender(item) {
- if (this.selectDateSet.length && (this.selectDateSet.length >= 2 || +item.date <= +(this.selectDateSet[0] as any).date)) {
- for (let i = 0; i < this.selectDateSet.length; i++) {
- this.$set(this.selectDateSet[i], 'dateClass', '')
- // set(this.selectDateSet[i], 'dateClass', '')
- // 遍历重置样式后,清空数组
- if (i === this.selectDateSet.length - 1) {
- this.selectDateSet.length = 0
- }
- }
- }
- },
- getMonthDateGroup(year, month) {
- let monthGroupIndex
- let monthGroupData = '' as any
-
- monthGroupData = this.dateList.find((item :any, index) => {
- if (item.year === year && item.month === month) {
- monthGroupIndex = index
- return item
- }
- return ''
- })
- return {
- data: monthGroupData,
- index: monthGroupIndex
- }
- },
- renderSelectedRangeDate(startDateObj, endDateObj) {
- let startDateWeekInMonth = startDateObj.weekInMonth
- let endDateWeekInMonth = endDateObj.weekInMonth
- let startDateInWeek = startDateObj.dayInWeek
- const startMonthIndex = this.getMonthDateGroup(startDateObj.year, startDateObj.month).index
- const endMonthIndex = this.getMonthDateGroup(endDateObj.year, endDateObj.month).index
- let monthDateGroup
- for (let currentMonthIndex = startMonthIndex; currentMonthIndex <= endMonthIndex; currentMonthIndex++) {
- monthDateGroup = this.dateList[currentMonthIndex]
-
- if (currentMonthIndex !== startMonthIndex) {
- startDateInWeek = 0
- startDateWeekInMonth = 0
- } else {
- startDateWeekInMonth = startDateObj.weekInMonth
- startDateInWeek = startDateObj.dayInWeek
- }
- endDateWeekInMonth = currentMonthIndex !== endMonthIndex
- ? monthDateGroup.dateArr.length - 1 // 取该月最后一周
- : endDateObj.weekInMonth
-
- this.renderDateInOneMonth(startDateInWeek, monthDateGroup, startDateWeekInMonth, endDateWeekInMonth, endDateObj.date)
- }
- this.selectDateSet.length && this.selectDateSet.shift()
- },
- renderDateInOneMonth(startDateInWeek, monthDateGroup, startDateWeekInMonth, endDateWeekInMonth, endDate) {
- console.log('startDateInWeek', startDateInWeek, monthDateGroup, startDateWeekInMonth, endDateWeekInMonth, endDate)
- let day = startDateInWeek
- const rangeArr = []
- let weekDateGroup
- let dateClass
- const endDateTimestamp = endDate.setHours(0, 0, 0, 0)
- for (let week = startDateWeekInMonth; week <= endDateWeekInMonth; week++) {
- weekDateGroup = monthDateGroup.dateArr[week]
-
- for (day; day <= 7; day++) {
- if (day === 7) {
- day = 0
- break
- }
-
- // 渲染开始日期样式
- if (+weekDateGroup[day].date === (this.selectDateSet[0] as any).date.setHours(0, 0, 0, 0)) {
- // this.setData(weekDateGroup[day], 'dateClass', 'start-date')
- this.$set(weekDateGroup[day], 'dateClass', 'start-date')
- }
- dateClass = weekDateGroup[day].dateClass && +weekDateGroup[day].date
- ? `${weekDateGroup[day].dateClass} transition-date`
- : 'transition-date'
- this.$set(weekDateGroup[day], 'dateClass', dateClass)
- console.log('groupDay', weekDateGroup[day])
- // set(weekDateGroup[day], 'dateClass', dateClass)
- rangeArr.push(weekDateGroup[day] as never)
-
- if (+weekDateGroup[day].date >= endDateTimestamp) {
- break
- }
- }
- }
- this.selectDateSet = [...this.selectDateSet, ...rangeArr]
-
- // 渲染结束日期样式
- if (this.selectDateSet.length >= 2 && +weekDateGroup[day].date === +(this.selectDateSet[this.selectDateSet.length - 1] as any).date) {
- this.$set(weekDateGroup[day], 'dateClass', weekDateGroup[day].dateClass ? `${weekDateGroup[day].dateClass} end-date` : 'end-date')
- // set(weekDateGroup[day], 'dateClass', weekDateGroup[day].dateClass ? `${weekDateGroup[day].dateClass} end-date` : 'end-date')
- }
- },
- getRangeDateArray() {
- // TODO: 校验传入的日期格式
- const minYear = this.min.getFullYear()
- const maxYear = this.max.getFullYear()
- const minMonth = this.min.getMonth() + 1
- const maxMonth = this.max.getMonth() + 1
-
- if (+this.min >= +this.max) {
- console.warn('传入props错误:时间的max值应大于min值!')
- return
- }
-
- for (let year = minYear; year <= maxYear; year++) {
- const monthLowerLimit = year === minYear ? minMonth : 1
- const monthUpperLimit = year === maxYear ? maxMonth : 12
- for (let month = monthLowerLimit; month <= monthUpperLimit; month++) {
- this.dateList.push(this.getCurrentMonthDaysArray(year, month) as never)
- }
- }
- this.testData = this.dateList
- },
- getCurrentMonthDaysArray(year, month) {
- const days = getDaysCountInMonth(year, month)
- const weeksCountInMonth = getWeeksCountInMonth(year, month)
-
- // 根据周数,初始化二维数组
- const daysArray = [] as any[]
- for (let i = 0; i < weeksCountInMonth; i++) {
- daysArray[i] = []
- }
-
- // 当月日历面板中的排列
- for (let day = 1; day <= days; day++) {
- const currentWeekInMonth = getWeekInMonth(year, month, day)
- daysArray[currentWeekInMonth - 1].push({
- day,
- month: month,
- year: year,
- date: new Date(year, month - 1, day),
- dayInWeek: getDayInWeek(year, month, day),
- weekInMonth: currentWeekInMonth - 1,
- active: false,
- disable: +new Date(year, month - 1, day) < +this.min || +new Date(year, month - 1, day) > +this.max
- })
- }
-
- this.fillDaysInMonth(year, month, days, weeksCountInMonth, daysArray)
-
- return {
- title: `${year}年${month}月`,
- dayCount: days,
- year: year,
- month: month,
- dateArr: [...daysArray]
- }
- },
- fillDaysInMonth(year, month, days, weeksCountInMonth, daysArray) {
- const firstDayInWeek = getDayInWeek(year, month, 1)
- const lastDayInWeek = getDayInWeek(year, month, days)
- if (firstDayInWeek !== 0) {
- const fillArr = [...new Array(firstDayInWeek).fill({ date: '' })]
- daysArray[0] = [...fillArr, ...daysArray[0]]
- }
- if (lastDayInWeek !== 6) {
- const fillArr = [...new Array(6 - lastDayInWeek).fill({ date: '' })]
- daysArray[weeksCountInMonth - 1] = [...daysArray[weeksCountInMonth - 1], ...fillArr]
- }
}
}
})
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
index 52dd88ba..34b85d1f 100644
--- a/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
@@ -1,55 +1,35 @@
-
+
-
+
选择日期
-
-
-
-
- {{item}}
-
-
-
-
-
-
-
-
-
-
- {{item.day}}
-
-
-
-
-
-
- {{dateList[0].dateArr[1]}}
-
- 完成
+
+
+ {{buttonText}}
@@ -57,108 +37,27 @@
-
+
+
+
+
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/utils.ts b/packages/mpx-cube-ui/src/components/calendar/utils.ts
similarity index 100%
rename from packages/mpx-cube-ui/src/components/calendar-modal/utils.ts
rename to packages/mpx-cube-ui/src/components/calendar/utils.ts
From 98c2f031e1312e8c94f69e50b93485cda33cd23b Mon Sep 17 00:00:00 2001
From: likecodeboys <1239288387@qq.com>
Date: Mon, 4 Aug 2025 16:46:59 +0800
Subject: [PATCH 04/13] =?UTF-8?q?feat:=20css=E6=8A=BD=E7=A6=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/guide/design-tokens.md | 2 +-
.../calendar-modal/customize-calendar.mpx | 4 +-
.../pages/calendar-modal/normal-calendar.mpx | 6 +--
example/static/wx/project.config.json | 3 +-
.../theme/components/calendar-modal.styl | 9 ++++
.../stylus/theme/components/calendar.styl | 6 ++-
.../calendar-modal/calendar-modal.ts | 2 +-
.../src/components/calendar-modal/index.mpx | 28 +++++------
.../src/components/calendar/calendar.ts | 8 +--
.../src/components/calendar/index.mpx | 50 +++++++++----------
.../src/components/calendar/utils.ts | 9 ++--
11 files changed, 70 insertions(+), 57 deletions(-)
diff --git a/docs/guide/design-tokens.md b/docs/guide/design-tokens.md
index d75f8279..45ce6245 100644
--- a/docs/guide/design-tokens.md
+++ b/docs/guide/design-tokens.md
@@ -35,7 +35,7 @@
|$color-secondary|#4F5E83
|基础-次要颜色|
|$color-disabled|#ccc
|基础-禁用色|
|$color-dark-grey|#333
|基础-灰色|
-|$color-dark-grey-s|#323233
|基础-浅灰|
+|$color-dark-grey-s|#000000
|-|
|$color-light-grey-opacity|rgba(0, 0, 0, .04)
|基础-透明灰|
|$mask-bgc_opacity|rgba(37, 38, 45, 0.4)
|遮罩层背景|
|$fill-bgc|#f2f2f2
|基础-填充背景色|
diff --git a/example/pages/calendar-modal/customize-calendar.mpx b/example/pages/calendar-modal/customize-calendar.mpx
index d8cac981..95757e25 100644
--- a/example/pages/calendar-modal/customize-calendar.mpx
+++ b/example/pages/calendar-modal/customize-calendar.mpx
@@ -20,9 +20,9 @@
diff --git a/packages/mpx-cube-ui/src/components/calendar/calendar.ts b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
index 93c5b780..fefa842b 100644
--- a/packages/mpx-cube-ui/src/components/calendar/calendar.ts
+++ b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
@@ -70,7 +70,6 @@ createComponent({
dateClass: '',
errTipTxt: '最多选择30天',
angleOffset: {},
- testData: [] as any[],
toastText: ''
},
watch: {
@@ -90,6 +89,7 @@ createComponent({
ready() {
this.getRangeDateArray()
this.reset(this.defaultDate)
+ console.log('node', this.customizeShowFunction)
}
},
methods: {
@@ -249,15 +249,15 @@ createComponent({
const monthLowerLimit = year === minYear ? minMonth : 1
const monthUpperLimit = year === maxYear ? maxMonth : 12
for (let month = monthLowerLimit; month <= monthUpperLimit; month++) {
+ console.log('year', year)
+ console.log('month', month)
this.dateList.push(this.getCurrentMonthDaysArray(year, month) as never)
}
}
- this.testData = this.dateList
},
getCurrentMonthDaysArray(year, month) {
const days = getDaysCountInMonth(year, month)
const weeksCountInMonth = getWeeksCountInMonth(year, month)
-
// 根据周数,初始化二维数组
const daysArray = [] as any[]
for (let i = 0; i < weeksCountInMonth; i++) {
@@ -267,20 +267,22 @@ createComponent({
// 当月日历面板中的排列
for (let day = 1; day <= days; day++) {
const currentWeekInMonth = getWeekInMonth(year, month, day)
+ const disable = +new Date(year, month - 1, day) < this.min || +new Date(year, month - 1, day) > this.max
+ console.log('customizeShowFunction', this.customizeShowFunction)
+ console.log('day', this.isCustomizeShow ? (this.customizeShowFunction as any)(day, disable) : day)
daysArray[currentWeekInMonth - 1].push({
- day,
+ day: this.isCustomizeShow ? (this.customizeShowFunction as any)(day, disable) : day,
month,
year,
date: new Date(year, month - 1, day),
dayInWeek: getDayInWeek(year, month, day),
weekInMonth: currentWeekInMonth - 1,
active: false,
- disable: +new Date(year, month - 1, day) < this.min || +new Date(year, month - 1, day) > this.max
+ disable
})
}
-
this.fillDaysInMonth(year, month, days, weeksCountInMonth, daysArray)
-
+ console.log('daysArray', daysArray)
return {
title: `${year}年${month}月`,
dayCount: days,
diff --git a/packages/mpx-cube-ui/src/components/calendar/index.mpx b/packages/mpx-cube-ui/src/components/calendar/index.mpx
index 8b38d3ab..607ea7e4 100644
--- a/packages/mpx-cube-ui/src/components/calendar/index.mpx
+++ b/packages/mpx-cube-ui/src/components/calendar/index.mpx
@@ -8,33 +8,34 @@
ref="scroll"
scroll-y="{{true}}"
>
-
+
-
-
-
-
-
-
-
+
+
+
+
+ 1{{customizeShowFunction}}
+
+
+
+
+
-
-
-
+
diff --git a/packages/mpx-cube-ui/src/components/calendar/utils.ts b/packages/mpx-cube-ui/src/components/calendar/utils.ts
index 30b38224..f35fc48b 100644
--- a/packages/mpx-cube-ui/src/components/calendar/utils.ts
+++ b/packages/mpx-cube-ui/src/components/calendar/utils.ts
@@ -69,17 +69,17 @@ function getDayInWeek(year, month, day) {
/**
* 获取日期对象
- * @param date
+ * @param inpuDate
* @returns {{date: *, month: number, year: number, day: number, dayInWeek: number, weekInMonth: number}}
*/
-function getDateObj(date) {
- const currentDate = new Date(date)
- const month = currentDate.getMonth() + 1
- const year = currentDate.getFullYear()
- const day = currentDate.getDate()
+function getDateObj(inpuDate) {
+ const date = new Date(inpuDate)
+ const month = date.getMonth() + 1
+ const year = date.getFullYear()
+ const day = date.getDate()
return {
- currentDate,
+ date,
month,
year,
day,
From 99002b65c1006aa73abd5fa44b336c5dbc5edefa Mon Sep 17 00:00:00 2001
From: likecodeboys <1239288387@qq.com>
Date: Mon, 1 Sep 2025 20:24:38 +0800
Subject: [PATCH 06/13] feat: update
---
.../calendar-modal/customize-calendar.mpx | 84 -------------------
example/pages/calendar-modal/index.mpx | 2 -
.../pages/calendar-modal/normal-calendar.mpx | 2 +-
.../calendar-modal/calendar-modal.ts | 10 ---
.../src/components/calendar-modal/index.mpx | 5 +-
.../src/components/calendar/calendar.ts | 21 +----
.../src/components/calendar/index.mpx | 77 ++++++-----------
7 files changed, 31 insertions(+), 170 deletions(-)
delete mode 100644 example/pages/calendar-modal/customize-calendar.mpx
diff --git a/example/pages/calendar-modal/customize-calendar.mpx b/example/pages/calendar-modal/customize-calendar.mpx
deleted file mode 100644
index eb457615..00000000
--- a/example/pages/calendar-modal/customize-calendar.mpx
+++ /dev/null
@@ -1,84 +0,0 @@
-
-
- 自定义日历组件
- 起始时间:{{toastText[0]}}
- 结束时间:{{toastText[1]}}
-
-
-
-
-
-
-
-
-
diff --git a/example/pages/calendar-modal/index.mpx b/example/pages/calendar-modal/index.mpx
index d3fbd9f5..6d992b82 100644
--- a/example/pages/calendar-modal/index.mpx
+++ b/example/pages/calendar-modal/index.mpx
@@ -1,7 +1,6 @@
-
@@ -28,7 +27,6 @@
{
"usingComponents": {
"base-container": "../../components/base-container/index.mpx",
- "customize-calendar": "./customize-calendar.mpx",
"normal-calendar": "./normal-calendar.mpx"
}
}
diff --git a/example/pages/calendar-modal/normal-calendar.mpx b/example/pages/calendar-modal/normal-calendar.mpx
index 0f1106e0..3c476c65 100644
--- a/example/pages/calendar-modal/normal-calendar.mpx
+++ b/example/pages/calendar-modal/normal-calendar.mpx
@@ -34,7 +34,7 @@ createComponent({
this.$refs.calendarModal.show()
},
confirm(date) {
- this.toastText = date
+ this.toastText = date.detail.value
}
}
})
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
index a2259ca6..54b5b8c6 100644
--- a/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
@@ -41,16 +41,6 @@ createComponent({
type: Boolean,
value: true
},
- isCustomizeShow: {
- type: Boolean,
- value: false
- },
- customizeShowFunction: {
- type: Object,
- value: function (day, disable) {
- return `${day}
`
- }
- },
title: {
type: String,
value: '选择日期'
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
index 753865d4..27cab3da 100644
--- a/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
@@ -18,8 +18,6 @@
{
- "styleIsolation": "shared",
"component": true,
"usingComponents": {
"cube-popup": "@mpxjs/mpx-cube-ui/src/components/popup/index",
diff --git a/packages/mpx-cube-ui/src/components/calendar/calendar.ts b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
index fefa842b..f211f87b 100644
--- a/packages/mpx-cube-ui/src/components/calendar/calendar.ts
+++ b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
@@ -48,18 +48,6 @@ createComponent({
height: {
type: String,
value: '300px'
- },
- isCustomizeShow: {
- type: Boolean,
- value: false
- },
- customizeShowFunction: {
- type: Object,
- value: () => {
- return function (day, disable) {
- return `${day}
`
- }
- }
}
},
data: {
@@ -89,7 +77,6 @@ createComponent({
ready() {
this.getRangeDateArray()
this.reset(this.defaultDate)
- console.log('node', this.customizeShowFunction)
}
},
methods: {
@@ -98,6 +85,8 @@ createComponent({
this.triggerEvent(EVENT_SELECT, { item, index })
},
selectDate(item) {
+ console.log('item', item)
+ console.log('dateList', this.dateList)
let selectDaysCount = 0
if (item.disable || !+item.date) return
this.resetDateRender(item)
@@ -268,10 +257,8 @@ createComponent({
for (let day = 1; day <= days; day++) {
const currentWeekInMonth = getWeekInMonth(year, month, day)
const disable = +new Date(year, month - 1, day) < this.min || +new Date(year, month - 1, day) > this.max
- console.log('customizeShowFunction', this.customizeShowFunction)
- console.log('day', this.isCustomizeShow ? (this.customizeShowFunction as any)(day, disable) : day)
daysArray[currentWeekInMonth - 1].push({
- day: this.isCustomizeShow ? (this.customizeShowFunction as any)(day, disable) : day,
+ day,
month,
year,
date: new Date(year, month - 1, day),
@@ -282,7 +269,7 @@ createComponent({
})
}
this.fillDaysInMonth(year, month, days, weeksCountInMonth, daysArray)
- console.log('daysArray', daysArray)
+
return {
title: `${year}年${month}月`,
dayCount: days,
diff --git a/packages/mpx-cube-ui/src/components/calendar/index.mpx b/packages/mpx-cube-ui/src/components/calendar/index.mpx
index 607ea7e4..53a73b9a 100644
--- a/packages/mpx-cube-ui/src/components/calendar/index.mpx
+++ b/packages/mpx-cube-ui/src/components/calendar/index.mpx
@@ -1,65 +1,34 @@
-
+
{{item}}
-
-
-
-
-
-
-
- 1{{customizeShowFunction}}
-
-
-
+
+
+
+
+
+ {{item.dateClass}}
+
+
+
+ {{item.day}}
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{item.day}}
-
-
-
+
-
+
@@ -107,6 +76,8 @@
// position: absolute
// top: 10px
// right: 10px
+ .date-render-content
+ overflow-y: auto
.date-render-wrapper
padding $var(calendar-render-wrapper-padding)
.date-header
From ce9f4cf370e96f791a15d1271012cdfa6d4054ca Mon Sep 17 00:00:00 2001
From: likecodeboys <1239288387@qq.com>
Date: Thu, 4 Sep 2025 15:20:08 +0800
Subject: [PATCH 07/13] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8Dbug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../pages/calendar-modal/normal-calendar.mpx | 6 ++-
.../src/components/calendar/calendar.ts | 54 ++++++++++++-------
.../src/components/calendar/index.mpx | 5 +-
3 files changed, 42 insertions(+), 23 deletions(-)
diff --git a/example/pages/calendar-modal/normal-calendar.mpx b/example/pages/calendar-modal/normal-calendar.mpx
index 3c476c65..047ca9d7 100644
--- a/example/pages/calendar-modal/normal-calendar.mpx
+++ b/example/pages/calendar-modal/normal-calendar.mpx
@@ -23,7 +23,7 @@ createComponent({
data: {
min: +new Date(2025, 1, 1),
max: +new Date(2025, 7, 25),
- maxRange: 3,
+ maxRange: 100,
scrollToEnd: true,
defaultDate: [+new Date(2025, 3, 1), +new Date(2025, 3, 2)],
maskClosable: true,
@@ -34,7 +34,9 @@ createComponent({
this.$refs.calendarModal.show()
},
confirm(date) {
- this.toastText = date.detail.value
+ const { year: startYear, month: startMonth, day: startDay } = date.detail.value[0]
+ const { year: endYear, month: endMonth, day: endDay } = date.detail.value[1]
+ this.toastText = [`${startYear}年${startMonth}月${startDay}日`,`${endYear}年${endMonth}月${endDay}日`]
}
}
})
diff --git a/packages/mpx-cube-ui/src/components/calendar/calendar.ts b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
index f211f87b..a4c4718f 100644
--- a/packages/mpx-cube-ui/src/components/calendar/calendar.ts
+++ b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
@@ -58,6 +58,11 @@ createComponent({
dateClass: '',
errTipTxt: '最多选择30天',
angleOffset: {},
+ agoClickIndex: {
+ listIndex: null,
+ weekInMonthIndex: null,
+ index: null
+ },
toastText: ''
},
watch: {
@@ -84,18 +89,16 @@ createComponent({
// 点击某项时触发
this.triggerEvent(EVENT_SELECT, { item, index })
},
- selectDate(item) {
- console.log('item', item)
- console.log('dateList', this.dateList)
+ selectDate(item, listIndex, weekInMonthIndex, index) {
let selectDaysCount = 0
- if (item.disable || !+item.date) return
+ if (item.disable || !item.date) return
this.resetDateRender(item)
// 选择开始时间
if (!this.selectDateSet.length) {
this.selectDateSet.push(item)
} else {
// 选择结束时间
- selectDaysCount = getRangeDaysCount(+(this.selectDateSet[0] as any).date, +item.date)
+ selectDaysCount = getRangeDaysCount(+(this.selectDateSet[0] as any).date, item.date)
if (this.maxRange && selectDaysCount > this.maxRange) {
this.toastText = `最多选择${this.maxRange}天`
this.$refs.toast.show()
@@ -105,8 +108,16 @@ createComponent({
this.renderSelectedRangeDate(this.selectDateSet[0], item)
}
}
- if (+item.date) {
- item.active = !item.active
+ if (item.date) {
+ // eslint-disable-next-line
+ let currentDate = (this.dateList[listIndex] as any).dateArr[weekInMonthIndex][index]
+ const { date: selectStartTime } = this.selectDateSet[0]
+ const { date: selectEndTime } = this.selectDateSet[this.selectDateSet.length - 1]
+ if (currentDate.date === selectStartTime || currentDate.date === selectEndTime) {
+ // eslint-disable-next-line
+ currentDate['active'] = true
+ }
+ this.agoClickIndex = { listIndex, weekInMonthIndex, index }
}
},
reset(dateRange) {
@@ -122,14 +133,22 @@ createComponent({
},
clear() {
if (!this.selectDateSet || !this.selectDateSet.length) { return }
+ this.resetSelectDate()
+ this.selectDateSet = []
+ },
+ resetSelectDate() {
this.selectDateSet.forEach((item, index) => {
this.$set(item, 'dateClass', '')
item.active && this.$set(item, 'active', false)
})
- this.selectDateSet = []
},
resetDateRender(item) {
- if (this.selectDateSet.length && (this.selectDateSet.length >= 2 || +item.date <= +(this.selectDateSet[0] as any).date)) {
+ if (this.selectDateSet.length && (this.selectDateSet.length >= 2 || item.date <= this.selectDateSet[0].date)) {
+ const { listIndex, weekInMonthIndex, index } = this.agoClickIndex
+ if (listIndex !== null && weekInMonthIndex !== null && index !== null) {
+ // eslint-disable-next-line
+ (this.dateList[listIndex] as any).dateArr[weekInMonthIndex][index]['active'] = false
+ }
for (let i = 0; i < this.selectDateSet.length; i++) {
this.$set(this.selectDateSet[i], 'dateClass', '')
this.$set(this.selectDateSet[i], 'active', false)
@@ -176,7 +195,6 @@ createComponent({
endDateWeekInMonth = currentMonthIndex !== endMonthIndex
? monthDateGroup.dateArr.length - 1 // 取该月最后一周
: endDateObj.weekInMonth
-
this.renderDateInOneMonth(startDateInWeek, monthDateGroup, startDateWeekInMonth, endDateWeekInMonth, endDateObj.date)
}
this.selectDateSet.length && this.selectDateSet.shift()
@@ -186,7 +204,8 @@ createComponent({
const rangeArr = []
let weekDateGroup
let dateClass
- const endDateTimestamp = endDate.setHours(0, 0, 0, 0)
+
+ const endDateTimestamp = new Date(endDate).setHours(0, 0, 0, 0)
for (let week = startDateWeekInMonth; week <= endDateWeekInMonth; week++) {
weekDateGroup = monthDateGroup.dateArr[week]
@@ -197,16 +216,17 @@ createComponent({
}
// 渲染开始日期样式
- if (+weekDateGroup[day].date === (this.selectDateSet[0] as any).date.setHours(0, 0, 0, 0)) {
+ const selectDateSetTime = new Date(this.selectDateSet[0].date).setHours(0, 0, 0, 0)
+
+ if (weekDateGroup[day].date === +selectDateSetTime) {
this.$set(weekDateGroup[day], 'dateClass', 'start-date')
}
- dateClass = weekDateGroup[day].dateClass && +weekDateGroup[day].date
+ dateClass = weekDateGroup[day].dateClass && weekDateGroup[day].date
? `${weekDateGroup[day].dateClass} transition-date`
: 'transition-date'
this.$set(weekDateGroup[day], 'dateClass', dateClass)
rangeArr.push(weekDateGroup[day] as never)
-
- if (+weekDateGroup[day].date >= endDateTimestamp) {
+ if (weekDateGroup[day].date >= +endDateTimestamp) {
break
}
}
@@ -238,8 +258,6 @@ createComponent({
const monthLowerLimit = year === minYear ? minMonth : 1
const monthUpperLimit = year === maxYear ? maxMonth : 12
for (let month = monthLowerLimit; month <= monthUpperLimit; month++) {
- console.log('year', year)
- console.log('month', month)
this.dateList.push(this.getCurrentMonthDaysArray(year, month) as never)
}
}
@@ -261,7 +279,7 @@ createComponent({
day,
month,
year,
- date: new Date(year, month - 1, day),
+ date: +new Date(year, month - 1, day),
dayInWeek: getDayInWeek(year, month, day),
weekInMonth: currentWeekInMonth - 1,
active: false,
diff --git a/packages/mpx-cube-ui/src/components/calendar/index.mpx b/packages/mpx-cube-ui/src/components/calendar/index.mpx
index 53a73b9a..d7b21689 100644
--- a/packages/mpx-cube-ui/src/components/calendar/index.mpx
+++ b/packages/mpx-cube-ui/src/components/calendar/index.mpx
@@ -14,13 +14,12 @@
wx:key="index"
wx:class="{{[item.dateClass, {'disable': item.disable}, {'active': item.active}]}}"
>
- {{item.dateClass}}
{{item.day}}
@@ -130,7 +129,7 @@
.date
color #FFF
background-color #4D6199
- &.active
+ &.disable
.date
color #969699
.date
From af0594955eafb60bc2d8eb5d4acd4f2689390463 Mon Sep 17 00:00:00 2001
From: likecodeboys <1239288387@qq.com>
Date: Thu, 4 Sep 2025 16:53:44 +0800
Subject: [PATCH 08/13] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8Dbug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/config/sidebar.js | 4 ++
example/common/config.ts | 2 +-
example/pages/calendar-modal/README.md | 51 ++++++++++++++++---
example/pages/calendar-modal/index.mpx | 10 +---
.../pages/calendar-modal/normal-calendar.mpx | 12 ++---
package.json | 2 +-
.../calendar-modal/calendar-modal.ts | 29 ++++++++---
.../src/components/calendar-modal/index.mpx | 3 +-
.../src/components/calendar/calendar.ts | 24 ++++-----
9 files changed, 92 insertions(+), 45 deletions(-)
diff --git a/docs/config/sidebar.js b/docs/config/sidebar.js
index 5f621541..d462deb3 100644
--- a/docs/config/sidebar.js
+++ b/docs/config/sidebar.js
@@ -120,6 +120,10 @@ module.exports = [
{
title: 'Switch 滑动开关',
path: '/components/base/switch'
+ },
+ {
+ title: 'CalendarModal 日历弹框',
+ path: '/components/base/calendar-modal'
}
]
},
diff --git a/example/common/config.ts b/example/common/config.ts
index 85405d7b..5925e970 100644
--- a/example/common/config.ts
+++ b/example/common/config.ts
@@ -85,7 +85,7 @@ export default {
'cascade-picker-popup',
'date-picker-popup',
'time-picker-popup',
- 'calendar-modal'
+ 'calendar-modal',
]
}
],
diff --git a/example/pages/calendar-modal/README.md b/example/pages/calendar-modal/README.md
index 2d08f024..dce0e62c 100644
--- a/example/pages/calendar-modal/README.md
+++ b/example/pages/calendar-modal/README.md
@@ -1,10 +1,10 @@
-## cube-calendar
+## cube-calendar-modal
### 介绍
-加载,提供了可自定义大小的加载动画。
+日历选择弹框
@@ -12,15 +12,54 @@
-### 基础用法
-
-默认大小为`24px`,可通过`size`属性配置
+### 用法
```vue
-
+
+
+ 常规日历组件
+ 起始时间:{{toastText[0]}}
+ 结束时间:{{toastText[1]}}
+
+
+
+
```
diff --git a/example/pages/calendar-modal/index.mpx b/example/pages/calendar-modal/index.mpx
index 6d992b82..e5cb3ff7 100644
--- a/example/pages/calendar-modal/index.mpx
+++ b/example/pages/calendar-modal/index.mpx
@@ -9,15 +9,7 @@
+
+
diff --git a/example/pages/calendar/index.mpx b/example/pages/calendar/index.mpx
new file mode 100644
index 00000000..b200e26a
--- /dev/null
+++ b/example/pages/calendar/index.mpx
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl b/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl
index 782895b5..6c699a08 100644
--- a/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl
+++ b/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl
@@ -1,5 +1,5 @@
// @type
-$calendar-inner-padding := 0 10px 10px 0 // 容器内边距
+$calendar-inner-padding := 0 8px 10px 8px // 容器内边距
$calendar-inner-border-radius := 10px 10px 0 0 // 容器圆角
$calendar-height := 320px // 容器高度
$calendar-days-li-lh := 23px // 日期文案行高
@@ -23,7 +23,7 @@ $calendar-date-li-size := 14px // 日期元素字体大小
$calendar-date-start-border-radius := 6px 0 0 6px // 日期元素开始时圆角
$calendar-date-end-border-radius := 0 6px 6px 0 // 日期元素结束时圆角
-$calendar-date-width := 50px // 日期元素宽度
+$calendar-date-width := 30px // 日期元素宽度
$calendar-date-min-height := 25px // 日期元素最小高度
$calendar-date-border-radius := 6px // 日期元素圆角
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
index ab264f4f..eb792fdb 100644
--- a/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
@@ -7,13 +7,12 @@
direction="horizontal"
mask-closable="{{ maskClosable }}"
removeCatchTouch="{{ true }}"
- title="选择日期"
bind:maskClick="maskClick"
position="bottom"
transition="move-up"
>
- 选择日期
+ {{title}}
@@ -25,7 +24,6 @@
max="{{max}}"
min="{{min}}"
maskClosable="{{maskClosable}}"
- title="{{title}}"
>
{{buttonText}}
diff --git a/packages/mpx-cube-ui/src/components/calendar/calendar.ts b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
index 8433832b..34ae0ef4 100644
--- a/packages/mpx-cube-ui/src/components/calendar/calendar.ts
+++ b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
@@ -8,14 +8,13 @@ import {
getDateObj
} from './utils'
-const EVENT_SELECT = 'select'
-
createComponent({
options: {
multipleSlots: true,
styleIsolation: 'shared'
},
properties: {
+ // 可选择的最小日期
min: {
type: Number,
value: +new Date(2016, 2, 12)
@@ -30,16 +29,12 @@ createComponent({
type: Number,
value: 30
},
- // 选择开始、结束时间时展示tip
- showTip: {
- type: Boolean,
- value: true
- },
// 日期默认值,区间选择Array格式
defaultDate: {
type: Array,
value: []
},
+ // 容器高度
height: {
type: String,
value: '300px'
@@ -61,14 +56,14 @@ createComponent({
},
watch: {
selectDateSet(v) {
- const startDate = v[0] && v[0].date
- const endDate = v.length > 1 ? v[v.length - 1].data : null
+ const startDate = v[0] || {}
+ const endDate = v.length > 1 ? v[v.length - 1] : {}
+ // 选择的日期改变时触发
+ // @arg event.detail = { len, startDate, endDate }, len表当前选中的时间间隔,startDate表当前选中的开始时间,endDate表当前选中的结束时间
this.triggerEvent('dateChange', {
- value: {
- len: v.length,
- startDate,
- endDate
- }
+ len: v.length,
+ startDate,
+ endDate
})
}
},
@@ -79,10 +74,6 @@ createComponent({
}
},
methods: {
- itemClick(item, index) {
- // 点击某项时触发
- this.triggerEvent(EVENT_SELECT, { item, index })
- },
selectDate(item, listIndex, weekInMonthIndex, index) {
let selectDaysCount = 0
if (item.disable || !item.date) return
diff --git a/packages/mpx-cube-ui/src/components/calendar/index.mpx b/packages/mpx-cube-ui/src/components/calendar/index.mpx
index 02a39f90..390b2d9c 100644
--- a/packages/mpx-cube-ui/src/components/calendar/index.mpx
+++ b/packages/mpx-cube-ui/src/components/calendar/index.mpx
@@ -132,7 +132,7 @@
display flex
justify-content center
align-items center
- width $var(calendar-date-width)
+ min-width $var(calendar-date-width)
min-height $var(calendar-date-min-height)
border-radius $var(calendar-date-border-radius)
.date-left,
From e7955b7084c66c8cade21056c9852f63d8aed094 Mon Sep 17 00:00:00 2001
From: likecodeboys <1239288387@qq.com>
Date: Mon, 5 Jan 2026 20:51:28 +0800
Subject: [PATCH 11/13] feat: update
---
example/static/wx/project.config.json | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/example/static/wx/project.config.json b/example/static/wx/project.config.json
index 3bc16f3f..591c48bb 100644
--- a/example/static/wx/project.config.json
+++ b/example/static/wx/project.config.json
@@ -55,6 +55,5 @@
"ignore": [],
"include": []
},
- "projectname": "wx",
- "appid": "wx603cbad725e536bf"
+ "projectname": "wx"
}
\ No newline at end of file
From 01c8a7acdb76144cf3001ad8a4f629e7579a4553 Mon Sep 17 00:00:00 2001
From: likecodeboys <1239288387@qq.com>
Date: Tue, 6 Jan 2026 20:13:07 +0800
Subject: [PATCH 12/13] =?UTF-8?q?feat:=20CR=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
example/pages/calendar-modal/README.md | 6 +++---
example/pages/calendar-modal/normal-calendar.mpx | 6 +++---
example/pages/calendar/README.md | 6 +++---
example/pages/calendar/calendar.mpx | 6 +++---
.../src/common/stylus/theme/components/calendar.styl | 2 +-
.../src/components/calendar-modal/calendar-modal.ts | 10 ++++++----
.../mpx-cube-ui/src/components/calendar/calendar.ts | 12 ++++++------
.../mpx-cube-ui/src/components/calendar/index.mpx | 2 +-
.../mpx-cube-ui/src/components/calendar/utils.ts | 12 +++++++++++-
9 files changed, 37 insertions(+), 25 deletions(-)
diff --git a/example/pages/calendar-modal/README.md b/example/pages/calendar-modal/README.md
index dce0e62c..4560bb8a 100644
--- a/example/pages/calendar-modal/README.md
+++ b/example/pages/calendar-modal/README.md
@@ -40,11 +40,11 @@ import { createComponent } from '@mpxjs/core'
createComponent({
data: {
- min: +new Date(2025, 1, 1),
- max: +new Date(2025, 7, 25),
+ min: +new Date(2026, 1, 1),
+ max: +new Date(2027, 7, 25),
maxRange: 100,
scrollToEnd: true,
- defaultDate: [+new Date(2025, 3, 1), +new Date(2025, 3, 2)],
+ defaultDate: [+new Date(2026, 3, 1), +new Date(2026, 3, 2)],
maskClosable: true,
toastText: ['暂未选择时间', '暂未选择时间']
},
diff --git a/example/pages/calendar-modal/normal-calendar.mpx b/example/pages/calendar-modal/normal-calendar.mpx
index 48722703..201eec01 100644
--- a/example/pages/calendar-modal/normal-calendar.mpx
+++ b/example/pages/calendar-modal/normal-calendar.mpx
@@ -21,11 +21,11 @@ import { createComponent } from '@mpxjs/core'
createComponent({
data: {
- min: +new Date(2025, 1, 1),
- max: +new Date(2025, 7, 25),
+ min: +new Date(2026, 0, 1),
+ max: +new Date(2027, 11, 30),
maxRange: 100,
scrollToEnd: true,
- defaultDate: [+new Date(2025, 3, 1), +new Date(2025, 3, 2)],
+ defaultDate: [+new Date(2026, 3, 1), +new Date(2026, 3, 2)],
maskClosable: true,
toastText: ['暂未选择时间', '暂未选择时间']
},
diff --git a/example/pages/calendar/README.md b/example/pages/calendar/README.md
index 19a52311..fcf8705c 100644
--- a/example/pages/calendar/README.md
+++ b/example/pages/calendar/README.md
@@ -50,11 +50,11 @@ import { createComponent } from '@mpxjs/core'
createComponent({
data: {
- min: +new Date(2025, 1, 1),
- max: +new Date(2025, 7, 25),
+ min: +new Date(2026, 1, 1),
+ max: +new Date(2027, 7, 25),
height: '270px',
maxRange: 100,
- defaultDate: [+new Date(2025, 3, 1), +new Date(2025, 3, 2)],
+ defaultDate: [+new Date(2026, 3, 1), +new Date(2026, 3, 2)],
currentStartDate: {},
currentEndDate: {}
},
diff --git a/example/pages/calendar/calendar.mpx b/example/pages/calendar/calendar.mpx
index 6e3b516f..87a9681a 100644
--- a/example/pages/calendar/calendar.mpx
+++ b/example/pages/calendar/calendar.mpx
@@ -31,11 +31,11 @@ import { createComponent } from '@mpxjs/core'
createComponent({
data: {
- min: +new Date(2025, 1, 1),
- max: +new Date(2025, 7, 25),
+ min: +new Date(2026, 0, 1),
+ max: +new Date(2027, 11, 30),
height: '270px',
maxRange: 100,
- defaultDate: [+new Date(2025, 3, 1), +new Date(2025, 3, 2)],
+ defaultDate: [+new Date(2026, 3, 1), +new Date(2026, 3, 2)],
currentStartDate: {},
currentEndDate: {}
},
diff --git a/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl b/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl
index 6c699a08..28fb82ed 100644
--- a/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl
+++ b/packages/mpx-cube-ui/src/common/stylus/theme/components/calendar.styl
@@ -1,7 +1,7 @@
// @type
$calendar-inner-padding := 0 8px 10px 8px // 容器内边距
$calendar-inner-border-radius := 10px 10px 0 0 // 容器圆角
-$calendar-height := 320px // 容器高度
+$calendar-height := 310px // 容器高度
$calendar-days-li-lh := 23px // 日期文案行高
$calendar-days-li-size := 14px // 日期文案字体大小
$calendar-days-li-padding := 10px 0 // 日期文案内边距
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
index 45ef3eed..ceaf1857 100644
--- a/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
@@ -1,6 +1,6 @@
import { createComponent } from '@mpxjs/core'
import { visibilityMixin } from '../../common/mixins'
-
+import { getCurrentOrNextYearDay } from '@mpxjs/mpx-cube-ui/src/components/calendar/utils'
const EVENT_MASK_CLOSE = 'maskClose'
const EVENT_CONFIRM = 'confirm'
const EVENT_CANCEL = 'cancel'
@@ -15,12 +15,14 @@ createComponent({
// 可选择的最小日期
min: {
type: Number,
- value: +new Date(2016, 2, 12)
+ // 今年1月1日
+ value: getCurrentOrNextYearDay()
},
- // 可选日期的最大时间
+ // 可选择的最大日期
max: {
type: Number,
- value: +new Date(2016, 4, 14)
+ // 明年12月31日
+ value: getCurrentOrNextYearDay(false)
},
// 可选的最大范围,0 为不限制
maxRange: {
diff --git a/packages/mpx-cube-ui/src/components/calendar/calendar.ts b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
index 34ae0ef4..0cc752a1 100644
--- a/packages/mpx-cube-ui/src/components/calendar/calendar.ts
+++ b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
@@ -5,24 +5,26 @@ import {
getRangeDaysCount,
getDaysCountInMonth,
getDayInWeek,
- getDateObj
+ getDateObj,
+ getCurrentOrNextYearDay
} from './utils'
createComponent({
options: {
- multipleSlots: true,
styleIsolation: 'shared'
},
properties: {
// 可选择的最小日期
min: {
type: Number,
- value: +new Date(2016, 2, 12)
+ // 今年1月1日
+ value: getCurrentOrNextYearDay()
},
// 可选日期的最大时间
max: {
type: Number,
- value: +new Date(2016, 4, 14)
+ // 明年12月31日
+ value: getCurrentOrNextYearDay(false)
},
// 可选的最大范围,0 为不限制
maxRange: {
@@ -45,8 +47,6 @@ createComponent({
dateList: [],
selectDateSet: [] as any[], // 记录已选起始和结束的时间
dateClass: '',
- errTipTxt: '最多选择30天',
- angleOffset: {},
agoClickIndex: {
listIndex: null,
weekInMonthIndex: null,
diff --git a/packages/mpx-cube-ui/src/components/calendar/index.mpx b/packages/mpx-cube-ui/src/components/calendar/index.mpx
index 1a47a0ee..0153bc44 100644
--- a/packages/mpx-cube-ui/src/components/calendar/index.mpx
+++ b/packages/mpx-cube-ui/src/components/calendar/index.mpx
@@ -5,7 +5,7 @@
{{item}}
-
+
Date: Tue, 6 Jan 2026 20:50:09 +0800
Subject: [PATCH 13/13] =?UTF-8?q?feat:=20CR=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../pages/calendar-modal/normal-calendar.mpx | 4 ++++
.../components/calendar-modal/calendar-modal.ts | 11 +++++++++++
.../src/components/calendar-modal/index.mpx | 2 ++
.../src/components/calendar/calendar.ts | 17 ++++++++++++-----
4 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/example/pages/calendar-modal/normal-calendar.mpx b/example/pages/calendar-modal/normal-calendar.mpx
index 201eec01..87924fc2 100644
--- a/example/pages/calendar-modal/normal-calendar.mpx
+++ b/example/pages/calendar-modal/normal-calendar.mpx
@@ -12,6 +12,7 @@
defaultDate="{{defaultDate}}"
maskClosable="{{maskClosable}}"
bindconfirm="confirm"
+ bindselectDateOverRange="selectDateOverRange"
/>
@@ -37,6 +38,9 @@ createComponent({
const { year: startYear, month: startMonth, day: startDay } = date.detail.value[0]
const { year: endYear, month: endMonth, day: endDay } = date.detail.value[1]
this.toastText = [`${startYear}年${startMonth}月${startDay}日`,`${endYear}年${endMonth}月${endDay}日`]
+ },
+ selectDateOverRange() {
+ console.log('自定义处理超出范围的选择逻辑')
}
}
})
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
index ceaf1857..0fb037d7 100644
--- a/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/calendar-modal.ts
@@ -4,6 +4,7 @@ import { getCurrentOrNextYearDay } from '@mpxjs/mpx-cube-ui/src/components/calen
const EVENT_MASK_CLOSE = 'maskClose'
const EVENT_CONFIRM = 'confirm'
const EVENT_CANCEL = 'cancel'
+const SELECT_DATE_OVER_RANGE = 'selectDateOverRange'
createComponent({
mixins: [visibilityMixin],
@@ -53,6 +54,11 @@ createComponent({
buttonText: {
type: String,
value: '完成'
+ },
+ // 展示超出范围提示语
+ showOverRangeTips: {
+ type: Boolean,
+ value: true
}
},
data: {
@@ -89,6 +95,11 @@ createComponent({
showCalendar() {
this.$refs.calendar.reset(this.lastValue)
this.show()
+ },
+ // 显示
+ selectDateOverRange() {
+ // 选择的日期超过最大范围时触发
+ this.triggerEvent(SELECT_DATE_OVER_RANGE)
}
}
})
diff --git a/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
index 5991c2bb..2ee4536a 100644
--- a/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
+++ b/packages/mpx-cube-ui/src/components/calendar-modal/index.mpx
@@ -23,7 +23,9 @@
maxRange="{{maxRange}}"
max="{{max}}"
min="{{min}}"
+ showOverRangeTips="{{showOverRangeTips}}"
maskClosable="{{maskClosable}}"
+ bind:selectDateOverRange="selectDateOverRange"
>
{{buttonText}}
diff --git a/packages/mpx-cube-ui/src/components/calendar/calendar.ts b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
index 0cc752a1..230121de 100644
--- a/packages/mpx-cube-ui/src/components/calendar/calendar.ts
+++ b/packages/mpx-cube-ui/src/components/calendar/calendar.ts
@@ -40,6 +40,11 @@ createComponent({
height: {
type: String,
value: '300px'
+ },
+ // 展示超出范围提示语
+ showOverRangeTips: {
+ type: Boolean,
+ value: true
}
},
data: {
@@ -85,8 +90,12 @@ createComponent({
// 选择结束时间
selectDaysCount = getRangeDaysCount(+(this.selectDateSet[0] as any).date, item.date)
if (this.maxRange && selectDaysCount > this.maxRange) {
- this.toastText = `最多选择${this.maxRange}天`
- this.$refs.toast.show()
+ if (this.showOverRangeTips) {
+ this.toastText = `最多选择${this.maxRange}天`
+ this.$refs.toast.show()
+ }
+ // 选择的日期超过最大范围时触发
+ this.triggerEvent('selectDateOverRange')
return
}
if (selectDaysCount > 0) {
@@ -234,9 +243,7 @@ createComponent({
const maxMonth = maxDate.getMonth() + 1
if (this.min >= this.max) {
- this.toastText = '传入props错误:时间的max值应大于min值!'
- this.$refs.toast.show()
- // console.warn('传入props错误:时间的max值应大于min值!')
+ console.warn('传入props错误:时间的max值应大于min值!')
return
}