Skip to content

Commit 236e0c8

Browse files
committed
feat:日历视图支持点击事件
1 parent 28016cb commit 236e0c8

File tree

17 files changed

+102
-19
lines changed

17 files changed

+102
-19
lines changed

examples/sites/demos/apis/calendar-view.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,16 @@ export default {
238238
pcDemo: 'multi-select',
239239
mfDemo: 'multi-select'
240240
},
241+
{
242+
name: 'date-click',
243+
desc: {
244+
'zh-CN': '日期点击事件,回调参数为当前点击日期和日程事件',
245+
'en-US': 'Date click event, The callback parameters are the current click date and schedule event'
246+
},
247+
mode: ['pc', 'mobile-first'],
248+
pcDemo: 'calendar-event',
249+
mfDemo: 'calendar-event'
250+
},
241251
{
242252
name: 'week-change',
243253
desc: {

examples/sites/demos/mobile-first/app/calendar-view/calendar-event.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
:events="eventslist"
44
:year="2023"
55
:month="5"
6+
@date-click="dateClick"
67
@prev-week-click="prevWeekClick"
78
@next-week-click="nextWeekClick"
89
@week-change="weekChange"
@@ -25,6 +26,9 @@ export default {
2526
}
2627
},
2728
methods: {
29+
dateClick(date, events) {
30+
TinyModal.message({ message: `点击日期: ${date};日程事件:${JSON.stringify(events)}`, status: 'info' })
31+
},
2832
prevWeekClick(date) {
2933
TinyModal.message({ message: `上一周按钮点击事件: ${date[0].value}`, status: 'info' })
3034
},

examples/sites/demos/pc/app/calendar-view/calendar-event-composition-api.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
:events="eventslist"
44
:year="2023"
55
:month="5"
6+
@date-click="dateClick"
67
@prev-week-click="prevWeekClick"
78
@next-week-click="nextWeekClick"
89
@week-change="weekChange"
@@ -19,6 +20,10 @@ import { TinyCalendarView, TinyModal } from '@opentiny/vue'
1920
2021
const eventslist = ref([])
2122
23+
const dateClick = (date, events) => {
24+
TinyModal.message({ message: `点击日期: ${date};日程事件:${JSON.stringify(events)}`, status: 'info' })
25+
}
26+
2227
const prevWeekClick = (date) => {
2328
TinyModal.message({ message: `上一周按钮点击事件: ${date[0].value}`, status: 'info' })
2429
}

examples/sites/demos/pc/app/calendar-view/calendar-event.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ test('事件', async ({ page }) => {
1111
const rightSvg = page.locator('.header-right > .tiny-svg')
1212
const mode = page.locator('label').nth(2)
1313
const modalVal = page.getByText('模式切换事件:schedule')
14+
const date = page.getByText('30周一')
15+
const dateVal = page.locator('div').filter({ hasText: '点击日期: 2022-5-30;日程事件:[]' }).nth(1)
16+
1417
await timeBtn.click()
1518
await page.waitForTimeout(100)
1619
await leftYear.click()
@@ -27,4 +30,7 @@ test('事件', async ({ page }) => {
2730
await mode.click()
2831
await page.waitForTimeout(100)
2932
await expect(modalVal).toBeVisible()
33+
await date.click()
34+
await page.waitForTimeout(100)
35+
await expect(dateVal).toBeVisible()
3036
})

examples/sites/demos/pc/app/calendar-view/calendar-event.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
:events="eventslist"
44
:year="2023"
55
:month="5"
6+
@date-click="dateClick"
67
@prev-week-click="prevWeekClick"
78
@next-week-click="nextWeekClick"
89
@week-change="weekChange"
@@ -26,6 +27,9 @@ export default {
2627
}
2728
},
2829
methods: {
30+
dateClick(date, events) {
31+
TinyModal.message({ message: `点击日期: ${date};日程事件:${JSON.stringify(events)}`, status: 'info' })
32+
},
2933
prevWeekClick(date) {
3034
TinyModal.message({ message: `上一周按钮点击事件: ${date[0].value}`, status: 'info' })
3135
},

examples/sites/demos/pc/app/calendar-view/webdoc/calendar-view.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export default {
167167
desc: {
168168
'zh-CN':
169169
'<p>日历抛出的事件有以下这些:</p>\n' +
170+
'<p>date-click:日期点击事件</p>\n' +
170171
'<p>new-schedule:新增日程按钮点击事件</p>\n' +
171172
'<p>selected-date-change:选中日期改变事件</p>\n' +
172173
'<p>prev-week-click:上一周按钮点击事件</p>\n' +
@@ -177,6 +178,7 @@ export default {
177178
'<p>mode-change:模式切换事件</p>',
178179
'en-US':
179180
'<p>Calendar throws the following events:</p>\n' +
181+
'<p>date-click:日期点击事件: Date click event</p>\n' +
180182
'<p>new-schedule: Add a schedule button click event</p>\n' +
181183
'<p>selected-date-change: selected date change event</p>\n' +
182184
'<p>prev-week-click: button click event of the last week</p>\n' +
@@ -371,11 +373,12 @@ export default {
371373
value: true
372374
},
373375
description:
374-
'日历抛出的事件包括:new-schedule、selected-date-change、prev-week-click、next-week-click、week-change、year-change、month-change、mode-change。',
376+
'日历抛出的事件包括:date-click、new-schedule、selected-date-change、prev-week-click、next-week-click、week-change、year-change、month-change、mode-change。',
375377
cloud: {
376378
value: false
377379
},
378380
apis: [
381+
'date-click',
379382
'new-schedule',
380383
'selected-date-change',
381384
'prev-week-click',

packages/renderless/src/calendar-view/index.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,19 @@ function splitEvent(props, event) {
307307
return result
308308
}
309309

310+
export const computedSelectDay = ({ state }) =>
311+
(day) => {
312+
if (!day || !day.value || day.disabled) return false
313+
314+
if (state.multiSelect) {
315+
return state.selectedDates.includes(day.value)
316+
} else{
317+
return state.selectedDate === day.value
318+
}
319+
}
320+
310321
export const selectDay =
311-
({ state, emit }) =>
322+
({ props, state, emit, api }) =>
312323
(day, i) => {
313324
if (!day || !day.value || day.disabled) return
314325

@@ -323,9 +334,11 @@ export const selectDay =
323334
state.selectedDates.push(date)
324335
}
325336

337+
const dateEvent = dealEvents(props, api, state.selectedDates)
338+
326339
emit('update:modelValue', state.selectedDates)
327340
emit('selected-date-change', state.selectedDates)
328-
emit('date-click', date)
341+
emit('date-click', state.selectedDates, dateEvent)
329342
} else {
330343
if (day.isNext) {
331344
const { year, month } = nextMonth(state.activeYear, state.activeMonth)
@@ -342,12 +355,26 @@ export const selectDay =
342355
state.selectedDate =
343356
day.value.toString().length > 2 ? day.value : `${state.activeYear}-${state.activeMonth}-${day.value}`
344357
state.showSelectedDateEvents = true
358+
359+
const dateEvent = dealEvents(props, api, [state.selectedDate])
345360

346361
emit('update:modelValue', state.selectedDate)
347-
emit('date-click', state.selectedDate)
362+
emit('date-click', state.selectedDate, dateEvent[0])
348363
}
349364
}
350365

366+
const dealEvents = (props, api, date) => {
367+
return date.map(item => {
368+
let event = api.getEventByTime(item, props._constants.DAY_START_TIME, props._constants.DAY_END_TIME)
369+
event.forEach(e => {
370+
delete e.dayArr;
371+
delete e.dayNumber;
372+
});
373+
return event
374+
})
375+
376+
}
377+
351378
export const getEventByMonth =
352379
({ state }) =>
353380
(year, month) => {

packages/renderless/src/calendar-view/vue.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
computedCalendar,
33
handleEvents,
4+
computedSelectDay,
45
selectDay,
56
getEventByTime,
67
isToday,
@@ -47,6 +48,7 @@ export const api = [
4748
'isToday',
4849
'dateIsToday',
4950
'getEventByTime',
51+
'computedSelectDay',
5052
'selectDay',
5153
'toToday',
5254
'getPrevWeek',
@@ -270,7 +272,8 @@ const initApi = ({ vm, api, state, t, props, emit, nextTick }) => {
270272
computeCascaderOptions: computeCascaderOptions(t),
271273
isToday: isToday(state),
272274
dateIsToday: dateIsToday(),
273-
selectDay: selectDay({ state, emit }),
275+
selectDay: selectDay({ props, state, emit, api }),
276+
computedSelectDay: computedSelectDay({ state }),
274277
getEventByTime: getEventByTime({ props, state }),
275278
toToday: toToday({ state, api, nextTick }),
276279
getAllWednesdaysInYear: getAllWednesdaysInYear({ state }),

packages/theme-saas/src/calendar-view/index.less

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
>li{
6464
@apply leading-10;
65+
@apply cursor-pointer;
6566

6667
>span{
6768
@apply text-sm;
@@ -351,14 +352,19 @@
351352

352353
>li{
353354
@apply leading-10;
355+
@apply cursor-pointer;
354356

355357
.date{
356358
@apply relative;
357359
@apply ~'mr-2.5';
358360
@apply text-base;
359361
@apply text-color-text-primary;
360362

361-
&.is-today{
363+
&.is-today {
364+
@apply text-color-brand;
365+
}
366+
367+
&.current {
362368
@apply text-color-brand;
363369
}
364370
}
@@ -407,7 +413,11 @@
407413
.week-day{
408414
@apply text-sm;
409415
@apply text-color-text-placeholder;
410-
&.is-today{
416+
&.is-today {
417+
@apply text-color-brand;
418+
}
419+
420+
&.current {
411421
@apply text-color-brand;
412422
}
413423
}

packages/theme/src/base/reset.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@
159159

160160
// x 和 y 滚动条交汇处
161161
::-webkit-scrollbar-corner {
162-
background: var(--tv-color-bg-scrollbar-track);
162+
background: transparent;
163163
}
164164

165165
// 滚动条轨道
166166
::-webkit-scrollbar-track {
167-
background: var(--tv-color-bg-scrollbar-track);
167+
background: transparent;
168168
}
169169

170170
// 滚动滑块

0 commit comments

Comments
 (0)