sadais-piui 1.2.7-beta3 → 1.2.7-beta30

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.
@@ -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,51 @@
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
+ @change="handleChange"
64
+ />
65
+ </swiper-item>
66
+ </swiper>
67
+ <view
68
+ v-if="canChangeWeekView"
69
+ class="pi-justify-center pi-align-center pi-pd-bottom-12 pi-light-gray"
70
+ @tap="handleChangeWeekView"
71
+ >
72
+ <pi-icon
73
+ name="arrow-down_fill"
74
+ :custom-style="{ transform: `rotate(${weekView ? '0deg' : '180deg'})` }"
75
+ />
76
+ <text class="pi-fz-24 ">{{ weekView ? '展开' : '收起' }}</text>
68
77
  </view>
69
78
  </view>
70
79
  </view>
@@ -74,12 +83,14 @@
74
83
  <script>
75
84
  import ValueSync from '../../mixin/value-sync'
76
85
  import { getConfig } from '../../config'
86
+ import CalandarDays from './components/calendar-days'
77
87
 
78
88
  const TAG = 'PiCalendarPanel'
79
89
  const { calendarPanel } = getConfig()
80
90
 
81
91
  export default {
82
92
  name: 'PiCalendarPanel',
93
+ components: { CalandarDays },
83
94
  mixins: [ValueSync],
84
95
  props: {
85
96
  // 自定义样式,对象形式
@@ -196,6 +207,18 @@ export default {
196
207
  type: String,
197
208
  // 'YYYY-MM-DD'
198
209
  default: calendarPanel.dateFormat
210
+ },
211
+ // 是否可切换周视图,默认(true)
212
+ canChangeWeekView: {
213
+ type: Boolean,
214
+ // true
215
+ default: calendarPanel.canChangeWeekView
216
+ },
217
+ // 是否默认显示周视图,默认(false)
218
+ defalutWeekView: {
219
+ type: Boolean,
220
+ // true
221
+ default: calendarPanel.defalutWeekView
199
222
  }
200
223
  },
201
224
  data() {
@@ -204,25 +227,21 @@ export default {
204
227
  now: now, // 当前时间
205
228
  year: '', // 年份
206
229
  month: '', // 月份
207
- calendarValue: ''
230
+ week: 1, // 当前周
231
+ calendarValue: '',
232
+ currentTabIndex: 1, // 当前选中的tab索引
233
+ weekView: this.defalutWeekView // 是否显示周视图
208
234
  }
209
235
  },
210
236
  computed: {
211
- getActiveBorderRadius() {
212
- return this.$pi.common.addUnit(this.activeBorderRadius)
213
- },
214
- weekDayZh() {
215
- return this.$pi.date.getWeekDayZh()
216
- },
217
237
  // 第一天
218
238
  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) : ''
239
+ const preMonthLastDay = this.getPreMonthLastDay
240
+ const firstDay = new Date(`${this.year}/${this.month}/01 00:00:00`).getDay()
241
+ return this.$pi.common.generateArray(preMonthLastDay - firstDay + 1, preMonthLastDay)
223
242
  },
