@tplc/wot 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/components/wd-calendar/index.scss +145 -58
- package/components/wd-calendar/types.ts +41 -23
- package/components/wd-calendar/wd-calendar.vue +130 -123
- package/components/wd-calendar-view/month/index.scss +65 -33
- package/components/wd-calendar-view/month/month.vue +113 -80
- package/components/wd-calendar-view/month/types.ts +1 -2
- package/components/wd-calendar-view/monthPanel/index.scss +15 -15
- package/components/wd-calendar-view/monthPanel/month-panel.vue +78 -64
- package/components/wd-calendar-view/monthPanel/types.ts +10 -58
- package/components/wd-calendar-view/types.ts +36 -12
- package/components/wd-calendar-view/utils.ts +36 -14
- package/components/wd-calendar-view/wd-calendar-view.vue +7 -7
- package/components/wd-calendar-view/year/index.scss +13 -18
- package/components/wd-calendar-view/year/types.ts +1 -2
- package/components/wd-calendar-view/year/year.vue +43 -25
- package/components/wd-calendar-view/yearPanel/index.scss +4 -4
- package/components/wd-calendar-view/yearPanel/types.ts +2 -2
- package/components/wd-calendar-view/yearPanel/year-panel.vue +41 -36
- package/components/wd-drop-menu/index.scss +45 -17
- package/components/wd-drop-menu/types.ts +3 -3
- package/components/wd-drop-menu/wd-drop-menu.vue +25 -61
- package/components/wd-drop-menu-item/index.scss +15 -15
- package/components/wd-drop-menu-item/types.ts +15 -18
- package/components/wd-drop-menu-item/wd-drop-menu-item.vue +54 -33
- package/package.json +1 -1
- package/types/components/common/dayjs.d.ts +26 -0
- package/types/components/wd-calendar/types.d.ts +18 -24
- package/types/components/wd-calendar/wd-calendar.vue.d.ts +24 -40
- package/types/components/wd-calendar-view/month/month.vue.d.ts +3 -11
- package/types/components/wd-calendar-view/month/types.d.ts +0 -4
- package/types/components/wd-calendar-view/monthPanel/month-panel.vue.d.ts +12 -18
- package/types/components/wd-calendar-view/monthPanel/types.d.ts +6 -48
- package/types/components/wd-calendar-view/types.d.ts +4 -11
- package/types/components/wd-calendar-view/utils.d.ts +12 -3
- package/types/components/wd-calendar-view/year/types.d.ts +0 -4
- package/types/components/wd-calendar-view/year/year.vue.d.ts +3 -11
- package/types/components/wd-cell/wd-cell.vue.d.ts +5 -5
- package/types/components/wd-col-picker/wd-col-picker.vue.d.ts +9 -9
- package/types/components/wd-datetime-picker/wd-datetime-picker.vue.d.ts +10 -10
- package/types/components/wd-datetime-picker-view/wd-datetime-picker-view.vue.d.ts +1 -1
- package/types/components/wd-drop-menu/types.d.ts +3 -3
- package/types/components/wd-drop-menu/wd-drop-menu.vue.d.ts +5 -5
- package/types/components/wd-drop-menu-item/types.d.ts +15 -27
- package/types/components/wd-drop-menu-item/wd-drop-menu-item.vue.d.ts +35 -46
- package/types/components/wd-floating-panel/wd-floating-panel.vue.d.ts +1 -1
- package/types/components/wd-form/wd-form.vue.d.ts +1 -1
- package/types/components/wd-form-item/wd-form-item.vue.d.ts +1 -1
- package/types/components/wd-grid-item/wd-grid-item.vue.d.ts +1 -1
- package/types/components/wd-input/wd-input.vue.d.ts +4 -4
- package/types/components/wd-keyboard/wd-keyboard.vue.d.ts +1 -1
- package/types/components/wd-notify/wd-notify.vue.d.ts +1 -1
- package/types/components/wd-number-keyboard/wd-number-keyboard.vue.d.ts +1 -1
- package/types/components/wd-picker/wd-picker.vue.d.ts +12 -12
- package/types/components/wd-picker-view/wd-picker-view.vue.d.ts +2 -2
- package/types/components/wd-select-picker/wd-select-picker.vue.d.ts +12 -12
- package/types/components/wd-signature/wd-signature.vue.d.ts +2 -2
- package/types/components/wd-steps/wd-steps.vue.d.ts +1 -1
- package/types/components/wd-swiper/wd-swiper.vue.d.ts +1 -1
- package/types/components/wd-tabs/wd-tabs.vue.d.ts +1 -1
- package/types/components/wd-textarea/wd-textarea.vue.d.ts +3 -3
- /package/components/wd-input/{placeholder.scss → placeholder.css} +0 -0
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
{{ title }}
|
|
5
5
|
</view>
|
|
6
6
|
<view class="wd-month-panel__weeks">
|
|
7
|
-
<view v-for="item in 7" :key="item" class="wd-month-panel__week">
|
|
7
|
+
<view v-for="item in 7" :key="item" class="wd-month-panel__week">
|
|
8
|
+
{{ weekLabel(item + firstDayOfWeek) }}
|
|
9
|
+
</view>
|
|
8
10
|
</view>
|
|
9
11
|
<scroll-view
|
|
10
12
|
:class="`wd-month-panel__container ${!!timeType ? 'wd-month-panel__container--time' : ''}`"
|
|
@@ -26,14 +28,15 @@
|
|
|
26
28
|
:range-prompt="rangePrompt"
|
|
27
29
|
:allow-same-day="allowSameDay"
|
|
28
30
|
:default-time="defaultTime"
|
|
29
|
-
:showTitle="index !== 0"
|
|
30
31
|
@change="handleDateChange"
|
|
31
32
|
/>
|
|
32
33
|
</view>
|
|
33
34
|
</scroll-view>
|
|
34
35
|
<view v-if="timeType" class="wd-month-panel__time">
|
|
35
36
|
<view v-if="type === 'datetimerange'" class="wd-month-panel__time-label">
|
|
36
|
-
<view class="wd-month-panel__time-text">
|
|
37
|
+
<view class="wd-month-panel__time-text">
|
|
38
|
+
{{ timeType === 'start' ? translate('startTime') : translate('endTime') }}
|
|
39
|
+
</view>
|
|
37
40
|
</view>
|
|
38
41
|
<view class="wd-month-panel__time-picker">
|
|
39
42
|
<wd-picker-view
|
|
@@ -56,18 +59,29 @@ export default {
|
|
|
56
59
|
options: {
|
|
57
60
|
addGlobalClass: true,
|
|
58
61
|
virtualHost: true,
|
|
59
|
-
styleIsolation: 'shared'
|
|
60
|
-
}
|
|
62
|
+
styleIsolation: 'shared',
|
|
63
|
+
},
|
|
61
64
|
}
|
|
62
65
|
</script>
|
|
63
66
|
|
|
64
67
|
<script lang="ts" setup>
|
|
65
|
-
import wdPickerView from '../../wd-picker-view/wd-picker-view.vue'
|
|
66
68
|
import { computed, ref, watch, onMounted } from 'vue'
|
|
67
|
-
import { debounce, isArray, isEqual, isNumber,
|
|
68
|
-
import {
|
|
69
|
+
import { debounce, isArray, isEqual, isNumber, requestAnimationFrame } from '../../common/util'
|
|
70
|
+
import {
|
|
71
|
+
compareMonth,
|
|
72
|
+
formatMonthTitle,
|
|
73
|
+
getMonthEndDay,
|
|
74
|
+
getMonths,
|
|
75
|
+
getTimeData,
|
|
76
|
+
getWeekLabel,
|
|
77
|
+
} from '../utils'
|
|
69
78
|
import Month from '../month/month.vue'
|
|
70
|
-
import {
|
|
79
|
+
import {
|
|
80
|
+
monthPanelProps,
|
|
81
|
+
type MonthInfo,
|
|
82
|
+
type MonthPanelTimeType,
|
|
83
|
+
type MonthPanelExpose,
|
|
84
|
+
} from './types'
|
|
71
85
|
import { useTranslate } from '../../composables/useTranslate'
|
|
72
86
|
import type { CalendarItem } from '../types'
|
|
73
87
|
|
|
@@ -85,7 +99,7 @@ const innerValue = ref<string | number | (number | null)[]>('') // 内部保存
|
|
|
85
99
|
|
|
86
100
|
const handleChange = debounce((value) => {
|
|
87
101
|
emit('change', {
|
|
88
|
-
value
|
|
102
|
+
value,
|
|
89
103
|
})
|
|
90
104
|
}, 50)
|
|
91
105
|
|
|
@@ -132,19 +146,20 @@ const weekLabel = computed(() => {
|
|
|
132
146
|
|
|
133
147
|
// 滚动区域的高度
|
|
134
148
|
const scrollHeight = computed(() => {
|
|
135
|
-
const scrollHeight: number = timeType.value
|
|
149
|
+
const scrollHeight: number = timeType.value
|
|
150
|
+
? (props.panelHeight || 378) - 125
|
|
151
|
+
: props.panelHeight || 378
|
|
136
152
|
return scrollHeight
|
|
137
153
|
})
|
|
138
154
|
|
|
139
155
|
// 月份日期和月份高度
|
|
140
156
|
const months = computed<MonthInfo[]>(() => {
|
|
141
|
-
return getMonths(props.minDate, props.maxDate).map((month
|
|
157
|
+
return getMonths(props.minDate, props.maxDate).map((month) => {
|
|
142
158
|
const offset = (7 + new Date(month).getDay() - props.firstDayOfWeek) % 7
|
|
143
159
|
const totalDay = getMonthEndDay(new Date(month).getFullYear(), new Date(month).getMonth() + 1)
|
|
144
|
-
const rows = Math.ceil((offset + totalDay) / 7)
|
|
145
160
|
return {
|
|
146
|
-
height:
|
|
147
|
-
date: month
|
|
161
|
+
height: (offset + totalDay > 35 ? 64 * 6 : 64 * 5) + 45,
|
|
162
|
+
date: month,
|
|
148
163
|
}
|
|
149
164
|
})
|
|
150
165
|
})
|
|
@@ -154,15 +169,19 @@ watch(
|
|
|
154
169
|
(val) => {
|
|
155
170
|
if (
|
|
156
171
|
(val === 'datetime' && props.value) ||
|
|
157
|
-
(val === 'datetimerange' &&
|
|
172
|
+
(val === 'datetimerange' &&
|
|
173
|
+
isArray(props.value) &&
|
|
174
|
+
props.value &&
|
|
175
|
+
props.value.length > 0 &&
|
|
176
|
+
props.value[0])
|
|
158
177
|
) {
|
|
159
178
|
setTime(props.value, 'start')
|
|
160
179
|
}
|
|
161
180
|
},
|
|
162
181
|
{
|
|
163
182
|
deep: true,
|
|
164
|
-
immediate: true
|
|
165
|
-
}
|
|
183
|
+
immediate: true,
|
|
184
|
+
},
|
|
166
185
|
)
|
|
167
186
|
|
|
168
187
|
watch(
|
|
@@ -170,14 +189,17 @@ watch(
|
|
|
170
189
|
(val) => {
|
|
171
190
|
if (isEqual(val, innerValue.value)) return
|
|
172
191
|
|
|
173
|
-
if (
|
|
192
|
+
if (
|
|
193
|
+
(props.type === 'datetime' && val) ||
|
|
194
|
+
(props.type === 'datetimerange' && val && isArray(val) && val.length > 0 && val[0])
|
|
195
|
+
) {
|
|
174
196
|
setTime(val, 'start')
|
|
175
197
|
}
|
|
176
198
|
},
|
|
177
199
|
{
|
|
178
200
|
deep: true,
|
|
179
|
-
immediate: true
|
|
180
|
-
}
|
|
201
|
+
immediate: true,
|
|
202
|
+
},
|
|
181
203
|
)
|
|
182
204
|
|
|
183
205
|
onMounted(() => {
|
|
@@ -187,45 +209,31 @@ onMounted(() => {
|
|
|
187
209
|
/**
|
|
188
210
|
* 使当前日期或者选中日期滚动到可视区域
|
|
189
211
|
*/
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
} else if (isNumber(props.value)) {
|
|
199
|
-
activeDate = props.value
|
|
200
|
-
}
|
|
212
|
+
function scrollIntoView() {
|
|
213
|
+
requestAnimationFrame(() => {
|
|
214
|
+
let activeDate: number | null = 0
|
|
215
|
+
if (isArray(props.value)) {
|
|
216
|
+
activeDate = props.value![0]
|
|
217
|
+
} else if (isNumber(props.value)) {
|
|
218
|
+
activeDate = props.value
|
|
219
|
+
}
|
|
201
220
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
221
|
+
if (!activeDate) {
|
|
222
|
+
activeDate = Date.now()
|
|
223
|
+
}
|
|
205
224
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const date = new Date(activeDate)
|
|
213
|
-
const day = date.getDate()
|
|
214
|
-
const firstDay = new Date(date.getFullYear(), date.getMonth(), 1)
|
|
215
|
-
const offset = (7 + firstDay.getDay() - props.firstDayOfWeek) % 7
|
|
216
|
-
const row = Math.floor((offset + day - 1) / 7)
|
|
217
|
-
// 每行高度64px,每行加4px margin
|
|
218
|
-
top += row * 64 + row * 4
|
|
219
|
-
break
|
|
225
|
+
let top: number = 0
|
|
226
|
+
for (let index = 0; index < months.value.length; index++) {
|
|
227
|
+
if (compareMonth(months.value[index].date, activeDate) === 0) {
|
|
228
|
+
break
|
|
229
|
+
}
|
|
230
|
+
top += months.value[index] ? Number(months.value[index].height) : 0
|
|
220
231
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
// 如果不是第一个月才加45
|
|
227
|
-
scrollTop.value = top + (activeMonthIndex > 0 ? 45 : 0)
|
|
228
|
-
}
|
|
232
|
+
scrollTop.value = 0
|
|
233
|
+
requestAnimationFrame(() => {
|
|
234
|
+
scrollTop.value = top
|
|
235
|
+
})
|
|
236
|
+
})
|
|
229
237
|
}
|
|
230
238
|
/**
|
|
231
239
|
* 获取时间 picker 的数据
|
|
@@ -239,7 +247,7 @@ function getTime(value: number | (number | null)[], type?: string) {
|
|
|
239
247
|
minDate: props.minDate,
|
|
240
248
|
maxDate: props.maxDate,
|
|
241
249
|
filter: props.timeFilter,
|
|
242
|
-
isHideSecond: props.hideSecond
|
|
250
|
+
isHideSecond: props.hideSecond,
|
|
243
251
|
})
|
|
244
252
|
} else {
|
|
245
253
|
if (type === 'start' && isArray(props.value)) {
|
|
@@ -248,7 +256,7 @@ function getTime(value: number | (number | null)[], type?: string) {
|
|
|
248
256
|
minDate: props.minDate,
|
|
249
257
|
maxDate: props.value[1] ? props.value[1] : props.maxDate,
|
|
250
258
|
filter: props.timeFilter,
|
|
251
|
-
isHideSecond: props.hideSecond
|
|
259
|
+
isHideSecond: props.hideSecond,
|
|
252
260
|
})
|
|
253
261
|
} else {
|
|
254
262
|
return getTimeData({
|
|
@@ -256,7 +264,7 @@ function getTime(value: number | (number | null)[], type?: string) {
|
|
|
256
264
|
minDate: (value as Array<number>)[0],
|
|
257
265
|
maxDate: props.maxDate,
|
|
258
266
|
filter: props.timeFilter,
|
|
259
|
-
isHideSecond: props.hideSecond
|
|
267
|
+
isHideSecond: props.hideSecond,
|
|
260
268
|
})
|
|
261
269
|
}
|
|
262
270
|
}
|
|
@@ -291,7 +299,13 @@ function setTime(value: number | (number | null)[], type?: MonthPanelTimeType) {
|
|
|
291
299
|
timeType.value = type || ''
|
|
292
300
|
timeValue.value = getTimeValue(value, type || '')
|
|
293
301
|
}
|
|
294
|
-
function handleDateChange({
|
|
302
|
+
function handleDateChange({
|
|
303
|
+
value,
|
|
304
|
+
type,
|
|
305
|
+
}: {
|
|
306
|
+
value: number | (number | null)[]
|
|
307
|
+
type?: MonthPanelTimeType
|
|
308
|
+
}) {
|
|
295
309
|
if (!isEqual(value, props.value)) {
|
|
296
310
|
// 内部保存一个值,用于判断新老值,避免监听器触发
|
|
297
311
|
innerValue.value = value
|
|
@@ -357,7 +371,7 @@ function doSetSubtitle(scrollTop: number) {
|
|
|
357
371
|
let height: number = 0 // 月份高度和
|
|
358
372
|
for (let index = 0; index < months.value.length; index++) {
|
|
359
373
|
height = height + months.value[index].height
|
|
360
|
-
if (scrollTop < height) {
|
|
374
|
+
if (scrollTop < height + 45) {
|
|
361
375
|
scrollIndex.value = index
|
|
362
376
|
return
|
|
363
377
|
}
|
|
@@ -365,10 +379,10 @@ function doSetSubtitle(scrollTop: number) {
|
|
|
365
379
|
}
|
|
366
380
|
|
|
367
381
|
defineExpose<MonthPanelExpose>({
|
|
368
|
-
scrollIntoView
|
|
382
|
+
scrollIntoView,
|
|
369
383
|
})
|
|
370
384
|
</script>
|
|
371
385
|
|
|
372
386
|
<style lang="scss" scoped>
|
|
373
|
-
@import './index
|
|
387
|
+
@import './index';
|
|
374
388
|
</style>
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { ComponentPublicInstance, ExtractPropTypes, PropType } from 'vue'
|
|
2
|
-
import { makeBooleanProp,
|
|
2
|
+
import { makeBooleanProp, makeRequiredProp } from '../../common/props'
|
|
3
3
|
import type { CalendarFormatter, CalendarTimeFilter, CalendarType } from '../types'
|
|
4
4
|
|
|
5
|
-
const now = new Date()
|
|
6
|
-
const defaultMinDate = new Date(now.getFullYear(), now.getMonth() - 6, now.getDate()).getTime()
|
|
7
|
-
const defaultMaxDate = new Date(now.getFullYear(), now.getMonth() + 6, now.getDate(), 23, 59, 59).getTime()
|
|
8
|
-
|
|
9
5
|
/**
|
|
10
6
|
* 月份信息
|
|
11
7
|
*/
|
|
@@ -15,71 +11,27 @@ export interface MonthInfo {
|
|
|
15
11
|
}
|
|
16
12
|
|
|
17
13
|
export const monthPanelProps = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* 选中值,为 13 位时间戳或时间戳数组
|
|
24
|
-
*/
|
|
25
|
-
value: {
|
|
26
|
-
type: [Number, Array, null] as PropType<number | (number | null)[] | null>,
|
|
27
|
-
default: null
|
|
28
|
-
},
|
|
29
|
-
/**
|
|
30
|
-
* 最小日期,为 13 位时间戳
|
|
31
|
-
*/
|
|
32
|
-
minDate: makeNumberProp(defaultMinDate),
|
|
33
|
-
/**
|
|
34
|
-
* 最大日期,为 13 位时间戳
|
|
35
|
-
*/
|
|
36
|
-
maxDate: makeNumberProp(defaultMaxDate),
|
|
37
|
-
/**
|
|
38
|
-
* 周起始天
|
|
39
|
-
*/
|
|
40
|
-
firstDayOfWeek: makeNumberProp(0),
|
|
41
|
-
/**
|
|
42
|
-
* 日期格式化函数
|
|
43
|
-
*/
|
|
14
|
+
type: makeRequiredProp(String as PropType<CalendarType>),
|
|
15
|
+
value: makeRequiredProp([Number, Array, null] as PropType<number | (number | null)[] | null>),
|
|
16
|
+
minDate: makeRequiredProp(Number),
|
|
17
|
+
maxDate: makeRequiredProp(Number),
|
|
18
|
+
firstDayOfWeek: makeRequiredProp(Number),
|
|
44
19
|
formatter: Function as PropType<CalendarFormatter>,
|
|
45
|
-
/**
|
|
46
|
-
* type 为范围选择时有效,最大日期范围
|
|
47
|
-
*/
|
|
48
20
|
maxRange: Number,
|
|
49
|
-
/**
|
|
50
|
-
* type 为范围选择时有效,选择超出最大日期范围时的错误提示文案
|
|
51
|
-
*/
|
|
52
21
|
rangePrompt: String,
|
|
53
|
-
/**
|
|
54
|
-
* type 为范围选择时有效,是否允许选择同一天
|
|
55
|
-
*/
|
|
56
22
|
allowSameDay: makeBooleanProp(false),
|
|
57
|
-
/**
|
|
58
|
-
* 是否展示面板标题,自动计算当前滚动的日期月份
|
|
59
|
-
*/
|
|
60
23
|
showPanelTitle: makeBooleanProp(false),
|
|
61
|
-
/**
|
|
62
|
-
* 选中日期所使用的当日内具体时刻
|
|
63
|
-
*/
|
|
64
24
|
defaultTime: {
|
|
65
|
-
type: [Array] as PropType<Array<number[]
|
|
25
|
+
type: [Array] as PropType<Array<number[]>>,
|
|
66
26
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
*/
|
|
70
|
-
panelHeight: makeNumberProp(378),
|
|
71
|
-
/**
|
|
72
|
-
* type 为 'datetime' 或 'datetimerange' 时有效,用于过滤时间选择器的数据
|
|
73
|
-
*/
|
|
27
|
+
panelHeight: makeRequiredProp(Number),
|
|
28
|
+
// type 为 'datetime' 或 'datetimerange' 时有效,用于过滤时间选择器的数据
|
|
74
29
|
timeFilter: Function as PropType<CalendarTimeFilter>,
|
|
75
|
-
/**
|
|
76
|
-
* type 为 'datetime' 或 'datetimerange' 时有效,是否不展示秒修改
|
|
77
|
-
*/
|
|
78
30
|
hideSecond: makeBooleanProp(false),
|
|
79
31
|
/**
|
|
80
32
|
* 是否在手指松开时立即触发picker-view的 change 事件。若不开启则会在滚动动画结束后触发 change 事件,1.2.25版本起提供,仅微信小程序和支付宝小程序支持。
|
|
81
33
|
*/
|
|
82
|
-
immediateChange: makeBooleanProp(false)
|
|
34
|
+
immediateChange: makeBooleanProp(false),
|
|
83
35
|
}
|
|
84
36
|
|
|
85
37
|
export type MonthPanelProps = ExtractPropTypes<typeof monthPanelProps>
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import type { ComponentPublicInstance, ExtractPropTypes, PropType } from 'vue'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
baseProps,
|
|
4
|
+
makeBooleanProp,
|
|
5
|
+
makeNumberProp,
|
|
6
|
+
makeRequiredProp,
|
|
7
|
+
makeStringProp,
|
|
8
|
+
} from '../common/props'
|
|
3
9
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
export type CalendarType =
|
|
11
|
+
| 'date'
|
|
12
|
+
| 'dates'
|
|
13
|
+
| 'datetime'
|
|
14
|
+
| 'week'
|
|
15
|
+
| 'month'
|
|
16
|
+
| 'daterange'
|
|
17
|
+
| 'datetimerange'
|
|
18
|
+
| 'weekrange'
|
|
19
|
+
| 'monthrange'
|
|
9
20
|
|
|
10
21
|
export const calendarViewProps = {
|
|
11
22
|
...baseProps,
|
|
@@ -20,11 +31,22 @@ export const calendarViewProps = {
|
|
|
20
31
|
/**
|
|
21
32
|
* 最小日期,为 13 位时间戳
|
|
22
33
|
*/
|
|
23
|
-
minDate: makeNumberProp(
|
|
34
|
+
minDate: makeNumberProp(
|
|
35
|
+
new Date(new Date().getFullYear(), new Date().getMonth() - 6, new Date().getDate()).getTime(),
|
|
36
|
+
),
|
|
24
37
|
/**
|
|
25
38
|
* 最大日期,为 13 位时间戳
|
|
26
39
|
*/
|
|
27
|
-
maxDate: makeNumberProp(
|
|
40
|
+
maxDate: makeNumberProp(
|
|
41
|
+
new Date(
|
|
42
|
+
new Date().getFullYear(),
|
|
43
|
+
new Date().getMonth() + 6,
|
|
44
|
+
new Date().getDate(),
|
|
45
|
+
23,
|
|
46
|
+
59,
|
|
47
|
+
59,
|
|
48
|
+
).getTime(),
|
|
49
|
+
),
|
|
28
50
|
/**
|
|
29
51
|
* 周起始天
|
|
30
52
|
*/
|
|
@@ -52,7 +74,7 @@ export const calendarViewProps = {
|
|
|
52
74
|
*/
|
|
53
75
|
defaultTime: {
|
|
54
76
|
type: [String, Array] as PropType<string | string[]>,
|
|
55
|
-
default: '00:00:00'
|
|
77
|
+
default: '00:00:00',
|
|
56
78
|
},
|
|
57
79
|
/**
|
|
58
80
|
* 可滚动面板的高度
|
|
@@ -69,21 +91,23 @@ export const calendarViewProps = {
|
|
|
69
91
|
/**
|
|
70
92
|
* 是否在手指松开时立即触发picker-view的 change 事件。若不开启则会在滚动动画结束后触发 change 事件,1.2.25版本起提供,仅微信小程序和支付宝小程序支持。
|
|
71
93
|
*/
|
|
72
|
-
immediateChange: makeBooleanProp(false)
|
|
94
|
+
immediateChange: makeBooleanProp(false),
|
|
73
95
|
}
|
|
74
96
|
|
|
75
97
|
export type CalendarViewProps = ExtractPropTypes<typeof calendarViewProps>
|
|
76
98
|
|
|
77
|
-
export type CalendarDayType = '' | 'start' | 'middle' | 'end' | 'selected' | 'same' | 'current'
|
|
99
|
+
export type CalendarDayType = '' | 'start' | 'middle' | 'end' | 'selected' | 'same' | 'current'
|
|
78
100
|
|
|
79
101
|
export type CalendarDayItem = {
|
|
80
102
|
date: number
|
|
81
103
|
text?: number | string
|
|
104
|
+
restFlag?: boolean
|
|
82
105
|
topInfo?: string
|
|
83
106
|
bottomInfo?: string
|
|
107
|
+
floorText?: string
|
|
84
108
|
type?: CalendarDayType
|
|
85
109
|
disabled?: boolean
|
|
86
|
-
|
|
110
|
+
day?: number | string
|
|
87
111
|
}
|
|
88
112
|
|
|
89
113
|
export type CalendarFormatter = (day: CalendarDayItem) => CalendarDayItem
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed } from 'vue'
|
|
2
|
-
import dayjs from '
|
|
2
|
+
import { dayjs } from '../common/dayjs'
|
|
3
3
|
import { isArray, isFunction, padZero } from '../common/util'
|
|
4
4
|
import { useTranslate } from '../composables/useTranslate'
|
|
5
5
|
import type { CalendarDayType, CalendarItem, CalendarTimeFilter, CalendarType } from './types'
|
|
@@ -13,7 +13,7 @@ const weeks = computed(() => {
|
|
|
13
13
|
translate('weeks.wed'),
|
|
14
14
|
translate('weeks.thu'),
|
|
15
15
|
translate('weeks.fri'),
|
|
16
|
-
translate('weeks.sat')
|
|
16
|
+
translate('weeks.sat'),
|
|
17
17
|
]
|
|
18
18
|
})
|
|
19
19
|
|
|
@@ -116,6 +116,24 @@ export function getWeekLabel(index: number) {
|
|
|
116
116
|
return weeks.value[index]
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* 获取一个月第一天的样式
|
|
121
|
+
* @param {number} index
|
|
122
|
+
* @param {timestamp} date
|
|
123
|
+
* @param {number} firstDayOfWeek
|
|
124
|
+
*/
|
|
125
|
+
export function getFirstDayStyle(index: number, date: number, firstDayOfWeek: number) {
|
|
126
|
+
if (firstDayOfWeek >= 7) {
|
|
127
|
+
firstDayOfWeek = firstDayOfWeek % 7
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (index !== 0) return ''
|
|
131
|
+
|
|
132
|
+
const offset = (7 + new Date(date).getDay() - firstDayOfWeek) % 7
|
|
133
|
+
|
|
134
|
+
return 'margin-left: ' + (100 / 7) * offset + '%'
|
|
135
|
+
}
|
|
136
|
+
|
|
119
137
|
/**
|
|
120
138
|
* 格式化年份
|
|
121
139
|
* @param {timestamp} date
|
|
@@ -204,9 +222,6 @@ export function getDayByOffset(date: number, offset: number) {
|
|
|
204
222
|
return dateValue.getTime()
|
|
205
223
|
}
|
|
206
224
|
|
|
207
|
-
export const getPrevDay = (date: number) => getDayByOffset(date, -1)
|
|
208
|
-
export const getNextDay = (date: number) => getDayByOffset(date, 1)
|
|
209
|
-
|
|
210
225
|
/**
|
|
211
226
|
* 获取月份偏移量
|
|
212
227
|
* @param {timestamp} date1
|
|
@@ -306,7 +321,7 @@ export function getTimeData({
|
|
|
306
321
|
minDate,
|
|
307
322
|
maxDate,
|
|
308
323
|
isHideSecond,
|
|
309
|
-
filter
|
|
324
|
+
filter,
|
|
310
325
|
}: {
|
|
311
326
|
date: number
|
|
312
327
|
minDate: number
|
|
@@ -357,25 +372,25 @@ export function getTimeData({
|
|
|
357
372
|
return {
|
|
358
373
|
label: translate('hour', padZero(index)),
|
|
359
374
|
value: index,
|
|
360
|
-
disabled: index < minHour || index > maxHour
|
|
375
|
+
disabled: index < minHour || index > maxHour,
|
|
361
376
|
}
|
|
362
377
|
})
|
|
363
378
|
let minutes = times(60, (index) => {
|
|
364
379
|
return {
|
|
365
380
|
label: translate('minute', padZero(index)),
|
|
366
381
|
value: index,
|
|
367
|
-
disabled: index < minMinute || index > maxMinute
|
|
382
|
+
disabled: index < minMinute || index > maxMinute,
|
|
368
383
|
}
|
|
369
384
|
})
|
|
370
385
|
let seconds: CalendarItem[] = []
|
|
371
386
|
if (filter && isFunction(filter)) {
|
|
372
387
|
hours = filter({
|
|
373
388
|
type: 'hour',
|
|
374
|
-
values: hours
|
|
389
|
+
values: hours,
|
|
375
390
|
})
|
|
376
391
|
minutes = filter({
|
|
377
392
|
type: 'minute',
|
|
378
|
-
values: minutes
|
|
393
|
+
values: minutes,
|
|
379
394
|
})
|
|
380
395
|
}
|
|
381
396
|
|
|
@@ -384,13 +399,13 @@ export function getTimeData({
|
|
|
384
399
|
return {
|
|
385
400
|
label: translate('second', padZero(index)),
|
|
386
401
|
value: index,
|
|
387
|
-
disabled: index < minSecond || index > maxSecond
|
|
402
|
+
disabled: index < minSecond || index > maxSecond,
|
|
388
403
|
}
|
|
389
404
|
})
|
|
390
405
|
if (filter && isFunction(filter)) {
|
|
391
406
|
seconds = filter({
|
|
392
407
|
type: 'second',
|
|
393
|
-
values: seconds
|
|
408
|
+
values: seconds,
|
|
394
409
|
})
|
|
395
410
|
}
|
|
396
411
|
}
|
|
@@ -413,10 +428,17 @@ export function getWeekNumber(date: number | Date) {
|
|
|
413
428
|
const week = new Date(date.getFullYear(), 0, 4)
|
|
414
429
|
// Adjust to Thursday in week 1 and count number of weeks from date to week 1.
|
|
415
430
|
// Rounding should be fine for Daylight Saving Time. Its shift should never be more than 12 hours.
|
|
416
|
-
return
|
|
431
|
+
return (
|
|
432
|
+
1 +
|
|
433
|
+
Math.round(((date.getTime() - week.getTime()) / 86400000 - 3 + ((week.getDay() + 6) % 7)) / 7)
|
|
434
|
+
)
|
|
417
435
|
}
|
|
418
436
|
|
|
419
|
-
export function getItemClass(
|
|
437
|
+
export function getItemClass(
|
|
438
|
+
monthType: CalendarDayType,
|
|
439
|
+
value: number | (number | null)[],
|
|
440
|
+
type: CalendarType,
|
|
441
|
+
) {
|
|
420
442
|
const classList = ['is-' + monthType]
|
|
421
443
|
|
|
422
444
|
if (type.indexOf('range') > -1 && isArray(value)) {
|
|
@@ -46,8 +46,8 @@ export default {
|
|
|
46
46
|
options: {
|
|
47
47
|
addGlobalClass: true,
|
|
48
48
|
virtualHost: true,
|
|
49
|
-
styleIsolation: 'shared'
|
|
50
|
-
}
|
|
49
|
+
styleIsolation: 'shared',
|
|
50
|
+
},
|
|
51
51
|
}
|
|
52
52
|
</script>
|
|
53
53
|
|
|
@@ -72,8 +72,8 @@ watch(
|
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
74
|
deep: true,
|
|
75
|
-
immediate: true
|
|
76
|
-
}
|
|
75
|
+
immediate: true,
|
|
76
|
+
},
|
|
77
77
|
)
|
|
78
78
|
|
|
79
79
|
/**
|
|
@@ -91,7 +91,7 @@ function getPanel() {
|
|
|
91
91
|
function handleChange({ value }: { value: number | number[] | null }) {
|
|
92
92
|
emit('update:modelValue', value)
|
|
93
93
|
emit('change', {
|
|
94
|
-
value
|
|
94
|
+
value,
|
|
95
95
|
})
|
|
96
96
|
}
|
|
97
97
|
function handlePickStart() {
|
|
@@ -102,10 +102,10 @@ function handlePickEnd() {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
defineExpose<CalendarViewExpose>({
|
|
105
|
-
scrollIntoView
|
|
105
|
+
scrollIntoView,
|
|
106
106
|
})
|
|
107
107
|
</script>
|
|
108
108
|
|
|
109
109
|
<style lang="scss" scoped>
|
|
110
|
-
@import './index
|
|
110
|
+
@import './index';
|
|
111
111
|
</style>
|