sadais-piui 1.2.7-beta7 → 1.2.7-beta8

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.
@@ -0,0 +1,371 @@
1
+ <!--
2
+ * @Author: zhangzhenfei
3
+ * @Date: 2022-06-28 16:53:54
4
+ * @LastEditTime: 2022-07-01 10:01:43
5
+ * @LastEditors: zhangzhenfei
6
+ * @Description: 日历日期数据
7
+ * @FilePath: /hfmp-checkin-front/Users/feilin/workspace/piui/piui-awesome/src/piui/components/pi-calendar-panel/components/calendar-days/index.vue
8
+ -->
9
+
10
+ <template>
11
+ <view class="pi-rela pi-align-center pi-flex-wrap pi-pd-24">
12
+ <view
13
+ v-for="day in days"
14
+ :key="day.key"
15
+ class="date-item"
16
+ style="cursor: pointer;"
17
+ :class="[{ 'pi-disabled': day.disabled || day.type === 'disabled' }, { range: day.range }]"
18
+ @tap.stop="handleSelectDate(day)"
19
+ >
20
+ <view class="pi-square">
21
+ <view class="pi-rela date-item-inner">
22
+ <view
23
+ class="pi-w-100P pi-h-100P pi-flex-column-center pi-lh-28"
24
+ :style="[day.rangeStyle, day.nowStyle, day.activeStyle]"
25
+ >
26
+ <text>{{ day.date }}</text>
27
+ <text v-if="day.tip" class=" pi-text-nowrap pi-fz-18 pi-mg-top-6">
28
+ {{ day.tip }}
29
+ </text>
30
+ </view>
31
+ </view>
32
+ </view>
33
+ </view>
34
+ <!-- 日历蒙层 -->
35
+ <view
36
+ class="pi-abso-center pi-fw-500 pi-light-gray pi-text-nowrap"
37
+ style="
38
+ z-index: -1;
39
+ pointer-events: none;
40
+ opacity: 0.15;"
41
+ :style="[
42
+ { fontSize: weekView ? '32rpx' : '300rpx' },
43
+ { marginTop: weekView ? '30rpx' : '0' }
44
+ ]"
45
+ >
46
+ {{ getBgTip }}
47
+ </view>
48
+ </view>
49
+ </template>
50
+
51
+ <script>
52
+ import { getConfig } from '../../../../config'
53
+ const { calendarPanel } = getConfig()
54
+
55
+ export default {
56
+ name: 'PiCalendarDays',
57
+ props: {
58
+ calendarValue: {
59
+ type: [String, Object, Array],
60
+ default: ''
61
+ },
62
+ year: {
63
+ type: [String, Number],
64
+ default: ''
65
+ },
66
+ month: {
67
+ type: [String, Number],
68
+ default: ''
69
+ },
70
+ // 当前展示周
71
+ week: {
72
+ type: Number,
73
+ default: 0
74
+ },
75
+ // 日历类型
76
+ type: {
77
+ // `'date'-单个日期`, `'range'-范围日期`
78
+ type: String,
79
+ // 'date'
80
+ default: calendarPanel.type,
81
+ validator: function(value) {
82
+ return ['date', 'range'].includes(value)
83
+ }
84
+ },
85
+ // 最小可选日期(不在范围内日期禁用不可选,默认'',不作限制)
86
+ minDate: {
87
+ type: [Number, String, Date],
88
+ // ''
89
+ default: calendarPanel.minDate
90
+ },
91
+ // 最大可选日期(不在范围内日期禁用不可选,默认'',不作限制)
92
+ maxDate: {
93
+ type: [Number, String, Date],
94
+ // ''
95
+ default: calendarPanel.maxDate
96
+ },
97
+ // 是否显示回到今日
98
+ showBackToday: {
99
+ type: Boolean,
100
+ // true
101
+ default: calendarPanel.showBackToday
102
+ },
103
+ // 今日日期激活边框颜色
104
+ todayActiveBorderColor: {
105
+ type: String,
106
+ // '#ff6a00'
107
+ default: calendarPanel.todayActiveBorderColor
108
+ },
109
+ // 选中|起始结束日期字体颜色
110
+ activeColor: {
111
+ type: String,
112
+ // '#ffffff'
113
+ default: calendarPanel.activeColor
114
+ },
115
+ // 选中|起始结束日期背景,默认
116
+ activeBg: {
117
+ type: String,
118
+ // '#ff6a00'
119
+ default: calendarPanel.activeBg
120
+ },
121
+ // 选中圆角效果
122
+ activeBorderRadius: {
123
+ type: [String, Number],
124
+ // '0 0 0 0'
125
+ default: calendarPanel.activeBorderRadius
126
+ },
127
+ // 范围内日期字体颜色默认
128
+ rangeColor: {
129
+ type: String,
130
+ // '#ff6a00'
131
+ default: calendarPanel.rangeColor
132
+ },
133
+ // 范围内日期背景色
134
+ rangeBg: {
135
+ type: String,
136
+ // 'rgba(254, 106, 0, 0.1)'
137
+ default: calendarPanel.rangeBg
138
+ },
139
+ // type=range时生效,起始日期自定义文案
140
+ startText: {
141
+ type: String,
142
+ // '开始'
143
+ default: calendarPanel.startText
144
+ },
145
+ // type=range时生效,结束日期自定义文案
146
+ endText: {
147
+ type: String,
148
+ // '结束'
149
+ default: calendarPanel.endText
150
+ },
151
+ weekView: {
152
+ type: Boolean,
153
+ // '是否显示周视图'
154
+ default: calendarPanel.defalutWeekView
155
+ }
156
+ },
157
+ data() {
158
+ const now = this.$pi.date.parseDate()
159
+ return {
160
+ now: now // 当前时间
161
+ }
162
+ },
163
+ computed: {
164
+ getActiveBorderRadius() {
165
+ return this.$pi.common.addUnit(this.activeBorderRadius)
166
+ },
167
+ // 获取上个月最后一天
168
+ getPreMonthLastDay() {
169
+ let year = this.year
170
+ let month = this.month - 1
171
+ if (month === 0) {
172
+ year = year - 1
173
+ month = 12
174
+ }
175
+ return new Date(year, month, '0')
176
+ },
177
+ getNexMonthFirstDay() {
178
+ let year = this.year
179
+ let month = this.month + 1
180
+ if (month === 13) {
181
+ year = year + 1
182
+ month = 1
183
+ }
184
+ return new Date(year, month - 1, '1')
185
+ },
186
+ // 第一天
187
+ firstDay() {
188
+ const firstDays = []
189
+ const preMonthLastDay = this.getPreMonthLastDay
190
+ const lastDay = preMonthLastDay.getDate()
191
+ const firstDay = new Date(`${this.year}/${this.month}/01 00:00:00`).getDay()
192
+ for (let i = 0; i < firstDay; i++) {
193
+ const day = preMonthLastDay.setDate(lastDay - firstDay + i + 1)
194
+ firstDays.push(new Date(day))
195
+ }
196
+ return firstDays
197
+ },
198
+ getMinDate() {
199
+ return this.minDate ? this.$pi.date.parseDate(this.minDate) : ''
200
+ },
201
+ getMaxDate() {
202
+ return this.maxDate ? this.$pi.date.parseDate(this.maxDate) : ''
203
+ },
204
+ // 总天数
205
+ days() {
206
+ const days = []
207
+ const dayCount = 7 * 6 // 固定显示6周
208
+ const monthDays = new Date(this.year, this.month, 0).getDate()
209
+ const firstDayCount = this.firstDay.length
210
+ const nextMonthFirstDay = this.getNexMonthFirstDay
211
+ for (let i = 1; i <= dayCount; i++) {
212
+ let day = {
213
+ key: 'pi-calander-day-item-' + i,
214
+ index: i
215
+ }
216
+
217
+ // 上月数据
218
+ if (i <= firstDayCount) {
219
+ day = {
220
+ ...day,
221
+ ...this.$pi.date.parseDate(this.firstDay[i - 1]),
222
+ type: this.weekView ? '' : 'disabled'
223
+ }
224
+ } else if (i > monthDays + firstDayCount) {
225
+ // 下月数据
226
+ day = {
227
+ ...day,
228
+ ...this.$pi.date.parseDate(
229
+ new Date(nextMonthFirstDay.setDate(i - monthDays - firstDayCount))
230
+ ),
231
+ type: this.weekView ? '' : 'disabled'
232
+ }
233
+ } else {
234
+ // 当月数据
235
+ day = {
236
+ ...day,
237
+ ...this.$pi.date.parseDate(`${this.year}/${this.month}/${i - firstDayCount}`)
238
+ }
239
+ const isDisabled = this.isDisabled(day)
240
+ // 禁用
241
+ if (isDisabled) {
242
+ day.disabled = true
243
+ }
244
+ // 单选选中样式
245
+ if (this.type === 'date' && this.isSameDay(this.calendarValue, day)) {
246
+ const activeStyle = {
247
+ color: this.activeColor,
248
+ borderRadius: this.getActiveBorderRadius
249
+ }
250
+ if (this.activeBg) activeStyle.background = this.activeBg
251
+ day.activeStyle = activeStyle
252
+ }
253
+ // 范围选中样式
254
+ if (this.type === 'range') {
255
+ const start = this.calendarValue[0]
256
+ const end = this.calendarValue[1]
257
+ const isBegin = this.isSameDay(start, day)
258
+ const isEnd = this.isSameDay(end, day)
259
+ const inRange =
260
+ start && end && day.timestamp > start.timestamp && day.timestamp < end.timestamp
261
+ const rangeStyle = {}
262
+ // 处理中间范围的样式
263
+ if (inRange) {
264
+ rangeStyle.color = this.rangeColor
265
+ rangeStyle.background = this.rangeBg
266
+ }
267
+ // 处理两端
268
+ if (isBegin || isEnd) {
269
+ rangeStyle.color = this.activeColor
270
+ rangeStyle.borderRadius = isBegin
271
+ ? `${this.getActiveBorderRadius} 0 0 0`
272
+ : `0 0 ${this.getActiveBorderRadius} 0`
273
+ if (this.activeBg) rangeStyle.background = this.activeBg
274
+ }
275
+ day.range = true
276
+ day.rangeStyle = rangeStyle
277
+ // type 为 range 开始和结束的提示
278
+ if (isBegin) day.tip = this.startText
279
+ if (isEnd) day.tip = this.endText
280
+ if (isBegin && isEnd) {
281
+ day.tip = this.startText + '-' + this.endText
282
+ }
283
+ }
284
+ }
285
+ // 当天样式
286
+ if (this.isSameDay(this.now, day)) {
287
+ day.today = true
288
+ if (this.showBackToday) {
289
+ day.nowStyle = {
290
+ color: this.todayActiveBorderColor,
291
+ border: '1px solid ' + this.todayActiveBorderColor,
292
+ borderRadius: this.getActiveBorderRadius
293
+ }
294
+ }
295
+ }
296
+ days.push(day)
297
+ }
298
+ if (this.weekView) {
299
+ days.splice(0, (this.week - 1) * 7)
300
+ days.splice(7, days.length - 7)
301
+ }
302
+ return days
303
+ },
304
+ getBgTip() {
305
+ if (!this.days.length) return ''
306
+ const startDay = this.days[0]
307
+ const endDay = this.days[this.days.length - 1]
308
+ return this.weekView
309
+ ? `${startDay.month}月 ${startDay.date}日 - ${endDay.month}月 ${endDay.date}日`
310
+ : this.month
311
+ }
312
+ },
313
+ methods: {
314
+ isSameDay(day1, day2) {
315
+ return (
316
+ day1 &&
317
+ day2 &&
318
+ day1.year === day2.year &&
319
+ day1.month === day2.month &&
320
+ day1.date === day2.date
321
+ )
322
+ },
323
+ isDisabled(day) {
324
+ const isDisabled =
325
+ (this.getMinDate && day.timestamp < this.getMinDate.timestamp) ||
326
+ (this.getMaxDate && day.timestamp > this.getMaxDate.timestamp)
327
+ return isDisabled
328
+ },
329
+ handleChange(value) {
330
+ this.$emit('change', value)
331
+ },
332
+ handleSelectDate(date) {
333
+ if (date.disabled) return
334
+ if (this.type === 'date') {
335
+ // 单选方式
336
+ this.handleChange(date)
337
+ return
338
+ }
339
+ // 处理范围选择方式
340
+ if (this.calendarValue.length === 2) {
341
+ // 如果选了两项,则重新开始选择范围
342
+ this.handleChange([date])
343
+ } else {
344
+ // 和第一项判断大小,小的放前面
345
+ if (date.timestamp > this.calendarValue[0].timestamp) {
346
+ this.handleChange([this.calendarValue[0], date])
347
+ } else {
348
+ this.handleChange([date, this.calendarValue[0]])
349
+ }
350
+ }
351
+ }
352
+ }
353
+ }
354
+ </script>
355
+
356
+ <style lang="scss" scoped>
357
+ .date-item {
358
+ position: relative;
359
+ z-index: 2;
360
+ width: calc(100% / 7);
361
+ overflow: hidden;
362
+ .date-item-inner {
363
+ padding: 8rpx;
364
+ }
365
+ &.range {
366
+ .date-item-inner {
367
+ padding: 6rpx 0rpx;
368
+ }
369
+ }
370
+ }
371
+ </style>
@@ -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 />
@@ -2,7 +2,7 @@
2
2
  <view class="dropdown-tab-item" :class="[{ opened: item.opened }]">
