|
57 | 57 | </view>
|
58 | 58 | </template>
|
59 | 59 |
|
60 |
| -<script> |
| 60 | +<script> |
61 | 61 | 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" /> |
81 | 81 | */
|
82 | 82 | export default {
|
83 | 83 | components: {
|
|
113 | 113 | insert: {
|
114 | 114 | type: Boolean,
|
115 | 115 | default: true
|
116 |
| - }, |
| 116 | + }, |
117 | 117 | showMonth: {
|
118 | 118 | type: Boolean,
|
119 | 119 | default: true
|
|
137 | 137 | created() {
|
138 | 138 | // 获取日历方法实例
|
139 | 139 | this.cale = new Calendar({
|
140 |
| - date: this.date, |
| 140 | + // date: new Date(), |
141 | 141 | selected: this.selected,
|
142 | 142 | startDate: this.startDate,
|
143 | 143 | endDate: this.endDate,
|
144 | 144 | range: this.range,
|
145 | 145 | })
|
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 |
147 | 151 | },
|
148 | 152 | methods: {
|
149 | 153 | // 取消穿透
|
150 |
| - clean() {}, |
| 154 | + clean() {}, |
| 155 | + /** |
| 156 | + * 初始化日期显示 |
| 157 | + * @param {Object} date |
| 158 | + */ |
151 | 159 | init(date) {
|
152 | 160 | this.weeks = this.cale.weeks
|
153 | 161 | this.nowDate = this.calendar = this.cale.getInfo(date)
|
154 |
| - }, |
| 162 | + }, |
| 163 | + /** |
| 164 | + * 打开日历弹窗 |
| 165 | + */ |
155 | 166 | open() {
|
156 | 167 | 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) |
161 | 172 | })
|
162 |
| - }, |
| 173 | + }, |
| 174 | + /** |
| 175 | + * 关闭日历弹窗 |
| 176 | + */ |
163 | 177 | close() {
|
164 | 178 | this.aniMaskShow = false
|
165 | 179 | this.$nextTick(() => {
|
166 | 180 | setTimeout(() => {
|
167 | 181 | this.show = false
|
168 | 182 | }, 300)
|
169 | 183 | })
|
170 |
| - }, |
| 184 | + }, |
| 185 | + /** |
| 186 | + * 确认按钮 |
| 187 | + */ |
171 | 188 | confirm() {
|
172 | 189 | this.setEmit('confirm')
|
173 | 190 | this.close()
|
174 |
| - }, |
| 191 | + }, |
| 192 | + /** |
| 193 | + * 变化触发 |
| 194 | + */ |
175 | 195 | change() {
|
176 | 196 | if (!this.insert) return
|
177 | 197 | this.setEmit('change')
|
178 |
| - }, |
| 198 | + }, |
| 199 | + /** |
| 200 | + * 选择月份触发 |
| 201 | + */ |
179 | 202 | monthSwitch() {
|
180 | 203 | let {
|
181 | 204 | year,
|
|
185 | 208 | year,
|
186 | 209 | month: Number(month)
|
187 | 210 | })
|
188 |
| - }, |
| 211 | + }, |
| 212 | + /** |
| 213 | + * 派发事件 |
| 214 | + * @param {Object} name |
| 215 | + */ |
189 | 216 | setEmit(name) {
|
190 | 217 | let {
|
191 | 218 | year,
|
|
204 | 231 | lunar,
|
205 | 232 | extraInfo: extraInfo || {}
|
206 | 233 | })
|
207 |
| - }, |
| 234 | + }, |
| 235 | + /** |
| 236 | + * 选择天触发 |
| 237 | + * @param {Object} weeks |
| 238 | + */ |
208 | 239 | choiceDate(weeks) {
|
209 | 240 | if (weeks.disable) return
|
210 | 241 | this.calendar = weeks
|
211 | 242 | // 设置多选
|
212 | 243 | this.cale.setMultiple(this.calendar.fullDate)
|
213 | 244 | this.weeks = this.cale.weeks
|
214 | 245 | this.change()
|
215 |
| - }, |
| 246 | + }, |
| 247 | + /** |
| 248 | + * 回到今天 |
| 249 | + */ |
216 | 250 | 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) |
218 | 254 | this.weeks = this.cale.weeks
|
219 |
| - this.nowDate = this.calendar = this.cale.getInfo(this.date) |
| 255 | + this.nowDate = this.calendar = this.cale.getInfo(date) |
220 | 256 | this.change()
|
221 |
| - }, |
| 257 | + }, |
| 258 | + /** |
| 259 | + * 上个月 |
| 260 | + */ |
222 | 261 | pre() {
|
223 | 262 | const preDate = this.cale.getDate(this.nowDate.fullDate, -1, 'month').fullDate
|
224 | 263 | this.setDate(preDate)
|
225 | 264 | this.monthSwitch()
|
226 | 265 |
|
227 |
| - }, |
| 266 | + }, |
| 267 | + /** |
| 268 | + * 下个月 |
| 269 | + */ |
228 | 270 | next() {
|
229 | 271 | const nextDate = this.cale.getDate(this.nowDate.fullDate, +1, 'month').fullDate
|
230 | 272 | this.setDate(nextDate)
|
231 | 273 | this.monthSwitch()
|
232 |
| - }, |
| 274 | + }, |
| 275 | + /** |
| 276 | + * 设置日期 |
| 277 | + * @param {Object} date |
| 278 | + */ |
233 | 279 | setDate(date) {
|
234 | 280 | this.cale.setDate(date)
|
235 | 281 | this.weeks = this.cale.weeks
|
|
394 | 440 | border-bottom-color: #F5F5F5;
|
395 | 441 | border-bottom-style: solid;
|
396 | 442 | 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; |
400 | 447 | }
|
401 | 448 |
|
402 | 449 | .uni-calendar__box {
|
|
0 commit comments