sadais-piui 1.2.7-beta113 → 1.2.7-beta115
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/.prettierrc +7 -7
- package/CHANGELOG.md +545 -545
- package/LICENSE +20 -20
- package/README.md +166 -166
- package/components/pi-action-sheet/index.vue +247 -247
- package/components/pi-badge/index.vue +146 -146
- package/components/pi-bottom-bar/index.vue +139 -139
- package/components/pi-bubble/index.vue +174 -174
- package/components/pi-button/index.vue +492 -492
- package/components/pi-calendar-input/index.vue +230 -230
- package/components/pi-calendar-panel/components/calendar-days/index.vue +410 -410
- package/components/pi-calendar-panel/index.vue +473 -473
- package/components/pi-canvas/index.vue +407 -407
- package/components/pi-card/index.vue +127 -127
- package/components/pi-cascader/index.vue +601 -601
- package/components/pi-checkbox/index.vue +363 -363
- package/components/pi-checkbox-group/index.vue +222 -222
- package/components/pi-circle-progress/index.vue +311 -311
- package/components/pi-code-input/index.vue +270 -270
- package/components/pi-collapse/index.vue +124 -124
- package/components/pi-collapse-item/index.vue +352 -352
- package/components/pi-count-down/index.vue +245 -245
- package/components/pi-count-up/index.vue +209 -209
- package/components/pi-date-picker-input/index.vue +219 -219
- package/components/pi-divider/index.vue +112 -112
- package/components/pi-dropdown/components/dropdown-tab.vue +71 -71
- package/components/pi-dropdown/index.vue +356 -356
- package/components/pi-dropdown-item/index.vue +252 -252
- package/components/pi-form/index.vue +273 -273
- package/components/pi-form-item/index.vue +603 -590
- package/components/pi-gap/index.vue +72 -72
- package/components/pi-grid/index.vue +92 -92
- package/components/pi-grid-item/index.vue +220 -220
- package/components/pi-icon/index.vue +147 -147
- package/components/pi-img/index.vue +266 -266
- package/components/pi-img-cropper/canvas.js +106 -106
- package/components/pi-img-cropper/index.vue +357 -357
- package/components/pi-img-cropper/touch.js +163 -163
- package/components/pi-img-cropper/vector.js +34 -34
- package/components/pi-input/index.vue +409 -401
- package/components/pi-line/index.vue +78 -78
- package/components/pi-line-progress/index.vue +198 -198
- package/components/pi-list/index.vue +115 -115
- package/components/pi-list-item/index.vue +335 -335
- package/components/pi-loading/index.vue +188 -188
- package/components/pi-marquee/index.vue +310 -310
- package/components/pi-marquee-item/index.vue +47 -47
- package/components/pi-mask/index.vue +198 -198
- package/components/pi-modal/index.vue +303 -303
- package/components/pi-navbar/index.vue +421 -421
- package/components/pi-notify/index.vue +239 -239
- package/components/pi-number-keyboard/index.vue +189 -189
- package/components/pi-opentype-button/index.vue +501 -501
- package/components/pi-pagination/index.vue +290 -290
- package/components/pi-picker/index.vue +317 -317
- package/components/pi-popup/index.vue +356 -356
- package/components/pi-popup-select/index.vue +300 -300
- package/components/pi-radio/index.vue +403 -403
- package/components/pi-radio-group/index.vue +300 -300
- package/components/pi-rate/index.vue +212 -212
- package/components/pi-regions-select/index.vue +349 -349
- package/components/pi-regions-select-input/index.vue +230 -230
- package/components/pi-search/index.vue +386 -386
- package/components/pi-section/index.vue +218 -218
- package/components/pi-select/index.vue +678 -678
- package/components/pi-select-input/index.vue +273 -273
- package/components/pi-skeleton/index.vue +280 -280
- package/components/pi-status-bar/index.vue +56 -56
- package/components/pi-stepper/index.vue +408 -408
- package/components/pi-steps/index.vue +378 -378
- package/components/pi-subsection/index.vue +403 -403
- package/components/pi-swiper/index.vue +344 -344
- package/components/pi-switch/index.vue +231 -231
- package/components/pi-table/index.vue +351 -351
- package/components/pi-tabs/index.vue +435 -435
- package/components/pi-tag/index.vue +488 -488
- package/components/pi-upload-img/index.vue +980 -980
- package/components/pi-waterfall/index.vue +130 -130
- package/config/actionSheet.js +24 -24
- package/config/badge.js +9 -9
- package/config/bottomBar.js +11 -11
- package/config/bubble.js +6 -6
- package/config/button.js +29 -29
- package/config/calendar.js +19 -19
- package/config/calendarInput.js +19 -19
- package/config/calendarPanel.js +27 -27
- package/config/card.js +8 -8
- package/config/cascader.js +22 -22
- package/config/checkbox.js +15 -15
- package/config/checkboxGroup.js +15 -15
- package/config/circleProgress.js +20 -20
- package/config/codeInput.js +13 -13
- package/config/collapse.js +7 -7
- package/config/collapseItem.js +11 -11
- package/config/countDown.js +12 -12
- package/config/countUp.js +13 -13
- package/config/datePickerInput.js +18 -18
- package/config/divider.js +10 -10
- package/config/dropdown.js +25 -25
- package/config/dropdownItem.js +26 -26
- package/config/form.js +29 -29
- package/config/formItem.js +27 -27
- package/config/gap.js +8 -8
- package/config/grid.js +9 -9
- package/config/gridItem.js +12 -12
- package/config/icon.js +11 -11
- package/config/img.js +21 -21
- package/config/imgCropper.js +26 -26
- package/config/index.js +28 -28
- package/config/input.js +37 -36
- package/config/line.js +8 -8
- package/config/lineProgress.js +14 -14
- package/config/list.js +12 -12
- package/config/listItem.js +25 -25
- package/config/loading.js +10 -10
- package/config/marquee.js +10 -10
- package/config/mask.js +12 -12
- package/config/modal.js +36 -36
- package/config/navbar.js +32 -32
- package/config/notify.js +13 -13
- package/config/numberKeyboard.js +21 -21
- package/config/pagination.js +10 -10
- package/config/picker.js +19 -19
- package/config/popup.js +23 -23
- package/config/popupSelect.js +35 -35
- package/config/radio.js +16 -16
- package/config/radioGroup.js +17 -17
- package/config/rate.js +15 -15
- package/config/regionsData.js +58 -58
- package/config/regionsSelect.js +19 -19
- package/config/regionsSelectInput.js +29 -29
- package/config/search.js +27 -27
- package/config/section.js +23 -23
- package/config/select.js +41 -41
- package/config/selectInput.js +29 -29
- package/config/skeleton.js +13 -13
- package/config/statusBar.js +5 -5
- package/config/stepper.js +19 -19
- package/config/steps.js +19 -19
- package/config/subsection.js +14 -14
- package/config/swiper.js +22 -22
- package/config/switch.js +13 -13
- package/config/table.js +8 -8
- package/config/tabs.js +23 -23
- package/config/tag.js +21 -21
- package/config/uploadImg.js +81 -81
- package/config/waterfall.js +6 -6
- package/index.js +41 -41
- package/mixin/component-custom.js +24 -24
- package/mixin/emitter.js +45 -45
- package/mixin/props-sync.js +65 -65
- package/mixin/value-sync.js +32 -32
- package/mixin/wx-code.js +30 -30
- package/package.json +28 -28
- package/plugins/async-validator.js +1511 -1511
- package/scss/animation.scss +260 -260
- package/scss/icon/icon.scss +595 -595
- package/scss/index.scss +5 -5
- package/scss/mixin.scss +47 -47
- package/tools/index.js +19 -19
|
@@ -1,410 +1,410 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
* @Author: zhangzhenfei
|
|
3
|
-
* @Date: 2022-06-28 16:53:54
|
|
4
|
-
* @LastEditTime: 2023-05-12 16:02:29
|
|
5
|
-
* @LastEditors: zhangzhenfei
|
|
6
|
-
* @Description: 日历日期数据
|
|
7
|
-
* @FilePath: /piui-awesome/src/piui/components/pi-calendar-panel/components/calendar-days/index.vue
|
|
8
|
-
-->
|
|
9
|
-
|
|
10
|
-
<template>
|
|
11
|
-
<view class="pi-rela pi-align-center pi-flex-wrap pi-pd-24">
|
|
12
|
-
<view
|
|
13
|
-
v-for="day in days"
|
|
14
|
-
:key="day.key"
|
|
15
|
-
class="date-item"
|
|
16
|
-
style="cursor: pointer;"
|
|
17
|
-
:class="[
|
|
18
|
-
{ 'pi-disabled': day.disabled || day.type === 'disabled' },
|
|
19
|
-
{ range: day.range },
|
|
20
|
-
{ marked: day.marked }
|
|
21
|
-
]"
|
|
22
|
-
@tap.stop="handleSelectDate(day)"
|
|
23
|
-
>
|
|
24
|
-
<view class="pi-square">
|
|
25
|
-
<view class="pi-rela date-item-inner">
|
|
26
|
-
<view
|
|
27
|
-
class="pi-w-100P pi-h-100P pi-flex-column-center pi-lh-28"
|
|
28
|
-
:style="[day.nowStyle, day.activeStyle, day.rangeStyle]"
|
|
29
|
-
>
|
|
30
|
-
<text>{{ day.date }}</text>
|
|
31
|
-
<text v-if="day.tip" class=" pi-text-nowrap pi-fz-18 pi-mg-top-6">
|
|
32
|
-
{{ day.tip }}
|
|
33
|
-
</text>
|
|
34
|
-
</view>
|
|
35
|
-
</view>
|
|
36
|
-
</view>
|
|
37
|
-
</view>
|
|
38
|
-
<!-- 日历蒙层 -->
|
|
39
|
-
<view
|
|
40
|
-
class="pi-abso-center pi-fw-500 pi-light-gray pi-text-nowrap"
|
|
41
|
-
style="
|
|
42
|
-
z-index: -1;
|
|
43
|
-
pointer-events: none;
|
|
44
|
-
opacity: 0.15;"
|
|
45
|
-
:style="[
|
|
46
|
-
{ fontSize: weekView ? '32rpx' : '300rpx' },
|
|
47
|
-
{ marginTop: weekView ? '30rpx' : '0' }
|
|
48
|
-
]"
|
|
49
|
-
>
|
|
50
|
-
{{ getBgTip }}
|
|
51
|
-
</view>
|
|
52
|
-
</view>
|
|
53
|
-
</template>
|
|
54
|
-
|
|
55
|
-
<script>
|
|
56
|
-
import { getConfig } from '../../../../config'
|
|
57
|
-
const { calendarPanel } = getConfig()
|
|
58
|
-
|
|
59
|
-
export default {
|
|
60
|
-
name: 'PiCalendarDays',
|
|
61
|
-
props: {
|
|
62
|
-
calendarValue: {
|
|
63
|
-
type: [String, Object, Array],
|
|
64
|
-
default: ''
|
|
65
|
-
},
|
|
66
|
-
year: {
|
|
67
|
-
type: [String, Number],
|
|
68
|
-
default: ''
|
|
69
|
-
},
|
|
70
|
-
month: {
|
|
71
|
-
type: [String, Number],
|
|
72
|
-
default: ''
|
|
73
|
-
},
|
|
74
|
-
// 当前展示周
|
|
75
|
-
week: {
|
|
76
|
-
type: Number,
|
|
77
|
-
default: 0
|
|
78
|
-
},
|
|
79
|
-
// 日历类型
|
|
80
|
-
type: {
|
|
81
|
-
// `'date'-单个日期`, `'range'-范围日期`
|
|
82
|
-
type: String,
|
|
83
|
-
// 'date'
|
|
84
|
-
default: calendarPanel.type,
|
|
85
|
-
validator: function(value) {
|
|
86
|
-
return ['date', 'range'].includes(value)
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
// 最小可选日期(不在范围内日期禁用不可选,默认'',不作限制)
|
|
90
|
-
minDate: {
|
|
91
|
-
type: [Number, String, Date],
|
|
92
|
-
// ''
|
|
93
|
-
default: calendarPanel.minDate
|
|
94
|
-
},
|
|
95
|
-
// 最大可选日期(不在范围内日期禁用不可选,默认'',不作限制)
|
|
96
|
-
maxDate: {
|
|
97
|
-
type: [Number, String, Date],
|
|
98
|
-
// ''
|
|
99
|
-
default: calendarPanel.maxDate
|
|
100
|
-
},
|
|
101
|
-
// 是否显示回到今日
|
|
102
|
-
showBackToday: {
|
|
103
|
-
type: Boolean,
|
|
104
|
-
// true
|
|
105
|
-
default: calendarPanel.showBackToday
|
|
106
|
-
},
|
|
107
|
-
// 今日日期激活边框颜色
|
|
108
|
-
todayActiveBorderColor: {
|
|
109
|
-
type: String,
|
|
110
|
-
// '#ff6a00'
|
|
111
|
-
default: calendarPanel.todayActiveBorderColor
|
|
112
|
-
},
|
|
113
|
-
// 选中|起始结束日期字体颜色
|
|
114
|
-
activeColor: {
|
|
115
|
-
type: String,
|
|
116
|
-
// '#ffffff'
|
|
117
|
-
default: calendarPanel.activeColor
|
|
118
|
-
},
|
|
119
|
-
// 选中|起始结束日期背景,默认
|
|
120
|
-
activeBg: {
|
|
121
|
-
type: String,
|
|
122
|
-
// '#ff6a00'
|
|
123
|
-
default: calendarPanel.activeBg
|
|
124
|
-
},
|
|
125
|
-
// 选中圆角效果
|
|
126
|
-
activeBorderRadius: {
|
|
127
|
-
type: [String, Number],
|
|
128
|
-
// '0 0 0 0'
|
|
129
|
-
default: calendarPanel.activeBorderRadius
|
|
130
|
-
},
|
|
131
|
-
// 范围内日期字体颜色默认
|
|
132
|
-
rangeColor: {
|
|
133
|
-
type: String,
|
|
134
|
-
// '#ff6a00'
|
|
135
|
-
default: calendarPanel.rangeColor
|
|
136
|
-
},
|
|
137
|
-
// 范围内日期背景色
|
|
138
|
-
rangeBg: {
|
|
139
|
-
type: String,
|
|
140
|
-
// 'rgba(254, 106, 0, 0.1)'
|
|
141
|
-
default: calendarPanel.rangeBg
|
|
142
|
-
},
|
|
143
|
-
// type=range时生效,起始日期自定义文案
|
|
144
|
-
startText: {
|
|
145
|
-
type: String,
|
|
146
|
-
// '开始'
|
|
147
|
-
default: calendarPanel.startText
|
|
148
|
-
},
|
|
149
|
-
// type=range时生效,结束日期自定义文案
|
|
150
|
-
endText: {
|
|
151
|
-
type: String,
|
|
152
|
-
// '结束'
|
|
153
|
-
default: calendarPanel.endText
|
|
154
|
-
},
|
|
155
|
-
weekView: {
|
|
156
|
-
type: Boolean,
|
|
157
|
-
// '是否显示周视图'
|
|
158
|
-
default: calendarPanel.defalutWeekView
|
|
159
|
-
},
|
|
160
|
-
// 日期标记,数组形式,默认([])
|
|
161
|
-
marks: {
|
|
162
|
-
type: Array,
|
|
163
|
-
// []
|
|
164
|
-
default: () => calendarPanel.marks
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
data() {
|
|
168
|
-
const now = this.$pi.date.parseDate()
|
|
169
|
-
return {
|
|
170
|
-
now: now // 当前时间
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
computed: {
|
|
174
|
-
getActiveBorderRadius() {
|
|
175
|
-
return this.$pi.common.addUnit(this.activeBorderRadius)
|
|
176
|
-
},
|
|
177
|
-
// 获取上个月最后一天
|
|
178
|
-
getPreMonthLastDay() {
|
|
179
|
-
let year = this.year
|
|
180
|
-
let month = this.month - 1
|
|
181
|
-
if (month === 0) {
|
|
182
|
-
year = year - 1
|
|
183
|
-
month = 12
|
|
184
|
-
}
|
|
185
|
-
return new Date(year, month, '0')
|
|
186
|
-
},
|
|
187
|
-
getNextMonthFirstDay() {
|
|
188
|
-
let year = this.year
|
|
189
|
-
let month = this.month + 1
|
|
190
|
-
if (month === 13) {
|
|
191
|
-
year = year + 1
|
|
192
|
-
month = 1
|
|
193
|
-
}
|
|
194
|
-
return new Date(year, month - 1, '1')
|
|
195
|
-
},
|
|
196
|
-
// 第一天
|
|
197
|
-
firstDay() {
|
|
198
|
-
const firstDays = []
|
|
199
|
-
const preMonthLastDay = this.getPreMonthLastDay
|
|
200
|
-
const lastDay = preMonthLastDay.getDate()
|
|
201
|
-
const firstDay = new Date(this.year, this.month - 1, '1').getDay()
|
|
202
|
-
for (let i = 0; i < firstDay; i++) {
|
|
203
|
-
const day = preMonthLastDay.setDate(lastDay - firstDay + i + 1)
|
|
204
|
-
firstDays.push(new Date(day))
|
|
205
|
-
}
|
|
206
|
-
return firstDays
|
|
207
|
-
},
|
|
208
|
-
getMinDate() {
|
|
209
|
-
return this.minDate ? this.$pi.date.parseDate(this.minDate) : ''
|
|
210
|
-
},
|
|
211
|
-
getMaxDate() {
|
|
212
|
-
return this.maxDate ? this.$pi.date.parseDate(this.maxDate) : ''
|
|
213
|
-
},
|
|
214
|
-
getMarks() {
|
|
215
|
-
return this.marks.map(item => {
|
|
216
|
-
return this.$pi.date.parseDate(item)
|
|
217
|
-
})
|
|
218
|
-
},
|
|
219
|
-
// 总天数
|
|
220
|
-
days() {
|
|
221
|
-
const days = []
|
|
222
|
-
const dayCount = 7 * 6 // 固定显示6周
|
|
223
|
-
const monthDays = new Date(this.year, this.month, 0).getDate()
|
|
224
|
-
const firstDayCount = this.firstDay.length
|
|
225
|
-
const nextMonthFirstDay = this.getNextMonthFirstDay
|
|
226
|
-
for (let i = 1; i <= dayCount; i++) {
|
|
227
|
-
let day = {
|
|
228
|
-
key: this.$pi.guid(),
|
|
229
|
-
index: i
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// 上月数据
|
|
233
|
-
if (i <= firstDayCount) {
|
|
234
|
-
day = {
|
|
235
|
-
...day,
|
|
236
|
-
...this.$pi.date.parseDate(this.firstDay[i - 1]),
|
|
237
|
-
type: this.weekView ? '' : 'disabled'
|
|
238
|
-
}
|
|
239
|
-
} else if (i > monthDays + firstDayCount) {
|
|
240
|
-
// 下月数据
|
|
241
|
-
day = {
|
|
242
|
-
...day,
|
|
243
|
-
...this.$pi.date.parseDate(
|
|
244
|
-
new Date(nextMonthFirstDay.setDate(i - monthDays - firstDayCount))
|
|
245
|
-
),
|
|
246
|
-
type: this.weekView ? '' : 'disabled'
|
|
247
|
-
}
|
|
248
|
-
} else {
|
|
249
|
-
// 当月数据
|
|
250
|
-
day = {
|
|
251
|
-
...day,
|
|
252
|
-
...this.$pi.date.parseDate(new Date(this.year, this.month - 1, i - firstDayCount))
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const isDisabled = this.isDisabled(day)
|
|
257
|
-
// 禁用
|
|
258
|
-
if (isDisabled) {
|
|
259
|
-
day.disabled = true
|
|
260
|
-
}
|
|
261
|
-
// 单选选中样式
|
|
262
|
-
if (this.type === 'date' && this.isSameDay(this.calendarValue, day)) {
|
|
263
|
-
const activeStyle = {
|
|
264
|
-
color: this.activeColor,
|
|
265
|
-
borderRadius: this.getActiveBorderRadius
|
|
266
|
-
}
|
|
267
|
-
if (this.activeBg) activeStyle.background = this.activeBg
|
|
268
|
-
day.activeStyle = activeStyle
|
|
269
|
-
}
|
|
270
|
-
// 范围选中样式
|
|
271
|
-
if (this.type === 'range') {
|
|
272
|
-
const start = this.calendarValue[0]
|
|
273
|
-
const end = this.calendarValue[1]
|
|
274
|
-
const isBegin = this.isSameDay(start, day)
|
|
275
|
-
const isEnd = this.isSameDay(end, day)
|
|
276
|
-
const inRange =
|
|
277
|
-
start && end && day.timestamp > start.timestamp && day.timestamp < end.timestamp
|
|
278
|
-
const rangeStyle = {}
|
|
279
|
-
// 处理中间范围的样式
|
|
280
|
-
if (inRange) {
|
|
281
|
-
rangeStyle.color = this.rangeColor
|
|
282
|
-
rangeStyle.background = this.rangeBg
|
|
283
|
-
}
|
|
284
|
-
// 处理两端
|
|
285
|
-
if (isBegin || isEnd) {
|
|
286
|
-
rangeStyle.color = this.activeColor
|
|
287
|
-
rangeStyle.borderRadius = isBegin
|
|
288
|
-
? `${this.getActiveBorderRadius} 0 0 0`
|
|
289
|
-
: `0 0 ${this.getActiveBorderRadius} 0`
|
|
290
|
-
if (this.activeBg) rangeStyle.background = this.activeBg
|
|
291
|
-
}
|
|
292
|
-
day.range = true
|
|
293
|
-
day.rangeStyle = rangeStyle
|
|
294
|
-
// type 为 range 开始和结束的提示
|
|
295
|
-
if (isBegin) day.tip = this.startText
|
|
296
|
-
if (isEnd) day.tip = this.endText
|
|
297
|
-
if (isBegin && isEnd) {
|
|
298
|
-
day.tip = this.startText + '-' + this.endText
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
// 是否打点
|
|
302
|
-
if (this.getMarks.length) {
|
|
303
|
-
const mark = this.getMarks.find(item => {
|
|
304
|
-
return this.isSameDay(item, day)
|
|
305
|
-
})
|
|
306
|
-
if (mark) {
|
|
307
|
-
day.marked = mark
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
// 当天样式
|
|
311
|
-
if (this.isSameDay(this.now, day)) {
|
|
312
|
-
day.today = true
|
|
313
|
-
if (this.showBackToday) {
|
|
314
|
-
day.nowStyle = {
|
|
315
|
-
color: this.todayActiveBorderColor,
|
|
316
|
-
border: '1px solid ' + this.todayActiveBorderColor,
|
|
317
|
-
borderRadius: this.getActiveBorderRadius
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
days.push(day)
|
|
322
|
-
}
|
|
323
|
-
if (this.weekView) {
|
|
324
|
-
days.splice(0, (this.week - 1) * 7)
|
|
325
|
-
days.splice(7, days.length - 7)
|
|
326
|
-
}
|
|
327
|
-
return days
|
|
328
|
-
},
|
|
329
|
-
getBgTip() {
|
|
330
|
-
if (!this.days.length) return ''
|
|
331
|
-
const startDay = this.days[0]
|
|
332
|
-
const endDay = this.days[this.days.length - 1]
|
|
333
|
-
return this.weekView
|
|
334
|
-
? `${startDay.month}月 ${startDay.date}日 - ${endDay.month}月 ${endDay.date}日`
|
|
335
|
-
: this.month
|
|
336
|
-
}
|
|
337
|
-
},
|
|
338
|
-
methods: {
|
|
339
|
-
isSameDay(day1, day2) {
|
|
340
|
-
return (
|
|
341
|
-
day1 &&
|
|
342
|
-
day2 &&
|
|
343
|
-
day1.year === day2.year &&
|
|
344
|
-
day1.month === day2.month &&
|
|
345
|
-
day1.date === day2.date
|
|
346
|
-
)
|
|
347
|
-
},
|
|
348
|
-
isDisabled(day) {
|
|
349
|
-
const isDisabled =
|
|
350
|
-
(this.getMinDate && day.timestamp < this.getMinDate.timestamp) ||
|
|
351
|
-
(this.getMaxDate && day.timestamp > this.getMaxDate.timestamp)
|
|
352
|
-
return isDisabled
|
|
353
|
-
},
|
|
354
|
-
handleChange(value) {
|
|
355
|
-
this.$emit('change', value)
|
|
356
|
-
},
|
|
357
|
-
handleSelectDate(date) {
|
|
358
|
-
if (date.disabled) return
|
|
359
|
-
if (this.type === 'date') {
|
|
360
|
-
// 单选方式
|
|
361
|
-
this.handleChange(date)
|
|
362
|
-
return
|
|
363
|
-
}
|
|
364
|
-
// 处理范围选择方式
|
|
365
|
-
if (this.calendarValue.length === 0 || this.calendarValue.length === 2) {
|
|
366
|
-
// 如果选了两项,则重新开始选择范围
|
|
367
|
-
this.handleChange([date])
|
|
368
|
-
} else {
|
|
369
|
-
// 和第一项判断大小,小的放前面
|
|
370
|
-
if (date.timestamp > this.calendarValue[0].timestamp) {
|
|
371
|
-
this.handleChange([this.calendarValue[0], date])
|
|
372
|
-
} else {
|
|
373
|
-
this.handleChange([date, this.calendarValue[0]])
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
</script>
|
|
380
|
-
|
|
381
|
-
<style lang="scss" scoped>
|
|
382
|
-
.date-item {
|
|
383
|
-
position: relative;
|
|
384
|
-
z-index: 2;
|
|
385
|
-
width: calc(100% / 7);
|
|
386
|
-
overflow: hidden;
|
|
387
|
-
&.marked {
|
|
388
|
-
&::after {
|
|
389
|
-
content: '';
|
|
390
|
-
position: absolute;
|
|
391
|
-
bottom: 18rpx;
|
|
392
|
-
left: 50%;
|
|
393
|
-
width: 8rpx;
|
|
394
|
-
height: 8rpx;
|
|
395
|
-
background: #ff0027;
|
|
396
|
-
border-radius: 50%;
|
|
397
|
-
transform: translateX(-50%);
|
|
398
|
-
overflow: hidden;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
.date-item-inner {
|
|
402
|
-
padding: 8rpx;
|
|
403
|
-
}
|
|
404
|
-
&.range {
|
|
405
|
-
.date-item-inner {
|
|
406
|
-
padding: 6rpx 0rpx;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
</style>
|
|
1
|
+
<!--
|
|
2
|
+
* @Author: zhangzhenfei
|
|
3
|
+
* @Date: 2022-06-28 16:53:54
|
|
4
|
+
* @LastEditTime: 2023-05-12 16:02:29
|
|
5
|
+
* @LastEditors: zhangzhenfei
|
|
6
|
+
* @Description: 日历日期数据
|
|
7
|
+
* @FilePath: /piui-awesome/src/piui/components/pi-calendar-panel/components/calendar-days/index.vue
|
|
8
|
+
-->
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<view class="pi-rela pi-align-center pi-flex-wrap pi-pd-24">
|
|
12
|
+
<view
|
|
13
|
+
v-for="day in days"
|
|
14
|
+
:key="day.key"
|
|
15
|
+
class="date-item"
|
|
16
|
+
style="cursor: pointer;"
|
|
17
|
+
:class="[
|
|
18
|
+
{ 'pi-disabled': day.disabled || day.type === 'disabled' },
|
|
19
|
+
{ range: day.range },
|
|
20
|
+
{ marked: day.marked }
|
|
21
|
+
]"
|
|
22
|
+
@tap.stop="handleSelectDate(day)"
|
|
23
|
+
>
|
|
24
|
+
<view class="pi-square">
|
|
25
|
+
<view class="pi-rela date-item-inner">
|
|
26
|
+
<view
|
|
27
|
+
class="pi-w-100P pi-h-100P pi-flex-column-center pi-lh-28"
|
|
28
|
+
:style="[day.nowStyle, day.activeStyle, day.rangeStyle]"
|
|
29
|
+
>
|
|
30
|
+
<text>{{ day.date }}</text>
|
|
31
|
+
<text v-if="day.tip" class=" pi-text-nowrap pi-fz-18 pi-mg-top-6">
|
|
32
|
+
{{ day.tip }}
|
|
33
|
+
</text>
|
|
34
|
+
</view>
|
|
35
|
+
</view>
|
|
36
|
+
</view>
|
|
37
|
+
</view>
|
|
38
|
+
<!-- 日历蒙层 -->
|
|
39
|
+
<view
|
|
40
|
+
class="pi-abso-center pi-fw-500 pi-light-gray pi-text-nowrap"
|
|
41
|
+
style="
|
|
42
|
+
z-index: -1;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
opacity: 0.15;"
|
|
45
|
+
:style="[
|
|
46
|
+
{ fontSize: weekView ? '32rpx' : '300rpx' },
|
|
47
|
+
{ marginTop: weekView ? '30rpx' : '0' }
|
|
48
|
+
]"
|
|
49
|
+
>
|
|
50
|
+
{{ getBgTip }}
|
|
51
|
+
</view>
|
|
52
|
+
</view>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<script>
|
|
56
|
+
import { getConfig } from '../../../../config'
|
|
57
|
+
const { calendarPanel } = getConfig()
|
|
58
|
+
|
|
59
|
+
export default {
|
|
60
|
+
name: 'PiCalendarDays',
|
|
61
|
+
props: {
|
|
62
|
+
calendarValue: {
|
|
63
|
+
type: [String, Object, Array],
|
|
64
|
+
default: ''
|
|
65
|
+
},
|
|
66
|
+
year: {
|
|
67
|
+
type: [String, Number],
|
|
68
|
+
default: ''
|
|
69
|
+
},
|
|
70
|
+
month: {
|
|
71
|
+
type: [String, Number],
|
|
72
|
+
default: ''
|
|
73
|
+
},
|
|
74
|
+
// 当前展示周
|
|
75
|
+
week: {
|
|
76
|
+
type: Number,
|
|
77
|
+
default: 0
|
|
78
|
+
},
|
|
79
|
+
// 日历类型
|
|
80
|
+
type: {
|
|
81
|
+
// `'date'-单个日期`, `'range'-范围日期`
|
|
82
|
+
type: String,
|
|
83
|
+
// 'date'
|
|
84
|
+
default: calendarPanel.type,
|
|
85
|
+
validator: function(value) {
|
|
86
|
+
return ['date', 'range'].includes(value)
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
// 最小可选日期(不在范围内日期禁用不可选,默认'',不作限制)
|
|
90
|
+
minDate: {
|
|
91
|
+
type: [Number, String, Date],
|
|
92
|
+
// ''
|
|
93
|
+
default: calendarPanel.minDate
|
|
94
|
+
},
|
|
95
|
+
// 最大可选日期(不在范围内日期禁用不可选,默认'',不作限制)
|
|
96
|
+
maxDate: {
|
|
97
|
+
type: [Number, String, Date],
|
|
98
|
+
// ''
|
|
99
|
+
default: calendarPanel.maxDate
|
|
100
|
+
},
|
|
101
|
+
// 是否显示回到今日
|
|
102
|
+
showBackToday: {
|
|
103
|
+
type: Boolean,
|
|
104
|
+
// true
|
|
105
|
+
default: calendarPanel.showBackToday
|
|
106
|
+
},
|
|
107
|
+
// 今日日期激活边框颜色
|
|
108
|
+
todayActiveBorderColor: {
|
|
109
|
+
type: String,
|
|
110
|
+
// '#ff6a00'
|
|
111
|
+
default: calendarPanel.todayActiveBorderColor
|
|
112
|
+
},
|
|
113
|
+
// 选中|起始结束日期字体颜色
|
|
114
|
+
activeColor: {
|
|
115
|
+
type: String,
|
|
116
|
+
// '#ffffff'
|
|
117
|
+
default: calendarPanel.activeColor
|
|
118
|
+
},
|
|
119
|
+
// 选中|起始结束日期背景,默认
|
|
120
|
+
activeBg: {
|
|
121
|
+
type: String,
|
|
122
|
+
// '#ff6a00'
|
|
123
|
+
default: calendarPanel.activeBg
|
|
124
|
+
},
|
|
125
|
+
// 选中圆角效果
|
|
126
|
+
activeBorderRadius: {
|
|
127
|
+
type: [String, Number],
|
|
128
|
+
// '0 0 0 0'
|
|
129
|
+
default: calendarPanel.activeBorderRadius
|
|
130
|
+
},
|
|
131
|
+
// 范围内日期字体颜色默认
|
|
132
|
+
rangeColor: {
|
|
133
|
+
type: String,
|
|
134
|
+
// '#ff6a00'
|
|
135
|
+
default: calendarPanel.rangeColor
|
|
136
|
+
},
|
|
137
|
+
// 范围内日期背景色
|
|
138
|
+
rangeBg: {
|
|
139
|
+
type: String,
|
|
140
|
+
// 'rgba(254, 106, 0, 0.1)'
|
|
141
|
+
default: calendarPanel.rangeBg
|
|
142
|
+
},
|
|
143
|
+
// type=range时生效,起始日期自定义文案
|
|
144
|
+
startText: {
|
|
145
|
+
type: String,
|
|
146
|
+
// '开始'
|
|
147
|
+
default: calendarPanel.startText
|
|
148
|
+
},
|
|
149
|
+
// type=range时生效,结束日期自定义文案
|
|
150
|
+
endText: {
|
|
151
|
+
type: String,
|
|
152
|
+
// '结束'
|
|
153
|
+
default: calendarPanel.endText
|
|
154
|
+
},
|
|
155
|
+
weekView: {
|
|
156
|
+
type: Boolean,
|
|
157
|
+
// '是否显示周视图'
|
|
158
|
+
default: calendarPanel.defalutWeekView
|
|
159
|
+
},
|
|
160
|
+
// 日期标记,数组形式,默认([])
|
|
161
|
+
marks: {
|
|
162
|
+
type: Array,
|
|
163
|
+
// []
|
|
164
|
+
default: () => calendarPanel.marks
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
data() {
|
|
168
|
+
const now = this.$pi.date.parseDate()
|
|
169
|
+
return {
|
|
170
|
+
now: now // 当前时间
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
computed: {
|
|
174
|
+
getActiveBorderRadius() {
|
|
175
|
+
return this.$pi.common.addUnit(this.activeBorderRadius)
|
|
176
|
+
},
|
|
177
|
+
// 获取上个月最后一天
|
|
178
|
+
getPreMonthLastDay() {
|
|
179
|
+
let year = this.year
|
|
180
|
+
let month = this.month - 1
|
|
181
|
+
if (month === 0) {
|
|
182
|
+
year = year - 1
|
|
183
|
+
month = 12
|
|
184
|
+
}
|
|
185
|
+
return new Date(year, month, '0')
|
|
186
|
+
},
|
|
187
|
+
getNextMonthFirstDay() {
|
|
188
|
+
let year = this.year
|
|
189
|
+
let month = this.month + 1
|
|
190
|
+
if (month === 13) {
|
|
191
|
+
year = year + 1
|
|
192
|
+
month = 1
|
|
193
|
+
}
|
|
194
|
+
return new Date(year, month - 1, '1')
|
|
195
|
+
},
|
|
196
|
+
// 第一天
|
|
197
|
+
firstDay() {
|
|
198
|
+
const firstDays = []
|
|
199
|
+
const preMonthLastDay = this.getPreMonthLastDay
|
|
200
|
+
const lastDay = preMonthLastDay.getDate()
|
|
201
|
+
const firstDay = new Date(this.year, this.month - 1, '1').getDay()
|
|
202
|
+
for (let i = 0; i < firstDay; i++) {
|
|
203
|
+
const day = preMonthLastDay.setDate(lastDay - firstDay + i + 1)
|
|
204
|
+
firstDays.push(new Date(day))
|
|
205
|
+
}
|
|
206
|
+
return firstDays
|
|
207
|
+
},
|
|
208
|
+
getMinDate() {
|
|
209
|
+
return this.minDate ? this.$pi.date.parseDate(this.minDate) : ''
|
|
210
|
+
},
|
|
211
|
+
getMaxDate() {
|
|
212
|
+
return this.maxDate ? this.$pi.date.parseDate(this.maxDate) : ''
|
|
213
|
+
},
|
|
214
|
+
getMarks() {
|
|
215
|
+
return this.marks.map(item => {
|
|
216
|
+
return this.$pi.date.parseDate(item)
|
|
217
|
+
})
|
|
218
|
+
},
|
|
219
|
+
// 总天数
|
|
220
|
+
days() {
|
|
221
|
+
const days = []
|
|
222
|
+
const dayCount = 7 * 6 // 固定显示6周
|
|
223
|
+
const monthDays = new Date(this.year, this.month, 0).getDate()
|
|
224
|
+
const firstDayCount = this.firstDay.length
|
|
225
|
+
const nextMonthFirstDay = this.getNextMonthFirstDay
|
|
226
|
+
for (let i = 1; i <= dayCount; i++) {
|
|
227
|
+
let day = {
|
|
228
|
+
key: this.$pi.guid(),
|
|
229
|
+
index: i
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// 上月数据
|
|
233
|
+
if (i <= firstDayCount) {
|
|
234
|
+
day = {
|
|
235
|
+
...day,
|
|
236
|
+
...this.$pi.date.parseDate(this.firstDay[i - 1]),
|
|
237
|
+
type: this.weekView ? '' : 'disabled'
|
|
238
|
+
}
|
|
239
|
+
} else if (i > monthDays + firstDayCount) {
|
|
240
|
+
// 下月数据
|
|
241
|
+
day = {
|
|
242
|
+
...day,
|
|
243
|
+
...this.$pi.date.parseDate(
|
|
244
|
+
new Date(nextMonthFirstDay.setDate(i - monthDays - firstDayCount))
|
|
245
|
+
),
|
|
246
|
+
type: this.weekView ? '' : 'disabled'
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
// 当月数据
|
|
250
|
+
day = {
|
|
251
|
+
...day,
|
|
252
|
+
...this.$pi.date.parseDate(new Date(this.year, this.month - 1, i - firstDayCount))
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const isDisabled = this.isDisabled(day)
|
|
257
|
+
// 禁用
|
|
258
|
+
if (isDisabled) {
|
|
259
|
+
day.disabled = true
|
|
260
|
+
}
|
|
261
|
+
// 单选选中样式
|
|
262
|
+
if (this.type === 'date' && this.isSameDay(this.calendarValue, day)) {
|
|
263
|
+
const activeStyle = {
|
|
264
|
+
color: this.activeColor,
|
|
265
|
+
borderRadius: this.getActiveBorderRadius
|
|
266
|
+
}
|
|
267
|
+
if (this.activeBg) activeStyle.background = this.activeBg
|
|
268
|
+
day.activeStyle = activeStyle
|
|
269
|
+
}
|
|
270
|
+
// 范围选中样式
|
|
271
|
+
if (this.type === 'range') {
|
|
272
|
+
const start = this.calendarValue[0]
|
|
273
|
+
const end = this.calendarValue[1]
|
|
274
|
+
const isBegin = this.isSameDay(start, day)
|
|
275
|
+
const isEnd = this.isSameDay(end, day)
|
|
276
|
+
const inRange =
|
|
277
|
+
start && end && day.timestamp > start.timestamp && day.timestamp < end.timestamp
|
|
278
|
+
const rangeStyle = {}
|
|
279
|
+
// 处理中间范围的样式
|
|
280
|
+
if (inRange) {
|
|
281
|
+
rangeStyle.color = this.rangeColor
|
|
282
|
+
rangeStyle.background = this.rangeBg
|
|
283
|
+
}
|
|
284
|
+
// 处理两端
|
|
285
|
+
if (isBegin || isEnd) {
|
|
286
|
+
rangeStyle.color = this.activeColor
|
|
287
|
+
rangeStyle.borderRadius = isBegin
|
|
288
|
+
? `${this.getActiveBorderRadius} 0 0 0`
|
|
289
|
+
: `0 0 ${this.getActiveBorderRadius} 0`
|
|
290
|
+
if (this.activeBg) rangeStyle.background = this.activeBg
|
|
291
|
+
}
|
|
292
|
+
day.range = true
|
|
293
|
+
day.rangeStyle = rangeStyle
|
|
294
|
+
// type 为 range 开始和结束的提示
|
|
295
|
+
if (isBegin) day.tip = this.startText
|
|
296
|
+
if (isEnd) day.tip = this.endText
|
|
297
|
+
if (isBegin && isEnd) {
|
|
298
|
+
day.tip = this.startText + '-' + this.endText
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// 是否打点
|
|
302
|
+
if (this.getMarks.length) {
|
|
303
|
+
const mark = this.getMarks.find(item => {
|
|
304
|
+
return this.isSameDay(item, day)
|
|
305
|
+
})
|
|
306
|
+
if (mark) {
|
|
307
|
+
day.marked = mark
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// 当天样式
|
|
311
|
+
if (this.isSameDay(this.now, day)) {
|
|
312
|
+
day.today = true
|
|
313
|
+
if (this.showBackToday) {
|
|
314
|
+
day.nowStyle = {
|
|
315
|
+
color: this.todayActiveBorderColor,
|
|
316
|
+
border: '1px solid ' + this.todayActiveBorderColor,
|
|
317
|
+
borderRadius: this.getActiveBorderRadius
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
days.push(day)
|
|
322
|
+
}
|
|
323
|
+
if (this.weekView) {
|
|
324
|
+
days.splice(0, (this.week - 1) * 7)
|
|
325
|
+
days.splice(7, days.length - 7)
|
|
326
|
+
}
|
|
327
|
+
return days
|
|
328
|
+
},
|
|
329
|
+
getBgTip() {
|
|
330
|
+
if (!this.days.length) return ''
|
|
331
|
+
const startDay = this.days[0]
|
|
332
|
+
const endDay = this.days[this.days.length - 1]
|
|
333
|
+
return this.weekView
|
|
334
|
+
? `${startDay.month}月 ${startDay.date}日 - ${endDay.month}月 ${endDay.date}日`
|
|
335
|
+
: this.month
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
methods: {
|
|
339
|
+
isSameDay(day1, day2) {
|
|
340
|
+
return (
|
|
341
|
+
day1 &&
|
|
342
|
+
day2 &&
|
|
343
|
+
day1.year === day2.year &&
|
|
344
|
+
day1.month === day2.month &&
|
|
345
|
+
day1.date === day2.date
|
|
346
|
+
)
|
|
347
|
+
},
|
|
348
|
+
isDisabled(day) {
|
|
349
|
+
const isDisabled =
|
|
350
|
+
(this.getMinDate && day.timestamp < this.getMinDate.timestamp) ||
|
|
351
|
+
(this.getMaxDate && day.timestamp > this.getMaxDate.timestamp)
|
|
352
|
+
return isDisabled
|
|
353
|
+
},
|
|
354
|
+
handleChange(value) {
|
|
355
|
+
this.$emit('change', value)
|
|
356
|
+
},
|
|
357
|
+
handleSelectDate(date) {
|
|
358
|
+
if (date.disabled) return
|
|
359
|
+
if (this.type === 'date') {
|
|
360
|
+
// 单选方式
|
|
361
|
+
this.handleChange(date)
|
|
362
|
+
return
|
|
363
|
+
}
|
|
364
|
+
// 处理范围选择方式
|
|
365
|
+
if (this.calendarValue.length === 0 || this.calendarValue.length === 2) {
|
|
366
|
+
// 如果选了两项,则重新开始选择范围
|
|
367
|
+
this.handleChange([date])
|
|
368
|
+
} else {
|
|
369
|
+
// 和第一项判断大小,小的放前面
|
|
370
|
+
if (date.timestamp > this.calendarValue[0].timestamp) {
|
|
371
|
+
this.handleChange([this.calendarValue[0], date])
|
|
372
|
+
} else {
|
|
373
|
+
this.handleChange([date, this.calendarValue[0]])
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
</script>
|
|
380
|
+
|
|
381
|
+
<style lang="scss" scoped>
|
|
382
|
+
.date-item {
|
|
383
|
+
position: relative;
|
|
384
|
+
z-index: 2;
|
|
385
|
+
width: calc(100% / 7);
|
|
386
|
+
overflow: hidden;
|
|
387
|
+
&.marked {
|
|
388
|
+
&::after {
|
|
389
|
+
content: '';
|
|
390
|
+
position: absolute;
|
|
391
|
+
bottom: 18rpx;
|
|
392
|
+
left: 50%;
|
|
393
|
+
width: 8rpx;
|
|
394
|
+
height: 8rpx;
|
|
395
|
+
background: #ff0027;
|
|
396
|
+
border-radius: 50%;
|
|
397
|
+
transform: translateX(-50%);
|
|
398
|
+
overflow: hidden;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
.date-item-inner {
|
|
402
|
+
padding: 8rpx;
|
|
403
|
+
}
|
|
404
|
+
&.range {
|
|
405
|
+
.date-item-inner {
|
|
406
|
+
padding: 6rpx 0rpx;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
</style>
|