hy-app 0.6.4 → 0.6.6
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/attributes.json +1 -1
- package/components/hy-address-picker/hy-address-picker.vue +249 -249
- package/components/hy-address-picker/props.ts +103 -103
- package/components/hy-button/hy-button.vue +320 -289
- package/components/hy-button/props.ts +143 -143
- package/components/hy-button/typing.d.ts +43 -35
- package/components/hy-calendar/header.vue +58 -58
- package/components/hy-calendar/hy-calendar.vue +8 -6
- package/components/hy-calendar/month.vue +402 -402
- package/components/hy-calendar/props.ts +169 -169
- package/components/hy-calendar/typing.d.ts +47 -45
- package/components/hy-cell-item/hy-cell-item.vue +161 -161
- package/components/hy-cell-item/props.ts +59 -59
- package/components/hy-check-button/hy-check-button.vue +135 -135
- package/components/hy-code-input/hy-code-input.vue +231 -231
- package/components/hy-code-input/props.ts +90 -90
- package/components/hy-config-provider/hy-config-provider.vue +53 -53
- package/components/hy-config-provider/props.ts +30 -30
- package/components/hy-coupon/hy-coupon.vue +183 -183
- package/components/hy-coupon/props.ts +108 -108
- package/components/hy-datetime-picker/hy-datetime-picker.vue +41 -55
- package/components/hy-datetime-picker/props.ts +144 -144
- package/components/hy-datetime-picker/typing.d.ts +2 -0
- package/components/hy-divider/props.ts +83 -83
- package/components/hy-empty/icon.ts +72 -72
- package/components/hy-folding-panel/hy-folding-panel-group.vue +162 -162
- package/components/hy-form/hy-form.vue +220 -220
- package/components/hy-icon/hy-icon.vue +112 -112
- package/components/hy-index-bar/hy-index-bar.vue +185 -185
- package/components/hy-index-bar/index.scss +64 -64
- package/components/hy-index-bar/props.ts +94 -94
- package/components/hy-index-bar/typing.d.ts +36 -36
- package/components/hy-input/hy-input.vue +333 -333
- package/components/hy-input/props.ts +186 -186
- package/components/hy-modal/hy-modal.vue +211 -211
- package/components/hy-modal/props.ts +94 -94
- package/components/hy-modal/typing.d.ts +16 -16
- package/components/hy-notice-bar/hy-row-notice.vue +121 -121
- package/components/hy-notify/hy-notify.vue +174 -174
- package/components/hy-number-step/hy-number-step.vue +367 -367
- package/components/hy-overlay/hy-overlay.vue +61 -61
- package/components/hy-overlay/props.ts +38 -38
- package/components/hy-pagination/hy-pagination.vue +136 -136
- package/components/hy-pagination/props.ts +58 -58
- package/components/hy-parse/hy-parse.vue +550 -550
- package/components/hy-parse/node/node.vue +781 -781
- package/components/hy-parse/parser.js +1455 -1455
- package/components/hy-parse/props.ts +19 -19
- package/components/hy-parse/typing.d.ts +68 -68
- package/components/hy-picker/hy-picker.vue +435 -435
- package/components/hy-picker/props.ts +122 -122
- package/components/hy-picker/typing.d.ts +38 -38
- package/components/hy-qrcode/props.ts +72 -72
- package/components/hy-qrcode/qrcode.js.bak +1433 -1433
- package/components/hy-radio/props.ts +97 -97
- package/components/hy-read-more/props.ts +48 -48
- package/components/hy-search/props.ts +133 -133
- package/components/hy-signature/canvasHelper.ts +51 -51
- package/components/hy-signature/props.ts +121 -121
- package/components/hy-skeleton/hy-skeleton.vue +142 -142
- package/components/hy-skeleton/props.ts +46 -46
- package/components/hy-skeleton/typing.d.ts +31 -31
- package/components/hy-steps/hy-steps.vue +275 -275
- package/components/hy-steps/typing.d.ts +25 -25
- package/components/hy-swiper/hy-swiper.vue +3 -3
- package/components/hy-swiper/index.scss +5 -5
- package/components/hy-swiper/props.ts +0 -1
- package/components/hy-table/hy-table.vue +630 -630
- package/components/hy-table/props.ts +62 -62
- package/components/hy-table/typing.d.ts +29 -29
- package/components/hy-tabs/hy-tabs.vue +336 -335
- package/components/hy-tabs/props.ts +84 -77
- package/components/hy-tag/hy-tag.vue +173 -173
- package/components/hy-tag/props.ts +89 -89
- package/components/hy-text/hy-text.vue +237 -237
- package/components/hy-text/props.ts +115 -115
- package/components/hy-textarea/hy-textarea.vue +198 -198
- package/components/hy-toast/hy-toast.vue +200 -200
- package/components/hy-toast/props.ts +3 -3
- package/components/hy-transition/hy-transition.vue +157 -157
- package/components/hy-transition/props.ts +32 -32
- package/components/hy-upload/hy-upload.vue +384 -384
- package/components/hy-watermark/hy-watermark.vue +1058 -1058
- package/components/hy-watermark/props.ts +109 -109
- package/global.d.ts +94 -94
- package/libs/api/http.ts +119 -119
- package/libs/composables/index.ts +8 -8
- package/libs/composables/useMessage.ts +149 -149
- package/libs/composables/useToast.ts +45 -45
- package/libs/composables/useTranslate.ts +10 -10
- package/libs/css/_config.scss +5 -5
- package/libs/index.ts +8 -8
- package/libs/locale/index.ts +32 -32
- package/libs/locale/lang/en-US.ts +84 -84
- package/libs/locale/lang/zh-CN.ts +87 -87
- package/libs/typing/index.ts +2 -2
- package/libs/typing/modules/common.d.ts +139 -139
- package/libs/typing/modules/form.ts +176 -176
- package/libs/typing/modules/http.d.ts +19 -19
- package/libs/typing/modules/index.d.ts +12 -12
- package/libs/utils/inside.ts +340 -340
- package/libs/utils/inspect.ts +140 -140
- package/libs/utils/utils.ts +525 -525
- package/package.json +81 -81
- package/tags.json +1 -1
- package/web-types.json +1 -1
|
@@ -1,402 +1,402 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="hy-calendar--month__wrapper" ref="wrapperRef">
|
|
3
|
-
<view
|
|
4
|
-
v-for="(item, index) in months"
|
|
5
|
-
:key="index"
|
|
6
|
-
:class="[`hy-calendar--month__${index}`]"
|
|
7
|
-
:id="`month-${index}`"
|
|
8
|
-
>
|
|
9
|
-
<!-- 月份标题 -->
|
|
10
|
-
<text v-if="index !== 0" class="hy-calendar--month__title">
|
|
11
|
-
{{ formatTime(`${item.year}-${item.month}`, t('monthFormat')) }}
|
|
12
|
-
</text>
|
|
13
|
-
|
|
14
|
-
<view class="hy-calendar--month__days">
|
|
15
|
-
<!-- 月份背景水印 -->
|
|
16
|
-
<view v-if="showMark" class="hy-calendar--month__days__month-mark-wrapper">
|
|
17
|
-
<text class="hy-calendar--month__days__month-mark-wrapper__text">{{
|
|
18
|
-
item.month
|
|
19
|
-
}}</text>
|
|
20
|
-
</view>
|
|
21
|
-
|
|
22
|
-
<!-- 每一天 -->
|
|
23
|
-
<view
|
|
24
|
-
class="hy-calendar--month__days__day"
|
|
25
|
-
v-for="(item1, index1) in item.date"
|
|
26
|
-
:key="index1"
|
|
27
|
-
:style="getDayStyle(index1, item1)"
|
|
28
|
-
@tap="clickHandler(item1)"
|
|
29
|
-
>
|
|
30
|
-
<view :class="getDaySelectClass(item1)" :style="getDaySelectStyle(item1)">
|
|
31
|
-
<!-- 日期文字 -->
|
|
32
|
-
<text
|
|
33
|
-
class="hy-calendar--month__days__day__select__info"
|
|
34
|
-
:class="[
|
|
35
|
-
item1.disabled || isForbid(item1)
|
|
36
|
-
? 'hy-calendar--month__days__day__select__info--disabled'
|
|
37
|
-
: ''
|
|
38
|
-
]"
|
|
39
|
-
:style="getTextStyle(item1)"
|
|
40
|
-
>
|
|
41
|
-
{{ item1.day }}
|
|
42
|
-
</text>
|
|
43
|
-
|
|
44
|
-
<!-- 底部提示文字 (开始/结束) -->
|
|
45
|
-
<text
|
|
46
|
-
v-if="getBottomInfoText(item1)"
|
|
47
|
-
class="hy-calendar--month__days__day__select__button-info"
|
|
48
|
-
:class="[
|
|
49
|
-
item1.disabled || isForbid(item1)
|
|
50
|
-
? 'hy-calendar--month__days__day__select__button-info--disabled'
|
|
51
|
-
: ''
|
|
52
|
-
]"
|
|
53
|
-
:style="getTextStyle(item1)"
|
|
54
|
-
>
|
|
55
|
-
{{ getBottomInfoText(item1) }}
|
|
56
|
-
</text>
|
|
57
|
-
|
|
58
|
-
<!-- 打点标记 -->
|
|
59
|
-
<text
|
|
60
|
-
v-if="item1.dot"
|
|
61
|
-
class="hy-calendar--month__days__day__select__dot"
|
|
62
|
-
></text>
|
|
63
|
-
</view>
|
|
64
|
-
</view>
|
|
65
|
-
</view>
|
|
66
|
-
</view>
|
|
67
|
-
</view>
|
|
68
|
-
</template>
|
|
69
|
-
|
|
70
|
-
<script lang="ts">
|
|
71
|
-
export default {
|
|
72
|
-
options: {
|
|
73
|
-
virtualHost: true,
|
|
74
|
-
styleIsolation: 'shared'
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
</script>
|
|
78
|
-
|
|
79
|
-
<script setup lang="ts">
|
|
80
|
-
import { ref, computed, watch, onMounted, getCurrentInstance, type CSSProperties } from 'vue'
|
|
81
|
-
import dayjs from 'dayjs'
|
|
82
|
-
import {
|
|
83
|
-
addUnit,
|
|
84
|
-
colorGradient,
|
|
85
|
-
deepClone,
|
|
86
|
-
getRect,
|
|
87
|
-
sleep,
|
|
88
|
-
formatTime,
|
|
89
|
-
useTranslate
|
|
90
|
-
} from '../../libs'
|
|
91
|
-
import type { DateItem, IMonthProps } from './typing'
|
|
92
|
-
|
|
93
|
-
const props = withDefaults(defineProps<IMonthProps>(), {
|
|
94
|
-
showMark: true,
|
|
95
|
-
color: '#3c9cff',
|
|
96
|
-
months: () => [],
|
|
97
|
-
mode: 'single',
|
|
98
|
-
rowHeight: 58,
|
|
99
|
-
maxCount: Infinity,
|
|
100
|
-
startText: '开始',
|
|
101
|
-
endText: '结束',
|
|
102
|
-
defaultDate: null,
|
|
103
|
-
minDate: 0,
|
|
104
|
-
maxDate: 0,
|
|
105
|
-
maxMonth: 2,
|
|
106
|
-
readonly: false,
|
|
107
|
-
maxRange: Infinity,
|
|
108
|
-
rangePrompt: '',
|
|
109
|
-
showRangePrompt: true,
|
|
110
|
-
allowSameDay: false,
|
|
111
|
-
forbidDays: () => [],
|
|
112
|
-
forbidDaysToast: ''
|
|
113
|
-
})
|
|
114
|
-
const emit = defineEmits(['monthSelected', 'updateMonthTop'])
|
|
115
|
-
|
|
116
|
-
const { t } = useTranslate('calendar')
|
|
117
|
-
// --- 响应式变量 ---
|
|
118
|
-
const wrapperWidth = ref(0)
|
|
119
|
-
const selected = ref<string[]>([])
|
|
120
|
-
const instance = getCurrentInstance()
|
|
121
|
-
|
|
122
|
-
// --- 逻辑计算 ---
|
|
123
|
-
|
|
124
|
-
// 日期格子的样式
|
|
125
|
-
const getDayStyle = (index2: number, item: DateItem): CSSProperties => {
|
|
126
|
-
const style: CSSProperties = {}
|
|
127
|
-
let week = item.week
|
|
128
|
-
const dayWidth = Number(
|
|
129
|
-
parseFloat(String(wrapperWidth.value / 7))
|
|
130
|
-
.toFixed(3)
|
|
131
|
-
.slice(0, -1)
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
style.width = `${dayWidth}px`
|
|
135
|
-
style.height = addUnit(props.rowHeight)
|
|
136
|
-
|
|
137
|
-
if (index2 === 0) {
|
|
138
|
-
week = (week === 0 ? 7 : week) - 1
|
|
139
|
-
style.marginLeft = `${week * dayWidth}px`
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (props.mode === 'range') {
|
|
143
|
-
style.padding = '0'
|
|
144
|
-
}
|
|
145
|
-
return style
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// 选中状态的 Class
|
|
149
|
-
const getDaySelectClass = (item: DateItem) => {
|
|
150
|
-
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
151
|
-
const classes = ['hy-calendar--month__days__day__select']
|
|
152
|
-
|
|
153
|
-
if (selected.value.some((d) => dateSame(d, dateStr))) {
|
|
154
|
-
classes.push('hy-calendar--month__days__day__select--selected')
|
|
155
|
-
if (selected.value.length >= 2) {
|
|
156
|
-
const len = selected.value.length - 1
|
|
157
|
-
if (!dateSame(dateStr, selected.value[0]) && !dateSame(dateStr, selected.value[len])) {
|
|
158
|
-
classes.push('hy-calendar--month__days__day__select--selected--center')
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return classes
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// 选中状态的 Inline Style
|
|
166
|
-
const getDaySelectStyle = (item: DateItem): CSSProperties => {
|
|
167
|
-
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
168
|
-
const style: CSSProperties = {}
|
|
169
|
-
const isIncluded = selected.value.some((d) => dateSame(d, dateStr))
|
|
170
|
-
|
|
171
|
-
if (isIncluded) {
|
|
172
|
-
style.backgroundColor = props.color
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (props.mode === 'single') {
|
|
176
|
-
if (dateStr === selected.value[0]) {
|
|
177
|
-
style.borderRadius = '3px'
|
|
178
|
-
}
|
|
179
|
-
} else if (props.mode === 'range') {
|
|
180
|
-
if (selected.value.length >= 2) {
|
|
181
|
-
const len = selected.value.length - 1
|
|
182
|
-
if (dateSame(dateStr, selected.value[0])) {
|
|
183
|
-
style.borderTopLeftRadius = '3px'
|
|
184
|
-
style.borderBottomLeftRadius = '3px'
|
|
185
|
-
}
|
|
186
|
-
if (dateSame(dateStr, selected.value[len])) {
|
|
187
|
-
style.borderTopRightRadius = '3px'
|
|
188
|
-
style.borderBottomRightRadius = '3px'
|
|
189
|
-
}
|
|
190
|
-
// 区间中间部分
|
|
191
|
-
if (
|
|
192
|
-
dayjs(dateStr).isAfter(dayjs(selected.value[0])) &&
|
|
193
|
-
dayjs(dateStr).isBefore(dayjs(selected.value[len]))
|
|
194
|
-
) {
|
|
195
|
-
style.backgroundColor = colorGradient(props.color, '#ffffff', 100)[90]
|
|
196
|
-
style.opacity = 0.7
|
|
197
|
-
}
|
|
198
|
-
} else if (selected.value.length === 1) {
|
|
199
|
-
style.borderTopLeftRadius = '3px'
|
|
200
|
-
style.borderBottomLeftRadius = '3px'
|
|
201
|
-
}
|
|
202
|
-
} else {
|
|
203
|
-
if (isIncluded) style.borderRadius = '3px'
|
|
204
|
-
}
|
|
205
|
-
return style
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// 文字颜色样式
|
|
209
|
-
const getTextStyle = (item: DateItem): CSSProperties => {
|
|
210
|
-
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
211
|
-
const style: CSSProperties = {}
|
|
212
|
-
|
|
213
|
-
if (selected.value.some((d) => dateSame(d, dateStr))) {
|
|
214
|
-
style.color = '#ffffff'
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (props.mode === 'range' && selected.value.length >= 2) {
|
|
218
|
-
const len = selected.value.length - 1
|
|
219
|
-
if (
|
|
220
|
-
dayjs(dateStr).isAfter(dayjs(selected.value[0])) &&
|
|
221
|
-
dayjs(dateStr).isBefore(dayjs(selected.value[len]))
|
|
222
|
-
) {
|
|
223
|
-
style.color = props.color
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return style
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// 获取底部提示
|
|
230
|
-
const getBottomInfoText = (item: DateItem) => {
|
|
231
|
-
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
232
|
-
const bottomInfo = item.bottomInfo || ''
|
|
233
|
-
|
|
234
|
-
if (props.mode === 'range' && selected.value.length > 0) {
|
|
235
|
-
if (selected.value.length === 1) {
|
|
236
|
-
return dateSame(dateStr, selected.value[0]) ? props.startText : bottomInfo
|
|
237
|
-
} else {
|
|
238
|
-
const len = selected.value.length - 1
|
|
239
|
-
if (
|
|
240
|
-
dateSame(dateStr, selected.value[0]) &&
|
|
241
|
-
dateSame(dateStr, selected.value[1]) &&
|
|
242
|
-
len === 1
|
|
243
|
-
) {
|
|
244
|
-
return `${props.startText}/${props.endText}`
|
|
245
|
-
} else if (dateSame(dateStr, selected.value[0])) {
|
|
246
|
-
return props.startText
|
|
247
|
-
} else if (dateSame(dateStr, selected.value[len])) {
|
|
248
|
-
return props.endText
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return bottomInfo
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// --- 方法 ---
|
|
256
|
-
|
|
257
|
-
const dateSame = (d1: any, d2: any) => dayjs(d1).isSame(dayjs(d2), 'day')
|
|
258
|
-
|
|
259
|
-
const isForbid = (item: DateItem) => {
|
|
260
|
-
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
261
|
-
return props.mode !== 'range' && props.forbidDays.includes(dateStr)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const getWrapperWidth = async () => {
|
|
265
|
-
const size: any = await getRect('.hy-calendar--month__wrapper', false, instance?.proxy)
|
|
266
|
-
if (size) wrapperWidth.value = size.width
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const getMonthRect = async () => {
|
|
270
|
-
const promiseAllArr = props.months.map(
|
|
271
|
-
(_, index) =>
|
|
272
|
-
new Promise((resolve) => {
|
|
273
|
-
getRect(`.hy-calendar--month__${index}`, false, instance?.proxy).then(resolve)
|
|
274
|
-
})
|
|
275
|
-
)
|
|
276
|
-
|
|
277
|
-
const sizes: any[] = await Promise.all(promiseAllArr)
|
|
278
|
-
let height = 1
|
|
279
|
-
const topArr = []
|
|
280
|
-
for (let i = 0; i < props.months.length; i++) {
|
|
281
|
-
topArr[i] = height
|
|
282
|
-
height += sizes[i]?.height || 0
|
|
283
|
-
}
|
|
284
|
-
emit('updateMonthTop', topArr)
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const clickHandler = (item: DateItem) => {
|
|
288
|
-
if (props.readonly || item.disabled) return
|
|
289
|
-
|
|
290
|
-
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
291
|
-
if (isForbid(item)) {
|
|
292
|
-
uni.showToast({ title: props.forbidDaysToast, icon: 'none' })
|
|
293
|
-
return
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
let newSelected = [...selected.value]
|
|
297
|
-
|
|
298
|
-
if (props.mode === 'single') {
|
|
299
|
-
newSelected = [dateStr]
|
|
300
|
-
} else if (props.mode === 'multiple') {
|
|
301
|
-
const idx = newSelected.findIndex((d) => dateSame(d, dateStr))
|
|
302
|
-
if (idx > -1) {
|
|
303
|
-
newSelected.splice(idx, 1)
|
|
304
|
-
} else if (newSelected.length < (props.maxCount as number)) {
|
|
305
|
-
newSelected.push(dateStr)
|
|
306
|
-
}
|
|
307
|
-
} else if (props.mode === 'range') {
|
|
308
|
-
if (newSelected.length === 0 || newSelected.length >= 2) {
|
|
309
|
-
newSelected = [dateStr]
|
|
310
|
-
} else {
|
|
311
|
-
const startDate = newSelected[0]
|
|
312
|
-
if (dayjs(dateStr).isBefore(dayjs(startDate))) {
|
|
313
|
-
newSelected = [dateStr]
|
|
314
|
-
} else if (dayjs(dateStr).isAfter(dayjs(startDate))) {
|
|
315
|
-
// 范围限制校验
|
|
316
|
-
const daysDiff = dayjs(dateStr).diff(dayjs(startDate), 'day')
|
|
317
|
-
if (daysDiff >= (props.maxRange as number) && props.showRangePrompt) {
|
|
318
|
-
uni.showToast({
|
|
319
|
-
title: props.rangePrompt || `选择天数不能超过 ${props.maxRange} 天`,
|
|
320
|
-
icon: 'none'
|
|
321
|
-
})
|
|
322
|
-
return
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// 填充中间日期
|
|
326
|
-
const arr = []
|
|
327
|
-
let curr = dayjs(startDate)
|
|
328
|
-
const end = dayjs(dateStr)
|
|
329
|
-
while (curr.isBefore(end)) {
|
|
330
|
-
arr.push(curr.format('YYYY-MM-DD'))
|
|
331
|
-
curr = curr.add(1, 'day')
|
|
332
|
-
}
|
|
333
|
-
arr.push(dateStr)
|
|
334
|
-
newSelected = arr
|
|
335
|
-
} else {
|
|
336
|
-
if (!props.allowSameDay) return
|
|
337
|
-
newSelected.push(dateStr)
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
setSelected(newSelected)
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
const setSelected = (val: string[], triggerEvent = true) => {
|
|
345
|
-
selected.value = val
|
|
346
|
-
if (triggerEvent) {
|
|
347
|
-
emit('monthSelected', selected.value, 'tap')
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
const setDefaultDate = () => {
|
|
352
|
-
if (!props.defaultDate) {
|
|
353
|
-
const today = dayjs().format('YYYY-MM-DD')
|
|
354
|
-
return setSelected([today], false)
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
let dates: string[] = []
|
|
358
|
-
if (props.mode === 'single') {
|
|
359
|
-
dates = Array.isArray(props.defaultDate)
|
|
360
|
-
? [props.defaultDate[0]]
|
|
361
|
-
: [dayjs(props.defaultDate).format('YYYY-MM-DD')]
|
|
362
|
-
} else {
|
|
363
|
-
if (!Array.isArray(props.defaultDate)) return
|
|
364
|
-
dates = props.defaultDate
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
const min = props.minDate || dayjs().format('YYYY-MM-DD')
|
|
368
|
-
const max =
|
|
369
|
-
props.maxDate ||
|
|
370
|
-
dayjs(min)
|
|
371
|
-
.add(props.maxMonth - 1, 'month')
|
|
372
|
-
.format('YYYY-MM-DD')
|
|
373
|
-
|
|
374
|
-
const filtered = dates.filter(
|
|
375
|
-
(d) =>
|
|
376
|
-
dayjs(d).isAfter(dayjs(min).subtract(1, 'day')) &&
|
|
377
|
-
dayjs(d).isBefore(dayjs(max).add(1, 'day'))
|
|
378
|
-
)
|
|
379
|
-
setSelected(filtered, false)
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// --- 监听器 ---
|
|
383
|
-
watch(
|
|
384
|
-
() => [props.minDate, props.maxDate, props.defaultDate],
|
|
385
|
-
() => {
|
|
386
|
-
setDefaultDate()
|
|
387
|
-
},
|
|
388
|
-
{ immediate: true }
|
|
389
|
-
)
|
|
390
|
-
|
|
391
|
-
// --- 生命周期 ---
|
|
392
|
-
onMounted(async () => {
|
|
393
|
-
emit('monthSelected', selected.value)
|
|
394
|
-
await sleep(50)
|
|
395
|
-
await getWrapperWidth()
|
|
396
|
-
await getMonthRect()
|
|
397
|
-
})
|
|
398
|
-
</script>
|
|
399
|
-
|
|
400
|
-
<style lang="scss" scoped>
|
|
401
|
-
@import './index';
|
|
402
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<view class="hy-calendar--month__wrapper" ref="wrapperRef">
|
|
3
|
+
<view
|
|
4
|
+
v-for="(item, index) in months"
|
|
5
|
+
:key="index"
|
|
6
|
+
:class="[`hy-calendar--month__${index}`]"
|
|
7
|
+
:id="`month-${index}`"
|
|
8
|
+
>
|
|
9
|
+
<!-- 月份标题 -->
|
|
10
|
+
<text v-if="index !== 0" class="hy-calendar--month__title">
|
|
11
|
+
{{ formatTime(`${item.year}-${item.month}`, t('monthFormat')) }}
|
|
12
|
+
</text>
|
|
13
|
+
|
|
14
|
+
<view class="hy-calendar--month__days">
|
|
15
|
+
<!-- 月份背景水印 -->
|
|
16
|
+
<view v-if="showMark" class="hy-calendar--month__days__month-mark-wrapper">
|
|
17
|
+
<text class="hy-calendar--month__days__month-mark-wrapper__text">{{
|
|
18
|
+
item.month
|
|
19
|
+
}}</text>
|
|
20
|
+
</view>
|
|
21
|
+
|
|
22
|
+
<!-- 每一天 -->
|
|
23
|
+
<view
|
|
24
|
+
class="hy-calendar--month__days__day"
|
|
25
|
+
v-for="(item1, index1) in item.date"
|
|
26
|
+
:key="index1"
|
|
27
|
+
:style="getDayStyle(index1, item1)"
|
|
28
|
+
@tap="clickHandler(item1)"
|
|
29
|
+
>
|
|
30
|
+
<view :class="getDaySelectClass(item1)" :style="getDaySelectStyle(item1)">
|
|
31
|
+
<!-- 日期文字 -->
|
|
32
|
+
<text
|
|
33
|
+
class="hy-calendar--month__days__day__select__info"
|
|
34
|
+
:class="[
|
|
35
|
+
item1.disabled || isForbid(item1)
|
|
36
|
+
? 'hy-calendar--month__days__day__select__info--disabled'
|
|
37
|
+
: ''
|
|
38
|
+
]"
|
|
39
|
+
:style="getTextStyle(item1)"
|
|
40
|
+
>
|
|
41
|
+
{{ item1.day }}
|
|
42
|
+
</text>
|
|
43
|
+
|
|
44
|
+
<!-- 底部提示文字 (开始/结束) -->
|
|
45
|
+
<text
|
|
46
|
+
v-if="getBottomInfoText(item1)"
|
|
47
|
+
class="hy-calendar--month__days__day__select__button-info"
|
|
48
|
+
:class="[
|
|
49
|
+
item1.disabled || isForbid(item1)
|
|
50
|
+
? 'hy-calendar--month__days__day__select__button-info--disabled'
|
|
51
|
+
: ''
|
|
52
|
+
]"
|
|
53
|
+
:style="getTextStyle(item1)"
|
|
54
|
+
>
|
|
55
|
+
{{ getBottomInfoText(item1) }}
|
|
56
|
+
</text>
|
|
57
|
+
|
|
58
|
+
<!-- 打点标记 -->
|
|
59
|
+
<text
|
|
60
|
+
v-if="item1.dot"
|
|
61
|
+
class="hy-calendar--month__days__day__select__dot"
|
|
62
|
+
></text>
|
|
63
|
+
</view>
|
|
64
|
+
</view>
|
|
65
|
+
</view>
|
|
66
|
+
</view>
|
|
67
|
+
</view>
|
|
68
|
+
</template>
|
|
69
|
+
|
|
70
|
+
<script lang="ts">
|
|
71
|
+
export default {
|
|
72
|
+
options: {
|
|
73
|
+
virtualHost: true,
|
|
74
|
+
styleIsolation: 'shared'
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<script setup lang="ts">
|
|
80
|
+
import { ref, computed, watch, onMounted, getCurrentInstance, type CSSProperties } from 'vue'
|
|
81
|
+
import dayjs from 'dayjs'
|
|
82
|
+
import {
|
|
83
|
+
addUnit,
|
|
84
|
+
colorGradient,
|
|
85
|
+
deepClone,
|
|
86
|
+
getRect,
|
|
87
|
+
sleep,
|
|
88
|
+
formatTime,
|
|
89
|
+
useTranslate
|
|
90
|
+
} from '../../libs'
|
|
91
|
+
import type { DateItem, IMonthProps } from './typing'
|
|
92
|
+
|
|
93
|
+
const props = withDefaults(defineProps<IMonthProps>(), {
|
|
94
|
+
showMark: true,
|
|
95
|
+
color: '#3c9cff',
|
|
96
|
+
months: () => [],
|
|
97
|
+
mode: 'single',
|
|
98
|
+
rowHeight: 58,
|
|
99
|
+
maxCount: Infinity,
|
|
100
|
+
startText: '开始',
|
|
101
|
+
endText: '结束',
|
|
102
|
+
defaultDate: null,
|
|
103
|
+
minDate: 0,
|
|
104
|
+
maxDate: 0,
|
|
105
|
+
maxMonth: 2,
|
|
106
|
+
readonly: false,
|
|
107
|
+
maxRange: Infinity,
|
|
108
|
+
rangePrompt: '',
|
|
109
|
+
showRangePrompt: true,
|
|
110
|
+
allowSameDay: false,
|
|
111
|
+
forbidDays: () => [],
|
|
112
|
+
forbidDaysToast: ''
|
|
113
|
+
})
|
|
114
|
+
const emit = defineEmits(['monthSelected', 'updateMonthTop'])
|
|
115
|
+
|
|
116
|
+
const { t } = useTranslate('calendar')
|
|
117
|
+
// --- 响应式变量 ---
|
|
118
|
+
const wrapperWidth = ref(0)
|
|
119
|
+
const selected = ref<string[]>([])
|
|
120
|
+
const instance = getCurrentInstance()
|
|
121
|
+
|
|
122
|
+
// --- 逻辑计算 ---
|
|
123
|
+
|
|
124
|
+
// 日期格子的样式
|
|
125
|
+
const getDayStyle = (index2: number, item: DateItem): CSSProperties => {
|
|
126
|
+
const style: CSSProperties = {}
|
|
127
|
+
let week = item.week
|
|
128
|
+
const dayWidth = Number(
|
|
129
|
+
parseFloat(String(wrapperWidth.value / 7))
|
|
130
|
+
.toFixed(3)
|
|
131
|
+
.slice(0, -1)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
style.width = `${dayWidth}px`
|
|
135
|
+
style.height = addUnit(props.rowHeight)
|
|
136
|
+
|
|
137
|
+
if (index2 === 0) {
|
|
138
|
+
week = (week === 0 ? 7 : week) - 1
|
|
139
|
+
style.marginLeft = `${week * dayWidth}px`
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (props.mode === 'range') {
|
|
143
|
+
style.padding = '0'
|
|
144
|
+
}
|
|
145
|
+
return style
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 选中状态的 Class
|
|
149
|
+
const getDaySelectClass = (item: DateItem) => {
|
|
150
|
+
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
151
|
+
const classes = ['hy-calendar--month__days__day__select']
|
|
152
|
+
|
|
153
|
+
if (selected.value.some((d) => dateSame(d, dateStr))) {
|
|
154
|
+
classes.push('hy-calendar--month__days__day__select--selected')
|
|
155
|
+
if (selected.value.length >= 2) {
|
|
156
|
+
const len = selected.value.length - 1
|
|
157
|
+
if (!dateSame(dateStr, selected.value[0]) && !dateSame(dateStr, selected.value[len])) {
|
|
158
|
+
classes.push('hy-calendar--month__days__day__select--selected--center')
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return classes
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 选中状态的 Inline Style
|
|
166
|
+
const getDaySelectStyle = (item: DateItem): CSSProperties => {
|
|
167
|
+
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
168
|
+
const style: CSSProperties = {}
|
|
169
|
+
const isIncluded = selected.value.some((d) => dateSame(d, dateStr))
|
|
170
|
+
|
|
171
|
+
if (isIncluded) {
|
|
172
|
+
style.backgroundColor = props.color
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (props.mode === 'single') {
|
|
176
|
+
if (dateStr === selected.value[0]) {
|
|
177
|
+
style.borderRadius = '3px'
|
|
178
|
+
}
|
|
179
|
+
} else if (props.mode === 'range') {
|
|
180
|
+
if (selected.value.length >= 2) {
|
|
181
|
+
const len = selected.value.length - 1
|
|
182
|
+
if (dateSame(dateStr, selected.value[0])) {
|
|
183
|
+
style.borderTopLeftRadius = '3px'
|
|
184
|
+
style.borderBottomLeftRadius = '3px'
|
|
185
|
+
}
|
|
186
|
+
if (dateSame(dateStr, selected.value[len])) {
|
|
187
|
+
style.borderTopRightRadius = '3px'
|
|
188
|
+
style.borderBottomRightRadius = '3px'
|
|
189
|
+
}
|
|
190
|
+
// 区间中间部分
|
|
191
|
+
if (
|
|
192
|
+
dayjs(dateStr).isAfter(dayjs(selected.value[0])) &&
|
|
193
|
+
dayjs(dateStr).isBefore(dayjs(selected.value[len]))
|
|
194
|
+
) {
|
|
195
|
+
style.backgroundColor = colorGradient(props.color, '#ffffff', 100)[90]
|
|
196
|
+
style.opacity = 0.7
|
|
197
|
+
}
|
|
198
|
+
} else if (selected.value.length === 1) {
|
|
199
|
+
style.borderTopLeftRadius = '3px'
|
|
200
|
+
style.borderBottomLeftRadius = '3px'
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
if (isIncluded) style.borderRadius = '3px'
|
|
204
|
+
}
|
|
205
|
+
return style
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// 文字颜色样式
|
|
209
|
+
const getTextStyle = (item: DateItem): CSSProperties => {
|
|
210
|
+
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
211
|
+
const style: CSSProperties = {}
|
|
212
|
+
|
|
213
|
+
if (selected.value.some((d) => dateSame(d, dateStr))) {
|
|
214
|
+
style.color = '#ffffff'
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (props.mode === 'range' && selected.value.length >= 2) {
|
|
218
|
+
const len = selected.value.length - 1
|
|
219
|
+
if (
|
|
220
|
+
dayjs(dateStr).isAfter(dayjs(selected.value[0])) &&
|
|
221
|
+
dayjs(dateStr).isBefore(dayjs(selected.value[len]))
|
|
222
|
+
) {
|
|
223
|
+
style.color = props.color
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return style
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// 获取底部提示
|
|
230
|
+
const getBottomInfoText = (item: DateItem) => {
|
|
231
|
+
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
232
|
+
const bottomInfo = item.bottomInfo || ''
|
|
233
|
+
|
|
234
|
+
if (props.mode === 'range' && selected.value.length > 0) {
|
|
235
|
+
if (selected.value.length === 1) {
|
|
236
|
+
return dateSame(dateStr, selected.value[0]) ? props.startText : bottomInfo
|
|
237
|
+
} else {
|
|
238
|
+
const len = selected.value.length - 1
|
|
239
|
+
if (
|
|
240
|
+
dateSame(dateStr, selected.value[0]) &&
|
|
241
|
+
dateSame(dateStr, selected.value[1]) &&
|
|
242
|
+
len === 1
|
|
243
|
+
) {
|
|
244
|
+
return `${props.startText}/${props.endText}`
|
|
245
|
+
} else if (dateSame(dateStr, selected.value[0])) {
|
|
246
|
+
return props.startText
|
|
247
|
+
} else if (dateSame(dateStr, selected.value[len])) {
|
|
248
|
+
return props.endText
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return bottomInfo
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// --- 方法 ---
|
|
256
|
+
|
|
257
|
+
const dateSame = (d1: any, d2: any) => dayjs(d1).isSame(dayjs(d2), 'day')
|
|
258
|
+
|
|
259
|
+
const isForbid = (item: DateItem) => {
|
|
260
|
+
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
261
|
+
return props.mode !== 'range' && props.forbidDays.includes(dateStr)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const getWrapperWidth = async () => {
|
|
265
|
+
const size: any = await getRect('.hy-calendar--month__wrapper', false, instance?.proxy)
|
|
266
|
+
if (size) wrapperWidth.value = size.width
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const getMonthRect = async () => {
|
|
270
|
+
const promiseAllArr = props.months.map(
|
|
271
|
+
(_, index) =>
|
|
272
|
+
new Promise((resolve) => {
|
|
273
|
+
getRect(`.hy-calendar--month__${index}`, false, instance?.proxy).then(resolve)
|
|
274
|
+
})
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
const sizes: any[] = await Promise.all(promiseAllArr)
|
|
278
|
+
let height = 1
|
|
279
|
+
const topArr = []
|
|
280
|
+
for (let i = 0; i < props.months.length; i++) {
|
|
281
|
+
topArr[i] = height
|
|
282
|
+
height += sizes[i]?.height || 0
|
|
283
|
+
}
|
|
284
|
+
emit('updateMonthTop', topArr)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const clickHandler = (item: DateItem) => {
|
|
288
|
+
if (props.readonly || item.disabled) return
|
|
289
|
+
|
|
290
|
+
const dateStr = dayjs(item.date).format('YYYY-MM-DD')
|
|
291
|
+
if (isForbid(item)) {
|
|
292
|
+
uni.showToast({ title: props.forbidDaysToast, icon: 'none' })
|
|
293
|
+
return
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
let newSelected = [...selected.value]
|
|
297
|
+
|
|
298
|
+
if (props.mode === 'single') {
|
|
299
|
+
newSelected = [dateStr]
|
|
300
|
+
} else if (props.mode === 'multiple') {
|
|
301
|
+
const idx = newSelected.findIndex((d) => dateSame(d, dateStr))
|
|
302
|
+
if (idx > -1) {
|
|
303
|
+
newSelected.splice(idx, 1)
|
|
304
|
+
} else if (newSelected.length < (props.maxCount as number)) {
|
|
305
|
+
newSelected.push(dateStr)
|
|
306
|
+
}
|
|
307
|
+
} else if (props.mode === 'range') {
|
|
308
|
+
if (newSelected.length === 0 || newSelected.length >= 2) {
|
|
309
|
+
newSelected = [dateStr]
|
|
310
|
+
} else {
|
|
311
|
+
const startDate = newSelected[0]
|
|
312
|
+
if (dayjs(dateStr).isBefore(dayjs(startDate))) {
|
|
313
|
+
newSelected = [dateStr]
|
|
314
|
+
} else if (dayjs(dateStr).isAfter(dayjs(startDate))) {
|
|
315
|
+
// 范围限制校验
|
|
316
|
+
const daysDiff = dayjs(dateStr).diff(dayjs(startDate), 'day')
|
|
317
|
+
if (daysDiff >= (props.maxRange as number) && props.showRangePrompt) {
|
|
318
|
+
uni.showToast({
|
|
319
|
+
title: props.rangePrompt || `选择天数不能超过 ${props.maxRange} 天`,
|
|
320
|
+
icon: 'none'
|
|
321
|
+
})
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// 填充中间日期
|
|
326
|
+
const arr = []
|
|
327
|
+
let curr = dayjs(startDate)
|
|
328
|
+
const end = dayjs(dateStr)
|
|
329
|
+
while (curr.isBefore(end)) {
|
|
330
|
+
arr.push(curr.format('YYYY-MM-DD'))
|
|
331
|
+
curr = curr.add(1, 'day')
|
|
332
|
+
}
|
|
333
|
+
arr.push(dateStr)
|
|
334
|
+
newSelected = arr
|
|
335
|
+
} else {
|
|
336
|
+
if (!props.allowSameDay) return
|
|
337
|
+
newSelected.push(dateStr)
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
setSelected(newSelected)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const setSelected = (val: string[], triggerEvent = true) => {
|
|
345
|
+
selected.value = val
|
|
346
|
+
if (triggerEvent) {
|
|
347
|
+
emit('monthSelected', selected.value, 'tap')
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const setDefaultDate = () => {
|
|
352
|
+
if (!props.defaultDate) {
|
|
353
|
+
const today = dayjs().format('YYYY-MM-DD')
|
|
354
|
+
return setSelected([today], false)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
let dates: string[] = []
|
|
358
|
+
if (props.mode === 'single') {
|
|
359
|
+
dates = Array.isArray(props.defaultDate)
|
|
360
|
+
? [props.defaultDate[0]]
|
|
361
|
+
: [dayjs(props.defaultDate).format('YYYY-MM-DD')]
|
|
362
|
+
} else {
|
|
363
|
+
if (!Array.isArray(props.defaultDate)) return
|
|
364
|
+
dates = props.defaultDate
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const min = props.minDate || dayjs().format('YYYY-MM-DD')
|
|
368
|
+
const max =
|
|
369
|
+
props.maxDate ||
|
|
370
|
+
dayjs(min)
|
|
371
|
+
.add(props.maxMonth - 1, 'month')
|
|
372
|
+
.format('YYYY-MM-DD')
|
|
373
|
+
|
|
374
|
+
const filtered = dates.filter(
|
|
375
|
+
(d) =>
|
|
376
|
+
dayjs(d).isAfter(dayjs(min).subtract(1, 'day')) &&
|
|
377
|
+
dayjs(d).isBefore(dayjs(max).add(1, 'day'))
|
|
378
|
+
)
|
|
379
|
+
setSelected(filtered, false)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// --- 监听器 ---
|
|
383
|
+
watch(
|
|
384
|
+
() => [props.minDate, props.maxDate, props.defaultDate],
|
|
385
|
+
() => {
|
|
386
|
+
setDefaultDate()
|
|
387
|
+
},
|
|
388
|
+
{ immediate: true }
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
// --- 生命周期 ---
|
|
392
|
+
onMounted(async () => {
|
|
393
|
+
emit('monthSelected', selected.value)
|
|
394
|
+
await sleep(50)
|
|
395
|
+
await getWrapperWidth()
|
|
396
|
+
await getMonthRect()
|
|
397
|
+
})
|
|
398
|
+
</script>
|
|
399
|
+
|
|
400
|
+
<style lang="scss" scoped>
|
|
401
|
+
@import './index';
|
|
402
|
+
</style>
|