Skip to content

Commit 43deeb7

Browse files
authored
fix(calendar-view): [calendar-view] modify the configuration of calendar view hours, minutes, and seconds, and adding an attribute (#2932)
* fix: modify the configuration of calendar view hours, minutes, and seconds * feat(calendar-view): add whether to display button properties on the mobile first * fix: revise the title to include line breaks in both Chinese and English
1 parent 0577809 commit 43deeb7

File tree

6 files changed

+101
-21
lines changed

6 files changed

+101
-21
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ export default {
171171
mode: ['pc', 'mobile-first'],
172172
pcDemo: 'basic-usage',
173173
mfDemo: 'basic-usage'
174+
},
175+
{
176+
name: 'show-back-today',
177+
type: 'boolean',
178+
defaultValue: 'true',
179+
desc: {
180+
'zh-CN': '是否展示左上侧按钮显示,默认展示',
181+
'en-US': 'Should the upper left button be displayed, Default Display'
182+
},
183+
meta: {
184+
stable: '3.22.0'
185+
},
186+
mode: ['mobile-first'],
187+
mfDemo: 'calendar-mode'
174188
}
175189
],
176190
events: [

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<template>
2-
<tiny-calendar-view :events="eventslist" :year="2023" :month="6" :modes="['month', 'timeline', 'schedule']">
2+
<tiny-calendar-view
3+
:show-back-today="false"
4+
:events="eventslist"
5+
:year="2023"
6+
:month="6"
7+
:modes="['month', 'timeline', 'schedule']"
8+
>
39
</tiny-calendar-view>
410
</template>
511

examples/sites/demos/mobile-first/app/calendar-view/webdoc/calendar-view.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export default {
2222
},
2323
desc: {
2424
'zh-CN':
25-
'<p>通过 <code>mode</code> 属性指定以年的形式显示,将展示当年的每个月份。可选值有 <code>month</code> / <code>timeline</code> / <code>schedule</code>。</p>\n',
25+
'<p>通过 <code>mode</code> 属性指定以年的形式显示,将展示当年的每个月份。可选值有 <code>month</code> / <code>timeline</code> / <code>schedule</code>。通过<code>show-back-today</code> 属性控制左侧按钮显示。</p>\n',
2626
'en-US':
27-
'<p>The <code>mode</code> attribute specifies that each month of the current year is displayed. The options are <code>month</code> / <code>timeline</code> / <code>schedule</code>. </p>\n'
27+
'<p>The <code>mode</code> attribute specifies that each month of the current year is displayed. The options are <code>month</code> / <code>timeline</code> / <code>schedule</code>. Control the display of the left button through the<code>show back today</code>attribute.</p>\n'
2828
},
2929
codeFiles: ['calendar-mode.vue']
3030
},

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

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,31 @@ export const parseDate = (time) => {
104104
} else {
105105
date = new Date()
106106
}
107-
108-
return {
109-
year: date.getFullYear(),
110-
month: date.getMonth() + 1,
111-
day: date.getDate(),
112-
hours: date.getHours(),
113-
minutes: date.getMinutes(),
114-
seconds: date.getSeconds()
107+
// 识别无时分秒的日期时间
108+
const timeParts = hasNoTime(time)
109+
let timesPartsOne = {}
110+
let timesPartsTwo = {}
111+
if (!timeParts.hours) {
112+
timesPartsOne = {
113+
year: timeParts.year,
114+
month: timeParts.month,
115+
day: timeParts.day,
116+
hours: 0,
117+
minutes: 0,
118+
seconds: 0
119+
}
120+
} else {
121+
timesPartsTwo = {
122+
year: date.getFullYear(),
123+
month: date.getMonth() + 1,
124+
day: date.getDate(),
125+
hours: date.getHours(),
126+
minutes: date.getMinutes(),
127+
seconds: date.getSeconds()
128+
}
115129
}
130+
const timePartsList = Object.assign(timesPartsOne, timesPartsTwo)
131+
return timePartsList
116132
}
117133

118134
export const computedCalendar =
@@ -160,6 +176,36 @@ const getCalendarItem = function (item, props, isFunction, type, isNext, isLast)
160176
return res
161177
}
162178