224
- getMaxDate() {
225
- return this.maxDate ? this.$pi.date.parseDate(this.maxDate) : ''
243
+ weekDayZh() {
244
+ return this.$pi.date.getWeekDayZh()
226
245
  },
227
246
  isMinYear() {
228
247
  return this.year === parseInt(this.minYear, 10)
@@ -230,74 +249,15 @@ export default {
230
249
  isMaxYear() {
231
250
  return this.year === parseInt(this.maxYear, 10)
232
251
  },
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)
252
+ // 获取上个月最后一天
253
+ getPreMonthLastDay() {
254
+ let year = this.year
255
+ let month = this.month
256
+ if (month === 1) {
257
+ year = year - 1
258
+ month = 12
299
259
  }
300
- return days
260
+ return new Date(year, month - 1, '0').getDate()
301
261
  }
302
262
  },
303
263
  watch: {
@@ -335,41 +295,36 @@ export default {
335
295
  initValue = nowDate
336
296
  }
337
297
  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
298
+ if (this.canChangeWeekView) {
299
+ // 如果可以切换周视图,则初始化当前周
300
+ let targetDay = this.type === 'date' ? this.calendarValue : this.calendarValue[0]
301
+ if (!targetDay) {
302
+ targetDay = this.now
303
+ }
304
+ const startDate = targetDay.date + this.firstDay.length
305
+ this.week = Math.ceil(startDate / 7)
361
306
  }
362
- // 处理范围选择方式
363
- if (this.calendarValue.length === 2) {
364
- // 如果选了两项,则重新开始选择范围
365
- this.handleChange([date])
307
+ },
308
+
309
+ handleChangeWeek(change) {
310
+ const week = this.week + change
311
+ if (week > 6) {
312
+ // 当月最后一天剩余周
313
+ const lastDay = new Date(this.year, this.month, '0').getDate()
314
+ const lastDayIndex = lastDay + this.firstDay.length
315
+ const remainWeek = 6 - Math.floor(lastDayIndex / 7)
316
+ // 下一月
317
+ this.handleChangeMonth(1)
318
+ this.week = remainWeek + (lastDayIndex % 7 === 0 ? 0 : 1)
319
+ } else if (week < 1) {
320
+ // 记录上个月的最后一天
321
+ const preMonthLastDay = this.getPreMonthLastDay
322
+ // 切换到上一月
323
+ this.handleChangeMonth(-1)
324
+ const week = Math.floor((preMonthLastDay + this.firstDay.length) / 7)
325
+ this.week = week
366
326
  } 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
- }
327
+ this.week = week
373
328
  }
374
329
  },
375
330
  handleChangeMonth(change) {
@@ -386,6 +341,22 @@ export default {
386
341
  this.month = month
387
342
  }
388
343
  },
344
+ handlePrevMonth() {
345
+ if (this.currentTabIndex === 0) {
346
+ this.currentTabIndex = 2
347
+ } else {
348
+ this.currentTabIndex--
349
+ }
350
+ this.handleChangeMonth(-1)
351
+ },
352
+ handleNextMonth() {
353
+ if (this.currentTabIndex === 2) {
354
+ this.currentTabIndex = 0
355
+ } else {
356
+ this.currentTabIndex++
357
+ }
358
+ this.handleChangeMonth(1)
359
+ },
389
360
  handleChangeYear(change) {
390
361
  if (change > 0 && this.isMaxYear) return
391
362
  if (change < 0 && this.isMinYear) return
@@ -407,6 +378,41 @@ export default {
407
378
  )
408
379
  : this.$pi.date.formatDate(new Date(this.calendarValue.timestamp), this.dateFormat)
409
380
  this.handleEmitChange()
381
+ },
382
+ handleTabChange(e) {
383
+ const { source, current } = e.detail
384
+ if (source !== 'touch') return
385
+ const isRightMove = [1, -2].includes(current - this.currentTabIndex)
386
+ if (this.weekView) {
387
+ this.handleChangeWeek(isRightMove ? 1 : -1)
388
+ } else {
389
+ this.handleChangeMonth(isRightMove ? 1 : -1)
390
+ }
391
+ this.currentTabIndex = current
392
+ },
393
+ getCalandarMonth(tab) {
394
+ if (this.weekView) {
395
+ return this.month
396
+ }
397
+ const changeMaps = [
398
+ [0, 1, -1],
399
+ [-1, 0, 0],
400
+ [1, 0, 0]
401
+ ]
402
+ const change = changeMaps[tab - 1][this.currentTabIndex]
403
+ return this.month + change
404
+ },
405
+ getCalandaWeek(tab) {
406
+ const changeMaps = [
407
+ [0, -1, 1],
408
+ [1, 0, -1],
409
+ [-1, 1, 0]
410
+ ]
411
+ const change = changeMaps[tab - 1][this.currentTabIndex]
412
+ return this.week + change
413
+ },
414
+ handleChangeWeekView() {
415
+ this.weekView = !this.weekView
410
416
  }
411
417
  }
412
418
  }
@@ -419,7 +425,6 @@ export default {
419
425
  position: relative;
420
426
  z-index: 2;
421
427
  width: calc(100% / 7);
422
- margin-bottom: 12rpx;
423
428
  overflow: hidden;
424
429
  }
