sadais-piui 1.2.6-beta8 → 1.2.7-beta10

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,174 @@
1
+ <template>
2
+ <view
3
+ class="pi-bubble pi-rela pi-flex pi-align-center pi-justify-center"
4
+ :style="[customStyle]"
5
+ :class="customClass"
6
+ @longpress.stop="handleLongpress"
7
+ >
8
+ <slot />
9
+ <view v-show="showBubble" class="pi-bubble-wrapper" :class="[bubbleClass]">
10
+ <view
11
+ ref="bubble"
12
+ class="pi-bubble-content pi-abso pi-bg-white pi-radius-4 pi-pd-20"
13
+ :style="[bubbleStyle]"
14
+ >
15
+ <slot name="bubble" />
16
+ <view class="pi-bubble-angle pi-abso" />
17
+ </view>
18
+ </view>
19
+ <pi-mask v-model="showMaks" background="transparent" @close="showBubble = false" />
20
+ </view>
21
+ </template>
22
+
23
+ <script>
24
+ /**
25
+ * bubble 气泡弹窗
26
+ */
27
+ import { getConfig } from '../../config'
28
+ const TAG = 'PiBubble'
29
+ const { bubble } = getConfig()
30
+
31
+ // 底部栏
32
+ export default {
33
+ name: 'PiBubble',
34
+ props: {
35
+ // 自定义样式,对象形式
36
+ customStyle: {
37
+ type: Object,
38
+ // {}
39
+ default() {
40
+ return bubble.customStyle
41
+ }
42
+ },
43
+ customClass: {
44
+ type: String,
45
+ // ''
46
+ default() {
47
+ return bubble.customClass
48
+ }
49
+ },
50
+ position: {
51
+ type: String,
52
+ default() {
53
+ return bubble.position
54
+ }
55
+ },
56
+ zIndex: {
57
+ type: Number,
58
+ default() {
59
+ return bubble.zIndex
60
+ }
61
+ }
62
+ },
63
+ data() {
64
+ return {
65
+ showBubble: false,
66
+ showMaks: false,
67
+ bubleWidth: 0,
68
+ sysInfo: {},
69
+ bublePosition: {
70
+ top: 0,
71
+ left: 0
72
+ }
73
+ }
74
+ },
75
+ computed: {
76
+ rpxRatio() {
77
+ return 750 / this.screenWidth
78
+ },
79
+ screenWidth() {
80
+ return this.sysInfo.screenWidth
81
+ },
82
+ bubblePosition() {
83
+ return this.position === 'bottom' ? 'top' : 'bottom'
84
+ },
85
+ bubbleStyle() {
86
+ return {
87
+ zIndex: this.zIndex,
88
+ ...this.bublePosition
89
+ }
90
+ },
91
+ bubbleClass() {
92
+ return this.position === 'top' ? 'isTop' : ''
93
+ }
94
+ },
95
+ mounted() {
96
+ this.init()
97
+ },
98
+ methods: {
99
+ init() {
100
+ this.sysInfo = uni.getSystemInfoSync()
101
+ },
102
+ async handleLongpress(e) {
103
+ await this.calcBubblePosition()
104
+ this.showBubble = true
105
+ this.showMaks = true
106
+ },
107
+ getBubbleWidth() {
108
+ return new Promise(reslove => {
109
+ this.$set(this, 'bublePosition', { top: '-9999vh', left: 0 })
110
+ this.showBubble = true
111
+ setTimeout(() => {
112
+ reslove(this.$refs.bubble ? this.$refs.bubble.$el.getBoundingClientRect().width : 0)
113
+ this.showBubble = false
114
+ }, 500)
115
+ })
116
+ },
117
+ async calcBubblePosition() {
118
+ let bublePosition = this.$el.getBoundingClientRect()
119
+ this.bubleWidth = await this.getBubbleWidth()
120
+ const lengthGap = (this.bubleWidth - bublePosition.width) / 2
121
+ const compRight = this.screenWidth - bublePosition.x - bublePosition.width
122
+ const posRes = {}
123
+ if (lengthGap <= 0 || (lengthGap < bublePosition.x && lengthGap < compRight)) {
124
+ posRes.left = -Math.abs(lengthGap) + 'px'
125
+ } else {
126
+ posRes.right = 4 - Math.min(bublePosition.x, compRight) + 'px'
127
+ }
128
+ posRes[this.bubblePosition] = 'calc(100% + 18rpx)'
129
+ this.$set(this, 'bublePosition', posRes)
130
+ }
131
+ }
132
+ }
133
+ </script>
134
+
135
+ <style lang="scss" scoped>
136
+ .pi-bubble {
137
+ width: fit-content;
138
+ height: fit-content;
139
+ .pi-bubble-wrapper {
140
+ filter: drop-shadow(0 0 2rpx #000);
141
+ z-index: 9999;
142
+ position: absolute;
143
+ width: 100%;
144
+ height: 0;
145
+ top: 100%;
146
+ &.isTop {
147
+ top: 0;
148
+ .pi-bubble-content {
149
+ .pi-bubble-angle {
150
+ top: initial;
151
+ bottom: -10rpx;
152
+ }
153
+ }
154
+ }
155
+ .pi-bubble-content {
156
+ max-width: 98vw;
157
+ line-height: 30rpx;
158
+ color: #fff;
159
+ z-index: 9999;
160
+ background-color: #000;
161
+ .pi-bubble-angle {
162
+ top: -10rpx;
163
+ left: 50%;
164
+ z-index: 9999;
165
+ width: 0rpx;
166
+ height: 0rpx;
167
+ border: 12rpx solid #000;
168
+ transform: translateX(-50%) rotate(45deg);
169
+ transform-origin: center;
170
+ }
171
+ }
172
+ }
173
+ }
174
+ </style>
@@ -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>