sadais-piui 1.2.7-beta4 → 1.2.7-beta41

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 (36) hide show
  1. package/components/pi-calendar/index.vue +1 -0
  2. package/components/pi-calendar-panel/components/calendar-days/index.vue +410 -0
  3. package/components/pi-calendar-panel/index.vue +201 -163
  4. package/components/pi-cascader/index.vue +493 -0
  5. package/components/pi-checkbox/index.vue +2 -2
  6. package/components/pi-checkbox-group/index.vue +2 -0
  7. package/components/pi-circle-progress/index.vue +65 -9
  8. package/components/pi-collapse/index.vue +124 -0
  9. package/components/pi-collapse-item/index.vue +352 -0
  10. package/components/pi-date-picker/index.vue +20 -6
  11. package/components/pi-dropdown/components/dropdown-tab.vue +33 -24
  12. package/components/pi-dropdown/index.vue +53 -21
  13. package/components/pi-dropdown-item/index.vue +73 -54
  14. package/components/pi-form-item/index.vue +7 -2
  15. package/components/pi-input/index.vue +1 -1
  16. package/components/pi-radio/index.vue +2 -2
  17. package/components/pi-radio-group/index.vue +2 -0
  18. package/components/pi-search/index.vue +116 -80
  19. package/components/pi-select/index.vue +14 -4
  20. package/components/pi-steps/index.vue +115 -36
  21. package/components/pi-tabs/index.vue +11 -4
  22. package/components/pi-tag/index.vue +488 -0
  23. package/components/pi-upload-img/index.vue +21 -5
  24. package/components/pi-webview/index.vue +9 -3
  25. package/config/calendarPanel.js +4 -1
  26. package/config/cascader.js +21 -0
  27. package/config/circleProgress.js +7 -8
  28. package/config/collapse.js +7 -0
  29. package/config/collapseItem.js +11 -0
  30. package/config/datePicker.js +1 -0
  31. package/config/dropdown.js +4 -1
  32. package/config/select.js +1 -0
  33. package/config/steps.js +1 -1
  34. package/config/tag.js +21 -0
  35. package/config/uploadImg.js +3 -7
  36. package/package.json +1 -1
@@ -9,14 +9,13 @@
9
9
  <view class="pi-icon-right pi-pd-14" @tap="handleChangeYear(1)" />
10
10
  </view>
11
11
  <view class="pi-align-center">
12
- <view class="pi-icon-back pi-pd-14" @tap="handleChangeMonth(-1)" />
12
+ <view class="pi-icon-back pi-pd-14" @tap="handlePrevMonth()" />
13
13
  <view class="pi-pd-lr-8 pi-text-nowrap">{{ month }}月</view>
14
- <view class="pi-icon-right pi-pd-14" @tap="handleChangeMonth(1)" />
14
+ <view class="pi-icon-right pi-pd-14" @tap="handleNextMonth()" />
15
15
  </view>
16
16
  </view>
17
17
  <view v-if="showBackToday" class="back-today" @tap="handleBackToday">回到今日</view>
18
18
  </view>
19
-
20
19
  <!-- 星期 -->
21
20
  <view
22
21
  class="pi-align-center pi-pd-24"
@@ -30,41 +29,52 @@
30
29
  {{ week }}
31
30
  </view>
32
31
  </view>
33
- <view class="pi-square">
32
+ <view
33
+ class="pi-square days-wrap"
34
+ :class="{ 'week-view': weekView, 'can-change-week': canChangeWeekView }"
35
+ >
34
36
  <!-- 固定日期面板正方形,避免高度变化造成界面抖动 -->
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
- z-index: 1;
62
- font-size: 300rpx;
63
- pointer-events: none;
64
- opacity: 0.1;"
65
- >
66
- {{ month }}
67
- </view>
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>
68
78
  </view>
69
79
  </view>
70
80
  </view>
@@ -74,12 +84,14 @@
74
84
  <script>
75
85
  import ValueSync from '../../mixin/value-sync'
76
86
  import { getConfig } from '../../config'
87
+ import CalandarDays from './components/calendar-days'
77
88
 
78
89
  const TAG = 'PiCalendarPanel'
79
90
  const { calendarPanel } = getConfig()
80
91
 