425
430
  .back-today {
@@ -431,5 +436,22 @@ export default {
431
436
  background: $pi-primary-color;
432
437
  border-radius: 50rpx 0 0 50rpx;
433
438
  }
439
+ .pi-square {
440
+ padding-bottom: 86%;
441
+ &.can-change-week {
442
+ padding-bottom: 90%;
443
+ }
444
+ }
445
+
446
+ .days-wrap {
447
+ transition: all $pi-animation-duration $pi-animation-timing-function;
448
+ &.week-view {
449
+ padding-bottom: 24%;
450
+ }
451
+ }
452
+ // 图标动态效果
453
+ ::v-deep .icon-wrap view {
454
+ transition: all $pi-animation-duration $pi-animation-timing-function;
455
+ }
434
456
  }
435
457
  </style>
@@ -3,13 +3,12 @@
3
3
  class="pi-check-wrap"
4
4
  :style="[customStyle]"
5
5
  :class="[getShape, getActiveMode, { disabled: getDisable }, { active: val }, customClass]"
6
- @tap="handleCheckboxToggle(true)"
7
6
  >
8
7
  <view
9
8
  v-if="getShape !== 'text'"
10
9
  class="check-icon"
11
10
  :style="[checkStyle]"
12
- @tap.stop="handleCheckboxToggle(false)"
11
+ @tap="handleCheckboxToggle(false)"
13
12
  >
14
13
  <view v-if="getShape === 'dot'" class="dot" :style="[dotStyle]" />
15
14
  <pi-icon v-else name="blod-check" :size="getIconSize" />
@@ -19,6 +18,7 @@
19
18
  class="check-label"
20
19
  :class="{ text: getShape === 'text' }"
21
20
  :style="[textStyle]"
21
+ @tap="handleCheckboxToggle(true)"
22
22
  >
23
23
  <!-- checkbox 内容 -->
24
24
  <slot />
@@ -13,6 +13,7 @@
13
13
  </template>
14
14
 
15
15
  <script>
16
+ import Emitter from '../../mixin/emitter'
16
17
  import ValueSync from '../../mixin/value-sync'
17
18
  import { parentInit } from '../../mixin/props-sync'
18
19
  import { getConfig } from '../../config'
@@ -24,6 +25,7 @@ export default {
24
25
  name: 'PiCheckboxGroup',
25
26
  // 混入自定义样式customStyle和customClass
26
27
  mixins: [
28
+ Emitter,
27
29
  ValueSync,
28
30
  parentInit([
29
31
  'value',
@@ -184,6 +186,8 @@ export default {
184
186
  })
185
187
  this.val = vals
186
188
  this.handleEmitChange()
189
+ this.dispatch('PiForm', 'form-change', this.val)
190
+ this.dispatch('PiFormItem', 'form-change', this.val)
187
191
  }
188
192
  }
189
193
  }
@@ -96,14 +96,24 @@ export default {
96
96
  text: {
97
97
  type: String,
98
98
  default: circleProgress.text
99
+ },
100
+ linearGradient: {
101
+ type: Object,
102
+ default() {
103
+ return circleProgress.linearGradient
104
+ }
99
105
  }
100
106
  },
