Skip to content

Commit d82fb84

Browse files
committed
fix:更新日历文档,优化选中日期显示今天的问题
1 parent e623ad2 commit d82fb84

File tree

4 files changed

+107
-58
lines changed

4 files changed

+107
-58
lines changed

src/components/uni-calendar/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"type": "功能组件",
77
"edition": "1.3.9",
88
"path": "https://ext.dcloud.net.cn/plugin?id=56",
9-
"update_log": "- 弹出模式下,动画异常的Bug"
9+
"update_log": "- 优化 自定义日期显示今天的问题"
1010
}

src/components/uni-calendar/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ export default {
4646
| startDate | String |- | 日期选择范围-开始日期 |
4747
| endDate | String |- | 日期选择范围-结束日期 |
4848
| range | Boolean | false | 范围选择 |
49-
| insert | Boolean | false | 插入模式,可选值,ture:弹窗模式;false:插入模式;默认为插入模式 |
49+
| insert | Boolean | false | 插入模式,可选值,ture:插入模式;false:弹窗模式;默认为插入模式 |
5050
| selected | Array |- | 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}] |
51-
|showMonth |Boolean | false | 是否显示月份为背景 |
51+
|showMonth | Boolean | true | 是否显示月份为背景 |
5252

5353
### 事件说明
5454

src/components/uni-calendar/uni-calendar.vue

Lines changed: 91 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,27 @@
5757
</view>
5858
</template>
5959