81
92
  export default {
82
93
  name: 'PiCalendarPanel',
94
+ components: { CalandarDays },
83
95
  mixins: [ValueSync],
84
96
  props: {
85
97
  // 自定义样式,对象形式
@@ -196,33 +208,47 @@ export default {
196
208
  type: String,
197
209
  // 'YYYY-MM-DD'
198
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
199
229
  }
200
230
  },
201
231
  data() {
202
232
  const now = this.$pi.date.parseDate()
203
233
  return {
204
234
  now: now, // 当前时间
205
- year: '', // 年份
206
- month: '', // 月份
207
- calendarValue: ''
235
+ year: now.year, // 年份
236
+ month: now.month, // 月份
237
+ week: 1, // 当前周
238
+ calendarValue: '',
239
+ currentTabIndex: 1, // 当前选中的tab索引
240
+ weekView: this.defalutWeekView // 是否显示周视图
208
241
  }
209
242
  },
210
243
  computed: {
211
- getActiveBorderRadius() {
212
- return this.$pi.common.addUnit(this.activeBorderRadius)
213
- },
214
- weekDayZh() {
215
- return this.$pi.date.getWeekDayZh()
216
- },
217
244
  // 第一天
218
245
  firstDay() {
219
- return new Date(`${this.year}/${this.month}/01 00:00:00`).getDay()
220
- },
221
- getMinDate() {
222
- return this.minDate ? this.$pi.date.parseDate(this.minDate) : ''
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)
223
249
  },
224
- getMaxDate() {
225
- return this.maxDate ? this.$pi.date.parseDate(this.maxDate) : ''
250
+ weekDayZh() {
251
+ return this.$pi.date.getWeekDayZh()
226
252
  },
227
253
  isMinYear() {
228
254
  return this.year === parseInt(this.minYear, 10)
@@ -230,74 +256,15 @@ export default {
230
256
  isMaxYear() {
231
257
  return this.year === parseInt(this.maxYear, 10)
232
258
  },
233
- // 总天数
234
- days() {
235
- const days = []
236
- const monthDays = new Date(this.year, this.month, 0).getDate()
237
- for (let i = 1; i <= monthDays; i++) {
238
- const day = {
239
- key: 'pi-calander-day-item-' + i,
240
- index: i,
241
- ...this.$pi.date.parseDate(`${this.year}/${this.month}/${i}`)
242
- }
243
- const isDisabled = this.isDisabled(day)
244
- // 禁用
245
- if (isDisabled) {
246
- day.disabledStyle = {
247
- opacity: '0.3',
248
- cursor: 'not-allowed'
249
- }
250
- }
251
- // 单选选中样式
252
- if (this.type === 'date' && this.isSameDay(this.calendarValue, day)) {
253
- const activeStyle = {
254
- color: this.activeColor,
255
- borderRadius: this.getActiveBorderRadius
256
- }
257
- if (this.activeBg) activeStyle.background = this.activeBg
258
- day.activeStyle = activeStyle
259
- }
260
- // 范围选中样式
261
- if (this.type === 'range') {
262
- const start = this.calendarValue[0]
263
- const end = this.calendarValue[1]
264
- const isBegin = this.isSameDay(start, day)
265
- const isEnd = this.isSameDay(end, day)
266
- const inRange =
267
- start && end && day.timestamp > start.timestamp && day.timestamp < end.timestamp
268
- const activeStyle = {}
269
- // 处理中间范围的样式
270
- if (inRange) {
271
- activeStyle.color = this.rangeColor
272
- activeStyle.background = this.rangeBg
273
- }
274
- // 处理两端
275
- if (isBegin || isEnd) {
276
- activeStyle.color = this.activeColor
277
- activeStyle.borderRadius = isBegin
278
- ? `${this.getActiveBorderRadius} 0 0 ${this.getActiveBorderRadius}`
279
- : `0 ${this.getActiveBorderRadius} ${this.getActiveBorderRadius} 0`
280
- if (this.activeBg) activeStyle.background = this.activeBg
281
- }
282
- day.activeStyle = activeStyle
283
- // type 为 range 开始和结束的提示
284
- if (isBegin) day.tip = this.startText
285
- if (isEnd) day.tip = this.endText
286
- if (isBegin && isEnd) {
287
- day.tip = this.startText + '-' + this.endText
288
- }
289
- }
290
- // 当天样式
291
- if (this.showBackToday && this.isSameDay(this.now, day)) {
292
- day.nowStyle = {
293
- color: this.todayActiveBorderColor,
294
- border: '1px solid ' + this.todayActiveBorderColor,
295
- borderRadius: this.getActiveBorderRadius
296
- }
297
- }
298
- days.push(day)
259
+ // 获取上个月最后一天
260
+ getPreMonthLastDay() {
261
+ let year = this.year
262
+ let month = this.month
263
+ if (month === 1) {
264
+ year = year - 1
265
+ month = 12
299
266
  }
300
- return days
267
+ return new Date(year, month - 1, '0').getDate()
301
268
  }
302
269
  },
303
270
  watch: {
@@ -311,65 +278,61 @@ export default {
311
278
  this.init()
312
279
  },
313
280
  methods: {
314
- valid() {
315
- if (this.type === 'date') return true
316
- if (this.type === 'range' && this.$pi.lang.isArray(this.value) && this.value.length === 2)
317
- return true
318
- return false
319
- },
320
281
  init() {
321
282
  console.log(TAG, '组件初始化', this.value)
322
- if (!this.valid()) return
323
283
  let initValue = this.value
324
284
  const nowDate = this.$pi.date.parseDate(this.type === 'date' ? this.value : this.value[0])
325
285
  if (this.type === 'range') {
326
- const endDate = this.$pi.date.parseDate(this.value[1])
327
- if (this.year !== endDate.year && this.month !== endDate.month) {
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
+
328
297
  this.year = nowDate.year
329
298
  this.month = nowDate.month
330
299
  }
331
- initValue = [nowDate, endDate]
332
300
  } else {
333
301
  this.year = nowDate.year
334
302
  this.month = nowDate.month
335
303
  initValue = nowDate
336
304
  }
337
305
  this.value && this.handleChange(initValue)
338
- },
339
- isSameDay(day1, day2) {
340
- return (
341
- day1 &&
342
- day2 &&
343
- day1.year === day2.year &&
344
- day1.month === day2.month &&
345
- day1.date === day2.date
346
- )
347
- },
348
- isDisabled(day) {
349
- const isDisabled =
350
- (this.getMinDate && day.timestamp < this.getMinDate.timestamp) ||
351
- (this.getMaxDate && day.timestamp > this.getMaxDate.timestamp)
352
- return isDisabled
353
- },
354
- handleSelectDate(date) {
355
- const isDisabled = this.isDisabled(date)
356
- if (isDisabled) return
357
- if (this.type === 'date') {
358
- // 单选方式
359
- this.handleChange(date)
360
- return
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)
361
314
  }
362
- // 处理范围选择方式
363
- if (this.calendarValue.length === 2) {
364
- // 如果选了两项,则重新开始选择范围
365
- this.handleChange([date])
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
366
334
  } else {
367
- // 和第一项判断大小,小的放前面
368
- if (date.timestamp > this.calendarValue[0].timestamp) {
369
- this.handleChange([this.calendarValue[0], date])
370
- } else {
371
- this.handleChange([date, this.calendarValue[0]])
372
- }
335
+ this.week = week
373
336
  }
374
337
  },
375
338
  handleChangeMonth(change) {
@@ -385,11 +348,35 @@ export default {
385
348
  } else {
386
349
  this.month = month
387
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)
388
371
  },
389
372
  handleChangeYear(change) {
390
373
  if (change > 0 && this.isMaxYear) return
391
374
  if (change < 0 && this.isMinYear) return
392
375
  this.year = this.year + change
376
+ this.$emit('date-change', {
377
+ year: this.year,
378
+ month: this.month
379
+ })
393
380
  },
394
381
  handleBackToday() {
395
382
  this.year = this.now.year
@@ -407,6 +394,41 @@ export default {
407
394
  )
408
395
  : this.$pi.date.formatDate(new Date(this.calendarValue.timestamp), this.dateFormat)
409
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
410
432
  }
411
433
  }
412
434
  }
@@ -419,7 +441,6 @@ export default {
419
441
  position: relative;
420
442
  z-index: 2;
421
443
  width: calc(100% / 7);
422
- margin-bottom: 12rpx;
423
444
  overflow: hidden;
424
445
  }
425
446
  .back-today {
@@ -431,5 +452,22 @@ export default {
431
452
  background: $pi-primary-color;
432
453
  border-radius: 50rpx 0 0 50rpx;
433
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
+ }
434
472
  }
435
473
  </style>