Skip to content

Commit 7134220

Browse files
committed
优化日历组件
1 parent b98e97a commit 7134220

2 files changed

Lines changed: 73 additions & 23 deletions

File tree

components/uni-calendar/uni-calendar.vue

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,25 +225,6 @@
225225
let after = this.getWeek(this.getDate(afteryear, +1, 'month'));
226226
this.selectDay = canlender.month + '' + canlender.date + '';
227227
this.canlender = canlender;
228-
if (this.isSilde) {
229-
let isClick = '';
230-
if (this.isClick) {
231-
isClick = 'to-click';
232-
this.isClick = false;
233-
} else {
234-
isClick = 'change';
235-
}
236-
this.$emit(isClick, {
237-
year: canlender.year,
238-
month: canlender.month,
239-
date: canlender.date,
240-
lunar: canlender.lunar,
241-
clockinfo: canlender.clockinfo || {},
242-
fulldate: canlender.year + '-' + canlender.month + '-' + canlender.date
243-
});
244-
this.isSilde = false;
245-
}
246-
247228
if (this.slide === 'none') {
248229
// console.log(before);
249230
this.duration = 0;
@@ -264,8 +245,12 @@
264245
}
265246
this.selectDay = canlender.month + '' + canlender.date + '';
266247
this.hold = false;
248+
// console.log(this.canlender)
249+
this.setEmit(this.canlender);
267250
return;
268251
}
252+
this.setEmit(canlender);
253+
269254
this.currentIndex = index;
270255
271256
if (first && index === 1) {
@@ -293,6 +278,26 @@
293278
return;
294279
}
295280
},
281+
setEmit(canlender) {
282+
if (this.isSilde) {
283+
let isClick = '';
284+
if (this.isClick) {
285+
isClick = 'to-click';
286+
this.isClick = false;
287+
} else {
288+
isClick = 'change';
289+
}
290+
this.$emit(isClick, {
291+
year: canlender.year,
292+
month: canlender.month,
293+
date: canlender.date,
294+
lunar: canlender.lunar,
295+
clockinfo: canlender.clockinfo || {},
296+
fulldate: canlender.year + '-' + canlender.month + '-' + canlender.date
297+
});
298+
this.isSilde = false;
299+
}
300+
},
296301
/**
297302
* 计算阴历日期显示
298303
*/
@@ -616,7 +621,7 @@
616621
setTimeout(() => this.getQueryDom(1), 50);
617622
return;
618623
}
619-
console.log(e[0][index])
624+
// console.log(e[0][index])
620625
if (e[0][index]) {
621626
this.domHeihgt = e[0][index].height;
622627
}

pages/extUI/calendar/calendar.vue

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,34 @@
99
</view>
1010
</view>
1111
<button class="calendar-button" type="button" @click="open">打开日历</button>
12-
12+
<text v-if="timeData.lunar" class="calendar-title">已选日期</text>
13+
<view v-if="timeData.lunar" class="calendar-info">
14+
<view>当前选择时间 : {{timeData.fulldate}}</view>
15+
<view v-if="tags['lunar'].checked">农历日期 : {{timeData.year +
16+
'年' +
17+
timeData.month +
18+
'月' +
19+
timeData.date +
20+
'日 (' +
21+
timeData.lunar.astro +
22+
')'}}</view>
23+
<view v-if="tags['lunar'].checked"> {{
24+
timeData.lunar.gzYear +
25+
'年' +
26+
timeData.lunar.gzMonth +
27+
'月' +
28+
timeData.lunar.gzDay +
29+
'日 (' +
30+
timeData.lunar.Animal +
31+
'年)'
32+
}}
33+
{{ timeData.lunar.IMonthCn + timeData.lunar.IDayCn }}
34+
{{ timeData.lunar.isTerm ? timeData.lunar.Term : '' }}</view>
35+
</view>
1336
<view v-if="show" class="calendar-mask" @click="closeMask">
1437
<view class="calendar-box" @click.stop="">
15-
<uni-calendar :lunar="tags['lunar'].checked" :fixedHeihgt="tags['fixedHeihgt'].checked" :slide="slide" :disableBefore="tags['disableBefore'].checked" :start-date="startDate" :end-date="endDate" :date="date" />
38+
<uni-calendar :lunar="tags['lunar'].checked" :fixedHeihgt="tags['fixedHeihgt'].checked" :slide="slide" :disableBefore="tags['disableBefore'].checked" :start-date="startDate" :end-date="endDate" :date="date" @change="change" @to-click="toClick" />
39+
<button class="calendar-button-confirm" @click="confirm">确认选择日期</button>
1640
</view>
1741
</view>
1842
</view>
@@ -75,7 +99,8 @@
7599
slide: 'none',
76100
date: '',
77101
startDate: '',
78-
endDate: ''
102+
endDate: '',
103+
timeData: {}
79104
};
80105
},
81106
onLoad() {},
@@ -118,6 +143,17 @@
118143
this.date = '';
119144
}
120145
this.show = true;
146+
},
147+
change(e) {
148+
console.log('change 返回:', e.fulldate);
149+
this.timeData = e;
150+
},
151+
toClick(e) {
152+
console.log('点击事件', e.fulldate);
153+
this.timeData = e;
154+
},
155+
confirm() {
156+
this.show = false;
121157
}
122158
}
123159
};
@@ -211,6 +247,10 @@
211247
margin: 10upx 20upx;
212248
}
213249
250+
.calendar-info {
251+
padding: 0 20upx;
252+
}
253+
214254
.calendar-mask {
215255
position: fixed;
216256
top: 0;
@@ -227,5 +267,10 @@
227267
border-radius: 10upx;
228268
width: 100%;
229269
overflow: hidden;
270+
background: #fff;
271+
}
272+
273+
.calendar-button-confirm {
274+
margin: 10upx;
230275
}
231276
</style>

0 commit comments

Comments
 (0)