60-
<script>
60+
<script>
6161
import Calendar from './util.js';
62-
import uniCalendarItem from './uni-calendar-item.vue'
63-
/**
64-
* Calendar 日历
65-
* @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等
66-
* @tutorial https://ext.dcloud.net.cn/plugin?id=56
67-
* @property {String} date 自定义当前时间,默认为今天
68-
* @property {Boolean} lunar 显示农历
69-
* @property {String} startDate 日期选择范围-开始日期
70-
* @property {String} endDate 日期选择范围-结束日期
71-
* @property {Boolean} range 范围选择
72-
* @property {Boolean} insert = [true|false] 插入模式,默认为false
73-
* @value true 弹窗模式
74-
* @value false 插入模式
75-
* @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
76-
* @property {Boolean} showMonth 是否选择月份为背景
77-
* @event {Function} change 日期改变,`insert :ture` 时生效
78-
* @event {Function} confirm 确认选择`insert :false` 时生效
79-
* @event {Function} monthSwitch 切换月份时触发
80-
* @example <uni-calendar :insert="true":lunar="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" />
62+
import uniCalendarItem from './uni-calendar-item.vue'
63+
/**
64+
* Calendar 日历
65+
* @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等
66+
* @tutorial https://ext.dcloud.net.cn/plugin?id=56
67+
* @property {String} date 自定义当前时间,默认为今天
68+
* @property {Boolean} lunar 显示农历
69+
* @property {String} startDate 日期选择范围-开始日期
70+
* @property {String} endDate 日期选择范围-结束日期
71+
* @property {Boolean} range 范围选择
72+
* @property {Boolean} insert = [true|false] 插入模式,默认为false
73+
* @value true 弹窗模式
74+
* @value false 插入模式
75+
* @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
76+
* @property {Boolean} showMonth 是否选择月份为背景
77+
* @event {Function} change 日期改变,`insert :ture` 时生效
78+
* @event {Function} confirm 确认选择`insert :false` 时生效
79+
* @event {Function} monthSwitch 切换月份时触发
80+
* @example <uni-calendar :insert="true":lunar="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" />
8181
*/
8282
export default {
8383
components: {
@@ -113,7 +113,7 @@
113113
insert: {
114114
type: Boolean,
115115
default: true
116-
},
116+
},
117117
showMonth: {
118118
type: Boolean,
119119
default: true
@@ -137,45 +137,68 @@
137137
created() {
138138
// 获取日历方法实例
139139
this.cale = new Calendar({
140-
date: this.date,
140+
// date: new Date(),
141141
selected: this.selected,
142142
startDate: this.startDate,
143143
endDate: this.endDate,
144144
range: this.range,
145145
})
146-
this.init(this.cale.date.fullDate)
146+
console.log(this.cale.date.fullDate);
147+
// 选中某一天
148+
this.cale.setDate(this.date)
149+
this.init(this.cale.selectDate.fullDate)
150+
// this.setDay
147151
},
148152
methods: {
149153
// 取消穿透
150-
clean() {},
154+
clean() {},
155+
/**
156+
* 初始化日期显示
157+
* @param {Object} date
158+
*/
151159
init(date) {
152160
this.weeks = this.cale.weeks
153161
this.nowDate = this.calendar = this.cale.getInfo(date)
154-
},
162+
},
163+
/**
164+
* 打开日历弹窗
165+
*/
155166
open() {
156167
this.show = true
157-
this.$nextTick(() => {
158-
setTimeout(()=>{
159-
this.aniMaskShow = true
160-
},50)
168+
this.$nextTick(() => {
169+
setTimeout(() => {
170+
this.aniMaskShow = true
171+
}, 50)
161172
})
162-
},
173+
},
174+
/**
175+
* 关闭日历弹窗
176+
*/
163177
close() {
164178
this.aniMaskShow = false
165179
this.$nextTick(() => {
166180
setTimeout(() => {
167181
this.show = false
168182
}, 300)
169183
})
170-
},
184+
},
185+
/**
186+
* 确认按钮
187+
*/
171188
confirm() {
172189
this.setEmit('confirm')
173190
this.close()
174-
},
191+
},
192+
/**
193+
* 变化触发
194+
*/
175195
change() {
176196
if (!this.insert) return
177197
this.setEmit('change')
178-
},
198+
},
199+
/**
200+
* 选择月份触发
201+
*/
179202
monthSwitch() {
180203
let {
181204
year,
@@ -185,7 +208,11 @@
185208
year,
186209
month: Number(month)
187210
})
188-
},
211+
},
212+
/**
213+
* 派发事件
214+
* @param {Object} name
215+
*/
189216
setEmit(name) {
190217
let {
191218
year,
@@ -204,32 +231,51 @@
204231
lunar,
205232
extraInfo: extraInfo || {}
206233
})
207-
},
234+
},
235+
/**
236+
* 选择天触发
237+
* @param {Object} weeks
238+
*/
208239
choiceDate(weeks) {
209240
if (weeks.disable) return
210241
this.calendar = weeks
211242
// 设置多选
212243
this.cale.setMultiple(this.calendar.fullDate)
213244
this.weeks = this.cale.weeks
214245
this.change()
215-
},
246+
},
247+
/**
248+
* 回到今天
249+
*/
216250
backtoday() {
217-
this.cale.setDate(this.date)
251+
console.log(this.cale.getDate(new Date()).fullDate);
252+
let date = this.cale.getDate(new Date()).fullDate
253+
this.cale.setDate(date)
218254
this.weeks = this.cale.weeks
219-
this.nowDate = this.calendar = this.cale.getInfo(this.date)
255+
this.nowDate = this.calendar = this.cale.getInfo(date)
220256
this.change()
221-
},
257+
},
258+
/**
259+
* 上个月
260+
*/
222261
pre() {
223262
const preDate = this.cale.getDate(this.nowDate.fullDate, -1, 'month').fullDate
224263
this.setDate(preDate)
225264
this.monthSwitch()
226265
227-
},
266+
},
267+
/**
268+
* 下个月
269+
*/
228270
next() {
229271
const nextDate = this.cale.getDate(this.nowDate.fullDate, +1, 'month').fullDate
230272
this.setDate(nextDate)
231273
this.monthSwitch()
232-
},
274+
},
275+
/**
276+
* 设置日期
277+
* @param {Object} date
278+
*/
233279
setDate(date) {
234280
this.cale.setDate(date)
235281
this.weeks = this.cale.weeks
@@ -394,9 +440,10 @@
394440
border-bottom-color: #F5F5F5;
395441
border-bottom-style: solid;
396442
border-bottom-width: 1px;
397-
}
398-
.uni-calendar__weeks-day-text {
399-
font-size: 14px;
443+
}
444+
445+
.uni-calendar__weeks-day-text {
446+
font-size: 14px;
400447
}
401448
402449
.uni-calendar__box {

src/components/uni-calendar/util.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Calendar {
99
range
1010
} = {}) {
1111
// 当前日期
12-
this.date = this.getDate(date) // 当前初入日期
12+
this.date = this.getDate(new Date()) // 当前初入日期
1313
// 打点信息
1414
this.selected = selected || [];
1515
// 范围开始
@@ -25,8 +25,15 @@ class Calendar {
2525
}
2626
// 每周日期
2727
this.weeks = {}
28-
29-
this._getWeek(this.date.fullDate)
28+
// this._getWeek(this.date.fullDate)
29+
}
30+
/**
31+
* 设置日期
32+
* @param {Object} date
33+
*/
34+
setDate(date) {
35+
this.selectDate = this.getDate(date)
36+
this._getWeek(this.selectDate.fullDate)
3037
}
3138

3239
/**
@@ -89,6 +96,7 @@ class Calendar {
8996
*/
9097
_currentMonthDys(dateData, full) {
9198
let dateArr = []
99+
console.log(this.date);
92100
let fullDate = this.date.fullDate
93101
for (let i = 1; i <= dateData; i++) {
94102
let isinfo = false
@@ -164,13 +172,7 @@ class Calendar {
164172
}
165173
return dateArr
166174
}
167-
/**
168-
* 设置日期
169-
* @param {Object} date
170-
*/
171-
setDate(date) {
172-
this._getWeek(date)
173-
}
175+
174176
/**
175177
* 获取当前日期详情
176178
* @param {Object} date
@@ -245,7 +247,7 @@ class Calendar {
245247
* 设置打点
246248
*/
247249
setSelectInfo(data, value) {
248-
this.selected = value
250+
this.selected = value
249251
this._getWeek(data)
250252
}
251253

0 commit comments

Comments
 (0)