hy-app 0.3.0 → 0.3.2
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/README.md +6 -3
- package/common/shakeService.ts +31 -29
- package/components/avatar.zip +0 -0
- package/components/hy-action-sheet/hy-action-sheet.vue +71 -46
- package/components/hy-address-picker/hy-address-picker.vue +94 -83
- package/components/hy-avatar/hy-avatar.vue +84 -85
- package/components/hy-back-top/hy-back-top.vue +8 -6
- package/components/hy-badge/hy-badge.vue +47 -46
- package/components/hy-button/hy-button.vue +117 -93
- package/components/hy-calendar/hy-calendar.vue +168 -160
- package/components/hy-card/hy-card.vue +50 -43
- package/components/hy-card/typing.d.ts +33 -32
- package/components/hy-cell/hy-cell.vue +73 -51
- package/components/hy-check-button/hy-check-button.vue +54 -47
- package/components/hy-checkbox/hy-checkbox.vue +97 -105
- package/components/hy-code-input/hy-code-input.vue +80 -89
- package/components/hy-config-provider/hy-config-provider.vue +20 -21
- package/components/hy-count-down/hy-count-down.vue +66 -67
- package/components/hy-count-to/hy-count-to.vue +105 -99
- package/components/hy-count-to/typing.d.ts +13 -12
- package/components/hy-datetime-picker/hy-datetime-picker.vue +261 -253
- package/components/hy-datetime-picker/typing.d.ts +42 -40
- package/components/hy-divider/hy-divider.vue +68 -73
- package/components/hy-dropdown/hy-dropdown.vue +20 -19
- package/components/hy-dropdown-item/hy-dropdown-item.vue +66 -61
- package/components/hy-dropdown-item/typing.d.ts +9 -9
- package/components/hy-empty/hy-empty.vue +42 -42
- package/components/hy-flex/hy-flex.vue +99 -0
- package/components/hy-flex/index.scss +8 -0
- package/components/hy-flex/typing.d.ts +23 -0
- package/components/hy-float-button/hy-float-button.vue +218 -210
- package/components/hy-folding-panel/hy-folding-panel.vue +32 -33
- package/components/hy-form/hy-form.vue +264 -252
- package/components/hy-form/typing.d.ts +4 -0
- package/components/hy-form-group/hy-form-group.vue +114 -183
- package/components/hy-form-item/hy-form-item.vue +12 -10
- package/components/hy-form-item/index.scss +2 -2
- package/components/hy-form-item/typing.d.ts +3 -6
- package/components/hy-grid/hy-grid.vue +44 -43
- package/components/hy-icon/hy-icon.vue +61 -67
- package/components/hy-image/hy-image.vue +112 -88
- package/components/hy-image/typing.d.ts +27 -23
- package/components/hy-input/hy-input.vue +157 -127
- package/components/hy-input/typing.d.ts +53 -47
- package/components/hy-line/hy-line.vue +26 -26
- package/components/hy-line-progress/hy-line-progress.vue +42 -35
- package/components/hy-list/hy-list.vue +76 -85
- package/components/hy-loading/hy-loading.vue +26 -23
- package/components/hy-login/TheUserLogin.vue +1 -1
- package/components/hy-menu/hy-menu.vue +48 -43
- package/components/hy-menu/typing.d.ts +18 -17
- package/components/hy-modal/hy-modal.vue +39 -35
- package/components/hy-navbar/hy-navbar.vue +25 -25
- package/components/hy-navbar/typing.d.ts +24 -22
- package/components/hy-notice-bar/hy-notice-bar.vue +26 -27
- package/components/hy-notify/hy-notify.vue +53 -53
- package/components/hy-number-step/hy-number-step.vue +134 -146
- package/components/hy-number-step/typing.d.ts +35 -35
- package/components/hy-overlay/hy-overlay.vue +23 -21
- package/components/hy-pagination/hy-pagination.vue +41 -36
- package/components/hy-picker/hy-picker.vue +184 -154
- package/components/hy-picker/typing.d.ts +39 -39
- package/components/hy-popover/hy-popover.vue +97 -77
- package/components/hy-popup/hy-popup.vue +107 -98
- package/components/hy-price/hy-price.vue +38 -34
- package/components/hy-qrcode/hy-qrcode.vue +50 -51
- package/components/hy-radio/hy-radio.vue +101 -113
- package/components/hy-rate/hy-rate.vue +107 -88
- package/components/hy-read-more/hy-read-more.vue +64 -49
- package/components/hy-scroll-list/hy-scroll-list.vue +45 -48
- package/components/hy-search/hy-search.vue +73 -66
- package/components/hy-search/typing.d.ts +36 -35
- package/components/hy-signature/hy-signature.vue +282 -240
- package/components/hy-slider/hy-slider.vue +195 -153
- package/components/hy-slider/typing.d.ts +21 -21
- package/components/hy-steps/hy-steps.vue +118 -90
- package/components/hy-steps/index.scss +31 -21
- package/components/hy-submit-bar/hy-submit-bar.vue +61 -70
- package/components/hy-subsection/hy-subsection.vue +99 -102
- package/components/hy-subsection/typing.d.ts +19 -19
- package/components/hy-swipe-action/hy-swipe-action.vue +131 -118
- package/components/hy-swiper/hy-swiper.vue +85 -71
- package/components/hy-switch/hy-switch.vue +67 -72
- package/components/hy-switch/typing.d.ts +21 -19
- package/components/hy-tabs/hy-tabs.vue +168 -113
- package/components/hy-tag/hy-tag.vue +90 -86
- package/components/hy-tag/typing.d.ts +26 -21
- package/components/hy-text/hy-text.vue +119 -111
- package/components/hy-textarea/hy-textarea.vue +100 -93
- package/components/hy-textarea/typing.d.ts +36 -31
- package/components/hy-toast/hy-toast.vue +77 -67
- package/components/hy-tooltip/hy-tooltip.vue +109 -91
- package/components/hy-transition/hy-transition.vue +62 -66
- package/components/hy-upload/hy-upload.vue +294 -152
- package/components/hy-upload/typing.d.ts +41 -36
- package/components/hy-warn/hy-warn.vue +34 -27
- package/components/hy-waterfall/hy-waterfall.vue +83 -74
- package/components/hy-watermark/hy-watermark.vue +134 -115
- package/components/index.ts +1 -1
- package/composables/usePopover.ts +236 -221
- package/composables/useQueue.ts +53 -52
- package/global.d.ts +1 -0
- package/package.json +2 -2
- package/store/index.ts +9 -1
- package/theme.scss +5 -5
- package/typing/index.ts +0 -1
- package/typing/modules/common.d.ts +0 -2
- package/web-types.json +1 -1
|
@@ -66,31 +66,46 @@
|
|
|
66
66
|
|
|
67
67
|
<script lang="ts">
|
|
68
68
|
export default {
|
|
69
|
-
name:
|
|
69
|
+
name: "hy-calendar",
|
|
70
70
|
options: {
|
|
71
71
|
virtualHost: true,
|
|
72
|
-
styleIsolation:
|
|
72
|
+
styleIsolation: "shared",
|
|
73
73
|
},
|
|
74
|
-
}
|
|
74
|
+
};
|
|
75
75
|
</script>
|
|
76
76
|
|
|
77
77
|
<script setup lang="ts">
|
|
78
|
-
import type { ICalendarEmits } from
|
|
79
|
-
import {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
import type { ICalendarEmits } from "./typing";
|
|
79
|
+
import {
|
|
80
|
+
computed,
|
|
81
|
+
nextTick,
|
|
82
|
+
onMounted,
|
|
83
|
+
type PropType,
|
|
84
|
+
ref,
|
|
85
|
+
toRefs,
|
|
86
|
+
watch,
|
|
87
|
+
} from "vue";
|
|
88
|
+
import {
|
|
89
|
+
addUnit,
|
|
90
|
+
error,
|
|
91
|
+
isArray,
|
|
92
|
+
isNumericString,
|
|
93
|
+
padZero,
|
|
94
|
+
range,
|
|
95
|
+
} from "../../utils";
|
|
96
|
+
import Calendar from "../../utils/calendar.js";
|
|
97
|
+
import dayjs from "dayjs/esm";
|
|
83
98
|
// 组件
|
|
84
|
-
import HyMount from
|
|
85
|
-
import HyHeader from
|
|
86
|
-
import HyPopup from
|
|
87
|
-
import HyButton from
|
|
99
|
+
import HyMount from "./month.vue";
|
|
100
|
+
import HyHeader from "./header.vue";
|
|
101
|
+
import HyPopup from "../hy-popup/hy-popup.vue";
|
|
102
|
+
import HyButton from "../hy-button/hy-button.vue";
|
|
88
103
|
|
|
89
104
|
/**
|
|
90
105
|
* 用于单个选择日期,范围选择日期等,日历被包裹在底部弹起的容器中。
|
|
91
106
|
* @displayName hy-calendar
|
|
92
107
|
*/
|
|
93
|
-
defineOptions({})
|
|
108
|
+
defineOptions({});
|
|
94
109
|
|
|
95
110
|
// const props = withDefaults(defineProps<IProps>(), defaultProps);
|
|
96
111
|
const props = defineProps({
|
|
@@ -103,7 +118,7 @@ const props = defineProps({
|
|
|
103
118
|
/** 标题内容 */
|
|
104
119
|
title: {
|
|
105
120
|
type: String,
|
|
106
|
-
default:
|
|
121
|
+
default: "日期选选择",
|
|
107
122
|
},
|
|
108
123
|
/** 是否显示标题 */
|
|
109
124
|
showTitle: {
|
|
@@ -121,17 +136,17 @@ const props = defineProps({
|
|
|
121
136
|
* */
|
|
122
137
|
mode: {
|
|
123
138
|
type: String,
|
|
124
|
-
default:
|
|
139
|
+
default: "single",
|
|
125
140
|
},
|
|
126
141
|
/** mode=range时,第一个日期底部的提示文字 */
|
|
127
142
|
startText: {
|
|
128
143
|
type: String,
|
|
129
|
-
default:
|
|
144
|
+
default: "开始",
|
|
130
145
|
},
|
|
131
146
|
/** mode=range时,最后一个日期底部的提示文字 */
|
|
132
147
|
endText: {
|
|
133
148
|
type: String,
|
|
134
|
-
default:
|
|
149
|
+
default: "结束",
|
|
135
150
|
},
|
|
136
151
|
/** 自定义列表 */
|
|
137
152
|
customList: {
|
|
@@ -141,7 +156,7 @@ const props = defineProps({
|
|
|
141
156
|
/** 主题色,对底部按钮和选中日期有效 */
|
|
142
157
|
color: {
|
|
143
158
|
type: String,
|
|
144
|
-
default:
|
|
159
|
+
default: "",
|
|
145
160
|
},
|
|
146
161
|
/** 最小的可选日期 */
|
|
147
162
|
minDate: {
|
|
@@ -182,12 +197,12 @@ const props = defineProps({
|
|
|
182
197
|
/** 确定按钮的文字 */
|
|
183
198
|
confirmText: {
|
|
184
199
|
type: String,
|
|
185
|
-
default:
|
|
200
|
+
default: "确定",
|
|
186
201
|
},
|
|
187
202
|
/** 确认按钮处于禁用状态时的文字 */
|
|
188
203
|
confirmDisabledText: {
|
|
189
204
|
type: String,
|
|
190
|
-
default:
|
|
205
|
+
default: "确定",
|
|
191
206
|
},
|
|
192
207
|
/** 是否允许点击遮罩关闭日历 */
|
|
193
208
|
closeOnClickOverlay: {
|
|
@@ -234,7 +249,7 @@ const props = defineProps({
|
|
|
234
249
|
/** 星期文案 */
|
|
235
250
|
weekText: {
|
|
236
251
|
type: Array as unknown as PropType<string[]>,
|
|
237
|
-
default: () => [
|
|
252
|
+
default: () => ["一", "二", "三", "四", "五", "六", "日"],
|
|
238
253
|
},
|
|
239
254
|
/** 单选与多选禁止选中的日期列表,mode!=range时有效。 */
|
|
240
255
|
forbidDays: {
|
|
@@ -244,51 +259,39 @@ const props = defineProps({
|
|
|
244
259
|
/** 单选与多选禁止选中的日期选择时提示 */
|
|
245
260
|
forbidDaysToast: {
|
|
246
261
|
type: String,
|
|
247
|
-
default:
|
|
262
|
+
default: "该日期已禁用",
|
|
248
263
|
},
|
|
249
|
-
})
|
|
250
|
-
const
|
|
251
|
-
show,
|
|
252
|
-
maxDate,
|
|
253
|
-
minDate,
|
|
254
|
-
defaultDate,
|
|
255
|
-
mode,
|
|
256
|
-
showConfirm,
|
|
257
|
-
rowHeight,
|
|
258
|
-
monthNum,
|
|
259
|
-
formatter,
|
|
260
|
-
showLunar,
|
|
261
|
-
} = toRefs(props)
|
|
262
|
-
const emit = defineEmits<ICalendarEmits>()
|
|
264
|
+
});
|
|
265
|
+
const emit = defineEmits<ICalendarEmits>();
|
|
263
266
|
|
|
264
267
|
// 需要显示的月份的数组
|
|
265
|
-
const months = ref<any[]>([])
|
|
268
|
+
const months = ref<any[]>([]);
|
|
266
269
|
// 在月份滚动区域中,当前视图中月份的index索引
|
|
267
|
-
const monthIndex = ref(0)
|
|
270
|
+
const monthIndex = ref(0);
|
|
268
271
|
// 月份滚动区域的高度
|
|
269
|
-
const listHeight = ref(0)
|
|
272
|
+
const listHeight = ref(0);
|
|
270
273
|
// month组件中选择的日期数组
|
|
271
|
-
const selected = ref<string[]>([])
|
|
272
|
-
const scrollIntoView = ref(
|
|
273
|
-
const scrollIntoViewScroll = ref(
|
|
274
|
-
const scrollTop = ref(0)
|
|
274
|
+
const selected = ref<string[]>([]);
|
|
275
|
+
const scrollIntoView = ref("");
|
|
276
|
+
const scrollIntoViewScroll = ref("");
|
|
277
|
+
const scrollTop = ref(0);
|
|
275
278
|
// 过滤处理方法
|
|
276
|
-
let innerFormatter = (value: string) => value
|
|
279
|
+
let innerFormatter = (value: string) => value;
|
|
277
280
|
|
|
278
281
|
// 由于maxDate和minDate可以为字符串(2021-10-10),或者数值(时间戳),但是dayjs如果接受字符串形式的时间戳会有问题,这里进行处理
|
|
279
282
|
const innerMaxDate = computed(() => {
|
|
280
|
-
return isNumericString(maxDate
|
|
281
|
-
})
|
|
283
|
+
return isNumericString(props.maxDate) ? Number(props.maxDate) : props.maxDate;
|
|
284
|
+
});
|
|
282
285
|
const innerMinDate = computed(() => {
|
|
283
|
-
return isNumericString(minDate
|
|
284
|
-
})
|
|
286
|
+
return isNumericString(props.minDate) ? Number(props.minDate) : props.minDate;
|
|
287
|
+
});
|
|
285
288
|
|
|
286
289
|
/**
|
|
287
290
|
* @description 多个条件的变化,会引起选中日期的变化,这里统一管理监听
|
|
288
291
|
* */
|
|
289
292
|
const selectedChange = computed(() => {
|
|
290
|
-
return [innerMinDate.value, innerMaxDate.value, defaultDate
|
|
291
|
-
})
|
|
293
|
+
return [innerMinDate.value, innerMaxDate.value, props.defaultDate];
|
|
294
|
+
});
|
|
292
295
|
|
|
293
296
|
/**
|
|
294
297
|
* @description 获得两个日期之间的月份数
|
|
@@ -296,167 +299,173 @@ const selectedChange = computed(() => {
|
|
|
296
299
|
* @param maxDate 最大日期
|
|
297
300
|
* */
|
|
298
301
|
const getMonths = (minDate: number | string, maxDate: number | string) => {
|
|
299
|
-
const minYear = dayjs(minDate).year()
|
|
300
|
-
const minMonth = dayjs(minDate).month() + 1
|
|
301
|
-
const maxYear = dayjs(maxDate).year()
|
|
302
|
-
const maxMonth = dayjs(maxDate).month() + 1
|
|
303
|
-
return (maxYear - minYear) * 12 + (maxMonth - minMonth) + 1
|
|
304
|
-
}
|
|
302
|
+
const minYear = dayjs(minDate).year();
|
|
303
|
+
const minMonth = dayjs(minDate).month() + 1;
|
|
304
|
+
const maxYear = dayjs(maxDate).year();
|
|
305
|
+
const maxMonth = dayjs(maxDate).month() + 1;
|
|
306
|
+
return (maxYear - minYear) * 12 + (maxMonth - minMonth) + 1;
|
|
307
|
+
};
|
|
305
308
|
|
|
306
309
|
/**
|
|
307
310
|
* @description 设置月份数据
|
|
308
311
|
* */
|
|
309
312
|
const setMonth = () => {
|
|
310
313
|
// 最小日期的毫秒数
|
|
311
|
-
const minDate = innerMinDate.value || dayjs().valueOf()
|
|
314
|
+
const minDate = innerMinDate.value || dayjs().valueOf();
|
|
312
315
|
// 如果没有指定最大日期,则往后推3个月
|
|
313
316
|
const maxDate =
|
|
314
317
|
innerMaxDate.value ||
|
|
315
318
|
dayjs(minDate)
|
|
316
|
-
.add(monthNum
|
|
317
|
-
.valueOf()
|
|
319
|
+
.add(props.monthNum - 1, "month")
|
|
320
|
+
.valueOf();
|
|
318
321
|
// 最大最小月份之间的共有多少个月份,
|
|
319
|
-
const monthList = range(1, monthNum
|
|
322
|
+
const monthList = range(1, props.monthNum, getMonths(minDate, maxDate));
|
|
320
323
|
// 先清空数组
|
|
321
|
-
months.value = []
|
|
324
|
+
months.value = [];
|
|
322
325
|
for (let i = 0; i < monthList; i++) {
|
|
323
326
|
months.value.push({
|
|
324
|
-
date: new Array(dayjs(minDate).add(i,
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
327
|
+
date: new Array(dayjs(minDate).add(i, "month").daysInMonth())
|
|
328
|
+
.fill(1)
|
|
329
|
+
.map((item, index) => {
|
|
330
|
+
// 日期,取值1-31
|
|
331
|
+
let day = index + 1;
|
|
332
|
+
// 星期,0-6,0为周日
|
|
333
|
+
const week = dayjs(minDate).add(i, "month").date(day).day();
|
|
334
|
+
const date = dayjs(minDate)
|
|
335
|
+
.add(i, "month")
|
|
336
|
+
.date(day)
|
|
337
|
+
.format("YYYY-MM-DD");
|
|
338
|
+
let bottomInfo = "";
|
|
339
|
+
if (props.showLunar) {
|
|
340
|
+
// 将日期转为农历格式
|
|
341
|
+
const lunar = Calendar.solar2lunar(
|
|
342
|
+
dayjs(date).year(),
|
|
343
|
+
dayjs(date).month() + 1,
|
|
344
|
+
dayjs(date).date(),
|
|
345
|
+
);
|
|
346
|
+
bottomInfo = lunar.IDayCn;
|
|
347
|
+
}
|
|
348
|
+
let config = {
|
|
349
|
+
day,
|
|
350
|
+
week,
|
|
351
|
+
// 小于最小允许的日期,或者大于最大的日期,则设置为disabled状态
|
|
352
|
+
disabled:
|
|
353
|
+
dayjs(date).isBefore(dayjs(minDate).format("YYYY-MM-DD")) ||
|
|
354
|
+
dayjs(date).isAfter(dayjs(maxDate).format("YYYY-MM-DD")),
|
|
355
|
+
// 返回一个日期对象,供外部的formatter获取当前日期的年月日等信息,进行加工处理
|
|
356
|
+
date: new Date(date),
|
|
357
|
+
bottomInfo,
|
|
358
|
+
dot: false,
|
|
359
|
+
month: dayjs(minDate).add(i, "month").month() + 1,
|
|
360
|
+
};
|
|
361
|
+
const format = props.formatter || innerFormatter;
|
|
362
|
+
return format(config as any);
|
|
363
|
+
}),
|
|
356
364
|
// 当前所属的月份
|
|
357
|
-
month: dayjs(minDate).add(i,
|
|
365
|
+
month: dayjs(minDate).add(i, "month").month() + 1,
|
|
358
366
|
// 当前年份
|
|
359
|
-
year: dayjs(minDate).add(i,
|
|
360
|
-
})
|
|
367
|
+
year: dayjs(minDate).add(i, "month").year(),
|
|
368
|
+
});
|
|
361
369
|
}
|
|
362
|
-
}
|
|
370
|
+
};
|
|
363
371
|
|
|
364
372
|
watch(
|
|
365
373
|
() => selectedChange.value,
|
|
366
374
|
() => setMonth(),
|
|
367
375
|
{ immediate: true },
|
|
368
|
-
)
|
|
376
|
+
);
|
|
369
377
|
|
|
370
378
|
watch(
|
|
371
|
-
() => show
|
|
379
|
+
() => props.show,
|
|
372
380
|
(newVal: boolean) => {
|
|
373
381
|
if (newVal) {
|
|
374
|
-
setMonth()
|
|
382
|
+
setMonth();
|
|
375
383
|
} else {
|
|
376
384
|
// 关闭时重置scrollIntoView,否则会出现二次打开日历,当前月份数据显示不正确。
|
|
377
385
|
// scrollIntoView需要有一个值变动过程,才会产生作用。
|
|
378
|
-
scrollIntoView.value =
|
|
386
|
+
scrollIntoView.value = "";
|
|
379
387
|
}
|
|
380
388
|
},
|
|
381
389
|
{ immediate: true },
|
|
382
|
-
)
|
|
390
|
+
);
|
|
383
391
|
|
|
384
392
|
const subtitle = computed(() => {
|
|
385
393
|
// 初始化时,this.months为空数组,所以需要特别判断处理
|
|
386
394
|
if (months.value.length) {
|
|
387
|
-
return `${months.value[monthIndex.value].year}年${months.value[monthIndex.value].month}
|
|
395
|
+
return `${months.value[monthIndex.value].year}年${months.value[monthIndex.value].month}月`;
|
|
388
396
|
} else {
|
|
389
|
-
return
|
|
397
|
+
return "";
|
|
390
398
|
}
|
|
391
|
-
})
|
|
399
|
+
});
|
|
392
400
|
|
|
393
401
|
const buttonDisabled = computed(() => {
|
|
394
402
|
// 如果为range类型,且选择的日期个数不足1个时,让底部的按钮出于disabled状态
|
|
395
|
-
if (mode
|
|
396
|
-
return selected.value.length <= 1
|
|
403
|
+
if (props.mode === "range") {
|
|
404
|
+
return selected.value.length <= 1;
|
|
397
405
|
} else {
|
|
398
|
-
return false
|
|
406
|
+
return false;
|
|
399
407
|
}
|
|
400
|
-
})
|
|
408
|
+
});
|
|
401
409
|
|
|
402
410
|
onMounted(() => {
|
|
403
411
|
// start.value = Date.now();
|
|
404
|
-
init()
|
|
405
|
-
})
|
|
412
|
+
init();
|
|
413
|
+
});
|
|
406
414
|
|
|
407
415
|
// 在微信小程序中,不支持将函数当做props参数,故只能通过ref形式调用
|
|
408
416
|
const setFormatter = (e: (value: string) => string) => {
|
|
409
|
-
innerFormatter = e
|
|
410
|
-
}
|
|
417
|
+
innerFormatter = e;
|
|
418
|
+
};
|
|
411
419
|
|
|
412
420
|
/**
|
|
413
421
|
* @description month组件内部选择日期后,通过事件通知给父组件
|
|
414
422
|
*/
|
|
415
|
-
const monthSelected = (e: string[], scene =
|
|
416
|
-
selected.value = e
|
|
417
|
-
if (!showConfirm
|
|
423
|
+
const monthSelected = (e: string[], scene = "init") => {
|
|
424
|
+
selected.value = e;
|
|
425
|
+
if (!props.showConfirm) {
|
|
418
426
|
// 在不需要确认按钮的情况下,如果为单选,或者范围多选且已选长度大于2,则直接进行返还
|
|
419
427
|
if (
|
|
420
|
-
mode
|
|
421
|
-
mode
|
|
422
|
-
(mode
|
|
428
|
+
props.mode === "multiple" ||
|
|
429
|
+
props.mode === "single" ||
|
|
430
|
+
(props.mode === "range" && selected.value.length >= 2)
|
|
423
431
|
) {
|
|
424
|
-
if (scene ===
|
|
425
|
-
return
|
|
432
|
+
if (scene === "init") {
|
|
433
|
+
return;
|
|
426
434
|
}
|
|
427
|
-
if (scene ===
|
|
428
|
-
emit(
|
|
435
|
+
if (scene === "tap") {
|
|
436
|
+
emit("confirm", selected.value);
|
|
429
437
|
}
|
|
430
438
|
}
|
|
431
439
|
}
|
|
432
|
-
}
|
|
440
|
+
};
|
|
433
441
|
|
|
434
442
|
const init = () => {
|
|
435
443
|
// 校验maxDate,不能小于minDate。
|
|
436
444
|
if (
|
|
437
445
|
innerMaxDate.value &&
|
|
438
446
|
innerMinDate.value &&
|
|
439
|
-
new Date(innerMaxDate.value).getTime() <
|
|
447
|
+
new Date(innerMaxDate.value).getTime() <
|
|
448
|
+
new Date(innerMinDate.value).getTime()
|
|
440
449
|
) {
|
|
441
|
-
return error(
|
|
450
|
+
return error("maxDate不能小于minDate时间");
|
|
442
451
|
}
|
|
443
452
|
// 滚动区域的高度
|
|
444
|
-
listHeight.value = rowHeight
|
|
445
|
-
setMonth()
|
|
446
|
-
}
|
|
453
|
+
listHeight.value = props.rowHeight * 5 + 30;
|
|
454
|
+
setMonth();
|
|
455
|
+
};
|
|
447
456
|
|
|
448
457
|
const close = () => {
|
|
449
|
-
emit(
|
|
450
|
-
}
|
|
458
|
+
emit("close");
|
|
459
|
+
};
|
|
451
460
|
|
|
452
461
|
/**
|
|
453
462
|
* @description 点击确定按钮
|
|
454
463
|
* */
|
|
455
464
|
const confirm = () => {
|
|
456
465
|
if (!buttonDisabled.value) {
|
|
457
|
-
emit(
|
|
466
|
+
emit("confirm", selected.value);
|
|
458
467
|
}
|
|
459
|
-
}
|
|
468
|
+
};
|
|
460
469
|
|
|
461
470
|
/**
|
|
462
471
|
* @description 滚动到默认设置的月份
|
|
@@ -465,62 +474,61 @@ const confirm = () => {
|
|
|
465
474
|
const scrollIntoDefaultMonth = (selected: string) => {
|
|
466
475
|
// 查询默认日期在可选列表的下标
|
|
467
476
|
const _index = months.value.findIndex(({ year, month }) => {
|
|
468
|
-
month = padZero(month)
|
|
469
|
-
return `${year}-${month}` === selected
|
|
470
|
-
})
|
|
477
|
+
month = padZero(month);
|
|
478
|
+
return `${year}-${month}` === selected;
|
|
479
|
+
});
|
|
471
480
|
if (_index !== -1) {
|
|
472
481
|
// #ifndef MP-WEIXIN
|
|
473
482
|
nextTick(() => {
|
|
474
|
-
scrollIntoView.value = `month-${_index}
|
|
475
|
-
scrollIntoViewScroll.value = scrollIntoView.value
|
|
476
|
-
})
|
|
483
|
+
scrollIntoView.value = `month-${_index}`;
|
|
484
|
+
scrollIntoViewScroll.value = scrollIntoView.value;
|
|
485
|
+
});
|
|
477
486
|
// #endif
|
|
478
487
|
// #ifdef MP-WEIXIN
|
|
479
|
-
scrollTop.value = months.value[_index].top || 0
|
|
488
|
+
scrollTop.value = months.value[_index].top || 0;
|
|
480
489
|
// #endif
|
|
481
490
|
}
|
|
482
|
-
}
|
|
491
|
+
};
|
|
483
492
|
// scroll-view滚动监听
|
|
484
493
|
const onScroll = (event: any) => {
|
|
485
494
|
// 不允许小于0的滚动值,如果scroll-view到顶了,继续下拉,会出现负数值
|
|
486
|
-
const scrollTop = Math.max(0, event.detail.scrollTop)
|
|
495
|
+
const scrollTop = Math.max(0, event.detail.scrollTop);
|
|
487
496
|
// 将当前滚动条数值,除以滚动区域的高度,可以得出当前滚动到了哪一个月份的索引
|
|
488
497
|
for (let i = 0; i < months.value.length; i++) {
|
|
489
498
|
if (scrollTop >= (months.value[i].top || listHeight.value)) {
|
|
490
|
-
monthIndex.value = i
|
|
491
|
-
scrollIntoViewScroll.value = `month-${i}
|
|
499
|
+
monthIndex.value = i;
|
|
500
|
+
scrollIntoViewScroll.value = `month-${i}`;
|
|
492
501
|
}
|
|
493
502
|
}
|
|
494
|
-
}
|
|
503
|
+
};
|
|
495
504
|
// 更新月份的top值
|
|
496
505
|
const updateMonthTop = (topArr = []) => {
|
|
497
506
|
// 设置对应月份的top值,用于onScroll方法更新月份
|
|
498
507
|
topArr.map((item, index) => {
|
|
499
|
-
months.value[index].top = item
|
|
500
|
-
})
|
|
508
|
+
months.value[index].top = item;
|
|
509
|
+
});
|
|
510
|
+
// 如果没有设置默认日期,则将当天日期设置为默认选中的日期
|
|
511
|
+
let selected = dayjs().format("YYYY-MM");
|
|
501
512
|
|
|
502
513
|
// 获取默认日期的下标
|
|
503
|
-
if (!defaultDate
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
scrollIntoDefaultMonth(selected)
|
|
507
|
-
return
|
|
514
|
+
if (!props.defaultDate) {
|
|
515
|
+
scrollIntoDefaultMonth(selected);
|
|
516
|
+
return;
|
|
508
517
|
}
|
|
509
|
-
let selected = dayjs().format('YYYY-MM')
|
|
510
518
|
// 单选模式,可以是字符串或数组,Date对象等
|
|
511
|
-
if (!
|
|
512
|
-
selected = dayjs(defaultDate
|
|
519
|
+
if (!isArray(props.defaultDate)) {
|
|
520
|
+
selected = dayjs(props.defaultDate).format("YYYY-MM");
|
|
513
521
|
} else {
|
|
514
|
-
selected = dayjs(defaultDate
|
|
522
|
+
selected = dayjs(props.defaultDate[0]).format("YYYY-MM");
|
|
515
523
|
}
|
|
516
|
-
scrollIntoDefaultMonth(selected)
|
|
517
|
-
}
|
|
524
|
+
scrollIntoDefaultMonth(selected);
|
|
525
|
+
};
|
|
518
526
|
|
|
519
527
|
defineExpose({
|
|
520
528
|
setFormatter,
|
|
521
|
-
})
|
|
529
|
+
});
|
|
522
530
|
</script>
|
|
523
531
|
|
|
524
532
|
<style scoped lang="scss">
|
|
525
|
-
@import
|
|
533
|
+
@import "./index.scss";
|
|
526
534
|
</style>
|