3
3
  <!-- 注意:slot内不能使用父组件data -->
4
4
  <view
5
- class="pi-align-center"
5
+ class="pi-justify-center pi-align-center"
6
6
  :style="{ color: item.opened && item.activeColor ? item.activeColor : 'inherit' }"
7
7
  @tap.stop="handleClick"
8
8
  >
@@ -18,10 +18,10 @@
18
18
  :custom-class="`pi-mg-right-8 ${item.iconOption.customClass}`"
19
19
  />
20
20
 
21
- <text class=" pi-pd-right-8 pi-fz-28">
21
+ <text class="pi-pd-right-12 pi-fz-28">
22
22
  {{ item.text }}
23
23
  </text>
24
- <pi-icon :class="{ rotate: item.opened }" name="unfold" size="26" />
24
+ <pi-icon :class="{ rotate: item.opened }" name="arrow-down_fill" size="26" color="#999" />
25
25
  </view>
26
26
  </view>
27
27
  </template>
@@ -6,6 +6,7 @@
6
6
  :items="tabs"
7
7
  :show-slider-bar="false"
8
8
  show-item-split-line
9
+ :stretch="stretch"
9
10
  active-text-color="inherit"
10
11
  >
11
12
  <view slot="item" slot-scope="{ item, index }">
@@ -31,6 +32,7 @@
31
32
  :style="[