179+
const hasNoTime = (date) => {
180+
const datetimeStr = date
181+
let hoursTime = 0
182+
let minutesTime = 0
183+
let secondsTime = 0
184+
const [datePart, timePart] = datetimeStr.split(' ')
185+
const [year, month, day] = datePart && datePart.split('-')
186+
if (timePart) {
187+
const [hours, minutes, seconds] = timePart && timePart.split(':')
188+
hoursTime = hours
189+
minutesTime = minutes
190+
secondsTime = seconds
191+
}
192+
// 提取时间
193+
return {
194+
year: Number(year),
195+
month: Number(month),
196+
day: Number(day),
197+
hours: hoursTime,
198+
minutes: minutesTime,
199+
seconds: secondsTime
200+
}
201+
}
202+
// 时间转GMT8
203+
const timesToGMT8 = (date) => {
204+
const originalDate = new Date(date)
205+
const gmt8 = new Date(originalDate.getTime() + 15 * 60 * 60 * 1000)
206+
return gmt8
207+
}
208+
163209
export const handleEvents =
164210
({ props, state }) =>
165211
() => {
@@ -197,14 +243,23 @@ export const handleEvents =
197243
([lastYear, +state.activeYear, nextYear].includes(endYear) &&
198244
[lastMon, +state.activeMonth, nextMon].includes(endMonth))
199245
) {
200-
item.start = getTime(item.start)
201-
item.end = getTime(item.end)
202-
item.startTime = makeUpZero(startHours) + ':' + makeUpZero(startMinutes) + ':' + makeUpZero(startSeconds)
203-
item.endTime = makeUpZero(endHours) + ':' + makeUpZero(endMinutes) + ':' + makeUpZero(endSeconds)
246+
const timeStartPart = hasNoTime(item.start)
247+
const timeEndPart = hasNoTime(item.end)
248+
249+
item.start = timeStartPart.hours ? getTime(item.start) : timesToGMT8(item.start)
250+
item.end = timeEndPart.hours ? getTime(item.end) : timesToGMT8(item.end)
251+
252+
item.startTime = timeStartPart.hours
253+
? makeUpZero(startHours) + ':' + makeUpZero(startMinutes) + ':' + makeUpZero(startSeconds)
254+
: ''
255+
item.endTime = timeEndPart.hours
256+
? makeUpZero(endHours) + ':' + makeUpZero(endMinutes) + ':' + makeUpZero(endSeconds)
257+
: ''
258+
204259
item.startDay = startYear + '-' + startMonth + '-' + startDay
205260
item.endDay = endYear + '-' + endMonth + '-' + endDay
206-
const startTimestamp = getTime(startYear + '-' + startMonth + '-' + startDay)
207-
const endTimestamp = getTime(endYear + '-' + endMonth + '-' + endDay)
261+
const startTimestamp = getTime(item.startDay)
262+
const endTimestamp = getTime(item.endDay)
208263
const days = Math.abs(endTimestamp - startTimestamp) / dayMillisecond
209264
item.dayNumber = days >= 1 ? days + 1 : 1
210265

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export const calendarViewProps = {
7676
multiSelect: {
7777
type: Boolean,
7878
default: false
79+
},
80+
showBackToday: {
81+
type: Boolean,
82+
default: true
7983
}
8084
}
8185

packages/vue/src/calendar-view/src/mobile-first.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
</template>
2121
</tiny-tooltip>
2222
<div data-tag="tiny-calendar-view-today" class="flex justify-around items-center mb-3">
23-
<tiny-button @click="toToday">{{ t('ui.calendarView.backToday') }}</tiny-button>
23+
<tiny-button v-if="showBackToday" @click="toToday">{{ t('ui.calendarView.backToday') }}</tiny-button>
2424
<tiny-date-picker
2525
v-model="state.currentDate"
26-
class="ml-5 shrink-0"
26+
:class="[showBackToday ? 'ml-5' : '', 'shrink-0']"
2727
shape="filter"
2828
type="month"
2929
:clearable="false"
@@ -292,7 +292,7 @@
292292
:key="idx"
293293
class="py-1.5 h-auto border border-color-border-separator rounded mb-2 shadow-sm"
294294
>
295-
<div class="px-1.5 mb-1.5 border-l-2 border-color-brand">{{ event.title }}</div>
295+
<div class="px-1.5 mb-1.5 border-l-2 border-color-brand break-all">{{ event.title }}</div>
296296
<div class="mb-1.5 px-2 text-color-text-placeholder">
297297
{{ getEventShowTime('start', event, date.value) }} - {{ getEventShowTime('end', event, date.value) }}
298298
</div>
@@ -376,7 +376,8 @@ export default defineComponent({
376376
'events',
377377
'height',
378378
'mark-color',
379-
'multi-select'
379+
'multi-select',
380+
'showBackToday'
380381
],
381382
setup(props, context) {
382383
return setup({

0 commit comments

Comments
 (0)