101
107
  data() {
102
108
  return {
109
+ // #ifdef MP-WEIXIN
103
110
  elBgId: 'pCircleProgressBgId', // 微信小程序中不能使用this.$pi形式动态生成id值,否则会报错
104
111
  elId: 'pCircleProgressElId',
112
+ // #endif
113
+ // #ifndef MP-WEIXIN
105
114
  elBgId: this.$pi.guid(), // 支付宝等小程序 动态生产ID
106
115
  elId: this.$pi.guid(),
116
+ // #endif
107
117
  progressContext: null,
108
118
  // 开始的角度
109
119
  widthPx: uni.upx2px(this.width), // 转成px后的整个组件的背景宽度
@@ -170,25 +180,50 @@ export default {
170
180
  ctx = uni.createCanvasContext(this.elId, this)
171
181
  this.progressContext = ctx
172
182
  }
183
+ let radius = this.widthPx / 2
173
184
  // 表示进度的两端为圆形
174
185
  ctx.setLineCap('round')
175
186
  // 设置线条的宽度和颜色
176
187
  ctx.setLineWidth(this.borderWidthPx)
177
- ctx.setStrokeStyle(this.circleColor)
178
- // 将总过渡时间除以100,得出每修改百分之一进度所需的时间
179
- let time = Math.floor(this.duration / 100)
180
- // 结束角的计算依据为:将2π分为100份,乘以当前的进度值,得出终止点的弧度值,加起始角,为整个圆从默认的
181
- // 3点钟方向开始画图,转为更好理解的12点钟方向开始作图,这需要起始角和终止角同时加上this.startAngle值
182
- let endAngle = ((2 * Math.PI) / 100) * progress + this.startAngle
188
+ if (
189
+ this.linearGradient &&
190
+ this.linearGradient.show &&
191
+ this.linearGradient.colorStop.length >= 2
192
+ ) {
193
+ // this.imageData.slice(pos * 4, pos * 4 + 4);
194
+ let colorData = this.createColorData()
195
+ for (let i = 0; i < progress; i++) {
196
+ const index = Math.round((i * 255) / progress)
197
+ const color = colorData.slice(index * 4, index * 4 + 4)
198
+ ctx.beginPath()
199
+
200
+ ctx.setStrokeStyle(`rgba(${color[0]},${color[1]},${color[2]},${color[3] / 255})`)
201
+ ctx.globalAlpha = color[3] / 255
202
+ let endAngle = ((2 * Math.PI) / 100) * (i + 1) + this.startAngle
203
+ let startAngle = this.startAngle + ((2 * Math.PI) / 100) * i
204
+ ctx.arc(radius, radius, radius - this.borderWidthPx, startAngle, endAngle, false)
205
+ ctx.stroke()
206
+ }
207
+ } else {
208
+ ctx.setStrokeStyle(this.circleColor)
209
+ // 结束角的计算依据为:将2π分为100份,乘以当前的进度值,得出终止点的弧度值,加起始角,为整个圆从默认的
210
+ // 3点钟方向开始画图,转为更好理解的12点钟方向开始作图,这需要起始角和终止角同时加上this.startAngle值
211
+ let endAngle = ((2 * Math.PI) / 100) * progress + this.startAngle
212
+ ctx.beginPath()
213
+ // 半径为整个canvas宽度的一半
214
+ ctx.arc(radius, radius, radius - this.borderWidthPx, this.startAngle, endAngle, false)
215
+ ctx.stroke()
216
+ }
183
217
  ctx.beginPath()
184
- // 半径为整个canvas宽度的一半
185
- let radius = this.widthPx / 2
186
- ctx.arc(radius, radius, radius - this.borderWidthPx, this.startAngle, endAngle, false)
187
218
  ctx.textAlign = 'center'
219
+ ctx.textBaseline = 'middle'
188
220
  ctx.font = this.fontSize + ' Arial'
189
221
  ctx.fillText(this.text, radius, radius)
190
222
  ctx.stroke()
191
223
  ctx.draw()
224
+
225
+ // 将总过渡时间除以100,得出每修改百分之一进度所需的时间
226
+ let time = Math.floor(this.duration / 100)
192
227
  // 如果变更后新值大于旧值,意味着增大了百分比
193
228
  if (this.newPercent > this.oldPercent) {
194
229
  // 每次递增百分之一
@@ -204,6 +239,27 @@ export default {
204
239
  // 定时器,每次操作间隔为time值,为了让进度条有动画效果
205
240
  this.drawCircleByProgress(progress)
206
241
  }, time)
242
+ },
243
+ createColorData() {
244
+ let canvas
245
+ let ctx
246
+ // #ifndef MP-WEIXIN
247
+ canvas = document.createElement('canvas')
248
+ canvas.width = 256
249
+ canvas.height = 1
250
+ ctx = canvas.getContext('2d')
251
+ // #endif
252
+ // #ifdef MP-WEIXIN
253
+ canvas = uni.createOffscreenCanvas({ type: '2d', width: 256, height: 1 })
254
+ ctx = canvas.getContext('2d')
255
+ // #endif
256
+ const linearGradient = ctx.createLinearGradient(0, 0, 256, 1)
257
+ this.linearGradient.colorStop.forEach(color => {
258
+ linearGradient.addColorStop(color.percent, color.value)
259
+ })
260
+ ctx.fillStyle = linearGradient
261
+ ctx.fillRect(0, 0, 256, 1)
262
+ return ctx.getImageData(0, 0, 256, 1).data
207
263
  }
208
264
  }
209
265
  }