Skip to content

Commit 5170aeb

Browse files
committed
refactor(CalendarTime): 添加 CalendarTime 界面布局
1 parent 65c9e9d commit 5170aeb

File tree

3 files changed

+63
-38
lines changed

3 files changed

+63
-38
lines changed

src/calendar/Calendar.tsx

+11-8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import languageUtil, { type LanguageEntityType } from './language';
4242
// hooks
4343
import { useExpose, useMountedOrActivated, useRect } from './hooks';
4444
import CalendarDate from './CalendarDate';
45+
import CalendarTime from './CalendarTime';
4546

4647
export const calendarProps = {
4748
themeColor: {
@@ -550,14 +551,16 @@ export default defineComponent({
550551
);
551552

552553
const renderTimePicker = () => {
553-
// return (<time-picker
554-
// v-if="pickerType !== 'date'"
555-
// :show="!isShowCalendar"
556-
// :default-time="currDateTime"
557-
// :calendarDate="checkedDate"
558-
// v-bind="{ ...$props, ...$attrs }"
559-
// @change="timeChange"
560-
// ></time-picker>)
554+
if (props.pickerType !== 'date') {
555+
return (
556+
<CalendarTime
557+
show={!isShowCalendar.value}
558+
defaultTime={currDateTime.value}
559+
calendarDate={checkedDate.value}
560+
onChange={timeChange}
561+
/>
562+
);
563+
}
561564
};
562565

563566
const renderYearMonthPicker = () => {

src/calendar/CalendarDate.tsx

+11-8
Original file line numberDiff line numberDiff line change
@@ -827,17 +827,20 @@ export default defineComponent({
827827
return (
828828
<div
829829
class={`calendar_day ${
830-
isFirstDayOfMonth(date, i) &&
831-
(props.firstDayOfMonthClassName || 'calendar_first_today')
830+
isFirstDayOfMonth(date, i)
831+
? props.firstDayOfMonthClassName || 'calendar_first_today'
832+
: ''
832833
} ${
833-
isToday(date) && (props.todayClassName || 'calendar_day_today')
834+
isToday(date) ? props.todayClassName || 'calendar_day_today' : ''
834835
} ${
835-
isCheckedDay(date) &&
836-
(props.checkedDayClassName || 'calendar_day_checked')
836+
isCheckedDay(date)
837+
? props.checkedDayClassName || 'calendar_day_checked'
838+
: ''
837839
} ${
838-
isNotCurrentMonthDay(date, i) &&
839-
(props.notCurrentMonthDayClassName || 'calendar_day_not')
840-
} ${markDateColor(date, 'circle') && 'calendar_mark_circle'}`}
840+
isNotCurrentMonthDay(date, i)
841+
? props.notCurrentMonthDayClassName || 'calendar_day_not'
842+
: ''
843+
} ${markDateColor(date, 'circle') ? 'calendar_mark_circle' : ''}`}
841844
style={{ 'border-color': markDateColor(date, 'circle') }}
842845
>
843846
{dayEle}

src/calendar/CalendarTime.tsx

+41-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import {
77
watch,
88
} from 'vue';
99
import { CalendarDateType } from './types';
10-
import { checkPlatform, makeDateProp, makeNumberProp } from './utils';
10+
import {
11+
checkPlatform,
12+
fillNumber,
13+
makeDateProp,
14+
makeNumberProp,
15+
} from './utils';
1116

1217
export const calendarTimeProps = {
1318
show: Boolean,
@@ -191,27 +196,6 @@ export default defineComponent({
191196
(index === 0 && time === checkedDate.value.hours) ||
192197
(index === 1 && time === checkedDate.value.minutes);
193198

194-
// 校验时间范围
195-
const checkTimeRange = (range: string) => {
196-
if (!range) return;
197-
const timeArr = range.split('-');
198-
if (timeArr.length === 0 || timeArr.length > 2) return false;
199-
200-
return timeArr.every((time) => {
201-
const mhArr = time.split(':');
202-
if (mhArr.length === 0 || mhArr.length > 2) return false;
203-
204-
// 校验单个时间是否符合规范 00:00 - 24:00
205-
if (parseInt(mhArr[0], 10) < 0 || parseInt(mhArr[0], 10) > 24)
206-
return false;
207-
if (parseInt(mhArr[1], 10) < 0 || parseInt(mhArr[1], 10) > 59)
208-
return false;
209-
if (parseInt(mhArr[0], 10) === 24 && parseInt(mhArr[1], 10) > 0)
210-
return false;
211-
return true;
212-
});
213-
};
214-
215199
watch(
216200
() => props.defaultTime,
217201
(val) => {
@@ -256,5 +240,40 @@ export default defineComponent({
256240
},
257241
{ immediate: true }
258242
);
243+
244+
const renderTimeItem = (time: number[], index: number) =>
245+
time.map((item, j) => (
246+
<div
247+
class={`time_item ${
248+
isBeSelectedTime(item, index) ? 'time_item_show' : ''
249+
} ${hashClass.value} ${
250+
formatDisabledDate(item, index) ? 'time-disabled' : ''
251+
}`}
252+
key={index + j}
253+
>
254+
{fillNumber(item)}
255+
</div>
256+
));
257+
258+
const renderCalendarTime = () => (
259+
<div class="time_body" style={{ display: props.show ? 'block' : 'none' }}>
260+
<div class="time_group">
261+
{timeArray.value.map((item, index) => (
262+
<div
263+
class="time_content"
264+
id={hashID.value[index]}
265+
key={index}
266+
onTouchstart={timeTouchStart}
267+
onTouchmove={(e) => timeTouchMove(e, index)}
268+
onTouchend={(e) => timeTouchEnd(e, index)}
269+
>
270+
{renderTimeItem(item, index)}
271+
</div>
272+
))}
273+
</div>
274+
</div>
275+
);
276+
277+
return () => renderCalendarTime();
259278
},
260279
});

0 commit comments

Comments
 (0)