sadais-piui 1.2.4-beta2 → 1.2.4-beta5
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 +512 -512
- package/LICENSE +20 -20
- package/README.md +166 -166
- package/components/pi-action-sheet/index.vue +247 -247
- package/components/pi-badge/index.vue +136 -136
- package/components/pi-bottom-bar/index.vue +139 -139
- package/components/pi-button/index.vue +492 -492
- package/components/pi-calendar/index.vue +178 -178
- package/components/pi-calendar-panel/index.vue +436 -432
- package/components/pi-canvas/index.vue +400 -400
- package/components/pi-card/index.vue +127 -127
- package/components/pi-checkbox/index.vue +345 -345
- package/components/pi-checkbox-group/index.vue +215 -215
- package/components/pi-circle-progress/index.vue +224 -224
- package/components/pi-code-input/index.vue +262 -262
- package/components/pi-count-down/index.vue +245 -245
- package/components/pi-count-up/index.vue +209 -209
- package/components/pi-date-picker/index.vue +366 -366
- package/components/pi-divider/index.vue +109 -109
- package/components/pi-dropdown/components/dropdown-tab.vue +62 -62
- package/components/pi-dropdown/index.vue +316 -316
- package/components/pi-dropdown-item/index.vue +233 -233
- package/components/pi-form/index.vue +237 -237
- package/components/pi-form-item/index.vue +534 -534
- 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 +267 -267
- package/components/pi-img-cropper/canvas.js +112 -112
- 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 +299 -299
- 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 +331 -331
- package/components/pi-loading/index.vue +188 -188
- package/components/pi-marquee/index.vue +281 -281
- 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 +277 -277
- package/components/pi-picker/index.vue +317 -317
- package/components/pi-popup/index.vue +353 -353
- package/components/pi-popup-select/index.vue +291 -291
- package/components/pi-radio/index.vue +387 -387
- package/components/pi-radio-group/index.vue +262 -262
- package/components/pi-rate/index.vue +212 -212
- package/components/pi-regions-select/index.vue +318 -318
- package/components/pi-search/index.vue +351 -351
- package/components/pi-section/index.vue +218 -218
- package/components/pi-select/index.vue +391 -391
- package/components/pi-skeleton/index.vue +280 -280
- package/components/pi-status-bar/index.vue +56 -56
- package/components/pi-stepper/index.vue +394 -394
- package/components/pi-steps/index.vue +299 -299
- package/components/pi-swiper/index.vue +344 -344
- package/components/pi-switch/index.vue +227 -227
- package/components/pi-tabs/index.vue +398 -398
- package/components/pi-upload-img/index.vue +508 -506
- package/components/pi-waterfall/index.vue +130 -130
- package/components/pi-webview/index.vue +82 -82
- package/config/actionSheet.js +25 -25
- package/config/badge.js +9 -9
- package/config/bottomBar.js +11 -11
- package/config/button.js +29 -29
- package/config/calendar.js +19 -19
- package/config/calendarPanel.js +24 -24
- package/config/card.js +8 -8
- package/config/checkbox.js +14 -14
- package/config/checkboxGroup.js +14 -14
- package/config/circleProgress.js +13 -13
- package/config/codeInput.js +12 -12
- package/config/countDown.js +12 -12
- package/config/countUp.js +13 -13
- package/config/datePicker.js +22 -22
- package/config/divider.js +10 -10
- package/config/dropdown.js +21 -21
- package/config/dropdownItem.js +26 -26
- package/config/form.js +27 -27
- package/config/formItem.js +25 -25
- 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 +25 -25
- 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 +8 -8
- 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 +15 -15
- package/config/radioGroup.js +16 -16
- package/config/rate.js +15 -15
- package/config/regionsData.js +58 -58
- package/config/regionsSelect.js +18 -18
- package/config/search.js +27 -27
- package/config/section.js +23 -23
- package/config/select.js +28 -28
- 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/swiper.js +22 -22
- package/config/switch.js +13 -13
- package/config/tabs.js +23 -23
- package/config/uploadImg.js +63 -63
- 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 +25 -25
- package/plugins/async-validator.js +1511 -1511
- package/scss/animation.scss +260 -260
- package/scss/icon/icon.scss +594 -594
- package/scss/index.scss +5 -5
- package/scss/mixin.scss +47 -47
- package/tools/index.js +11 -11
|
@@ -1,432 +1,436 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="pi-calendar-panel" :style="[customStyle]" :class="[customClass]">
|
|
3
|
-
<!-- 操作栏 -->
|
|
4
|
-
<view class="pi-align-center">
|
|
5
|
-
<view class="pi-flex-sub pi-justify-center pi-align-center">
|
|
6
|
-
<view class="pi-align-center">
|
|
7
|
-
<view class="pi-icon-back pi-pd-14" @tap="handleChangeYear(-1)" />
|
|
8
|
-
<view class="pi-pd-lr-8 pi-text-nowrap">{{ year }}年</view>
|
|
9
|
-
<view class="pi-icon-right pi-pd-14" @tap="handleChangeYear(1)" />
|
|
10
|
-
</view>
|
|
11
|
-
<view class="pi-align-center">
|
|
12
|
-
<view class="pi-icon-back pi-pd-14" @tap="handleChangeMonth(-1)" />
|
|
13
|
-
<view class="pi-pd-lr-8 pi-text-nowrap">{{ month }}月</view>
|
|
14
|
-
<view class="pi-icon-right pi-pd-14" @tap="handleChangeMonth(1)" />
|
|
15
|
-
</view>
|
|
16
|
-
</view>
|
|
17
|
-
<view v-if="showBackToday" class="back-today" @tap="handleBackToday">回到今日</view>
|
|
18
|
-
</view>
|
|
19
|
-
|
|
20
|
-
<!-- 星期 -->
|
|
21
|
-
<view
|
|
22
|
-
class="pi-align-center pi-pd-24"
|
|
23
|
-
style="box-shadow: 0 15px 10px -15px rgba(125, 126, 128, 0.16);"
|
|
24
|
-
>
|
|
25
|
-
<view
|
|
26
|
-
v-for="(week, index) in weekDayZh"
|
|
27
|
-
:key="index"
|
|
28
|
-
class="date-item pi-justify-center pi-fw-500"
|
|
29
|
-
>
|
|
30
|
-
{{ week }}
|
|
31
|
-
</view>
|
|
32
|
-
</view>
|
|
33
|
-
<view class="pi-square">
|
|
34
|
-
<!-- 固定日期面板正方形,避免高度变化造成界面抖动 -->
|
|
35
|
-
<view class="pi-rela">
|
|
36
|
-
<view class="pi-rela pi-align-center pi-flex-wrap pi-pd-24">
|
|
37
|
-
<!-- 前置空项目 -->
|
|
38
|
-
<view v-for="emptyDay in firstDay" :key="emptyDay" class="date-item" />
|
|
39
|
-
<!-- 天 -->
|
|
40
|
-
<view
|
|
41
|
-
v-for="day in days"
|
|
42
|
-
:key="day.key"
|
|
43
|
-
class="date-item"
|
|
44
|
-
style="cursor: pointer;"
|
|
45
|
-
:style="[day.nowStyle, day.activeStyle, day.disabledStyle]"
|
|
46
|
-
@tap.stop="handleSelectDate(day)"
|
|
47
|
-
>
|
|
48
|
-
<view class="pi-square">
|
|
49
|
-
<view class="pi-rela pi-flex-column-center pi-lh-28">
|
|
50
|
-
<text>{{ day.date }}</text>
|
|
51
|
-
<text v-if="day.tip" class=" pi-text-nowrap pi-fz-18 pi-mg-top-6">
|
|
52
|
-
{{ day.tip }}
|
|
53
|
-
</text>
|
|
54
|
-
</view>
|
|
55
|
-
</view>
|
|
56
|
-
</view>
|
|
57
|
-
<!-- 日历蒙层 -->
|
|
58
|
-
<view
|
|
59
|
-
class="pi-abso-center pi-fw-500 pi-light-gray"
|
|
60
|
-
style="
|
|
61
|
-
|
|
62
|
-
z-index: 1;
|
|
63
|
-
font-size: 300rpx;
|
|
64
|
-
pointer-events: none;
|
|
65
|
-
opacity: 0.1;"
|
|
66
|
-
>
|
|
67
|
-
{{ month }}
|
|
68
|
-
</view>
|
|
69
|
-
</view>
|
|
70
|
-
</view>
|
|
71
|
-
</view>
|
|
72
|
-
</view>
|
|
73
|
-
</template>
|
|
74
|
-
|
|
75
|
-
<script>
|
|
76
|
-
import ValueSync from '../../mixin/value-sync'
|
|
77
|
-
import { getConfig } from '../../config'
|
|
78
|
-
|
|
79
|
-
const TAG = 'PiCalendarPanel'
|
|
80
|
-
const { calendarPanel } = getConfig()
|
|
81
|
-
|
|
82
|
-
export default {
|
|
83
|
-
name: 'PiCalendarPanel',
|
|
84
|
-
mixins: [ValueSync],
|
|
85
|
-
props: {
|
|
86
|
-
// 自定义样式,对象形式
|
|
87
|
-
customStyle: {
|
|
88
|
-
type: Object,
|
|
89
|
-
// {}
|
|
90
|
-
default() {
|
|
91
|
-
return calendarPanel.customStyle
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
// 自定义样式类,字符串形式
|
|
95
|
-
customClass: {
|
|
96
|
-
type: String,
|
|
97
|
-
// ''
|
|
98
|
-
default() {
|
|
99
|
-
return calendarPanel.customClass
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
// 日历类型
|
|
103
|
-
type: {
|
|
104
|
-
// `'date'-单个日期`, `'range'-范围日期`
|
|
105
|
-
type: String,
|
|
106
|
-
// 'date'
|
|
107
|
-
default: calendarPanel.type,
|
|
108
|
-
validator: function(value) {
|
|
109
|
-
return ['date', 'range'].includes(value)
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
// 日期默认值,单选时候,传入Date(时间戳,时间字符串,Date类型),日历范围,传入Date[]
|
|
113
|
-
value: {
|
|
114
|
-
type: [Number, String, Date, Array]
|
|
115
|
-
// -
|
|
116
|
-
},
|
|
117
|
-
// 可切换的最小年份
|
|
118
|
-
minYear: {
|
|
119
|
-
type: [Number, String],
|
|
120
|
-
// 当前年份 - 80
|
|
121
|
-
default: calendarPanel.minYear
|
|
122
|
-
},
|
|
123
|
-
// 可切换的最大年份(默认当前年份)
|
|
124
|
-
maxYear: {
|
|
125
|
-
type: [Number, String],
|
|
126
|
-
// 当前年份 + 30
|
|
127
|
-
default: calendarPanel.maxYear
|
|
128
|
-
},
|
|
129
|
-
// 最小可选日期(不在范围内日期禁用不可选,默认'',不作限制)
|
|
130
|
-
minDate: {
|
|
131
|
-
type: [Number, String, Date],
|
|
132
|
-
// ''
|
|
133
|
-
default: calendarPanel.minDate
|
|
134
|
-
},
|
|
135
|
-
// 最大可选日期(不在范围内日期禁用不可选,默认'',不作限制)
|
|
136
|
-
maxDate: {
|
|
137
|
-
type: [Number, String, Date],
|
|
138
|
-
// ''
|
|
139
|
-
default: calendarPanel.maxDate
|
|
140
|
-
},
|
|
141
|
-
// 是否显示回到今日
|
|
142
|
-
showBackToday: {
|
|
143
|
-
type: Boolean,
|
|
144
|
-
// true
|
|
145
|
-
default: calendarPanel.showBackToday
|
|
146
|
-
},
|
|
147
|
-
// 今日日期激活边框颜色
|
|
148
|
-
todayActiveBorderColor: {
|
|
149
|
-
type: String,
|
|
150
|
-
// '#ff6a00'
|
|
151
|
-
default: calendarPanel.todayActiveBorderColor
|
|
152
|
-
},
|
|
153
|
-
// 选中|起始结束日期字体颜色
|
|
154
|
-
activeColor: {
|
|
155
|
-
type: String,
|
|
156
|
-
// '#ffffff'
|
|
157
|
-
default: calendarPanel.activeColor
|
|
158
|
-
},
|
|
159
|
-
// 选中|起始结束日期背景,默认
|
|
160
|
-
activeBg: {
|
|
161
|
-
type: String,
|
|
162
|
-
// '#ff6a00'
|
|
163
|
-
default: calendarPanel.activeBg
|
|
164
|
-
},
|
|
165
|
-
// 选中圆角效果
|
|
166
|
-
activeBorderRadius: {
|
|
167
|
-
type: [String, Number],
|
|
168
|
-
// '0 0 0 0'
|
|
169
|
-
default: calendarPanel.activeBorderRadius
|
|
170
|
-
},
|
|
171
|
-
// 范围内日期字体颜色默认
|
|
172
|
-
rangeColor: {
|
|
173
|
-
type: String,
|
|
174
|
-
// '#ff6a00'
|
|
175
|
-
default: calendarPanel.rangeColor
|
|
176
|
-
},
|
|
177
|
-
// 范围内日期背景色
|
|
178
|
-
rangeBg: {
|
|
179
|
-
type: String,
|
|
180
|
-
// 'rgba(254, 106, 0, 0.1)'
|
|
181
|
-
default: calendarPanel.rangeBg
|
|
182
|
-
},
|
|
183
|
-
// type=range时生效,起始日期自定义文案
|
|
184
|
-
startText: {
|
|
185
|
-
type: String,
|
|
186
|
-
// '开始'
|
|
187
|
-
default: calendarPanel.startText
|
|
188
|
-
},
|
|
189
|
-
// type=range时生效,结束日期自定义文案
|
|
190
|
-
endText: {
|
|
191
|
-
type: String,
|
|
192
|
-
// '结束'
|
|
193
|
-
default: calendarPanel.endText
|
|
194
|
-
},
|
|
195
|
-
// 已选择的时间格式化显示规则
|
|
196
|
-
dateFormat: {
|
|
197
|
-
type: String,
|
|
198
|
-
// 'YYYY-MM-DD'
|
|
199
|
-
default: calendarPanel.dateFormat
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
data() {
|
|
203
|
-
const now = this.$pi.date.parseDate()
|
|
204
|
-
return {
|
|
205
|
-
now: now, // 当前时间
|
|
206
|
-
year: '', // 年份
|
|
207
|
-
month: '', // 月份
|
|
208
|
-
calendarValue: ''
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
computed: {
|
|
212
|
-
getActiveBorderRadius() {
|
|
213
|
-
return this.$pi.common.addUnit(this.activeBorderRadius)
|
|
214
|
-
},
|
|
215
|
-
weekDayZh() {
|
|
216
|
-
return this.$pi.date.getWeekDayZh()
|
|
217
|
-
},
|
|
218
|
-
// 第一天
|
|
219
|
-
firstDay() {
|
|
220
|
-
return new Date(`${this.year}/${this.month}/01 00:00:00`).getDay()
|
|
221
|
-
},
|
|
222
|
-
getMinDate() {
|
|
223
|
-
return this.minDate ? this.$pi.date.parseDate(this.minDate) : ''
|
|
224
|
-
},
|
|
225
|
-
getMaxDate() {
|
|
226
|
-
return this.maxDate ? this.$pi.date.parseDate(this.maxDate) : ''
|
|
227
|
-
},
|
|
228
|
-
isMinYear() {
|
|
229
|
-
return this.year === parseInt(this.minYear, 10)
|
|
230
|
-
},
|
|
231
|
-
isMaxYear() {
|
|
232
|
-
return this.year === parseInt(this.maxYear, 10)
|
|
233
|
-
},
|
|
234
|
-
// 总天数
|
|
235
|
-
days() {
|
|
236
|
-
const days = []
|
|
237
|
-
const monthDays = new Date(this.year, this.month, 0).getDate()
|
|
238
|
-
for (let i = 1; i <= monthDays; i++) {
|
|
239
|
-
const day = {
|
|
240
|
-
key: 'pi-calander-day-item-' + i,
|
|
241
|
-
index: i,
|
|
242
|
-
...this.$pi.date.parseDate(`${this.year}/${this.month}/${i}`)
|
|
243
|
-
}
|
|
244
|
-
const isDisabled = this.isDisabled(day)
|
|
245
|
-
// 禁用
|
|
246
|
-
if (isDisabled) {
|
|
247
|
-
day.disabledStyle = {
|
|
248
|
-
opacity: '0.3',
|
|
249
|
-
cursor: 'not-allowed'
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
// 单选选中样式
|
|
253
|
-
if (this.type === 'date' && this.isSameDay(this.calendarValue, day)) {
|
|
254
|
-
const activeStyle = {
|
|
255
|
-
color: this.activeColor,
|
|
256
|
-
borderRadius: this.getActiveBorderRadius
|
|
257
|
-
}
|
|
258
|
-
if (this.activeBg) activeStyle.background = this.activeBg
|
|
259
|
-
day.activeStyle = activeStyle
|
|
260
|
-
}
|
|
261
|
-
// 范围选中样式
|
|
262
|
-
if (this.type === 'range') {
|
|
263
|
-
const start = this.calendarValue[0]
|
|
264
|
-
const end = this.calendarValue[1]
|
|
265
|
-
const isBegin = this.isSameDay(start, day)
|
|
266
|
-
const isEnd = this.isSameDay(end, day)
|
|
267
|
-
const inRange =
|
|
268
|
-
start && end && day.timestamp > start.timestamp && day.timestamp < end.timestamp
|
|
269
|
-
const activeStyle = {}
|
|
270
|
-
// 处理两端
|
|
271
|
-
if (isBegin || isEnd) {
|
|
272
|
-
activeStyle.color = this.activeColor
|
|
273
|
-
activeStyle.borderRadius = isBegin
|
|
274
|
-
? `${this.getActiveBorderRadius} 0 0 ${this.getActiveBorderRadius}`
|
|
275
|
-
: `0 ${this.getActiveBorderRadius} ${this.getActiveBorderRadius} 0`
|
|
276
|
-
if (this.activeBg) activeStyle.background = this.activeBg
|
|
277
|
-
}
|
|
278
|
-
// 处理中间范围的样式
|
|
279
|
-
if (inRange) {
|
|
280
|
-
activeStyle.color = this.rangeColor
|
|
281
|
-
activeStyle.background = this.rangeBg
|
|
282
|
-
}
|
|
283
|
-
day.activeStyle = activeStyle
|
|
284
|
-
// type 为 range 开始和结束的提示
|
|
285
|
-
if (isBegin) day.tip = this.startText
|
|
286
|
-
if (isEnd) day.tip = this.endText
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
this.
|
|
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
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
this.handleChange([
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
this.month =
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
overflow: hidden;
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<view class="pi-calendar-panel" :style="[customStyle]" :class="[customClass]">
|
|
3
|
+
<!-- 操作栏 -->
|
|
4
|
+
<view class="pi-align-center">
|
|
5
|
+
<view class="pi-flex-sub pi-justify-center pi-align-center">
|
|
6
|
+
<view class="pi-align-center">
|
|
7
|
+
<view class="pi-icon-back pi-pd-14" @tap="handleChangeYear(-1)" />
|
|
8
|
+
<view class="pi-pd-lr-8 pi-text-nowrap">{{ year }}年</view>
|
|
9
|
+
<view class="pi-icon-right pi-pd-14" @tap="handleChangeYear(1)" />
|
|
10
|
+
</view>
|
|
11
|
+
<view class="pi-align-center">
|
|
12
|
+
<view class="pi-icon-back pi-pd-14" @tap="handleChangeMonth(-1)" />
|
|
13
|
+
<view class="pi-pd-lr-8 pi-text-nowrap">{{ month }}月</view>
|
|
14
|
+
<view class="pi-icon-right pi-pd-14" @tap="handleChangeMonth(1)" />
|
|
15
|
+
</view>
|
|
16
|
+
</view>
|
|
17
|
+
<view v-if="showBackToday" class="back-today" @tap="handleBackToday">回到今日</view>
|
|
18
|
+
</view>
|
|
19
|
+
|
|
20
|
+
<!-- 星期 -->
|
|
21
|
+
<view
|
|
22
|
+
class="pi-align-center pi-pd-24"
|
|
23
|
+
style="box-shadow: 0 15px 10px -15px rgba(125, 126, 128, 0.16);"
|
|
24
|
+
>
|
|
25
|
+
<view
|
|
26
|
+
v-for="(week, index) in weekDayZh"
|
|
27
|
+
:key="index"
|
|
28
|
+
class="date-item pi-justify-center pi-fw-500"
|
|
29
|
+
>
|
|
30
|
+
{{ week }}
|
|
31
|
+
</view>
|
|
32
|
+
</view>
|
|
33
|
+
<view class="pi-square">
|
|
34
|
+
<!-- 固定日期面板正方形,避免高度变化造成界面抖动 -->
|
|
35
|
+
<view class="pi-rela">
|
|
36
|
+
<view class="pi-rela pi-align-center pi-flex-wrap pi-pd-24">
|
|
37
|
+
<!-- 前置空项目 -->
|
|
38
|
+
<view v-for="emptyDay in firstDay" :key="emptyDay" class="date-item" />
|
|
39
|
+
<!-- 天 -->
|
|
40
|
+
<view
|
|
41
|
+
v-for="day in days"
|
|
42
|
+
:key="day.key"
|
|
43
|
+
class="date-item"
|
|
44
|
+
style="cursor: pointer;"
|
|
45
|
+
:style="[day.nowStyle, day.activeStyle, day.disabledStyle]"
|
|
46
|
+
@tap.stop="handleSelectDate(day)"
|
|
47
|
+
>
|
|
48
|
+
<view class="pi-square">
|
|
49
|
+
<view class="pi-rela pi-flex-column-center pi-lh-28">
|
|
50
|
+
<text>{{ day.date }}</text>
|
|
51
|
+
<text v-if="day.tip" class=" pi-text-nowrap pi-fz-18 pi-mg-top-6">
|
|
52
|
+
{{ day.tip }}
|
|
53
|
+
</text>
|
|
54
|
+
</view>
|
|
55
|
+
</view>
|
|
56
|
+
</view>
|
|
57
|
+
<!-- 日历蒙层 -->
|
|
58
|
+
<view
|
|
59
|
+
class="pi-abso-center pi-fw-500 pi-light-gray"
|
|
60
|
+
style="
|
|
61
|
+
|
|
62
|
+
z-index: 1;
|
|
63
|
+
font-size: 300rpx;
|
|
64
|
+
pointer-events: none;
|
|
65
|
+
opacity: 0.1;"
|
|
66
|
+
>
|
|
67
|
+
{{ month }}
|
|
68
|
+
</view>
|
|
69
|
+
</view>
|
|
70
|
+
</view>
|
|
71
|
+
</view>
|
|
72
|
+
</view>
|
|
73
|
+
</template>
|
|
74
|
+
|
|
75
|
+
<script>
|
|
76
|
+
import ValueSync from '../../mixin/value-sync'
|
|
77
|
+
import { getConfig } from '../../config'
|
|
78
|
+
|
|
79
|
+
const TAG = 'PiCalendarPanel'
|
|
80
|
+
const { calendarPanel } = getConfig()
|
|
81
|
+
|
|
82
|
+
export default {
|
|
83
|
+
name: 'PiCalendarPanel',
|
|
84
|
+
mixins: [ValueSync],
|
|
85
|
+
props: {
|
|
86
|
+
// 自定义样式,对象形式
|
|
87
|
+
customStyle: {
|
|
88
|
+
type: Object,
|
|
89
|
+
// {}
|
|
90
|
+
default() {
|
|
91
|
+
return calendarPanel.customStyle
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
// 自定义样式类,字符串形式
|
|
95
|
+
customClass: {
|
|
96
|
+
type: String,
|
|
97
|
+
// ''
|
|
98
|
+
default() {
|
|
99
|
+
return calendarPanel.customClass
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
// 日历类型
|
|
103
|
+
type: {
|
|
104
|
+
// `'date'-单个日期`, `'range'-范围日期`
|
|
105
|
+
type: String,
|
|
106
|
+
// 'date'
|
|
107
|
+
default: calendarPanel.type,
|
|
108
|
+
validator: function(value) {
|
|
109
|
+
return ['date', 'range'].includes(value)
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
// 日期默认值,单选时候,传入Date(时间戳,时间字符串,Date类型),日历范围,传入Date[]
|
|
113
|
+
value: {
|
|
114
|
+
type: [Number, String, Date, Array]
|
|
115
|
+
// -
|
|
116
|
+
},
|
|
117
|
+
// 可切换的最小年份
|
|
118
|
+
minYear: {
|
|
119
|
+
type: [Number, String],
|
|
120
|
+
// 当前年份 - 80
|
|
121
|
+
default: calendarPanel.minYear
|
|
122
|
+
},
|
|
123
|
+
// 可切换的最大年份(默认当前年份)
|
|
124
|
+
maxYear: {
|
|
125
|
+
type: [Number, String],
|
|
126
|
+
// 当前年份 + 30
|
|
127
|
+
default: calendarPanel.maxYear
|
|
128
|
+
},
|
|
129
|
+
// 最小可选日期(不在范围内日期禁用不可选,默认'',不作限制)
|
|
130
|
+
minDate: {
|
|
131
|
+
type: [Number, String, Date],
|
|
132
|
+
// ''
|
|
133
|
+
default: calendarPanel.minDate
|
|
134
|
+
},
|
|
135
|
+
// 最大可选日期(不在范围内日期禁用不可选,默认'',不作限制)
|
|
136
|
+
maxDate: {
|
|
137
|
+
type: [Number, String, Date],
|
|
138
|
+
// ''
|
|
139
|
+
default: calendarPanel.maxDate
|
|
140
|
+
},
|
|
141
|
+
// 是否显示回到今日
|
|
142
|
+
showBackToday: {
|
|
143
|
+
type: Boolean,
|
|
144
|
+
// true
|
|
145
|
+
default: calendarPanel.showBackToday
|
|
146
|
+
},
|
|
147
|
+
// 今日日期激活边框颜色
|
|
148
|
+
todayActiveBorderColor: {
|
|
149
|
+
type: String,
|
|
150
|
+
// '#ff6a00'
|
|
151
|
+
default: calendarPanel.todayActiveBorderColor
|
|
152
|
+
},
|
|
153
|
+
// 选中|起始结束日期字体颜色
|
|
154
|
+
activeColor: {
|
|
155
|
+
type: String,
|
|
156
|
+
// '#ffffff'
|
|
157
|
+
default: calendarPanel.activeColor
|
|
158
|
+
},
|
|
159
|
+
// 选中|起始结束日期背景,默认
|
|
160
|
+
activeBg: {
|
|
161
|
+
type: String,
|
|
162
|
+
// '#ff6a00'
|
|
163
|
+
default: calendarPanel.activeBg
|
|
164
|
+
},
|
|
165
|
+
// 选中圆角效果
|
|
166
|
+
activeBorderRadius: {
|
|
167
|
+
type: [String, Number],
|
|
168
|
+
// '0 0 0 0'
|
|
169
|
+
default: calendarPanel.activeBorderRadius
|
|
170
|
+
},
|
|
171
|
+
// 范围内日期字体颜色默认
|
|
172
|
+
rangeColor: {
|
|
173
|
+
type: String,
|
|
174
|
+
// '#ff6a00'
|
|
175
|
+
default: calendarPanel.rangeColor
|
|
176
|
+
},
|
|
177
|
+
// 范围内日期背景色
|
|
178
|
+
rangeBg: {
|
|
179
|
+
type: String,
|
|
180
|
+
// 'rgba(254, 106, 0, 0.1)'
|
|
181
|
+
default: calendarPanel.rangeBg
|
|
182
|
+
},
|
|
183
|
+
// type=range时生效,起始日期自定义文案
|
|
184
|
+
startText: {
|
|
185
|
+
type: String,
|
|
186
|
+
// '开始'
|
|
187
|
+
default: calendarPanel.startText
|
|
188
|
+
},
|
|
189
|
+
// type=range时生效,结束日期自定义文案
|
|
190
|
+
endText: {
|
|
191
|
+
type: String,
|
|
192
|
+
// '结束'
|
|
193
|
+
default: calendarPanel.endText
|
|
194
|
+
},
|
|
195
|
+
// 已选择的时间格式化显示规则
|
|
196
|
+
dateFormat: {
|
|
197
|
+
type: String,
|
|
198
|
+
// 'YYYY-MM-DD'
|
|
199
|
+
default: calendarPanel.dateFormat
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
data() {
|
|
203
|
+
const now = this.$pi.date.parseDate()
|
|
204
|
+
return {
|
|
205
|
+
now: now, // 当前时间
|
|
206
|
+
year: '', // 年份
|
|
207
|
+
month: '', // 月份
|
|
208
|
+
calendarValue: ''
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
computed: {
|
|
212
|
+
getActiveBorderRadius() {
|
|
213
|
+
return this.$pi.common.addUnit(this.activeBorderRadius)
|
|
214
|
+
},
|
|
215
|
+
weekDayZh() {
|
|
216
|
+
return this.$pi.date.getWeekDayZh()
|
|
217
|
+
},
|
|
218
|
+
// 第一天
|
|
219
|
+
firstDay() {
|
|
220
|
+
return new Date(`${this.year}/${this.month}/01 00:00:00`).getDay()
|
|
221
|
+
},
|
|
222
|
+
getMinDate() {
|
|
223
|
+
return this.minDate ? this.$pi.date.parseDate(this.minDate) : ''
|
|
224
|
+
},
|
|
225
|
+
getMaxDate() {
|
|
226
|
+
return this.maxDate ? this.$pi.date.parseDate(this.maxDate) : ''
|
|
227
|
+
},
|
|
228
|
+
isMinYear() {
|
|
229
|
+
return this.year === parseInt(this.minYear, 10)
|
|
230
|
+
},
|
|
231
|
+
isMaxYear() {
|
|
232
|
+
return this.year === parseInt(this.maxYear, 10)
|
|
233
|
+
},
|
|
234
|
+
// 总天数
|
|
235
|
+
days() {
|
|
236
|
+
const days = []
|
|
237
|
+
const monthDays = new Date(this.year, this.month, 0).getDate()
|
|
238
|
+
for (let i = 1; i <= monthDays; i++) {
|
|
239
|
+
const day = {
|
|
240
|
+
key: 'pi-calander-day-item-' + i,
|
|
241
|
+
index: i,
|
|
242
|
+
...this.$pi.date.parseDate(`${this.year}/${this.month}/${i}`)
|
|
243
|
+
}
|
|
244
|
+
const isDisabled = this.isDisabled(day)
|
|
245
|
+
// 禁用
|
|
246
|
+
if (isDisabled) {
|
|
247
|
+
day.disabledStyle = {
|
|
248
|
+
opacity: '0.3',
|
|
249
|
+
cursor: 'not-allowed'
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// 单选选中样式
|
|
253
|
+
if (this.type === 'date' && this.isSameDay(this.calendarValue, day)) {
|
|
254
|
+
const activeStyle = {
|
|
255
|
+
color: this.activeColor,
|
|
256
|
+
borderRadius: this.getActiveBorderRadius
|
|
257
|
+
}
|
|
258
|
+
if (this.activeBg) activeStyle.background = this.activeBg
|
|
259
|
+
day.activeStyle = activeStyle
|
|
260
|
+
}
|
|
261
|
+
// 范围选中样式
|
|
262
|
+
if (this.type === 'range') {
|
|
263
|
+
const start = this.calendarValue[0]
|
|
264
|
+
const end = this.calendarValue[1]
|
|
265
|
+
const isBegin = this.isSameDay(start, day)
|
|
266
|
+
const isEnd = this.isSameDay(end, day)
|
|
267
|
+
const inRange =
|
|
268
|
+
start && end && day.timestamp > start.timestamp && day.timestamp < end.timestamp
|
|
269
|
+
const activeStyle = {}
|
|
270
|
+
// 处理两端
|
|
271
|
+
if (isBegin || isEnd) {
|
|
272
|
+
activeStyle.color = this.activeColor
|
|
273
|
+
activeStyle.borderRadius = isBegin
|
|
274
|
+
? `${this.getActiveBorderRadius} 0 0 ${this.getActiveBorderRadius}`
|
|
275
|
+
: `0 ${this.getActiveBorderRadius} ${this.getActiveBorderRadius} 0`
|
|
276
|
+
if (this.activeBg) activeStyle.background = this.activeBg
|
|
277
|
+
}
|
|
278
|
+
// 处理中间范围的样式
|
|
279
|
+
if (inRange) {
|
|
280
|
+
activeStyle.color = this.rangeColor
|
|
281
|
+
activeStyle.background = this.rangeBg
|
|
282
|
+
}
|
|
283
|
+
day.activeStyle = activeStyle
|
|
284
|
+
// type 为 range 开始和结束的提示
|
|
285
|
+
if (isBegin) day.tip = this.startText
|
|
286
|
+
if (isEnd) day.tip = this.endText
|
|
287
|
+
if (isBegin && isEnd) {
|
|
288
|
+
day.tip = this.startText + '-' + this.endText
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// 当天样式
|
|
292
|
+
if (this.showBackToday && this.isSameDay(this.now, day)) {
|
|
293
|
+
day.nowStyle = {
|
|
294
|
+
color: this.todayActiveBorderColor,
|
|
295
|
+
border: '1px solid ' + this.todayActiveBorderColor,
|
|
296
|
+
borderRadius: this.getActiveBorderRadius
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
days.push(day)
|
|
300
|
+
}
|
|
301
|
+
return days
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
watch: {
|
|
305
|
+
value(newVal, oldVal) {
|
|
306
|
+
if (JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
|
|
307
|
+
this.init()
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
created() {
|
|
312
|
+
this.init()
|
|
313
|
+
},
|
|
314
|
+
methods: {
|
|
315
|
+
valid() {
|
|
316
|
+
if (this.type === 'date') return true
|
|
317
|
+
if (this.type === 'range' && this.$pi.lang.isArray(this.value) && this.value.length === 2)
|
|
318
|
+
return true
|
|
319
|
+
return false
|
|
320
|
+
},
|
|
321
|
+
init() {
|
|
322
|
+
console.log(TAG, '组件初始化', this.value)
|
|
323
|
+
if (!this.valid()) return
|
|
324
|
+
let initValue = this.value
|
|
325
|
+
const nowDate = this.$pi.date.parseDate(this.type === 'date' ? this.value : this.value[0])
|
|
326
|
+
if (this.type === 'range') {
|
|
327
|
+
const endDate = this.$pi.date.parseDate(this.value[1])
|
|
328
|
+
if (this.year !== endDate.year && this.month !== endDate.month) {
|
|
329
|
+
this.year = nowDate.year
|
|
330
|
+
this.month = nowDate.month
|
|
331
|
+
}
|
|
332
|
+
initValue = [nowDate, endDate]
|
|
333
|
+
} else {
|
|
334
|
+
this.year = nowDate.year
|
|
335
|
+
this.month = nowDate.month
|
|
336
|
+
initValue = nowDate
|
|
337
|
+
}
|
|
338
|
+
this.value && this.handleChange(initValue)
|
|
339
|
+
},
|
|
340
|
+
isSameDay(day1, day2) {
|
|
341
|
+
return (
|
|
342
|
+
day1 &&
|
|
343
|
+
day2 &&
|
|
344
|
+
day1.year === day2.year &&
|
|
345
|
+
day1.month === day2.month &&
|
|
346
|
+
day1.date === day2.date
|
|
347
|
+
)
|
|
348
|
+
},
|
|
349
|
+
isDisabled(day) {
|
|
350
|
+
const isDisabled =
|
|
351
|
+
(this.getMinDate && day.timestamp < this.getMinDate.timestamp) ||
|
|
352
|
+
(this.getMaxDate && day.timestamp > this.getMaxDate.timestamp)
|
|
353
|
+
return isDisabled
|
|
354
|
+
},
|
|
355
|
+
handleSelectDate(date) {
|
|
356
|
+
const isDisabled = this.isDisabled(date)
|
|
357
|
+
if (isDisabled) return
|
|
358
|
+
if (this.type === 'date') {
|
|
359
|
+
// 单选方式
|
|
360
|
+
this.handleChange(date)
|
|
361
|
+
return
|
|
362
|
+
}
|
|
363
|
+
// 处理范围选择方式
|
|
364
|
+
if (this.calendarValue.length === 2) {
|
|
365
|
+
// 如果选了两项,则重新开始选择范围
|
|
366
|
+
this.handleChange([date])
|
|
367
|
+
} else {
|
|
368
|
+
// 和第一项判断大小,小的放前面
|
|
369
|
+
if (date.timestamp > this.calendarValue[0].timestamp) {
|
|
370
|
+
this.handleChange([this.calendarValue[0], date])
|
|
371
|
+
} else {
|
|
372
|
+
this.handleChange([date, this.calendarValue[0]])
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
handleChangeMonth(change) {
|
|
377
|
+
const month = this.month + change
|
|
378
|
+
if (month > 12 && !this.isMaxYear) {
|
|
379
|
+
// 下一年
|
|
380
|
+
this.year = this.year + 1
|
|
381
|
+
this.month = 1
|
|
382
|
+
} else if (month < 1 && !this.isMinYear) {
|
|
383
|
+
// 上一年
|
|
384
|
+
this.year = this.year - 1
|
|
385
|
+
this.month = 12
|
|
386
|
+
} else {
|
|
387
|
+
this.month = month
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
handleChangeYear(change) {
|
|
391
|
+
if (change > 0 && this.isMaxYear) return
|
|
392
|
+
if (change < 0 && this.isMinYear) return
|
|
393
|
+
this.year = this.year + change
|
|
394
|
+
},
|
|
395
|
+
handleBackToday() {
|
|
396
|
+
this.year = this.now.year
|
|
397
|
+
this.month = this.now.month
|
|
398
|
+
if (this.type === 'date') {
|
|
399
|
+
this.handleChange(this.now)
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
handleChange(calendarValue) {
|
|
403
|
+
this.calendarValue = calendarValue
|
|
404
|
+
this.val =
|
|
405
|
+
this.type === 'range'
|
|
406
|
+
? this.calendarValue.map(cv =>
|
|
407
|
+
this.$pi.date.formatDate(new Date(cv.timestamp), this.dateFormat)
|
|
408
|
+
)
|
|
409
|
+
: this.$pi.date.formatDate(new Date(this.calendarValue.timestamp), this.dateFormat)
|
|
410
|
+
this.handleEmitChange()
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
</script>
|
|
415
|
+
|
|
416
|
+
<style lang="scss" scoped>
|
|
417
|
+
.pi-calendar-panel {
|
|
418
|
+
width: 100%;
|
|
419
|
+
.date-item {
|
|
420
|
+
position: relative;
|
|
421
|
+
z-index: 2;
|
|
422
|
+
width: calc(100% / 7);
|
|
423
|
+
margin-bottom: 12rpx;
|
|
424
|
+
overflow: hidden;
|
|
425
|
+
}
|
|
426
|
+
.back-today {
|
|
427
|
+
padding: 12rpx 24rpx;
|
|
428
|
+
overflow: hidden;
|
|
429
|
+
font-size: 20rpx;
|
|
430
|
+
color: #ffffff;
|
|
431
|
+
white-space: nowrap;
|
|
432
|
+
background: $pi-primary-color;
|
|
433
|
+
border-radius: 50rpx 0 0 50rpx;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
</style>
|