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.
Files changed (160) hide show
  1. package/.prettierrc +7 -7
  2. package/CHANGELOG.md +545 -545
  3. package/LICENSE +20 -20
  4. package/README.md +166 -166
  5. package/components/pi-action-sheet/index.vue +247 -247
  6. package/components/pi-badge/index.vue +146 -146
  7. package/components/pi-bottom-bar/index.vue +139 -139
  8. package/components/pi-bubble/index.vue +174 -174
  9. package/components/pi-button/index.vue +492 -492
  10. package/components/pi-calendar-input/index.vue +230 -230
  11. package/components/pi-calendar-panel/components/calendar-days/index.vue +410 -410
  12. package/components/pi-calendar-panel/index.vue +473 -473
  13. package/components/pi-canvas/index.vue +407 -407
  14. package/components/pi-card/index.vue +127 -127
  15. package/components/pi-cascader/index.vue +601 -601
  16. package/components/pi-checkbox/index.vue +363 -363
  17. package/components/pi-checkbox-group/index.vue +222 -222
  18. package/components/pi-circle-progress/index.vue +311 -311
  19. package/components/pi-code-input/index.vue +270 -270
  20. package/components/pi-collapse/index.vue +124 -124
  21. package/components/pi-collapse-item/index.vue +352 -352
  22. package/components/pi-count-down/index.vue +245 -245
  23. package/components/pi-count-up/index.vue +209 -209
  24. package/components/pi-date-picker-input/index.vue +219 -219
  25. package/components/pi-divider/index.vue +112 -112
  26. package/components/pi-dropdown/components/dropdown-tab.vue +71 -71
  27. package/components/pi-dropdown/index.vue +356 -356
  28. package/components/pi-dropdown-item/index.vue +252 -252
  29. package/components/pi-form/index.vue +273 -273
  30. package/components/pi-form-item/index.vue +603 -590
  31. package/components/pi-gap/index.vue +72 -72
  32. package/components/pi-grid/index.vue +92 -92
  33. package/components/pi-grid-item/index.vue +220 -220
  34. package/components/pi-icon/index.vue +147 -147
  35. package/components/pi-img/index.vue +266 -266
  36. package/components/pi-img-cropper/canvas.js +106 -106
  37. package/components/pi-img-cropper/index.vue +357 -357
  38. package/components/pi-img-cropper/touch.js +163 -163
  39. package/components/pi-img-cropper/vector.js +34 -34
  40. package/components/pi-input/index.vue +409 -401
  41. package/components/pi-line/index.vue +78 -78
  42. package/components/pi-line-progress/index.vue +198 -198
  43. package/components/pi-list/index.vue +115 -115
  44. package/components/pi-list-item/index.vue +335 -335
  45. package/components/pi-loading/index.vue +188 -188
  46. package/components/pi-marquee/index.vue +310 -310
  47. package/components/pi-marquee-item/index.vue +47 -47
  48. package/components/pi-mask/index.vue +198 -198
  49. package/components/pi-modal/index.vue +303 -303
  50. package/components/pi-navbar/index.vue +421 -421
  51. package/components/pi-notify/index.vue +239 -239
  52. package/components/pi-number-keyboard/index.vue +189 -189
  53. package/components/pi-opentype-button/index.vue +501 -501
  54. package/components/pi-pagination/index.vue +290 -290
  55. package/components/pi-picker/index.vue +317 -317
  56. package/components/pi-popup/index.vue +356 -356
  57. package/components/pi-popup-select/index.vue +300 -300
  58. package/components/pi-radio/index.vue +403 -403
  59. package/components/pi-radio-group/index.vue +300 -300
  60. package/components/pi-rate/index.vue +212 -212
  61. package/components/pi-regions-select/index.vue +349 -349
  62. package/components/pi-regions-select-input/index.vue +230 -230
  63. package/components/pi-search/index.vue +386 -386
  64. package/components/pi-section/index.vue +218 -218
  65. package/components/pi-select/index.vue +678 -678
  66. package/components/pi-select-input/index.vue +273 -273
  67. package/components/pi-skeleton/index.vue +280 -280
  68. package/components/pi-status-bar/index.vue +56 -56
  69. package/components/pi-stepper/index.vue +408 -408
  70. package/components/pi-steps/index.vue +378 -378
  71. package/components/pi-subsection/index.vue +403 -403
  72. package/components/pi-swiper/index.vue +344 -344
  73. package/components/pi-switch/index.vue +231 -231
  74. package/components/pi-table/index.vue +351 -351
  75. package/components/pi-tabs/index.vue +435 -435
  76. package/components/pi-tag/index.vue +488 -488
  77. package/components/pi-upload-img/index.vue +980 -980
  78. package/components/pi-waterfall/index.vue +130 -130
  79. package/config/actionSheet.js +24 -24
  80. package/config/badge.js +9 -9
  81. package/config/bottomBar.js +11 -11
  82. package/config/bubble.js +6 -6
  83. package/config/button.js +29 -29
  84. package/config/calendar.js +19 -19
  85. package/config/calendarInput.js +19 -19
  86. package/config/calendarPanel.js +27 -27
  87. package/config/card.js +8 -8
  88. package/config/cascader.js +22 -22
  89. package/config/checkbox.js +15 -15
  90. package/config/checkboxGroup.js +15 -15
  91. package/config/circleProgress.js +20 -20
  92. package/config/codeInput.js +13 -13
  93. package/config/collapse.js +7 -7
  94. package/config/collapseItem.js +11 -11
  95. package/config/countDown.js +12 -12
  96. package/config/countUp.js +13 -13
  97. package/config/datePickerInput.js +18 -18
  98. package/config/divider.js +10 -10
  99. package/config/dropdown.js +25 -25
  100. package/config/dropdownItem.js +26 -26
  101. package/config/form.js +29 -29
  102. package/config/formItem.js +27 -27
  103. package/config/gap.js +8 -8
  104. package/config/grid.js +9 -9
  105. package/config/gridItem.js +12 -12
  106. package/config/icon.js +11 -11
  107. package/config/img.js +21 -21
  108. package/config/imgCropper.js +26 -26
  109. package/config/index.js +28 -28
  110. package/config/input.js +37 -36
  111. package/config/line.js +8 -8
  112. package/config/lineProgress.js +14 -14
  113. package/config/list.js +12 -12
  114. package/config/listItem.js +25 -25
  115. package/config/loading.js +10 -10
  116. package/config/marquee.js +10 -10
  117. package/config/mask.js +12 -12
  118. package/config/modal.js +36 -36
  119. package/config/navbar.js +32 -32
  120. package/config/notify.js +13 -13
  121. package/config/numberKeyboard.js +21 -21
  122. package/config/pagination.js +10 -10
  123. package/config/picker.js +19 -19
  124. package/config/popup.js +23 -23
  125. package/config/popupSelect.js +35 -35
  126. package/config/radio.js +16 -16
  127. package/config/radioGroup.js +17 -17
  128. package/config/rate.js +15 -15
  129. package/config/regionsData.js +58 -58
  130. package/config/regionsSelect.js +19 -19
  131. package/config/regionsSelectInput.js +29 -29
  132. package/config/search.js +27 -27
  133. package/config/section.js +23 -23
  134. package/config/select.js +41 -41
  135. package/config/selectInput.js +29 -29
  136. package/config/skeleton.js +13 -13
  137. package/config/statusBar.js +5 -5
  138. package/config/stepper.js +19 -19
  139. package/config/steps.js +19 -19
  140. package/config/subsection.js +14 -14
  141. package/config/swiper.js +22 -22
  142. package/config/switch.js +13 -13
  143. package/config/table.js +8 -8
  144. package/config/tabs.js +23 -23
  145. package/config/tag.js +21 -21
  146. package/config/uploadImg.js +81 -81
  147. package/config/waterfall.js +6 -6
  148. package/index.js +41 -41
  149. package/mixin/component-custom.js +24 -24
  150. package/mixin/emitter.js +45 -45
  151. package/mixin/props-sync.js +65 -65
  152. package/mixin/value-sync.js +32 -32
  153. package/mixin/wx-code.js +30 -30
  154. package/package.json +28 -28
  155. package/plugins/async-validator.js +1511 -1511
  156. package/scss/animation.scss +260 -260
  157. package/scss/icon/icon.scss +595 -595
  158. package/scss/index.scss +5 -5
  159. package/scss/mixin.scss +47 -47
  160. package/tools/index.js +19 -19