32
33
  {
33
34
  'z-index': getMask.zIndex,
35
+ 'top': maskAlignTop ? containerRect.top + 'px' : '-9999px',
34
36
  'background': getMask.background,
35
37
  'animation-duration': getDuration.css
36
38
  }
@@ -158,11 +160,27 @@ export default {
158
160
  },
159
161
  // 选中checkbox配置
160
162
  selectedCheckbox: {
161
- type: Object,
163
+ type: [Object, String],
162
164
  default() {
163
165
  // 参照checkbox
164
166
  return dropdown.selectedCheckbox
165
167
  }
168
+ },
169
+ // 标签是否均分布局,可选值 `true`
170
+ stretch: {
171
+ type: Boolean,
172
+ // `false`
173
+ default() {
174
+ return dropdown.stretch
175
+ }
176
+ },
177
+ // 是否需要蒙层顶部对齐组件,可选值 `false`
178
+ maskAlignTop: {
179
+ type: Boolean,
180
+ // `true`
181
+ default() {
182
+ return dropdown.maskAlignTop
183
+ }
166
184
  }
167
185
  },
168
186
  data() {
@@ -182,8 +200,8 @@ export default {
182
200
  const { containerRect, closed } = this
183
201
  return {
184
202
  top: `${containerRect.height}px`,
185
- left: 0,
186
- width: `${containerRect.width}px`,
203
+ left: `-${containerRect.left}px`,
204
+ width: `${$pi.system.systemInfo.windowWidth}px`,
187
205
  zIndex: !closed ? 101 : -1
188
206
  }
189
207
  },
@@ -246,6 +264,10 @@ export default {
246
264
  // 显示当前Tab
247
265
  async handleClickTab(item) {
248
266
  if (item.disabled) return
267
+ if (this.show && item.id === this.activeItem.id) {
268
+ this.closeMask()
269
+ return
270
+ }
249
271
  // 更新打开的tab标志
250
272
  this.tabs = this.tabs.map(tab => {
251
273
  tab.opened = tab.id === item.id
@@ -304,10 +326,8 @@ export default {
304
326
  .pi-dropdown-content {
305
327
  position: absolute;
306
328
  background: #ffffff;
307
- border-radius: 12rpx;
308
329
  }
309
330
  .pi-dropdown-mask {
310
- top: -9999px;
311
331
  left: -9999px;
312
332
  right: -9999px;
313
333
  bottom: -9999px;
@@ -4,17 +4,21 @@
4
4
  <view
5
5
  v-for="item in options"
6
6
  :key="item[getKeyField]"
7
- class="item-wrap pi-pd-tb-24 pi-pd-lr-32 pi-w-100P pi-justify-between pi-align-center"
8
- :class="[customClass, item[getDisabledField] ? 'disabled' : '']"
7
+ class="item-wrap pi-pd-tb-24 pi-pd-lr-32 pi-w-100P pi-align-center"
8
+ :class="[
9
+ customClass,
10
+ item[getDisabledField] ? 'disabled' : '',
11
+ getSelectedCheckbox === 'none' ? 'pi-justify-center' : 'pi-justify-between'
12
+ ]"
9
13
  :style="[customStyle, getItemStyle]"
10
14
  @tap="handleSelectItem(item)"
11
15
  >
12
- <view>
16
+ <view :class="[{ 'pi-primary': item[keyField] === val }]">
13
17
  {{ item[getDisplayField] }}
14
18
  </view>
15
19
  <!-- 如果配置了图片地址,使用图片 -->
16
20
  <pi-img
17
- v-if="getSelectedImg.src && item.id === val"
21
+ v-if="getSelectedImg.src && item[keyField] === val"
18
22
  :src="getSelectedImg.src"
19
23
  :mode="getSelectedImg.mode"
20
24
  :width="getSelectedImg.width"
@@ -34,9 +38,9 @@
34
38
  />
35
39
  <!-- 默认使用复选框 -->
36
40
  <pi-checkbox
37
- v-if="!getSelectedImg.src"
41
+ v-if="!getSelectedImg.src && getSelectedCheckbox !== 'none'"
38
42
  readonly
39
- :value="item.id === val"
43
+ :value="item[keyField] === val"
40
44
  :name="getSelectedCheckbox.name"
41
45
  :shape="getSelectedCheckbox.shape"
42
46
  :border-radius="getSelectedCheckbox.borderRadius"
@@ -148,7 +152,7 @@ export default {
148
152
  },
149
153
  // 选中checkbox配置
150
154
  selectedCheckbox: {
151
- type: Object,
155
+ type: [Object, String],
152
156
  default() {
153
157
  // 参照checkbox
154
158
  return dropdownItem.selectedCheckbox
@@ -185,6 +189,9 @@ export default {
185
189
  return this.$pi.lang.mergeDeep(selectedImg, this.selectedImg)
186
190
  },
187
191
  getSelectedCheckbox() {
192
+ if (this.inheritProps.selectedCheckbox === 'none') {
193
+ return this.inheritProps.selectedCheckbox
194
+ }
188
195
  const selectedCheckbox = this.inheritProps.selectedCheckbox || dropdownItem.selectedCheckbox
189
196
  return this.$pi.lang.mergeDeep(selectedCheckbox, this.selectedCheckbox)
190
197
  },
@@ -10,13 +10,12 @@
10
10
  { stretch: getStretch },
11
11
  customClass
12
12
  ]"
13
- @tap="handleRadioToggle(true)"
14
13
  >
15
14
  <view
16
15
  v-if="!['text', 'button'].includes(getShape)"
17
16
  class="radio-icon"
18
17
  :style="[radioStyle]"
19
- @tap.stop="handleRadioToggle(false)"
18
+ @tap="handleRadioToggle(false)"
20
19
  >
21
20
  <view v-if="getShape === 'dot'" class="dot" />
22
21
  <pi-icon v-else name="blod-check" :size="getIconSize" />
@@ -26,6 +25,7 @@
26
25
  class="radio-label"
27
26
  :class="[getShape]"
28
27
  :style="[textStyle]"
28
+ @tap="handleRadioToggle(true)"
29
29
  >
30
30
  <slot />
31
31
  </view>
@@ -20,5 +20,7 @@ export default {
20
20
  rangeBg: '#5A7DFF25', // 范围内日期背景色,默认('#5A7DFF25')
21
21
  startText: '开始', // type=range时生效,起始日期自定义文案,默认('开始')
22
22
  endText: '结束', // type=range时生效,结束日期自定义文案,默认('结束')
23
- dateFormat: 'YYYY-MM-DD' // 已选择的时间格式化显示规则,默认('YYYY-MM-DD')
23
+ dateFormat: 'YYYY-MM-DD', // 已选择的时间格式化显示规则,默认('YYYY-MM-DD')
24
+ canChangeWeekView: false, // 是否可切换周视图,默认(false)
25
+ defalutWeekView: false // 是否默认显示周视图,默认(false)
24
26
  }
@@ -17,5 +17,7 @@ export default {
17
17
  displayField: null, // 选项显示字段,默认为text
18
18
  disabledField: null, // 选项禁用字段,默认为disabled
19
19
  selectedImg: null, // 选中图标的配置
20
- selectedCheckbox: null // 选中复选框配置
20
+ selectedCheckbox: null, // 选中复选框配置
21
+ stretch: false, // 标签是否均分布局,可选值 `true`
22
+ maskAlignTop: true // 是否需要蒙层顶部对齐组件,可选值 `false`
21
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7beta7",
3
+ "version": "1.2.7beta8",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {