sadais-piui 1.2.7-beta35 → 1.2.7-beta38

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.
@@ -1,7 +1,7 @@
1
1
  <!--
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2022-06-28 16:53:54
4
- * @LastEditTime: 2022-08-19 17:25:53
4
+ * @LastEditTime: 2022-08-23 11:45:24
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 日历日期数据
7
7
  * @FilePath: /dt-weitibao-console/Users/feilin/workspace/piui/piui-awesome/src/piui/components/pi-calendar-panel/components/calendar-days/index.vue
@@ -361,7 +361,7 @@ export default {
361
361
  return
362
362
  }
363
363
  // 处理范围选择方式
364
- if (this.calendarValue.length === 2) {
364
+ if (this.calendarValue.length === 0 || this.calendarValue.length === 2) {
365
365
  // 如果选了两项,则重新开始选择范围
366
366
  this.handleChange([date])
367
367
  } else {
@@ -232,8 +232,8 @@ export default {
232
232
  const now = this.$pi.date.parseDate()
233
233
  return {
234
234
  now: now, // 当前时间
235
- year: '', // 年份
236
- month: '', // 月份
235
+ year: now.year, // 年份
236
+ month: now.month, // 月份
237
237
  week: 1, // 当前周
238
238
  calendarValue: '',
239
239
  currentTabIndex: 1, // 当前选中的tab索引
@@ -278,24 +278,25 @@ export default {
278
278
  this.init()
279
279
  },
280
280
  methods: {
281
- valid() {
282
- if (this.type === 'date') return true
283
- if (this.type === 'range' && this.$pi.lang.isArray(this.value) && this.value.length === 2)
284
- return true
285
- return false
286
- },
287
281
  init() {
288
282
  console.log(TAG, '组件初始化', this.value)
289
- if (!this.valid()) return
290
283
  let initValue = this.value
291
284
  const nowDate = this.$pi.date.parseDate(this.type === 'date' ? this.value : this.value[0])
292
285
  if (this.type === 'range') {
293
- const endDate = this.$pi.date.parseDate(this.value[1])
294
- 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
+
295
297
  this.year = nowDate.year
296
298
  this.month = nowDate.month
297
299
  }
298
- initValue = [nowDate, endDate]
299
300
  } else {
300
301
  this.year = nowDate.year
301
302
  this.month = nowDate.month
@@ -0,0 +1,493 @@
1
+ <template>
2
+ <pi-popup-select
3
+ :value="val"
4
+ :custom-style="getPopupSelect.customStyle"
5
+ :custom-class="getPopupSelect.customClass"
6
+ :height="getPopupSelect.height"
7
+ :show-title="getPopupSelect.showTitle"
8
+ :title="getPopupSelect.title"
9
+ :title-padding="getPopupSelect.titlePadding"
10
+ :toolbar-position="getPopupSelect.toolbarPosition"
11
+ :on-confirm-close="getPopupSelect.onConfirmClose"
12
+ :on-cancel-close="getPopupSelect.onCancelClose"
13
+ :confirm-btn="getConfirmBtn"
14
+ :cancel-btn="getCancelBtn"
15
+ :popup="getPopup"
16
+ @close="handlePopupClose"
17
+ @cancel="handleCancel"
18
+ @confirm="handleConfirm"
19
+ >
20
+ <view
21
+ class="pi-cascader pi-h-100P pi-flex-column"
22
+ :style="[customStyle]"
23
+ :class="[customClass]"
24
+ >
25
+ <slot name="header" />
26
+ <view class="cascader-wrap pi-flex-sub pi-flex-column">
27
+ <!-- 顶部面包屑 -->
28
+ <scroll-view class="node-breadcrumb pi-solid-bottom-1" scroll-x>
29
+ <view
30
+ v-for="(item, index) in pathItems"
31
+ :key="index"
32
+ class="breadcrumb-item"
33
+ @click="handleClickItem(item)"
34
+ >
35
+ <pi-icon v-if="item[keyField] !== ROOT_NODE" name="right" custom-class="pi-mg-lr-6" />
36
+ <view
37
+ class="breadcrumb-item-title"
38
+ :class="{
39
+ active: currentItem && currentItem[keyField] === item[keyField]
40
+ }"
41
+ >
42
+ {{ item[displayField] }}
43
+ </view>
44
+ </view>
45
+ </scroll-view>
46
+ <!-- 选择区域 -->
47
+ <scroll-view class="scroll-view" :scroll-left="scrollLeft" scroll-x scroll-with-animation>
48
+ <scroll-view
49
+ v-for="(col, index) of columns"
50
+ :key="index"
51
+ scroll-y
52
+ class="column"
53
+ :style="[{ width: isOnlyColumn ? '100%' : '50%' }]"
54
+ >
55
+ <view
56
+ v-for="item in col"
57
+ :key="item[keyField]"
58
+ class="column-item pi-align-center"
59
+ :class="{
60
+ active: activeIds.includes(item[keyField]),
61
+ selected: selectedIds.includes(item[keyField])
62
+ }"
63
+ @click="handleClickItem(item)"
64
+ >
65
+ <view class="pi-flex-sub pi-lh-36">
66
+ <slot name="item" :item="item">
67
+ {{ item[displayField] || '' }}
68
+ </slot>
69
+ </view>
70
+ <pi-icon v-if="selectedIds.includes(item[keyField])" name="blod-check" />
71
+ <pi-icon v-if="item[childrenField] && item[childrenField].length > 0" name="right" />
72
+ </view>
73
+ </scroll-view>
74
+ </scroll-view>
75
+ <!-- 已选区域 -->
76
+ <view class="cascader-area">
77
+ <text>{{ `已选(${selectedIds.length})` }}</text>
78
+ <scroll-view class="scroll-area" scroll-x>
79
+ <view
80
+ v-for="id in selectedIds"
81
+ :key="id"
82
+ class="cascader-item"
83
+ @tap="handleRemoveItem(id)"
84
+ >
85
+ <text class="pi-mg-right-12">{{ itemsMap[id][displayField] }}</text>
86
+ <pi-icon name="close" />
87
+ </view>
88
+ </scroll-view>
89
+ </view>
90
+ </view>
91
+ <slot name="footer" />
92
+ </view>
93
+ </pi-popup-select>
94
+ </template>
95
+
96
+ <script>
97
+ import ValueSync from '../../mixin/value-sync'
98
+ import cloneDeep from 'lodash/cloneDeep'
99
+ import { getConfig } from '../../config'
100
+
101
+ const TAG = 'PiCascader'
102
+ const ROOT_NODE = 'ROOT'
103
+ const { cascader } = getConfig()
104
+
105
+ export default {
106
+ name: 'PiCascader',
107
+ // 混入v-model
108
+ mixins: [ValueSync],
109
+ props: {
110
+ // 初始值
111
+ value: {
112
+ required: false
113
+ },
114
+ // 自定义样式
115
+ customStyle: {
116
+ type: Object,
117
+ // {}
118
+ default() {
119
+ return cascader.customStyle
120
+ }
121
+ },
122
+ // 自定义样式类
123
+ customClass: {
124
+ type: String,
125
+ // ''
126
+ default() {
127
+ return cascader.customClass
128
+ }
129
+ },
130
+ // 数据源
131
+ items: {
132
+ type: Array,
133
+ default() {
134
+ return []
135
+ }
136
+ },
137
+ defaultValue: {
138
+ type: Array,
139
+ default: () => []
140
+ },
141
+ // 列表选项的唯一标识
142
+ keyField: {
143
+ type: String,
144
+ // 'id'
145
+ default: cascader.keyField
146
+ },
147
+ // 选项显示字段
148
+ displayField: {
149
+ type: String,
150
+ // 'text'
151
+ default: cascader.displayField
152
+ },
153
+ // children字段,默认为desc
154
+ childrenField: {
155
+ type: String,
156
+ // 'children'
157
+ default: cascader.childrenField
158
+ },
159
+ // 弹窗选择参数设置
160
+ popupSelect: {
161
+ type: Object,
162
+ default() {
163
+ // 参照popupSelect
164
+ return cascader.popupSelect
165
+ }
166
+ },
167
+ // 确认按钮配置
168
+ confirmBtn: {
169
+ type: Object,
170
+ default() {
171
+ return cascader.confirmBtn
172
+ }
173
+ },
174
+ // 取消按钮配置
175
+ cancelBtn: {
176
+ type: Object,
177
+ default() {
178
+ return cascader.cancelBtn
179
+ }
180
+ },
181
+ // 弹窗参数设置
182
+ popup: {
183
+ type: Object,
184
+ default() {
185
+ // 参照popup
186
+ return cascader.popup
187
+ }
188
+ }
189
+ },
190
+ data() {
191
+ const rootItem = {
192
+ [this.displayField]: '全部',
193
+ [this.keyField]: ROOT_NODE
194
+ }
195
+ return {
196
+ rootItem,
197
+ currentItem: cloneDeep(rootItem),
198
+ innerItems: [],
199
+ itemsMap: {}, // 已选数据id索引
200
+ selectedIds: [], // 已选数据
201
+ cascaderWidth: 0, // 容器宽度
202
+ scrollLeft: 0 // 视图左侧滚动区域,自动对齐到选择的栏目
203
+ }
204
+ },
205
+ computed: {
206
+ ROOT_NODE() {
207
+ return ROOT_NODE
208
+ },
209
+ getPopupSelect() {
210
+ const popupSelect = this.$pi.lang.mergeDeep(cascader.popupSelect, this.popupSelect)
211
+ if (!this.singleCancel && this.singleConfirm) {
212
+ popupSelect.toolbarPosition = 'none'
213
+ }
214
+ return popupSelect
215
+ },
216
+ getConfirmBtn() {
217
+ const cascaderConfirmBtn = this.$pi.lang.mergeDeep(
218
+ cascader.confirmBtn,
219
+ this.popupSelect.confirmBtn
220
+ )
221
+ return this.$pi.lang.mergeDeep(cascaderConfirmBtn, this.confirmBtn)
222
+ },
223
+ getCancelBtn() {
224
+ const cascaderCancelBtn = this.$pi.lang.mergeDeep(
225
+ cascader.cancelBtn,
226
+ this.popupSelect.cancelBtn
227
+ )
228
+ return this.$pi.lang.mergeDeep(cascaderCancelBtn, this.cancelBtn)
229
+ },
230
+ getPopup() {
231
+ const cascaderPopup = this.$pi.lang.mergeDeep(cascader.popup, this.popupSelect.popup)
232
+ return this.$pi.lang.mergeDeep(cascaderPopup, this.popup)
233
+ },
234
+ getItemStyle() {
235
+ return {
236
+ height: this.$pi.common.addUnit(this.itemHeight)
237
+ }
238
+ },
239
+ columns() {
240
+ let columns = []
241
+ if (this.currentItem) {
242
+ // 如果有当前显示的节点,往上找父节点下的所有children放到数组的前面
243
+ let p = this.currentItem
244
+ while (p) {
245
+ const children = p[this.childrenField] || []
246
+ if (children.length > 0) {
247
+ columns.unshift(children)
248
+ }
249
+ p = p.pid ? this.itemsMap[p.pid] : undefined
250
+ }
251
+ columns.unshift(this.innerItems)
252
+ } else {
253
+ columns = [this.innerItems]
254
+ }
255
+ return columns
256
+ },
257
+ isOnlyColumn() {
258
+ return this.columns.length === 1
259
+ },
260
+ activeIds() {
261
+ return this.pathItems.map(i => i[this.keyField])
262
+ },
263
+ pathItems() {
264
+ const pathItems = []
265
+ if (this.currentItem[this.keyField] !== ROOT_NODE) {
266
+ // 往上找构建完整路径
267
+ let p = this.currentItem
268
+ while (p) {
269
+ pathItems.unshift(p)
270
+ p = this.itemsMap[p.pid]
271
+ }
272
+ }
273
+ return [
274
+ {
275
+ [this.displayField]: '全部',
276
+ [this.keyField]: 'ROOT'
277
+ }
278
+ ].concat(pathItems)
279
+ },
280
+ syncIds() {
281
+ return `${this.innerItems.length}-${this.defaultValue.length}`
282
+ }
283
+ },
284
+ watch: {
285
+ items: {
286
+ immediate: true,
287
+ handler() {
288
+ this.rebuildItems()
289
+ }
290
+ }
291
+ },
292
+
293
+ methods: {
294
+ rebuildItems() {
295
+ /**
296
+ * 以非递归的方式 深度拷贝items 且建立父子节点关系
297
+ * 目的为了不影响外部传入的prop: items
298
+ * 写成非递归的目的 是为了防止树的层次太深,
299
+ * 递归调用太多次,导致栈溢出
300
+ */
301
+ const innerItems = []
302
+ // 初始化堆栈 为items的根节点
303
+ const stack = [...this.items]
304
+ const itemsMap = {}
305
+ while (stack.length > 0) {
306
+ // 将栈顶元素出栈进行处理
307
+ let item = stack.shift()
308
+ if (!item.pid) {
309
+ item = {
310
+ ...item,
311
+ level: 0
312
+ }
313
+ innerItems.push(item)
314
+ }
315
+ const children = item[this.childrenField] || []
316
+ const newChilds = []
317
+ for (let i = children.length - 1; i >= 0; i--) {
318
+ // 浅拷贝子孩子
319
+ const subItem = {
320
+ ...children[i],
321
+ level: item.level + 1
322
+ }
323
+ // 建立父子关系
324
+ subItem.pid = item[this.keyField]
325
+ // 放置到新数组中
326
+ newChilds.unshift(subItem)
327
+ // 入栈 模拟递归效果 等待之后的while循环出栈进行处理
328
+ stack.unshift(subItem)
329
+ }
330
+ // 更新children 为新的数组
331
+ item[this.childrenField] = newChilds
332
+ itemsMap[item[this.keyField]] = item
333
+ }
334
+ // 此时的innerItems无论怎么修改 均不影响items
335
+ this.innerItems = innerItems
336
+ // 方便通过节点的id 为key快速定位到对应的节点dto
337
+ this.itemsMap = itemsMap
338
+ },
339
+ handleRemoveItem(id) {
340
+ this.selectedIds = this.selectedIds.filter(i => i !== id)
341
+ },
342
+ handleClickItem(item) {
343
+ if (item[this.keyField] === ROOT_NODE) {
344
+ this.currentItem = cloneDeep(this.rootItem)
345
+ this.$nextTick(this.syncScrollLeft)
346
+ return
347
+ }
348
+ if (
349
+ item &&
350
+ item[this.childrenField]?.length &&
351
+ this.currentItem[this.keyField] !== item[this.keyField]
352
+ ) {
353
+ this.currentItem = item
354
+ this.$nextTick(this.syncScrollLeft)
355
+ return
356
+ }
357
+ if (item && item[this.childrenField]?.length === 0) {
358
+ // 点击的是叶子节点
359
+ if (this.selectedIds.includes(item[this.keyField])) {
360
+ this.handleRemoveItem(item[this.keyField])
361
+ } else {
362
+ // 选中
363
+ this.selectedIds.push(item[this.keyField])
364
+ }
365
+ }
366
+ },
367
+ async syncScrollLeft() {
368
+ // 调用此方法的时候,必须使用$nextTick,因为column是动态变化的,需要等待界面更新渲染后,才能正确设置scrollLeft的位置
369
+ let scrollLeft = 0
370
+ if (this.cascaderWidth === 0) {
371
+ const srollWrapRect = await this.$pi.common.queryRect(this, '.pi-cascader', false)
372
+ if (srollWrapRect) {
373
+ this.cascaderWidth = srollWrapRect.width
374
+ }
375
+ }
376
+ if (this.columns.length > 2) {
377
+ scrollLeft = (this.columns.length - 2) * (this.cascaderWidth / 2)
378
+ }
379
+ this.scrollLeft = scrollLeft
380
+ },
381
+ handlePopupClose() {
382
+ this.val = false
383
+ // 关闭弹窗
384
+ this.$emit('close')
385
+ this.handleEmitChange()
386
+ },
387
+ /**
388
+ * @vuese
389
+ * 根据id获取item
390
+ */
391
+ getItemByKeyField(keyField) {
392
+ return this.itemsMap[keyField]
393
+ },
394
+ /**
395
+ * @vuese
396
+ * 取消选择
397
+ */
398
+ handleCancel() {
399
+ this.$emit('cancel')
400
+ this.getPopupSelect.onCancelClose && this.handlePopupClose()
401
+ },
402
+ /**
403
+ * @vuese
404
+ * 确认选择
405
+ */
406
+ handleConfirm() {
407
+ this.$emit('confirm', this.selectedIds)
408
+ this.getPopupSelect.onConfirmClose && this.handlePopupClose()
409
+ }
410
+ }
411
+ }
412
+ </script>
413
+
414
+ <style lang="scss" scoped>
415
+ .cascader-wrap {
416
+ width: 100%;
417
+ height: 100%;
418
+ background: #f4f2f6;
419
+ }
420
+ .scroll-view {
421
+ width: 100%;
422
+ flex: 1;
423
+ white-space: nowrap;
424
+ overflow: auto hidden;
425
+ .column {
426
+ display: inline-block;
427
+ height: 100%;
428
+ width: 50%;
429
+ overflow: hidden auto;
430
+ &:last-child {
431
+ background: #ffffff;
432
+ }
433
+ .column-item {
434
+ position: relative;
435
+ height: 100rpx;
436
+ width: 100%;
437
+ white-space: initial;
438
+ padding: 0 16rpx 0 32rpx;
439
+ font-size: 28rpx;
440
+ color: #333333;
441
+ overflow: hidden;
442
+ &.active {
443
+ color: $pi-primary-color;
444
+ background: #ffffff;
445
+ }
446
+ &.selected {
447
+ color: $pi-primary-color;
448
+ }
449
+ }
450
+ }
451
+ }
452
+
453
+ .node-breadcrumb {
454
+ width: 100%;
455
+ padding-left: 32rpx;
456
+ background: #ffffff;
457
+ white-space: nowrap;
458
+ .breadcrumb-item {
459
+ display: inline-flex;
460
+ align-items: center;
461
+ font-size: 14px;
462
+ padding: 32rpx 0;
463
+
464
+ .breadcrumb-item-title.active {
465
+ color: $pi-primary-color;
466
+ }
467
+ }
468
+ }
469
+
470
+ .cascader-area {
471
+ background: #ffffff;
472
+ padding: 22rpx 24rpx;
473
+ color: #333333;
474
+ display: flex;
475
+ align-items: center;
476
+ white-space: nowrap;
477
+
478
+ .scroll-area {
479
+ width: calc(100% - 128rpx);
480
+ flex: 1;
481
+ white-space: nowrap;
482
+ }
483
+ .cascader-item {
484
+ display: inline-flex;
485
+ padding: 14rpx 24rpx;
486
+ background: rgba($pi-primary-color, 0.1);
487
+ align-items: center;
488
+ margin-left: 16rpx;
489
+ border-radius: 8rpx;
490
+ color: $pi-primary-color;
491
+ }
492
+ }
493
+ </style>
@@ -0,0 +1,21 @@
1
+ import popupSelect from './popupSelect'
2
+
3
+ export default {
4
+ customClass: '', // 自定义样式类,字符串形式('')
5
+ customStyle: {}, // 自定义样式,对象形式(默认值:{})
6
+ items: [], // 选项列表,默认([])
7
+ keyField: 'id', // 选项id字段,默认为id
8
+ displayField: 'text', // 选项显示字段,默认为text
9
+ childrenField: 'children', // 描述显示字段,默认为children
10
+ defaultValue: null, // 默认值,单选是传Object,多选时传Array,默认null
11
+ itemHeight: 110, // 行高(默认:'110rpx')
12
+ showItemBottomBorder: false, // 是否显示item下边框(默认:'true')
13
+ itemStyle: {}, // 行样式(默认:'{}')
14
+ popupSelect: popupSelect, // popupSelect配置
15
+ popup: popupSelect.popup, // 弹窗的配置,默认选项请参照popup
16
+ confirmBtn: popupSelect.confirmBtn, // 确认按钮配置
17
+ cancelBtn: {
18
+ ...popupSelect.cancelBtn,
19
+ show: true
20
+ } // 取消按钮配置
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7beta35",
3
+ "version": "1.2.7beta38",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {