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.
Files changed (140) hide show
  1. package/CHANGELOG.md +512 -512
  2. package/LICENSE +20 -20
  3. package/README.md +166 -166
  4. package/components/pi-action-sheet/index.vue +247 -247
  5. package/components/pi-badge/index.vue +136 -136
  6. package/components/pi-bottom-bar/index.vue +139 -139
  7. package/components/pi-button/index.vue +492 -492
  8. package/components/pi-calendar/index.vue +178 -178
  9. package/components/pi-calendar-panel/index.vue +436 -432
  10. package/components/pi-canvas/index.vue +400 -400
  11. package/components/pi-card/index.vue +127 -127
  12. package/components/pi-checkbox/index.vue +345 -345
  13. package/components/pi-checkbox-group/index.vue +215 -215
  14. package/components/pi-circle-progress/index.vue +224 -224
  15. package/components/pi-code-input/index.vue +262 -262
  16. package/components/pi-count-down/index.vue +245 -245
  17. package/components/pi-count-up/index.vue +209 -209
  18. package/components/pi-date-picker/index.vue +366 -366
  19. package/components/pi-divider/index.vue +109 -109
  20. package/components/pi-dropdown/components/dropdown-tab.vue +62 -62
  21. package/components/pi-dropdown/index.vue +316 -316
  22. package/components/pi-dropdown-item/index.vue +233 -233
  23. package/components/pi-form/index.vue +237 -237
  24. package/components/pi-form-item/index.vue +534 -534
  25. package/components/pi-gap/index.vue +72 -72
  26. package/components/pi-grid/index.vue +92 -92
  27. package/components/pi-grid-item/index.vue +220 -220
  28. package/components/pi-icon/index.vue +147 -147
  29. package/components/pi-img/index.vue +267 -267
  30. package/components/pi-img-cropper/canvas.js +112 -112
  31. package/components/pi-img-cropper/index.vue +357 -357
  32. package/components/pi-img-cropper/touch.js +163 -163
  33. package/components/pi-img-cropper/vector.js +34 -34
  34. package/components/pi-input/index.vue +299 -299
  35. package/components/pi-line/index.vue +78 -78
  36. package/components/pi-line-progress/index.vue +198 -198
  37. package/components/pi-list/index.vue +115 -115
  38. package/components/pi-list-item/index.vue +331 -331
  39. package/components/pi-loading/index.vue +188 -188
  40. package/components/pi-marquee/index.vue +281 -281
  41. package/components/pi-marquee-item/index.vue +47 -47
  42. package/components/pi-mask/index.vue +198 -198
  43. package/components/pi-modal/index.vue +303 -303
  44. package/components/pi-navbar/index.vue +421 -421
  45. package/components/pi-notify/index.vue +239 -239
  46. package/components/pi-number-keyboard/index.vue +189 -189
  47. package/components/pi-opentype-button/index.vue +501 -501
  48. package/components/pi-pagination/index.vue +277 -277
  49. package/components/pi-picker/index.vue +317 -317
  50. package/components/pi-popup/index.vue +353 -353
  51. package/components/pi-popup-select/index.vue +291 -291
  52. package/components/pi-radio/index.vue +387 -387
  53. package/components/pi-radio-group/index.vue +262 -262
  54. package/components/pi-rate/index.vue +212 -212
  55. package/components/pi-regions-select/index.vue +318 -318
  56. package/components/pi-search/index.vue +351 -351
  57. package/components/pi-section/index.vue +218 -218
  58. package/components/pi-select/index.vue +391 -391
  59. package/components/pi-skeleton/index.vue +280 -280
  60. package/components/pi-status-bar/index.vue +56 -56
  61. package/components/pi-stepper/index.vue +394 -394
  62. package/components/pi-steps/index.vue +299 -299
  63. package/components/pi-swiper/index.vue +344 -344
  64. package/components/pi-switch/index.vue +227 -227
  65. package/components/pi-tabs/index.vue +398 -398
  66. package/components/pi-upload-img/index.vue +508 -506
  67. package/components/pi-waterfall/index.vue +130 -130
  68. package/components/pi-webview/index.vue +82 -82
  69. package/config/actionSheet.js +25 -25
  70. package/config/badge.js +9 -9
  71. package/config/bottomBar.js +11 -11
  72. package/config/button.js +29 -29
  73. package/config/calendar.js +19 -19
  74. package/config/calendarPanel.js +24 -24
  75. package/config/card.js +8 -8
  76. package/config/checkbox.js +14 -14
  77. package/config/checkboxGroup.js +14 -14
  78. package/config/circleProgress.js +13 -13
  79. package/config/codeInput.js +12 -12
  80. package/config/countDown.js +12 -12
  81. package/config/countUp.js +13 -13
  82. package/config/datePicker.js +22 -22
  83. package/config/divider.js +10 -10
  84. package/config/dropdown.js +21 -21
  85. package/config/dropdownItem.js +26 -26
  86. package/config/form.js +27 -27
  87. package/config/formItem.js +25 -25
  88. package/config/gap.js +8 -8
  89. package/config/grid.js +9 -9
  90. package/config/gridItem.js +12 -12
  91. package/config/icon.js +11 -11
  92. package/config/img.js +21 -21
  93. package/config/imgCropper.js +26 -26
  94. package/config/index.js +28 -28
  95. package/config/input.js +25 -25
  96. package/config/line.js +8 -8
  97. package/config/lineProgress.js +14 -14
  98. package/config/list.js +12 -12
  99. package/config/listItem.js +25 -25
  100. package/config/loading.js +10 -10
  101. package/config/marquee.js +8 -8
  102. package/config/mask.js +12 -12
  103. package/config/modal.js +36 -36
  104. package/config/navbar.js +32 -32
  105. package/config/notify.js +13 -13
  106. package/config/numberKeyboard.js +21 -21
  107. package/config/pagination.js +10 -10
  108. package/config/picker.js +19 -19
  109. package/config/popup.js +23 -23
  110. package/config/popupSelect.js +35 -35
  111. package/config/radio.js +15 -15
  112. package/config/radioGroup.js +16 -16
  113. package/config/rate.js +15 -15
  114. package/config/regionsData.js +58 -58
  115. package/config/regionsSelect.js +18 -18
  116. package/config/search.js +27 -27
  117. package/config/section.js +23 -23
  118. package/config/select.js +28 -28
  119. package/config/skeleton.js +13 -13
  120. package/config/statusBar.js +5 -5
  121. package/config/stepper.js +19 -19
  122. package/config/steps.js +19 -19
  123. package/config/swiper.js +22 -22
  124. package/config/switch.js +13 -13
  125. package/config/tabs.js +23 -23
  126. package/config/uploadImg.js +63 -63
  127. package/config/waterfall.js +6 -6
  128. package/index.js +41 -41
  129. package/mixin/component-custom.js +24 -24
  130. package/mixin/emitter.js +45 -45
  131. package/mixin/props-sync.js +65 -65
  132. package/mixin/value-sync.js +32 -32
  133. package/mixin/wx-code.js +30 -30
  134. package/package.json +25 -25
  135. package/plugins/async-validator.js +1511 -1511
  136. package/scss/animation.scss +260 -260
  137. package/scss/icon/icon.scss +594 -594
  138. package/scss/index.scss +5 -5
  139. package/scss/mixin.scss +47 -47
  140. 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