@@ -1,473 +1,473 @@
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="handlePrevMonth()" />
13
- <view class="pi-pd-lr-8 pi-text-nowrap">{{ month }}月</view>
14
- <view class="pi-icon-right pi-pd-14" @tap="handleNextMonth()" />
15
- </view>
16
- </view>
17
- <view v-if="showBackToday" class="back-today" @tap="handleBackToday">回到今日</view>
18
- </view>
19
- <!-- 星期 -->
20
- <view
21
- class="pi-align-center pi-pd-24"
22
- style="box-shadow: 0 15px 10px -15px rgba(125, 126, 128, 0.16);"
23
- >
24
- <view
25
- v-for="(week, index) in weekDayZh"
26
- :key="index"
27
- class="date-item pi-justify-center pi-fw-500"
28
- >
29
- {{ week }}
30
- </view>
31
- </view>
32
- <view
33
- class="pi-square days-wrap"
34
- :class="{ 'week-view': weekView, 'can-change-week': canChangeWeekView }"
35
- >
36
- <!-- 固定日期面板正方形,避免高度变化造成界面抖动 -->
37
- <view class="pi-rela pi-flex-column pi-h-100P">
38
- <swiper
39
- class="pi-w-100P pi-flex-sub pi-h-100P"
40
- :current="currentTabIndex"
41
- circular
42
- @change="handleTabChange"
43
- >
44
- <swiper-item v-for="tab in [1, 2, 3]" :key="tab">
45
- <calandar-days
46
- :calendar-value="calendarValue"
47
- :year="year"
48
- :month="getCalandarMonth(tab)"
49
- :week="getCalandaWeek(tab)"
50
- :type="type"
51
- :min-date="minDate"
52
- :max-date="maxDate"
53
- :today-active-border-color="todayActiveBorderColor"
54
- :active-color="activeColor"
55
- :active-bg="activeBg"
56
- :active-border-radius="activeBorderRadius"
57
- :range-color="rangeColor"
58
- :range-bg="rangeBg"
59
- :start-text="startText"
60
- :end-text="endText"
61
- :week-view="weekView"
62
- :show-back-today="showBackToday"
63
- :marks="marks"
64
- @change="handleChange"
65
- />
66
- </swiper-item>
67
- </swiper>
68
- <view
69
- v-if="canChangeWeekView"
70
- class="pi-justify-center pi-align-center pi-pd-bottom-12 pi-light-gray"
71
- @tap="handleChangeWeekView"
72
- >
73
- <pi-icon
74
- name="arrow-down_fill"
75
- :custom-style="{ transform: `rotate(${weekView ? '0deg' : '180deg'})` }"
76
- />
77
- <text class="pi-fz-24 ">{{ weekView ? '展开' : '收起' }}</text>
78
- </view>
79
- </view>
80
- </view>
81
- </view>
82
- </template>
83
-
84
- <script>
85
- import ValueSync from '../../mixin/value-sync'
86
- import { getConfig } from '../../config'
87
- import CalandarDays from './components/calendar-days'
88
-
89
- const TAG = 'PiCalendarPanel'
90
- const { calendarPanel } = getConfig()
91
-
92
- export default {
93
- name: 'PiCalendarPanel',
94
- components: { CalandarDays },
95
- mixins: [ValueSync],
96
- props: {
97
- // 自定义样式,对象形式
98
- customStyle: {
99
- type: Object,
100
- // {}
101
- default() {
102
- return calendarPanel.customStyle
103
- }
104
- },
105
- // 自定义样式类,字符串形式
106
- customClass: {
107
- type: String,
108
- // ''
109
- default() {
110
- return calendarPanel.customClass
111
- }
112
- },
113
- // 日历类型
114
- type: {
115
- // `'date'-单个日期`, `'range'-范围日期`
116
- type: String,
117
- // 'date'
118
- default: calendarPanel.type,
119
- validator: function(value) {
120
- return ['date', 'range'].includes(value)
121
- }
122
- },
123
- // 日期默认值,单选时候,传入Date(时间戳,时间字符串,Date类型),日历范围,传入Date[]
124
- value: {
125
- type: [Number, String, Date, Array]
126
- // -
127
- },
128
- // 可切换的最小年份
129
- minYear: {
130
- type: [Number, String],
131
- // 当前年份 - 80
132
- default: calendarPanel.minYear
133
- },
134
- // 可切换的最大年份(默认当前年份)
135
- maxYear: {
136
- type: [Number, String],
137
- // 当前年份 + 30
138
- default: calendarPanel.maxYear
139
- },
140
- // 最小可选日期(不在范围内日期禁用不可选,默认'',不作限制)
141
- minDate: {
142
- type: [Number, String, Date],
143
- // ''
144
- default: calendarPanel.minDate
145
- },
146
- // 最大可选日期(不在范围内日期禁用不可选,默认'',不作限制)
147
- maxDate: {
148
- type: [Number, String, Date],
149
- // ''
150
- default: calendarPanel.maxDate
151
- },
152
- // 是否显示回到今日
153
- showBackToday: {
154
- type: Boolean,
155
- // true
156
- default: calendarPanel.showBackToday
157
- },
158
- // 今日日期激活边框颜色
159
- todayActiveBorderColor: {
160
- type: String,
161
- // '#ff6a00'
162
- default: calendarPanel.todayActiveBorderColor
163
- },
164
- // 选中|起始结束日期字体颜色
165
- activeColor: {
166
- type: String,
167
- // '#ffffff'
168
- default: calendarPanel.activeColor
169
- },
170
- // 选中|起始结束日期背景,默认
171
- activeBg: {
172
- type: String,
173
- // '#ff6a00'
174
- default: calendarPanel.activeBg
175
- },
176
- // 选中圆角效果
177
- activeBorderRadius: {
178
- type: [String, Number],
179
- // '0 0 0 0'
180
- default: calendarPanel.activeBorderRadius
181
- },
182
- // 范围内日期字体颜色默认
183
- rangeColor: {
184
- type: String,
185
- // '#ff6a00'
186
- default: calendarPanel.rangeColor
187
- },
188
- // 范围内日期背景色
189
- rangeBg: {
190
- type: String,
191
- // 'rgba(254, 106, 0, 0.1)'
192
- default: calendarPanel.rangeBg
193
- },
194
- // type=range时生效,起始日期自定义文案
195
- startText: {
196
- type: String,
197
- // '开始'
198
- default: calendarPanel.startText
199
- },
200
- // type=range时生效,结束日期自定义文案
201
- endText: {
202
- type: String,
203
- // '结束'
204
- default: calendarPanel.endText
205
- },
206
- // 已选择的时间格式化显示规则
207
- dateFormat: {
208
- type: String,
209
- // 'YYYY-MM-DD'
210
- default: calendarPanel.dateFormat
211
- },
212
- // 是否可切换周视图,默认(true)
213
- canChangeWeekView: {
214
- type: Boolean,
215
- // true
216
- default: calendarPanel.canChangeWeekView
217
- },
218
- // 是否默认显示周视图,默认(false)
219
- defalutWeekView: {
220
- type: Boolean,
221
- // true
222
- default: calendarPanel.defalutWeekView
223
- },
224
- // 日期标记,数组形式,默认([])
225
- marks: {
226
- type: Array,
227
- // []
228
- default: () => calendarPanel.marks
229
- }
230
- },
231
- data() {
232
- const now = this.$pi.date.parseDate()
233
- return {
234
- now: now, // 当前时间
235
- year: now.year, // 年份
236
- month: now.month, // 月份
237
- week: 1, // 当前周
238
- calendarValue: '',
239
- currentTabIndex: 1, // 当前选中的tab索引
240
- weekView: this.defalutWeekView // 是否显示周视图
241
- }
242
- },
243
- computed: {
244
- // 第一天
245
- firstDay() {
246
- const preMonthLastDay = this.getPreMonthLastDay
247
- const firstDay = new Date(`${this.year}/${this.month}/01 00:00:00`).getDay()
248
- return this.$pi.common.generateArray(preMonthLastDay - firstDay + 1, preMonthLastDay)
249
- },
250
- weekDayZh() {
251
- return this.$pi.date.getWeekDayZh()
252
- },
253
- isMinYear() {
254
- return this.year === parseInt(this.minYear, 10)
255
- },
256
- isMaxYear() {
257
- return this.year === parseInt(this.maxYear, 10)
258
- },
259
- // 获取上个月最后一天
260
- getPreMonthLastDay() {
261
- let year = this.year
262
- let month = this.month
263
- if (month === 1) {
264
- year = year - 1
265
- month = 12
266
- }
267
- return new Date(year, month - 1, '0').getDate()
268
- }
269
- },
270
- watch: {
271
- value(newVal, oldVal) {
272
- if (JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
273
- this.init()
274
- }
275
- }
276
- },
277
- created() {
278
- this.init()
279
- },
280
- methods: {
281
- init() {
282
- console.log(TAG, '组件初始化', this.value)
283
- let initValue = this.value
284
- const nowDate = this.$pi.date.parseDate(this.type === 'date' ? this.value : this.value[0])
285
- if (this.type === 'range') {
286
- initValue = initValue || []
287
- if (this.value[1]) {
288
- const endDate = this.$pi.date.parseDate(this.value[1])
289
-
290
- this.year = endDate.year
291
- this.month = endDate.month
292
-
293
- initValue = [nowDate, endDate]
294
- } else if (initValue.length === 1) {
295
- initValue = [nowDate]
296
-
297
- this.year = nowDate.year
298
- this.month = nowDate.month
299
- }
300
- } else {
301
- this.year = nowDate.year
302
- this.month = nowDate.month
303
- initValue = nowDate
304
- }
305
- this.value && this.handleChange(initValue)
306
- if (this.canChangeWeekView) {
307
- // 如果可以切换周视图,则初始化当前周
308
- let targetDay = this.type === 'date' ? this.calendarValue : this.calendarValue[0]
309
- if (!targetDay) {
310
- targetDay = this.now
311
- }
312
- const startDate = targetDay.date + this.firstDay.length
313
- this.week = Math.ceil(startDate / 7)
314
- }
315
- },
316
-
317
- handleChangeWeek(change) {
318
- const week = this.week + change
319
- if (week > 6) {
320
- // 当月最后一天剩余周
321
- const lastDay = new Date(this.year, this.month, '0').getDate()
322
- const lastDayIndex = lastDay + this.firstDay.length
323
- const remainWeek = 6 - Math.floor(lastDayIndex / 7)
324
- // 下一月
325
- this.handleChangeMonth(1)
326
- this.week = remainWeek + (lastDayIndex % 7 === 0 ? 0 : 1)
327
- } else if (week < 1) {
328
- // 记录上个月的最后一天
329
- const preMonthLastDay = this.getPreMonthLastDay
330
- // 切换到上一月
331
- this.handleChangeMonth(-1)
332
- const week = Math.floor((preMonthLastDay + this.firstDay.length) / 7)
333
- this.week = week
334
- } else {
335
- this.week = week
336
- }
337
- },
338
- handleChangeMonth(change) {
339
- const month = this.month + change
340
- if (month > 12 && !this.isMaxYear) {
341
- // 下一年
342
- this.year = this.year + 1
343
- this.month = 1
344
- } else if (month < 1 && !this.isMinYear) {
345
- // 上一年
346
- this.year = this.year - 1
347
- this.month = 12
348
- } else {
349
- this.month = month
350
- }
351
- this.$emit('date-change', {
352
- year: this.year,
353
- month: this.month
354
- })
355
- },
356
- handlePrevMonth() {
357
- if (this.currentTabIndex === 0) {
358
- this.currentTabIndex = 2
359
- } else {
360
- this.currentTabIndex--
361
- }
362
- this.handleChangeMonth(-1)
363
- },
364
- handleNextMonth() {
365
- if (this.currentTabIndex === 2) {
366
- this.currentTabIndex = 0
367
- } else {
368
- this.currentTabIndex++
369
- }
370
- this.handleChangeMonth(1)
371
- },
372
- handleChangeYear(change) {
373
- if (change > 0 && this.isMaxYear) return
374
- if (change < 0 && this.isMinYear) return
375
- this.year = this.year + change
376
- this.$emit('date-change', {
377
- year: this.year,
378
- month: this.month
379
- })
380
- },
381
- handleBackToday() {
382
- this.year = this.now.year
383
- this.month = this.now.month
384
- if (this.type === 'date') {
385
- this.handleChange(this.now)
386
- }
387
- },
388
- handleChange(calendarValue) {
389
- this.calendarValue = calendarValue
390
- this.val =
391
- this.type === 'range'
392
- ? this.calendarValue.map(cv =>
393
- this.$pi.date.formatDate(new Date(cv.timestamp), this.dateFormat)
394
- )
395
- : this.$pi.date.formatDate(new Date(this.calendarValue.timestamp), this.dateFormat)
396
- this.handleEmitChange()
397
- },
398
- handleTabChange(e) {
399
- const { source, current } = e.detail
400
- if (source !== 'touch') return
401
- const isRightMove = [1, -2].includes(current - this.currentTabIndex)
402
- if (this.weekView) {
403
- this.handleChangeWeek(isRightMove ? 1 : -1)
404
- } else {
405
- this.handleChangeMonth(isRightMove ? 1 : -1)
406
- }
407
- this.currentTabIndex = current
408
- },
409
- getCalandarMonth(tab) {
410
- if (this.weekView) {
411
- return this.month
412
- }
413
- const changeMaps = [
414
- [0, 1, -1],
415
- [-1, 0, 0],
416
- [1, 0, 0]
417
- ]
418
- const change = changeMaps[tab - 1][this.currentTabIndex]
419
- return this.month + change
420
- },
421
- getCalandaWeek(tab) {
422
- const changeMaps = [
423
- [0, -1, 1],
424
- [1, 0, -1],
425
- [-1, 1, 0]
426
- ]
427
- const change = changeMaps[tab - 1][this.currentTabIndex]
428
- return this.week + change
429
- },
430
- handleChangeWeekView() {
431
- this.weekView = !this.weekView
432
- }
433
- }
434
- }
435
- </script>
436
-
437
- <style lang="scss" scoped>
438
- .pi-calendar-panel {
439
- width: 100%;
440
- .date-item {
441
- position: relative;
442
- z-index: 2;
443
- width: calc(100% / 7);
444
- overflow: hidden;
445
- }
446
- .back-today {
447
- padding: 12rpx 24rpx;
448
- overflow: hidden;
449
- font-size: 20rpx;
450
- color: #ffffff;
451
- white-space: nowrap;
452
- background: $pi-primary-color;
453
- border-radius: 50rpx 0 0 50rpx;
454
- }
455
- .pi-square {
456
- padding-bottom: 86%;
457
- &.can-change-week {
458
- padding-bottom: 90%;
459
- }
460
- }
461
-
462
- .days-wrap {
463
- transition: all $pi-animation-duration $pi-animation-timing-function;
464
- &.week-view {
465
- padding-bottom: 24%;
466
- }
467
- }
468
- // 图标动态效果
469
- ::v-deep .icon-wrap view {
470
- transition: all $pi-animation-duration $pi-animation-timing-function;
471
- }
472
- }
473
- </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="handlePrevMonth()" />
13
+ <view class="pi-pd-lr-8 pi-text-nowrap">{{ month }}月</view>
14
+ <view class="pi-icon-right pi-pd-14" @tap="handleNextMonth()" />
15
+ </view>
16
+ </view>
17
+ <view v-if="showBackToday" class="back-today" @tap="handleBackToday">回到今日</view>
18
+ </view>
19
+ <!-- 星期 -->
20
+ <view
21
+ class="pi-align-center pi-pd-24"
22
+ style="box-shadow: 0 15px 10px -15px rgba(125, 126, 128, 0.16);"
23
+ >
24
+ <view
25
+ v-for="(week, index) in weekDayZh"
26
+ :key="index"
27
+ class="date-item pi-justify-center pi-fw-500"
28
+ >
29
+ {{ week }}
30
+ </view>
31
+ </view>
32
+ <view
33
+ class="pi-square days-wrap"
34
+ :class="{ 'week-view': weekView, 'can-change-week': canChangeWeekView }"
35
+ >
36
+ <!-- 固定日期面板正方形,避免高度变化造成界面抖动 -->
37
+ <view class="pi-rela pi-flex-column pi-h-100P">
38
+ <swiper
39
+ class="pi-w-100P pi-flex-sub pi-h-100P"
40
+ :current="currentTabIndex"
41
+ circular
42
+ @change="handleTabChange"
43
+ >
44
+ <swiper-item v-for="tab in [1, 2, 3]" :key="tab">
45
+ <calandar-days
46
+ :calendar-value="calendarValue"
47
+ :year="year"
48
+ :month="getCalandarMonth(tab)"
49
+ :week="getCalandaWeek(tab)"
50
+ :type="type"
51
+ :min-date="minDate"
52
+ :max-date="maxDate"
53
+ :today-active-border-color="todayActiveBorderColor"
54
+ :active-color="activeColor"
55
+ :active-bg="activeBg"
56
+ :active-border-radius="activeBorderRadius"
57
+ :range-color="rangeColor"
58
+ :range-bg="rangeBg"
59
+ :start-text="startText"
60
+ :end-text="endText"
61
+ :week-view="weekView"
62
+ :show-back-today="showBackToday"
63
+ :marks="marks"
64
+ @change="handleChange"
65
+ />
66
+ </swiper-item>
67
+ </swiper>
68
+ <view
69
+ v-if="canChangeWeekView"
70
+ class="pi-justify-center pi-align-center pi-pd-bottom-12 pi-light-gray"
71
+ @tap="handleChangeWeekView"
72
+ >
73
+ <pi-icon
74
+ name="arrow-down_fill"
75
+ :custom-style="{ transform: `rotate(${weekView ? '0deg' : '180deg'})` }"
76
+ />
77
+ <text class="pi-fz-24 ">{{ weekView ? '展开' : '收起' }}</text>
78
+ </view>
79
+ </view>
80
+ </view>
81
+ </view>
82
+ </template>
83
+
84
+ <script>
85
+ import ValueSync from '../../mixin/value-sync'
86
+ import { getConfig } from '../../config'
87
+ import CalandarDays from './components/calendar-days'
88
+
89
+ const TAG = 'PiCalendarPanel'
90
+ const { calendarPanel } = getConfig()
91
+
92
+ export default {
93
+ name: 'PiCalendarPanel',
94
+ components: { CalandarDays },
95
+ mixins: [ValueSync],
96
+ props: {
97
+ // 自定义样式,对象形式
98
+ customStyle: {
99
+ type: Object,
100
+ // {}
101
+ default() {
102
+ return calendarPanel.customStyle
103
+ }
104
+ },
105
+ // 自定义样式类,字符串形式
106
+ customClass: {
107
+ type: String,
108
+ // ''
109
+ default() {
110
+ return calendarPanel.customClass
111
+ }
112
+ },
113
+ // 日历类型
114
+ type: {
115
+ // `'date'-单个日期`, `'range'-范围日期`
116
+ type: String,
117
+ // 'date'
118
+ default: calendarPanel.type,
119
+ validator: function(value) {
120
+ return ['date', 'range'].includes(value)
121
+ }
122
+ },
123
+ // 日期默认值,单选时候,传入Date(时间戳,时间字符串,Date类型),日历范围,传入Date[]
124
+ value: {
125
+ type: [Number, String, Date, Array]
126
+ // -
127
+ },
128
+ // 可切换的最小年份
129
+ minYear: {
130
+ type: [Number, String],
131
+ // 当前年份 - 80
132
+ default: calendarPanel.minYear
133
+ },
134
+ // 可切换的最大年份(默认当前年份)
135
+ maxYear: {
136
+ type: [Number, String],
137
+ // 当前年份 + 30
138
+ default: calendarPanel.maxYear
139
+ },
140
+ // 最小可选日期(不在范围内日期禁用不可选,默认'',不作限制)
141
+ minDate: {
142
+ type: [Number, String, Date],
143
+ // ''
144
+ default: calendarPanel.minDate
145
+ },
146
+ // 最大可选日期(不在范围内日期禁用不可选,默认'',不作限制)
147
+ maxDate: {
148
+ type: [Number, String, Date],
149
+ // ''
150
+ default: calendarPanel.maxDate
151
+ },
152
+ // 是否显示回到今日
153
+ showBackToday: {
154
+ type: Boolean,
155
+ // true
156
+ default: calendarPanel.showBackToday
157
+ },
158
+ // 今日日期激活边框颜色
159
+ todayActiveBorderColor: {
160
+ type: String,
161
+ // '#ff6a00'
162
+ default: calendarPanel.todayActiveBorderColor
163
+ },
164
+ // 选中|起始结束日期字体颜色
165
+ activeColor: {
166
+ type: String,
167
+ // '#ffffff'
168
+ default: calendarPanel.activeColor
169
+ },
170
+ // 选中|起始结束日期背景,默认
171
+ activeBg: {
172
+ type: String,
173
+ // '#ff6a00'
174
+ default: calendarPanel.activeBg
175
+ },
176
+ // 选中圆角效果
177
+ activeBorderRadius: {
178
+ type: [String, Number],
179
+ // '0 0 0 0'
180
+ default: calendarPanel.activeBorderRadius
181
+ },
182
+ // 范围内日期字体颜色默认
183
+ rangeColor: {
184
+ type: String,
185
+ // '#ff6a00'
186
+ default: calendarPanel.rangeColor
187
+ },
188
+ // 范围内日期背景色
189
+ rangeBg: {
190
+ type: String,
191
+ // 'rgba(254, 106, 0, 0.1)'
192
+ default: calendarPanel.rangeBg
193
+ },
194
+ // type=range时生效,起始日期自定义文案
195
+ startText: {
196
+ type: String,
197
+ // '开始'
198
+ default: calendarPanel.startText
199
+ },
200
+ // type=range时生效,结束日期自定义文案
201
+ endText: {
202
+ type: String,
203
+ // '结束'
204
+ default: calendarPanel.endText
205
+ },
206
+ // 已选择的时间格式化显示规则
207
+ dateFormat: {
208
+ type: String,
209
+ // 'YYYY-MM-DD'
210
+ default: calendarPanel.dateFormat
211
+ },
212
+ // 是否可切换周视图,默认(true)
213
+ canChangeWeekView: {
214
+ type: Boolean,
215
+ // true
216
+ default: calendarPanel.canChangeWeekView
217
+ },
218
+ // 是否默认显示周视图,默认(false)
219
+ defalutWeekView: {
220
+ type: Boolean,
221
+ // true
222
+ default: calendarPanel.defalutWeekView
223
+ },
224
+ // 日期标记,数组形式,默认([])
225
+ marks: {
226
+ type: Array,
227
+ // []
228
+ default: () => calendarPanel.marks
229
+ }
230
+ },
231
+ data() {
232
+ const now = this.$pi.date.parseDate()
233
+ return {
234
+ now: now, // 当前时间
235
+ year: now.year, // 年份
236
+ month: now.month, // 月份
237
+ week: 1, // 当前周
238
+ calendarValue: '',
239
+ currentTabIndex: 1, // 当前选中的tab索引
240
+ weekView: this.defalutWeekView // 是否显示周视图
241
+ }
242
+ },
243
+ computed: {
244
+ // 第一天
245
+ firstDay() {
246
+ const preMonthLastDay = this.getPreMonthLastDay
247
+ const firstDay = new Date(`${this.year}/${this.month}/01 00:00:00`).getDay()
248
+ return this.$pi.common.generateArray(preMonthLastDay - firstDay + 1, preMonthLastDay)
249
+ },
250
+ weekDayZh() {
251
+ return this.$pi.date.getWeekDayZh()
252
+ },
253
+ isMinYear() {
254
+ return this.year === parseInt(this.minYear, 10)
255
+ },
256
+ isMaxYear() {
257
+ return this.year === parseInt(this.maxYear, 10)
258
+ },
259
+ // 获取上个月最后一天
260
+ getPreMonthLastDay() {
261
+ let year = this.year
262
+ let month = this.month
263
+ if (month === 1) {
264
+ year = year - 1
265
+ month = 12
266
+ }
267
+ return new Date(year, month - 1, '0').getDate()
268
+ }
269
+ },
270
+ watch: {
271
+ value(newVal, oldVal) {
272
+ if (JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
273
+ this.init()
274
+ }
275
+ }
276
+ },
277
+ created() {
278
+ this.init()
279
+ },
280
+ methods: {
281
+ init() {
282
+ console.log(TAG, '组件初始化', this.value)
283
+ let initValue = this.value
284
+ const nowDate = this.$pi.date.parseDate(this.type === 'date' ? this.value : this.value[0])
285
+ if (this.type === 'range') {
286
+ initValue = initValue || []
287
+ if (this.value[1]) {
288
+ const endDate = this.$pi.date.parseDate(this.value[1])
289
+
290
+ this.year = endDate.year
291
+ this.month = endDate.month
292
+
293
+ initValue = [nowDate, endDate]
294
+ } else if (initValue.length === 1) {
295
+ initValue = [nowDate]
296
+
297
+ this.year = nowDate.year
298
+ this.month = nowDate.month
299
+ }
300
+ } else {
301
+ this.year = nowDate.year
302
+ this.month = nowDate.month
303
+ initValue = nowDate
304
+ }
305
+ this.value && this.handleChange(initValue)
306
+ if (this.canChangeWeekView) {
307
+ // 如果可以切换周视图,则初始化当前周
308
+ let targetDay = this.type === 'date' ? this.calendarValue : this.calendarValue[0]
309
+ if (!targetDay) {
310
+ targetDay = this.now
311
+ }
312
+ const startDate = targetDay.date + this.firstDay.length
313
+ this.week = Math.ceil(startDate / 7)
314
+ }
315
+ },
316
+
317
+ handleChangeWeek(change) {
318
+ const week = this.week + change
319
+ if (week > 6) {
320
+ // 当月最后一天剩余周
321
+ const lastDay = new Date(this.year, this.month, '0').getDate()
322
+ const lastDayIndex = lastDay + this.firstDay.length
323
+ const remainWeek = 6 - Math.floor(lastDayIndex / 7)
324
+ // 下一月
325
+ this.handleChangeMonth(1)
326
+ this.week = remainWeek + (lastDayIndex % 7 === 0 ? 0 : 1)
327
+ } else if (week < 1) {
328
+ // 记录上个月的最后一天
329
+ const preMonthLastDay = this.getPreMonthLastDay
330
+ // 切换到上一月
331
+ this.handleChangeMonth(-1)
332
+ const week = Math.floor((preMonthLastDay + this.firstDay.length) / 7)
333
+ this.week = week
334
+ } else {
335
+ this.week = week
336
+ }
337
+ },
338
+ handleChangeMonth(change) {
339
+ const month = this.month + change
340
+ if (month > 12 && !this.isMaxYear) {
341
+ // 下一年
342
+ this.year = this.year + 1
343
+ this.month = 1
344
+ } else if (month < 1 && !this.isMinYear) {
345
+ // 上一年
346
+ this.year = this.year - 1
347
+ this.month = 12
348
+ } else {
349
+ this.month = month
350
+ }
351
+ this.$emit('date-change', {
352
+ year: this.year,
353
+ month: this.month
354
+ })
355
+ },
356
+ handlePrevMonth() {
357
+ if (this.currentTabIndex === 0) {
358
+ this.currentTabIndex = 2
359
+ } else {
360
+ this.currentTabIndex--
361
+ }
362
+ this.handleChangeMonth(-1)
363
+ },
364
+ handleNextMonth() {
365
+ if (this.currentTabIndex === 2) {
366
+ this.currentTabIndex = 0
367
+ } else {
368
+ this.currentTabIndex++
369
+ }
370
+ this.handleChangeMonth(1)
371
+ },
372
+ handleChangeYear(change) {
373
+ if (change > 0 && this.isMaxYear) return
374
+ if (change < 0 && this.isMinYear) return
375
+ this.year = this.year + change
376
+ this.$emit('date-change', {
377
+ year: this.year,
378
+ month: this.month
379
+ })
380
+ },
381
+ handleBackToday() {
382
+ this.year = this.now.year
383
+ this.month = this.now.month
384
+ if (this.type === 'date') {
385
+ this.handleChange(this.now)
386
+ }
387
+ },
388
+ handleChange(calendarValue) {
389
+ this.calendarValue = calendarValue
390
+ this.val =
391
+ this.type === 'range'
392
+ ? this.calendarValue.map(cv =>
393
+ this.$pi.date.formatDate(new Date(cv.timestamp), this.dateFormat)
394
+ )
395
+ : this.$pi.date.formatDate(new Date(this.calendarValue.timestamp), this.dateFormat)
396
+ this.handleEmitChange()
397
+ },
398
+ handleTabChange(e) {
399
+ const { source, current } = e.detail
400
+ if (source !== 'touch') return
401
+ const isRightMove = [1, -2].includes(current - this.currentTabIndex)
402
+ if (this.weekView) {
403
+ this.handleChangeWeek(isRightMove ? 1 : -1)
404
+ } else {
405
+ this.handleChangeMonth(isRightMove ? 1 : -1)
406
+ }
407
+ this.currentTabIndex = current
408
+ },
409
+ getCalandarMonth(tab) {
410
+ if (this.weekView) {
411
+ return this.month
412
+ }
413
+ const changeMaps = [
414
+ [0, 1, -1],
415
+ [-1, 0, 0],
416
+ [1, 0, 0]
417
+ ]
418
+ const change = changeMaps[tab - 1][this.currentTabIndex]
419
+ return this.month + change
420
+ },
421
+ getCalandaWeek(tab) {
422
+ const changeMaps = [
423
+ [0, -1, 1],
424
+ [1, 0, -1],
425
+ [-1, 1, 0]
426
+ ]
427
+ const change = changeMaps[tab - 1][this.currentTabIndex]
428
+ return this.week + change
429
+ },
430
+ handleChangeWeekView() {
431
+ this.weekView = !this.weekView
432
+ }
433
+ }
434
+ }
435
+ </script>
436
+
437
+ <style lang="scss" scoped>
438
+ .pi-calendar-panel {
439
+ width: 100%;
440
+ .date-item {
441
+ position: relative;
442
+ z-index: 2;
443
+ width: calc(100% / 7);
444
+ overflow: hidden;
445
+ }
446
+ .back-today {
447
+ padding: 12rpx 24rpx;
448
+ overflow: hidden;
449
+ font-size: 20rpx;
450
+ color: #ffffff;
451
+ white-space: nowrap;
452
+ background: $pi-primary-color;
453
+ border-radius: 50rpx 0 0 50rpx;
454
+ }
455
+ .pi-square {
456
+ padding-bottom: 86%;
457
+ &.can-change-week {
458
+ padding-bottom: 90%;
459
+ }
460
+ }
461
+
462
+ .days-wrap {
463
+ transition: all $pi-animation-duration $pi-animation-timing-function;
464
+ &.week-view {
465
+ padding-bottom: 24%;
466
+ }
467
+ }
468
+ // 图标动态效果
469
+ ::v-deep .icon-wrap view {
470
+ transition: all $pi-animation-duration $pi-animation-timing-function;
471
+ }
472
+ }
473
+ </style>