sadais-piui 1.2.7-beta33 → 1.2.7-beta36

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.
@@ -39,6 +39,7 @@
39
39
  :start-text="getCalendarPanel.startText"
40
40
  :end-text="getCalendarPanel.endText"
41
41
  :date-format="getCalendarPanel.dateFormat"
42
+ @date-change="$emit('date-change', $event)"
42
43
  />
43
44
  <!-- footer -->
44
45
  <view class="pi-w-100P pi-align-center pi-pd-24 pi-solid-top-1">
@@ -1,10 +1,10 @@
1
1
  <!--
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2022-06-28 16:53:54
4
- * @LastEditTime: 2022-07-01 10:01:43
4
+ * @LastEditTime: 2022-08-23 11:45:24
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 日历日期数据
7
- * @FilePath: /hfmp-checkin-front/Users/feilin/workspace/piui/piui-awesome/src/piui/components/pi-calendar-panel/components/calendar-days/index.vue
7
+ * @FilePath: /dt-weitibao-console/Users/feilin/workspace/piui/piui-awesome/src/piui/components/pi-calendar-panel/components/calendar-days/index.vue
8
8
  -->
9
9
 
10
10
  <template>
@@ -14,14 +14,18 @@
14
14
  :key="day.key"
15
15
  class="date-item"
16
16
  style="cursor: pointer;"
17
- :class="[{ 'pi-disabled': day.disabled || day.type === 'disabled' }, { range: day.range }]"
17
+ :class="[
18
+ { 'pi-disabled': day.disabled || day.type === 'disabled' },
19
+ { range: day.range },
20
+ { marked: day.marked }
21
+ ]"
18
22
  @tap.stop="handleSelectDate(day)"
19
23
  >
20
24
  <view class="pi-square">
21
25
  <view class="pi-rela date-item-inner">
22
26
  <view
23
27
  class="pi-w-100P pi-h-100P pi-flex-column-center pi-lh-28"
24
- :style="[day.rangeStyle, day.nowStyle, day.activeStyle]"
28
+ :style="[day.nowStyle, day.activeStyle, day.rangeStyle]"
25
29
  >
26
30
  <text>{{ day.date }}</text>
27
31
  <text v-if="day.tip" class=" pi-text-nowrap pi-fz-18 pi-mg-top-6">
@@ -152,6 +156,12 @@ export default {
152
156
  type: Boolean,
153
157
  // '是否显示周视图'
154
158
  default: calendarPanel.defalutWeekView
159
+ },
160
+ // 日期标记,数组形式,默认([])
161
+ marks: {
162
+ type: Array,
163
+ // []
164
+ default: () => calendarPanel.marks
155
165
  }
156
166
  },