- if (this.showBackToday && this.isSameDay(this.now, day)) {
290
- day.nowStyle = {
291
- color: this.todayActiveBorderColor,
292
- border: '1px solid ' + this.todayActiveBorderColor,
293
- borderRadius: this.getActiveBorderRadius
294
- }
295
- }
296
- days.push(day)
297
- }
298
- return days
299
- }
300
- },
301
- watch: {
302
- value(val) {
303
- console.log(val)
304
- this.init()
305
- }
306
- },
307
- created() {
308
- this.init()
309
- },
310
- methods: {
311
- valid() {
312
- if (this.type === 'date') return true
313
- if (this.type === 'range' && this.$pi.lang.isArray(this.value) && this.value.length === 2)
314
- return true
315
- console.error(TAG, 'value 参数不合法,请检查')
316
- return false
317
- },
318
- init() {
319
- console.log(TAG, '组件初始化')
320
- if (!this.valid()) return
321
- const nowDate = this.$pi.date.parseDate(this.type === 'date' ? this.value : this.value[0])
322
- if (this.type === 'range') {
323
- const endDate = this.$pi.date.parseDate(this.value[1])
324
- if (this.year !== endDate.year && this.month !== endDate.month) {
325
- this.year = nowDate.year
326
- this.month = nowDate.month
327
- }
328
- this.calendarValue = [nowDate, endDate]
329
- } else {
330
- this.year = nowDate.year
331
- this.month = nowDate.month
332
- this.calendarValue = nowDate
333
- }
334
- },
335
- isSameDay(day1, day2) {
336
- return (
337
- day1 &&
338
- day2 &&
339
- day1.year === day2.year &&
340
- day1.month === day2.month &&
341
- day1.date === day2.date
342
- )
343
- },
344
- isDisabled(day) {
345
- const isDisabled =
346
- (this.getMinDate && day.timestamp < this.getMinDate.timestamp) ||
347
- (this.getMaxDate && day.timestamp > this.getMaxDate.timestamp)
348
- return isDisabled
349
- },
350
- handleSelectDate(date) {
351
- const isDisabled = this.isDisabled(date)
352
- if (isDisabled) return
353
- if (this.type === 'date') {
354
- // 单选方式
355
- this.handleChange(date)
356
- return
357
- }
358
- // 处理范围选择方式
359
- if (this.calendarValue.length === 2) {
360
- // 如果选了两项,则重新开始选择范围
361
- this.calendarValue = [date]
362
- } else {
363
- // 如果第二项选择的和第一项一样,不做处理
364
- const isSameDay = this.isSameDay(this.calendarValue[0], date)
365
- if (isSameDay) return
366
- // 和第一项判断大小,小的放前面
367
- if (date.timestamp > this.calendarValue[0].timestamp) {
368
- this.handleChange([this.calendarValue[0], date])
369
- } else {
370
- this.handleChange([date, this.calendarValue[0]])
371
- }
372
- }
373
- },
374
- handleChangeMonth(change) {
375
- const month = this.month + change
376
- if (month > 12 && !this.isMaxYear) {
377
- // 下一年
378
- this.year = this.year + 1
379
- this.month = 1
380
- } else if (month < 1 && !this.isMinYear) {
381
- // 上一年
382
- this.year = this.year - 1
383
- this.month = 12
384
- } else {
385
- this.month = month
386
- }
387
- },
388
- handleChangeYear(change) {
389
- if (change > 0 && this.isMaxYear) return
390
- if (change < 0 && this.isMinYear) return
391
- this.year = this.year + change
392
- },
393
- handleBackToday() {
394
- this.year = this.now.year
395
- this.month = this.now.month
396
- if (this.type === 'date') {
397
- this.calendarValue = this.now
398
- }
399
- },
400
- handleChange(calendarValue) {
401
- this.calendarValue = calendarValue
402
- this.val =
403
- this.type === 'range'
404
- ? this.calendarValue.map(cv => cv.format(this.dateFormat))
405
- : this.calendarValue.format(this.dateFormat)
406
- this.handleEmitChange()
407
- }
408
- }
409
- }
410
- </script>
411
-
412
- <style lang="scss" scoped>
413
- .pi-calendar-panel {
414
- width: 100%;
415
- .date-item {
416
- position: relative;
417
- z-index: 2;
418
- width: calc(100% / 7);
419
- margin-bottom: 12rpx;
420
- overflow: hidden;
421
- }
422
- .back-today {
423
- padding: 12rpx 24rpx;
424
- overflow: hidden;
425
- font-size: 20rpx;
426
- color: #ffffff;
427
- white-space: nowrap;
428
- background: $pi-primary-color;
429
- border-radius: 50rpx 0 0 50rpx;
430
- }
431
- }
432
- </style>
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>