157
167
  data() {
@@ -201,6 +211,11 @@ export default {
201
211
  getMaxDate() {
202
212
  return this.maxDate ? this.$pi.date.parseDate(this.maxDate) : ''
203
213
  },
214
+ getMarks() {
215
+ return this.marks.map(item => {
216
+ return this.$pi.date.parseDate(item)
217
+ })
218
+ },
204
219
  // 总天数
205
220
  days() {
206
221
  const days = []
@@ -282,6 +297,15 @@ export default {
282
297
  }
283
298
  }
284
299
  }
300
+ // 是否打点
301
+ if (this.getMarks.length) {
302
+ const mark = this.getMarks.find(item => {
303
+ return this.isSameDay(item, day)
304
+ })
305
+ if (mark) {
306
+ day.marked = mark
307
+ }
308
+ }
285
309
  // 当天样式
286
310
  if (this.isSameDay(this.now, day)) {
287
311
  day.today = true
@@ -337,7 +361,7 @@ export default {
337
361
  return
338
362
  }
339
363
  // 处理范围选择方式
340
- if (this.calendarValue.length === 2) {
364
+ if (this.calendarValue.length === 0 || this.calendarValue.length === 2) {
341
365
  // 如果选了两项,则重新开始选择范围
342
366
  this.handleChange([date])
343
367
  } else {
@@ -359,6 +383,20 @@ export default {
359
383
  z-index: 2;
360
384
  width: calc(100% / 7);
361
385
  overflow: hidden;
386
+ &.marked {
387
+ &::after {
388
+ content: '';
389
+ position: absolute;
390
+ bottom: 18rpx;
391
+ left: 50%;
392
+ width: 8rpx;
393
+ height: 8rpx;
394
+ background: #ff0027;
395
+ border-radius: 50%;
396
+ transform: translateX(-50%);
397
+ overflow: hidden;
398
+ }
399
+ }
362
400
  .date-item-inner {
363
401
  padding: 8rpx;
364
402
  }
@@ -60,6 +60,7 @@
60
60
  :end-text="endText"
61
61
  :week-view="weekView"
62
62
  :show-back-today="showBackToday"
63
+ :marks="marks"
63
64
  @change="handleChange"
64
65
  />
65
66
  </swiper-item>
@@ -219,14 +220,20 @@ export default {
219
220
  type: Boolean,
220
221
  // true
221
222
  default: calendarPanel.defalutWeekView
223
+ },
224
+ // 日期标记,数组形式,默认([])
225
+ marks: {
226
+ type: Array,
227
+ // []
228
+ default: () => calendarPanel.marks
222
229
  }
223
230
  },
224
231
  data() {
225
232
  const now = this.$pi.date.parseDate()
226
233
  return {
227
234
  now: now, // 当前时间
228
- year: '', // 年份
229
- month: '', // 月份
235
+ year: now.year, // 年份
236
+ month: now.month, // 月份
230
237
  week: 1, // 当前周
231
238
  calendarValue: '',
232
239
  currentTabIndex: 1, // 当前选中的tab索引
@@ -271,24 +278,25 @@ export default {
271
278
  this.init()
272
279
  },
273
280
  methods: {
274
- valid() {
275
- if (this.type === 'date') return true
276
- if (this.type === 'range' && this.$pi.lang.isArray(this.value) && this.value.length === 2)
277
- return true
278
- return false
279
- },
280
281
  init() {
281
282
  console.log(TAG, '组件初始化', this.value)
282
- if (!this.valid()) return
283
283
  let initValue = this.value
284
284
  const nowDate = this.$pi.date.parseDate(this.type === 'date' ? this.value : this.value[0])
285
285
  if (this.type === 'range') {
286
- const endDate = this.$pi.date.parseDate(this.value[1])
287
- 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
+
288
297
  this.year = nowDate.year
289
298
  this.month = nowDate.month
290
299
  }
291
- initValue = [nowDate, endDate]
292
300
  } else {
293
301
  this.year = nowDate.year
294
302
  this.month = nowDate.month
@@ -340,6 +348,10 @@ export default {
340
348
  } else {
341
349
  this.month = month
342
350
  }
351
+ this.$emit('date-change', {
352
+ year: this.year,
353
+ month: this.month
354
+ })
343
355
  },
344
356
  handlePrevMonth() {
345
357
  if (this.currentTabIndex === 0) {
@@ -361,6 +373,10 @@ export default {
361
373
  if (change > 0 && this.isMaxYear) return
362
374
  if (change < 0 && this.isMinYear) return
363
375
  this.year = this.year + change
376
+ this.$emit('date-change', {
377
+ year: this.year,
378
+ month: this.month
379
+ })
364
380
  },
365
381
  handleBackToday() {
366
382
  this.year = this.now.year
@@ -0,0 +1,324 @@
1
+ <template>
2
+ <scroll-view class="cascader-wrap" scroll-x :scroll-left="scrollLeft">
3
+ <view v-for="(col, idx) of columns" :key="idx" class="column">
4
+ <view
5
+ v-for="(item, subidx) in col"
6
+ :key="getKey(item, subidx)"
7
+ class="column-item"
8
+ :class="{
9
+ active: activeIds.includes(item.uid),
10
+ arrow: item.children && item.children.length > 0,
11
+ }"
12
+ @click="handleClickItem(item)"
13
+ >
14
+ {{ item[props.label] || "" }}
15
+ </view>
16
+ </view>
17
+ </scroll-view>
18
+ </template>
19
+
20
+ <script>
21
+ export default {
22
+ name: "PiCascader",
23
+ model: {
24
+ prop: "value",
25
+ event: "input",
26
+ },
27
+ props: {
28
+ // 自定义样式,对象形式
29
+ customStyle: {
30
+ type: Object,
31
+ default() {
32
+ // {}
33
+ return {};
34
+ },
35
+ },
36
+ // 自定义样式类,字符串形式
37
+ customClass: {
38
+ type: String,
39
+ // ''
40
+ default() {
41
+ return "";
42
+ },
43
+ },
44
+ // 数据源
45
+ options: {
46
+ type: Array,
47
+ default() {
48
+ return [];
49
+ },
50
+ },
51
+ value: {
52
+ type: Array,
53
+ default: () => [],
54
+ },
55
+ // 配置数据源的key
56
+ props: {
57
+ type: Object,
58
+ default() {
59
+ return {
60
+ label: "label",
61
+ value: "value",
62
+ children: "children",
63
+ id: "id",
64
+ expandTrigger: true,
65
+ };
66
+ },
67
+ },
68
+ },
69
+ data() {
70
+ return {
71
+ curItem: null,
72
+ innerOptions: [],
73
+ optMap: {},
74
+ selectedIds: [],
75
+ scrollLeft: 0,
76
+ };
77
+ },
78
+ computed: {
79
+ columns() {
80
+ if (this.curItem) {
81
+ const arr = [];
82
+ let p = this.curItem;
83
+ while (p) {
84
+ const tmp = p[this.props.children] || [];
85
+ if (tmp.length > 0) {
86
+ arr.unshift(tmp);
87
+ }
88
+ p = this.optMap[p.pid];
89
+ }
90
+ arr.unshift(this.innerOptions);
91
+ return arr;
92
+ }
93
+ return [this.innerOptions];
94
+ },
95
+ activeIds() {
96
+ if (this.curItem) {
97
+ const arr = [];
98
+ let p = this.curItem;
99
+ while (p) {
100
+ arr.unshift(p.uid);
101
+ p = this.optMap[p.pid];
102
+ }
103
+ return arr;
104
+ }
105
+ return [];
106
+ },
107
+ syncIds() {
108
+ return this.innerOptions.length + this.value.length;
109
+ },
110
+ },
111
+ watch: {
112
+ options: {
113
+ immediate: true,
114
+ handler() {
115
+ this.rebuildOptions();
116
+ },
117
+ },
118
+ syncIds: {
119
+ handler() {
120
+ this.initSelectedIds();
121
+ },
122
+ },
123
+ },
124
+ methods: {
125
+ getKey(item, idx) {
126
+ if (this.props.id) {
127
+ return item[this.props.id];
128
+ }
129
+ return `${item.level}-${idx}`;
130
+ },
131
+ randomId() {
132
+ const x = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
133
+ return x.replace(/[xy]/g, (g) => {
134
+ const t = (Math.random() * 16) | 0;
135
+ const c = g === "x" ? t : (t & 0x03) | 0x08;
136
+ return c.toString(16);
137
+ });
138
+ },
139
+ initSelectedIds() {
140
+ let curs = [...this.innerOptions];
141
+ const items = Object.values(this.optMap);
142
+ const results = [];
143
+ for (const val of this.value) {
144
+ const item = items.filter((i) => i[this.props.value] === val)[0];
145
+ if (item) {
146
+ results.push(item.uid);
147
+ }
148
+ }
149
+ this.selectedIds = results;
150
+ },
151
+ rebuildOptions() {
152
+ // 以非递归的方式 深度拷贝options 且建立父子节点关系
153
+ // 目的为了不影响外部传入的prop: options
154
+ const newOptions = [];
155
+ // 初始化堆栈 为options的根节点
156
+ const stack = [...this.options];
157
+ const optMap = {};
158
+ while (stack.length > 0) {
159
+ let item = stack.shift();
160
+ if (!item.pid) {
161
+ // 拷贝
162
+ item = { ...item, level: 0, uid: this.randomId() };
163
+ newOptions.push(item);
164
+ }
165
+ const children = item[this.props.children] || [];
166
+ const newChilds = [];
167
+ for (let i = children.length - 1; i >= 0; i--) {
168
+ // 拷贝子孩子
169
+ const subItem = {
170
+ ...children[i],
171
+ level: item.level + 1,
172
+ uid: this.randomId(),
173
+ };
174
+ // 建立父子关系
175
+ subItem.pid = item.uid;
176
+ // 放置到新数组中
177
+ newChilds.unshift(subItem);
178
+ // 入栈 模拟递归效果
179
+ stack.unshift(subItem);
180
+ }
181
+ // 更新children 为新的数组
182
+ item[this.props.children] = newChilds;
183
+ optMap[item.uid] = item;
184
+ }
185
+ this.innerOptions = newOptions;
186
+ this.optMap = optMap;
187
+ },
188
+ handleClickItem(item) {
189
+ this.curItem = item;
190
+ if (item?.children?.length === 0) {
191
+ // 点击的是叶子节点
192
+ if (this.selectedIds.includes(item.uid)) {
193
+ // 取消选中 其中uid是在rebuildOptions方法中生成的
194
+ this.selectedIds = this.selectedIds.filter((i) => i !== item.uid);
195
+ } else {
196
+ // 选中
197
+ this.selectedIds.push(item.uid);
198
+ }
199
+ // 根据选中的uid转换为对应的value
200
+ const values = this.selectedIds.reduce((prev, i) => {
201
+ const item = this.optMap[i];
202
+ if (item) {
203
+ prev.push(item[this.props.value]);
204
+ }
205
+ return prev;
206
+ }, []);
207
+ this.$emit("input", values);
208
+ this.$emit("change", values);
209
+ }
210
+ this.$nextTick(async () => {
211
+ const maxx = await this.getMaxX();
212
+ const containerWidth = await this.getViewport();
213
+ const left = await this.getScrollLeft();
214
+ const diff = maxx - (left + containerWidth);
215
+ this.scrollLeft = left + diff;
216
+ });
217
+ },
218
+ getViewport() {
219
+ return new Promise((resolve) => {
220
+ const ctx = uni.createSelectorQuery();
221
+ //#ifndef MP-ALIPAY
222
+ ctx.in(this);
223
+ //#endif
224
+ const columns = ctx
225
+ .select(".cascader-wrap")
226
+ .boundingClientRect((res) => {
227
+ console.log(res);
228
+ resolve(res?.width || 0);
229
+ })
230
+ .exec();
231
+ });
232
+ },
233
+ getScrollLeft() {
234
+ return new Promise((resolve) => {
235
+ const ctx = uni.createSelectorQuery();
236
+ //#ifndef MP-ALIPAY
237
+ ctx.in(this);
238
+ //#endif
239
+ const columns = ctx
240
+ .select(".cascader-wrap")
241
+ .scrollOffset((res) => {
242
+ console.log(res);
243
+ resolve(res?.scrollLeft || 0);
244
+ })
245
+ .exec();
246
+ });
247
+ },
248
+ getMaxX(ctx) {
249
+ return new Promise((resolve) => {
250
+ const ctx = uni.createSelectorQuery();
251
+ //#ifndef MP-ALIPAY
252
+ ctx.in(this);
253
+ //#endif
254
+ const columns = ctx
255
+ .selectAll(".column")
256
+ .boundingClientRect((res) => {
257
+ console.log(res);
258
+ if (res?.length > 0) {
259
+ const x = res.reduce((prev, i) => {
260
+ prev += i.width;
261
+ return prev;
262
+ }, 0);
263
+ resolve(x);
264
+ } else {
265
+ resolve(0);
266
+ }
267
+ })
268
+ .exec();
269
+ });
270
+ },
271
+ },
272
+ };
273
+ </script>
274
+
275
+ <style lang="scss" scoped>
276
+ ::-webkit-scrollbar {
277
+ width: 8rpx;
278
+ height: 8rpx;
279
+ }
280
+ ::-webkit-scrollbar-thumb {
281
+ background: #00ff00;
282
+ }
283
+ .cascader-wrap {
284
+ width: 100%;
285
+ height: 100%;
286
+ white-space: nowrap;
287
+ overflow: auto hidden;
288
+ background: #f4f2f6;
289
+ box-sizing: border-box;
290
+ font-size: 0;
291
+ .column {
292
+ display: inline-block;
293
+ height: 100%;
294
+ width: 50%;
295
+ overflow: hidden auto;
296
+ .column-item {
297
+ position: relative;
298
+ display: block;
299
+ height: 60rpx;
300
+ line-height: 60rpx;
301
+ padding: 0 calc(#{16rpx / 0.7 + 16rpx}) 0 32rpx;
302
+ font-size: 28rpx;
303
+ color: #333333;
304
+ &.active {
305
+ color: #2069f0;
306
+ background: #ffffff;
307
+ }
308
+ &.arrow::after {
309
+ display: block;
310
+ content: "";
311
+ width: 16rpx;
312
+ height: 16rpx;
313
+ border: 2rpx solid #333333;
314
+ border-top: none;
315
+ border-left: none;
316
+ position: absolute;
317
+ right: 8rpx;
318
+ top: 50%;
319
+ transform: translateY(-50%) rotate(-45deg);
320
+ }
321
+ }
322
+ }
323
+ }
324
+ </style>
@@ -31,7 +31,7 @@
31
31
  </view>
32
32
  <view
33
33
  class="slider-bar-guide"
34
- :style="[{ 'background-color': showSliderBarGuide ? '#e4e7ed' : 'transparent' }]"
34
+ :style="[{ 'background-color': showSliderBarGuide ? '#e4e7ed' : 'unset' }]"
35
35
  >
36
36
  <view v-if="showSliderBar" class="slider-bar" :style="[getSliderBarStyle]" />
37
37
  </view>
@@ -22,5 +22,6 @@ export default {
22
22
  endText: '结束', // type=range时生效,结束日期自定义文案,默认('结束')
23
23
  dateFormat: 'YYYY-MM-DD', // 已选择的时间格式化显示规则,默认('YYYY-MM-DD')
24
24
  canChangeWeekView: false, // 是否可切换周视图,默认(false)
25
- defalutWeekView: false // 是否默认显示周视图,默认(false)
25
+ defalutWeekView: false, // 是否默认显示周视图,默认(false)
26
+ marks: [] // 日期标记,数组形式,默认([])
26
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7beta33",
3
+ "version": "1.2.7beta36",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {