sadais-piui 1.2.7-beta113 → 1.2.7-beta115

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.
Files changed (160) hide show
  1. package/.prettierrc +7 -7
  2. package/CHANGELOG.md +545 -545
  3. package/LICENSE +20 -20
  4. package/README.md +166 -166
  5. package/components/pi-action-sheet/index.vue +247 -247
  6. package/components/pi-badge/index.vue +146 -146
  7. package/components/pi-bottom-bar/index.vue +139 -139
  8. package/components/pi-bubble/index.vue +174 -174
  9. package/components/pi-button/index.vue +492 -492
  10. package/components/pi-calendar-input/index.vue +230 -230
  11. package/components/pi-calendar-panel/components/calendar-days/index.vue +410 -410
  12. package/components/pi-calendar-panel/index.vue +473 -473
  13. package/components/pi-canvas/index.vue +407 -407
  14. package/components/pi-card/index.vue +127 -127
  15. package/components/pi-cascader/index.vue +601 -601
  16. package/components/pi-checkbox/index.vue +363 -363
  17. package/components/pi-checkbox-group/index.vue +222 -222
  18. package/components/pi-circle-progress/index.vue +311 -311
  19. package/components/pi-code-input/index.vue +270 -270
  20. package/components/pi-collapse/index.vue +124 -124
  21. package/components/pi-collapse-item/index.vue +352 -352
  22. package/components/pi-count-down/index.vue +245 -245
  23. package/components/pi-count-up/index.vue +209 -209
  24. package/components/pi-date-picker-input/index.vue +219 -219
  25. package/components/pi-divider/index.vue +112 -112
  26. package/components/pi-dropdown/components/dropdown-tab.vue +71 -71
  27. package/components/pi-dropdown/index.vue +356 -356
  28. package/components/pi-dropdown-item/index.vue +252 -252
  29. package/components/pi-form/index.vue +273 -273
  30. package/components/pi-form-item/index.vue +603 -590
  31. package/components/pi-gap/index.vue +72 -72
  32. package/components/pi-grid/index.vue +92 -92
  33. package/components/pi-grid-item/index.vue +220 -220
  34. package/components/pi-icon/index.vue +147 -147
  35. package/components/pi-img/index.vue +266 -266
  36. package/components/pi-img-cropper/canvas.js +106 -106
  37. package/components/pi-img-cropper/index.vue +357 -357
  38. package/components/pi-img-cropper/touch.js +163 -163
  39. package/components/pi-img-cropper/vector.js +34 -34
  40. package/components/pi-input/index.vue +409 -401
  41. package/components/pi-line/index.vue +78 -78
  42. package/components/pi-line-progress/index.vue +198 -198
  43. package/components/pi-list/index.vue +115 -115
  44. package/components/pi-list-item/index.vue +335 -335
  45. package/components/pi-loading/index.vue +188 -188
  46. package/components/pi-marquee/index.vue +310 -310
  47. package/components/pi-marquee-item/index.vue +47 -47
  48. package/components/pi-mask/index.vue +198 -198
  49. package/components/pi-modal/index.vue +303 -303
  50. package/components/pi-navbar/index.vue +421 -421
  51. package/components/pi-notify/index.vue +239 -239
  52. package/components/pi-number-keyboard/index.vue +189 -189
  53. package/components/pi-opentype-button/index.vue +501 -501
  54. package/components/pi-pagination/index.vue +290 -290
  55. package/components/pi-picker/index.vue +317 -317
  56. package/components/pi-popup/index.vue +356 -356
  57. package/components/pi-popup-select/index.vue +300 -300
  58. package/components/pi-radio/index.vue +403 -403
  59. package/components/pi-radio-group/index.vue +300 -300
  60. package/components/pi-rate/index.vue +212 -212
  61. package/components/pi-regions-select/index.vue +349 -349
  62. package/components/pi-regions-select-input/index.vue +230 -230
  63. package/components/pi-search/index.vue +386 -386
  64. package/components/pi-section/index.vue +218 -218
  65. package/components/pi-select/index.vue +678 -678
  66. package/components/pi-select-input/index.vue +273 -273
  67. package/components/pi-skeleton/index.vue +280 -280
  68. package/components/pi-status-bar/index.vue +56 -56
  69. package/components/pi-stepper/index.vue +408 -408
  70. package/components/pi-steps/index.vue +378 -378
  71. package/components/pi-subsection/index.vue +403 -403
  72. package/components/pi-swiper/index.vue +344 -344
  73. package/components/pi-switch/index.vue +231 -231
  74. package/components/pi-table/index.vue +351 -351
  75. package/components/pi-tabs/index.vue +435 -435
  76. package/components/pi-tag/index.vue +488 -488
  77. package/components/pi-upload-img/index.vue +980 -980
  78. package/components/pi-waterfall/index.vue +130 -130
  79. package/config/actionSheet.js +24 -24
  80. package/config/badge.js +9 -9
  81. package/config/bottomBar.js +11 -11
  82. package/config/bubble.js +6 -6
  83. package/config/button.js +29 -29
  84. package/config/calendar.js +19 -19
  85. package/config/calendarInput.js +19 -19
  86. package/config/calendarPanel.js +27 -27
  87. package/config/card.js +8 -8
  88. package/config/cascader.js +22 -22
  89. package/config/checkbox.js +15 -15
  90. package/config/checkboxGroup.js +15 -15
  91. package/config/circleProgress.js +20 -20
  92. package/config/codeInput.js +13 -13
  93. package/config/collapse.js +7 -7
  94. package/config/collapseItem.js +11 -11
  95. package/config/countDown.js +12 -12
  96. package/config/countUp.js +13 -13
  97. package/config/datePickerInput.js +18 -18
  98. package/config/divider.js +10 -10
  99. package/config/dropdown.js +25 -25
  100. package/config/dropdownItem.js +26 -26
  101. package/config/form.js +29 -29
  102. package/config/formItem.js +27 -27
  103. package/config/gap.js +8 -8
  104. package/config/grid.js +9 -9
  105. package/config/gridItem.js +12 -12
  106. package/config/icon.js +11 -11
  107. package/config/img.js +21 -21
  108. package/config/imgCropper.js +26 -26
  109. package/config/index.js +28 -28
  110. package/config/input.js +37 -36
  111. package/config/line.js +8 -8
  112. package/config/lineProgress.js +14 -14
  113. package/config/list.js +12 -12
  114. package/config/listItem.js +25 -25
  115. package/config/loading.js +10 -10
  116. package/config/marquee.js +10 -10
  117. package/config/mask.js +12 -12
  118. package/config/modal.js +36 -36
  119. package/config/navbar.js +32 -32
  120. package/config/notify.js +13 -13
  121. package/config/numberKeyboard.js +21 -21
  122. package/config/pagination.js +10 -10
  123. package/config/picker.js +19 -19
  124. package/config/popup.js +23 -23
  125. package/config/popupSelect.js +35 -35
  126. package/config/radio.js +16 -16
  127. package/config/radioGroup.js +17 -17
  128. package/config/rate.js +15 -15
  129. package/config/regionsData.js +58 -58
  130. package/config/regionsSelect.js +19 -19
  131. package/config/regionsSelectInput.js +29 -29
  132. package/config/search.js +27 -27
  133. package/config/section.js +23 -23
  134. package/config/select.js +41 -41
  135. package/config/selectInput.js +29 -29
  136. package/config/skeleton.js +13 -13
  137. package/config/statusBar.js +5 -5
  138. package/config/stepper.js +19 -19
  139. package/config/steps.js +19 -19
  140. package/config/subsection.js +14 -14
  141. package/config/swiper.js +22 -22
  142. package/config/switch.js +13 -13
  143. package/config/table.js +8 -8
  144. package/config/tabs.js +23 -23
  145. package/config/tag.js +21 -21
  146. package/config/uploadImg.js +81 -81
  147. package/config/waterfall.js +6 -6
  148. package/index.js +41 -41
  149. package/mixin/component-custom.js +24 -24
  150. package/mixin/emitter.js +45 -45
  151. package/mixin/props-sync.js +65 -65
  152. package/mixin/value-sync.js +32 -32
  153. package/mixin/wx-code.js +30 -30
  154. package/package.json +28 -28
  155. package/plugins/async-validator.js +1511 -1511
  156. package/scss/animation.scss +260 -260
  157. package/scss/icon/icon.scss +595 -595
  158. package/scss/index.scss +5 -5
  159. package/scss/mixin.scss +47 -47
  160. package/tools/index.js +19 -19
@@ -1,601 +1,601 @@
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
- @showed="handlePopupShow"
20
- >
21
- <view
22
- class="pi-cascader pi-h-100P pi-flex-column"
23
- :style="[customStyle]"
24
- :class="[customClass]"
25
- >
26
- <slot name="header" />
27
- <view class="cascader-wrap pi-flex-sub pi-flex-column">
28
- <!-- 顶部面包屑 -->
29
- <scroll-view class="node-breadcrumb pi-solid-bottom-1" scroll-x>
30
- <view
31
- v-for="(item, index) in pathItems"
32
- :key="index"
33
- class="breadcrumb-item"
34
- @click="handleClickItem(item)"
35
- >
36
- <pi-icon v-if="item[keyField] !== ROOT_NODE" name="right" custom-class="pi-mg-lr-6" />
37
- <view
38
- class="breadcrumb-item-title"
39
- :class="{
40
- active: currentItem && currentItem[keyField] === item[keyField]
41
- }"
42
- >
43
- {{ item[displayField] }}
44
- </view>
45
- </view>
46
- </scroll-view>
47
- <!-- 选择区域 -->
48
- <scroll-view class="scroll-view" :scroll-left="scrollLeft" scroll-x scroll-with-animation>
49
- <scroll-view
50
- v-for="(col, index) of columns"
51
- :key="index"
52
- scroll-y
53
- class="column"
54
- :style="[{ width: isOnlyColumn ? '100%' : '50%' }]"
55
- >
56
- <view
57
- v-for="item in col"
58
- :key="item[keyField]"
59
- class="column-item pi-align-center"
60
- :class="{
61
- active: activeIds.includes(item[keyField]),
62
- selected: selectedIds.includes(item[keyField])
63
- }"
64
- >
65
- <view class="pi-flex-sub column-item-inner">
66
- <slot name="item" :item="item">
67
- <view class="pi-align-center column-item-inner">
68
- <pi-checkbox
69
- v-if="parentCanSelect"
70
- :value="selectedIds.includes(item[keyField])"
71
- shape="round"
72
- active-mode="fill-circle"
73
- class="pi-mg-right-16"
74
- @change="handleChangeParentSelect(item, $event)"
75
- />
76
- <view class="pi-align-center pi-lh-36 pi-flex-sub column-item-inner" @click="handleClickItem(item)">
77
- {{ item[displayField] || '' }}
78
- </view>
79
- </view>
80
- </slot>
81
- </view>
82
- <pi-icon
83
- v-if="!parentCanSelect && selectedIds.includes(item[keyField])"
84
- name="blod-check"
85
- size="36"
86
- />
87
- <pi-icon
88
- v-if="item[childrenField] && item[childrenField].length > 0"
89
- name="right"
90
- @click="handleClickItem(item)"
91
- />
92
- </view>
93
- </scroll-view>
94
- </scroll-view>
95
- <!-- 已选区域 -->
96
- <view v-if="!isSingle" class="cascader-area">
97
- <text>{{ `已选(${selectedIds.length})` }}</text>
98
- <scroll-view class="scroll-area" scroll-x>
99
- <view
100
- v-for="id in selectedIds"
101
- :key="id"
102
- class="cascader-item"
103
- @tap="handleRemoveItem(id)"
104
- >
105
- <text class="pi-mg-right-12">
106
- {{ itemsMap && itemsMap[id] && itemsMap[id][displayField] }}
107
- </text>
108
- <pi-icon name="close" />
109
- </view>
110
- </scroll-view>
111
- </view>
112
- <view v-else class="cascader-area">
113
- <text>已选:</text>
114
- <scroll-view
115
- class="node-breadcrumb pi-solid-bottom-1"
116
- scroll-x
117
- style="flex: 1;padding-left: 0;overflow: hidden;"
118
- >
119
- <view
120
- v-for="(item, index) in currentPathItems"
121
- :key="index"
122
- class="breadcrumb-item"
123
- @click="handleClickItem(item)"
124
- >
125
- <pi-icon v-if="index > 0" name="right" custom-class="pi-mg-lr-6" />
126
- <view
127
- class="breadcrumb-item-title"
128
- >
129
- {{ item[displayField] }}
130
- </view>
131
- </view>
132
- </scroll-view>
133
- </view>
134
- </view>
135
- <slot name="footer" />
136
- </view>
137
- </pi-popup-select>
138
- </template>
139
-
140
- <script>
141
- import ValueSync from '../../mixin/value-sync'
142
- import { getConfig } from '../../config'
143
-
144
- const TAG = 'PiCascader'
145
- const ROOT_NODE = 'ROOT'
146
- const { cascader } = getConfig()
147
-
148
- export default {
149
- name: 'PiCascader',
150
- // 混入v-model
151
- mixins: [ValueSync],
152
- props: {
153
- // 初始值
154
- value: {
155
- required: false
156
- },
157
- // 自定义样式
158
- customStyle: {
159
- type: Object,
160
- // {}
161
- default() {
162
- return cascader.customStyle
163
- }
164
- },
165
- // 自定义样式类
166
- customClass: {
167
- type: String,
168
- // ''
169
- default() {
170
- return cascader.customClass
171
- }
172
- },
173
- // 数据源
174
- items: {
175
- type: Array,
176
- default() {
177
- return []
178
- }
179
- },
180
- defaultValue: {
181
- type: [Array, String, Number],
182
- default: () => []
183
- },
184
- // 列表选项的唯一标识
185
- keyField: {
186
- type: String,
187
- // 'id'
188
- default: cascader.keyField
189
- },
190
- // 选项显示字段
191
- displayField: {
192
- type: String,
193
- // 'text'
194
- default: cascader.displayField
195
- },
196
- // children字段,默认为desc
197
- childrenField: {
198
- type: String,
199
- // 'children'
200
- default: cascader.childrenField
201
- },
202
- // 父节点是否可选(默认:'false')
203
- parentCanSelect: {
204
- type: Boolean,
205
- // false
206
- default: cascader.parentCanSelect
207
- },
208
- // 是否单选(默认:'false')
209
- isSingle: {
210
- type: Boolean,
211
- // false
212
- default: cascader.isSingle
213
- },
214
- // 弹窗选择参数设置
215
- popupSelect: {
216
- type: Object,
217
- default() {
218
- // 参照popupSelect
219
- return cascader.popupSelect
220
- }
221
- },
222
- // 确认按钮配置
223
- confirmBtn: {
224
- type: Object,
225
- default() {
226
- return cascader.confirmBtn
227
- }
228
- },
229
- // 取消按钮配置
230
- cancelBtn: {
231
- type: Object,
232
- default() {
233
- return cascader.cancelBtn
234
- }
235
- },
236
- // 弹窗参数设置
237
- popup: {
238
- type: Object,
239
- default() {
240
- // 参照popup
241
- return cascader.popup
242
- }
243
- }
244
- },
245
- data() {
246
- const rootItem = {
247
- [this.displayField]: '全部',
248
- [this.keyField]: ROOT_NODE
249
- }
250
- return {
251
- rootItem,
252
- currentItem: this.$pi.lang.cloneDeep(rootItem),
253
- innerItems: [],
254
- itemsMap: {}, // 已选数据id索引
255
- selectedIds: [], // 已选数据
256
- cascaderWidth: this.$pi.system.systemInfo.screenWidth, // 容器宽度
257
- scrollLeft: 0 // 视图左侧滚动区域,自动对齐到选择的栏目
258
- }
259
- },
260
- computed: {
261
- ROOT_NODE() {
262
- return ROOT_NODE
263
- },
264
- getPopupSelect() {
265
- const popupSelect = this.$pi.lang.mergeDeep(cascader.popupSelect, this.popupSelect)
266
- if (!this.singleCancel && this.singleConfirm) {
267
- popupSelect.toolbarPosition = 'none'
268
- }
269
- return popupSelect
270
- },
271
- getConfirmBtn() {
272
- const cascaderConfirmBtn = this.$pi.lang.mergeDeep(
273
- cascader.confirmBtn,
274
- this.popupSelect.confirmBtn
275
- )
276
- return this.$pi.lang.mergeDeep(cascaderConfirmBtn, this.confirmBtn)
277
- },
278
- getCancelBtn() {
279
- const cascaderCancelBtn = this.$pi.lang.mergeDeep(
280
- cascader.cancelBtn,
281
- this.popupSelect.cancelBtn
282
- )
283
- return this.$pi.lang.mergeDeep(cascaderCancelBtn, this.cancelBtn)
284
- },
285
- getPopup() {
286
- const cascaderPopup = this.$pi.lang.mergeDeep(cascader.popup, this.popupSelect.popup)
287
- return this.$pi.lang.mergeDeep(cascaderPopup, this.popup)
288
- },
289
- getItemStyle() {
290
- return {
291
- height: this.$pi.common.addUnit(this.itemHeight)
292
- }
293
- },
294
- columns() {
295
- let columns = []
296
- if (this.currentItem) {
297
- // 如果有当前显示的节点,往上找父节点下的所有children放到数组的前面
298
- let p = this.currentItem
299
- while (p) {
300
- const children = p[this.childrenField] || []
301
- if (children.length > 0) {
302
- columns.unshift(children)
303
- }
304
- p = p.pid ? this.itemsMap[p.pid] : undefined
305
- }
306
- columns.unshift(this.innerItems)
307
- } else {
308
- columns = [this.innerItems]
309
- }
310
- return columns
311
- },
312
- isOnlyColumn() {
313
- return this.columns.length === 1
314
- },
315
- activeIds() {
316
- return this.pathItems.map(i => i[this.keyField])
317
- },
318
- pathItems() {
319
- const pathItems = []
320
- if (this.currentItem[this.keyField] !== ROOT_NODE) {
321
- // 往上找构建完整路径
322
- let p = this.currentItem
323
- while (p) {
324
- pathItems.unshift(p)
325
- p = this.itemsMap[p.pid]
326
- }
327
- }
328
- return [
329
- {
330
- [this.displayField]: '全部',
331
- [this.keyField]: 'ROOT'
332
- }
333
- ].concat(pathItems)
334
- },
335
- currentPathItems() {
336
- const pathItems = []
337
- if (this.isSingle) {
338
- // 往上找构建完整路径
339
- let p = this.itemsMap[this.selectedIds[0]]
340
- while (p) {
341
- pathItems.unshift(p)
342
- p = this.itemsMap[p.pid]
343
- }
344
- }
345
- return pathItems
346
- }
347
- },
348
- watch: {
349
- items: {
350
- immediate: true,
351
- deep: true,
352
- handler() {
353
- this.rebuildItems()
354
- }
355
- },
356
- defaultValue: {
357
- immediate: true,
358
- handler(vals) {
359
- this.selectedIds = this.isSingle ? [vals] : vals
360
- }
361
- }
362
- },
363
-
364
- methods: {
365
- rebuildItems() {
366
- console.log('重建innerItems')
367
- /**
368
- * 以非递归的方式 深度拷贝items 且建立父子节点关系
369
- * 目的为了不影响外部传入的prop: items
370
- * 写成非递归的目的 是为了防止树的层次太深,
371
- * 递归调用太多次,导致栈溢出
372
- */
373
- this.currentItem = this.$pi.lang.cloneDeep(this.rootItem)
374
- const innerItems = []
375
- // 初始化堆栈 为items的根节点
376
- const stack = [...this.items]
377
- const itemsMap = {}
378
- while (stack.length > 0) {
379
- // 将栈顶元素出栈进行处理
380
- let item = stack.shift()
381
- if (!item.pid) {
382
- item = {
383
- ...item,
384
- level: 0
385
- }
386
- innerItems.push(item)
387
- }
388
- const children = item[this.childrenField] || []
389
- const newChilds = []
390
- for (let i = children.length - 1; i >= 0; i--) {
391
- // 浅拷贝子孩子
392
- const subItem = {
393
- ...children[i],
394
- level: item.level + 1
395
- }
396
- // 建立父子关系
397
- subItem.pid = item[this.keyField]
398
- // 放置到新数组中
399
- newChilds.unshift(subItem)
400
- // 入栈 模拟递归效果 等待之后的while循环出栈进行处理
401
- stack.unshift(subItem)
402
- }
403
- // 更新children 为新的数组
404
- item[this.childrenField] = newChilds
405
- itemsMap[item[this.keyField]] = item
406
- }
407
- // 此时的innerItems无论怎么修改 均不影响items
408
- this.innerItems = innerItems
409
- // 方便通过节点的id 为key快速定位到对应的节点dto
410
- this.itemsMap = itemsMap
411
- if (this.currentItem[this.keyField] === ROOT_NODE) {
412
- if (this.isSingle && this.defaultValue) {
413
- this.currentItem = this.getItemByKeyField(this.defaultValue)
414
- }
415
- if (!this.isSingle && this.defaultValue.length > 0) {
416
- this.currentItem = this.getItemByKeyField(this.defaultValue[0])
417
- }
418
- }
419
- },
420
- handleRemoveItem(id) {
421
- this.selectedIds = this.selectedIds.filter(i => i !== id)
422
- },
423
- handleClickItem(item) {
424
- // 点击全部
425
- if (item[this.keyField] === ROOT_NODE) {
426
- this.currentItem = this.$pi.lang.cloneDeep(this.rootItem)
427
- this.$nextTick(this.syncScrollLeft)
428
- return
429
- }
430
- const isLeafNode = !item[this.childrenField] || item[this.childrenField]?.length === 0
431
- // 点击非叶子节点
432
- if (item && !isLeafNode && this.currentItem[this.keyField] !== item[this.keyField]) {
433
- this.currentItem = item
434
- this.$nextTick(this.syncScrollLeft)
435
- return
436
- }
437
- // 点击的是叶子节点
438
- if (isLeafNode) {
439
- if (this.selectedIds.includes(item[this.keyField])) {
440
- this.handleRemoveItem(item[this.keyField])
441
- } else {
442
- // 选中
443
- if (this.isSingle) {
444
- this.selectedIds = [item[this.keyField]]
445
- } else {
446
- this.selectedIds.push(item[this.keyField])
447
- }
448
- }
449
- }
450
- },
451
- handleChangeParentSelect(item, selected) {
452
- if (this.selectedIds.includes(item[this.keyField])) {
453
- this.handleRemoveItem(item[this.keyField])
454
- } else {
455
- // 选中
456
- this.selectedIds.push(item[this.keyField])
457
- }
458
- },
459
- handlePopupShow() {
460
- this.$emit('showd')
461
- this.syncScrollLeft()
462
- },
463
- async syncScrollLeft() {
464
- // 调用此方法的时候,必须使用$nextTick,因为column是动态变化的,需要等待界面更新渲染后,才能正确设置scrollLeft的位置
465
- let scrollLeft = 0
466
- if (this.cascaderWidth === 0) {
467
- const srollWrapRect = await this.$pi.common.queryRect(this, '.cascader-wrap', false)
468
- console.log(this, srollWrapRect)
469
- if (srollWrapRect) {
470
- this.cascaderWidth = srollWrapRect.width
471
- }
472
- }
473
- if (this.columns.length > 2) {
474
- scrollLeft = (this.columns.length - 2) * (this.cascaderWidth / 2)
475
- }
476
- this.scrollLeft = scrollLeft
477
- },
478
- handlePopupClose() {
479
- this.val = false
480
- // 关闭弹窗
481
- this.$emit('close')
482
- this.handleEmitChange()
483
- },
484
- /**
485
- * @vuese
486
- * 根据id获取item
487
- */
488
- getItemByKeyField(keyField) {
489
- return this.itemsMap[keyField]
490
- },
491
- /**
492
- * @vuese
493
- * 取消选择
494
- */
495
- handleCancel() {
496
- this.$emit('cancel')
497
- this.selectedIds = this.isSingle ? [this.defaultValue] : [...this.defaultValue]
498
- this.getPopupSelect.onCancelClose && this.handlePopupClose()
499
- },
500
- /**
501
- * @vuese
502
- * 确认选择
503
- */
504
- handleConfirm() {
505
- this.$emit('confirm', this.isSingle ? this.selectedIds[0] || '' : this.selectedIds)
506
- this.getPopupSelect.onConfirmClose && this.handlePopupClose()
507
- }
508
- }
509
- }
510
- </script>
511
-
512
- <style lang="scss" scoped>
513
- .cascader-wrap {
514
- width: 100%;
515
- height: 100%;
516
- background: #f4f2f6;
517
- }
518
- .scroll-view {
519
- width: 100%;
520
- flex: 1;
521
- white-space: nowrap;
522
- overflow: auto hidden;
523
- .column {
524
- display: inline-block;
525
- height: 100%;
526
- width: 50%;
527
- overflow: hidden auto;
528
- &:last-child {
529
- background: #ffffff;
530
- }
531
- .column-item {
532
- position: relative;
533
- min-height: 100rpx;
534
- width: 100%;
535
- white-space: initial;
536
- padding: 16rpx 32rpx;
537
- font-size: 28rpx;
538
- color: #333333;
539
- overflow: hidden;
540
- .column-item-inner {
541
- min-height: 100rpx;
542
- }
543
- &.active {
544
- color: $pi-primary-color;
545
- background: #ffffff;
546
- ::v-deep .pi-icon-right {
547
- color: #333333;
548
- }
549
- }
550
- &.selected {
551
- color: $pi-primary-color;
552
- ::v-deep .pi-icon-right {
553
- color: #333333;
554
- }
555
- }
556
- }
557
- }
558
- }
559
-
560
- .node-breadcrumb {
561
- width: 100%;
562
- padding-left: 32rpx;
563
- padding-right: 32rpx;
564
- background: #ffffff;
565
- white-space: nowrap;
566
- .breadcrumb-item {
567
- display: inline-flex;
568
- align-items: center;
569
- font-size: 14px;
570
- padding: 32rpx 0;
571
-
572
- .breadcrumb-item-title.active {
573
- color: $pi-primary-color;
574
- }
575
- }
576
- }
577
-
578
- .cascader-area {
579
- background: #ffffff;
580
- padding: 22rpx 24rpx;
581
- color: #333333;
582
- display: flex;
583
- align-items: center;
584
- white-space: nowrap;
585
-
586
- .scroll-area {
587
- width: calc(100% - 128rpx);
588
- flex: 1;
589
- white-space: nowrap;
590
- }
591
- .cascader-item {
592
- display: inline-flex;
593
- padding: 14rpx 24rpx;
594
- background: rgba($pi-primary-color, 0.1);
595
- align-items: center;
596
- margin-left: 16rpx;
597
- border-radius: 8rpx;
598
- color: $pi-primary-color;
599
- }
600
- }
601
- </style>
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
+ @showed="handlePopupShow"
20
+ >
21
+ <view
22
+ class="pi-cascader pi-h-100P pi-flex-column"
23
+ :style="[customStyle]"
24
+ :class="[customClass]"
25
+ >
26
+ <slot name="header" />
27
+ <view class="cascader-wrap pi-flex-sub pi-flex-column">
28
+ <!-- 顶部面包屑 -->
29
+ <scroll-view class="node-breadcrumb pi-solid-bottom-1" scroll-x>
30
+ <view
31
+ v-for="(item, index) in pathItems"
32
+ :key="index"
33
+ class="breadcrumb-item"
34
+ @click="handleClickItem(item)"
35
+ >
36
+ <pi-icon v-if="item[keyField] !== ROOT_NODE" name="right" custom-class="pi-mg-lr-6" />
37
+ <view
38
+ class="breadcrumb-item-title"
39
+ :class="{
40
+ active: currentItem && currentItem[keyField] === item[keyField]
41
+ }"
42
+ >
43
+ {{ item[displayField] }}
44
+ </view>
45
+ </view>
46
+ </scroll-view>
47
+ <!-- 选择区域 -->
48
+ <scroll-view class="scroll-view" :scroll-left="scrollLeft" scroll-x scroll-with-animation>
49
+ <scroll-view
50
+ v-for="(col, index) of columns"
51
+ :key="index"
52
+ scroll-y
53
+ class="column"
54
+ :style="[{ width: isOnlyColumn ? '100%' : '50%' }]"
55
+ >
56
+ <view
57
+ v-for="item in col"
58
+ :key="item[keyField]"
59
+ class="column-item pi-align-center"
60
+ :class="{
61
+ active: activeIds.includes(item[keyField]),
62
+ selected: selectedIds.includes(item[keyField])
63
+ }"
64
+ >
65
+ <view class="pi-flex-sub column-item-inner">
66
+ <slot name="item" :item="item">
67
+ <view class="pi-align-center column-item-inner">
68
+ <pi-checkbox
69
+ v-if="parentCanSelect"
70
+ :value="selectedIds.includes(item[keyField])"
71
+ shape="round"
72
+ active-mode="fill-circle"
73
+ class="pi-mg-right-16"
74
+ @change="handleChangeParentSelect(item, $event)"
75
+ />
76
+ <view class="pi-align-center pi-lh-36 pi-flex-sub column-item-inner" @click="handleClickItem(item)">
77
+ {{ item[displayField] || '' }}
78
+ </view>
79
+ </view>
80
+ </slot>
81
+ </view>
82
+ <pi-icon
83
+ v-if="!parentCanSelect && selectedIds.includes(item[keyField])"
84
+ name="blod-check"
85
+ size="36"
86
+ />
87
+ <pi-icon
88
+ v-if="item[childrenField] && item[childrenField].length > 0"
89
+ name="right"
90
+ @click="handleClickItem(item)"
91
+ />
92
+ </view>
93
+ </scroll-view>
94
+ </scroll-view>
95
+ <!-- 已选区域 -->
96
+ <view v-if="!isSingle" class="cascader-area">
97
+ <text>{{ `已选(${selectedIds.length})` }}</text>
98
+ <scroll-view class="scroll-area" scroll-x>
99
+ <view
100
+ v-for="id in selectedIds"
101
+ :key="id"
102
+ class="cascader-item"
103
+ @tap="handleRemoveItem(id)"
104
+ >
105
+ <text class="pi-mg-right-12">
106
+ {{ itemsMap && itemsMap[id] && itemsMap[id][displayField] }}
107
+ </text>
108
+ <pi-icon name="close" />
109
+ </view>
110
+ </scroll-view>
111
+ </view>
112
+ <view v-else class="cascader-area">
113
+ <text>已选:</text>
114
+ <scroll-view
115
+ class="node-breadcrumb pi-solid-bottom-1"
116
+ scroll-x
117
+ style="flex: 1;padding-left: 0;overflow: hidden;"
118
+ >
119
+ <view
120
+ v-for="(item, index) in currentPathItems"
121
+ :key="index"
122
+ class="breadcrumb-item"
123
+ @click="handleClickItem(item)"
124
+ >
125
+ <pi-icon v-if="index > 0" name="right" custom-class="pi-mg-lr-6" />
126
+ <view
127
+ class="breadcrumb-item-title"
128
+ >
129
+ {{ item[displayField] }}
130
+ </view>
131
+ </view>
132
+ </scroll-view>
133
+ </view>
134
+ </view>
135
+ <slot name="footer" />
136
+ </view>
137
+ </pi-popup-select>
138
+ </template>
139
+
140
+ <script>
141
+ import ValueSync from '../../mixin/value-sync'
142
+ import { getConfig } from '../../config'
143
+
144
+ const TAG = 'PiCascader'
145
+ const ROOT_NODE = 'ROOT'
146
+ const { cascader } = getConfig()
147
+
148
+ export default {
149
+ name: 'PiCascader',
150
+ // 混入v-model
151
+ mixins: [ValueSync],
152
+ props: {
153
+ // 初始值
154
+ value: {
155
+ required: false
156
+ },
157
+ // 自定义样式
158
+ customStyle: {
159
+ type: Object,
160
+ // {}
161
+ default() {
162
+ return cascader.customStyle
163
+ }
164
+ },
165
+ // 自定义样式类
166
+ customClass: {
167
+ type: String,
168
+ // ''
169
+ default() {
170
+ return cascader.customClass
171
+ }
172
+ },
173
+ // 数据源
174
+ items: {
175
+ type: Array,
176
+ default() {
177
+ return []
178
+ }
179
+ },
180
+ defaultValue: {
181
+ type: [Array, String, Number],
182
+ default: () => []
183
+ },
184
+ // 列表选项的唯一标识
185
+ keyField: {
186
+ type: String,
187
+ // 'id'
188
+ default: cascader.keyField
189
+ },
190
+ // 选项显示字段
191
+ displayField: {
192
+ type: String,
193
+ // 'text'
194
+ default: cascader.displayField
195
+ },
196
+ // children字段,默认为desc
197
+ childrenField: {
198
+ type: String,
199
+ // 'children'
200
+ default: cascader.childrenField
201
+ },
202
+ // 父节点是否可选(默认:'false')
203
+ parentCanSelect: {
204
+ type: Boolean,
205
+ // false
206
+ default: cascader.parentCanSelect
207
+ },
208
+ // 是否单选(默认:'false')
209
+ isSingle: {
210
+ type: Boolean,
211
+ // false
212
+ default: cascader.isSingle
213
+ },
214
+ // 弹窗选择参数设置
215
+ popupSelect: {
216
+ type: Object,
217
+ default() {
218
+ // 参照popupSelect
219
+ return cascader.popupSelect
220
+ }
221
+ },
222
+ // 确认按钮配置
223
+ confirmBtn: {
224
+ type: Object,
225
+ default() {
226
+ return cascader.confirmBtn
227
+ }
228
+ },
229
+ // 取消按钮配置
230
+ cancelBtn: {
231
+ type: Object,
232
+ default() {
233
+ return cascader.cancelBtn
234
+ }
235
+ },
236
+ // 弹窗参数设置
237
+ popup: {
238
+ type: Object,
239
+ default() {
240
+ // 参照popup
241
+ return cascader.popup
242
+ }
243
+ }
244
+ },
245
+ data() {
246
+ const rootItem = {
247
+ [this.displayField]: '全部',
248
+ [this.keyField]: ROOT_NODE
249
+ }
250
+ return {
251
+ rootItem,
252
+ currentItem: this.$pi.lang.cloneDeep(rootItem),
253
+ innerItems: [],
254
+ itemsMap: {}, // 已选数据id索引
255
+ selectedIds: [], // 已选数据
256
+ cascaderWidth: this.$pi.system.systemInfo.screenWidth, // 容器宽度
257
+ scrollLeft: 0 // 视图左侧滚动区域,自动对齐到选择的栏目
258
+ }
259
+ },
260
+ computed: {
261
+ ROOT_NODE() {
262
+ return ROOT_NODE
263
+ },
264
+ getPopupSelect() {
265
+ const popupSelect = this.$pi.lang.mergeDeep(cascader.popupSelect, this.popupSelect)
266
+ if (!this.singleCancel && this.singleConfirm) {
267
+ popupSelect.toolbarPosition = 'none'
268
+ }
269
+ return popupSelect
270
+ },
271
+ getConfirmBtn() {
272
+ const cascaderConfirmBtn = this.$pi.lang.mergeDeep(
273
+ cascader.confirmBtn,
274
+ this.popupSelect.confirmBtn
275
+ )
276
+ return this.$pi.lang.mergeDeep(cascaderConfirmBtn, this.confirmBtn)
277
+ },
278
+ getCancelBtn() {
279
+ const cascaderCancelBtn = this.$pi.lang.mergeDeep(
280
+ cascader.cancelBtn,
281
+ this.popupSelect.cancelBtn
282
+ )
283
+ return this.$pi.lang.mergeDeep(cascaderCancelBtn, this.cancelBtn)
284
+ },
285
+ getPopup() {
286
+ const cascaderPopup = this.$pi.lang.mergeDeep(cascader.popup, this.popupSelect.popup)
287
+ return this.$pi.lang.mergeDeep(cascaderPopup, this.popup)
288
+ },
289
+ getItemStyle() {
290
+ return {
291
+ height: this.$pi.common.addUnit(this.itemHeight)
292
+ }
293
+ },
294
+ columns() {
295
+ let columns = []
296
+ if (this.currentItem) {
297
+ // 如果有当前显示的节点,往上找父节点下的所有children放到数组的前面
298
+ let p = this.currentItem
299
+ while (p) {
300
+ const children = p[this.childrenField] || []
301
+ if (children.length > 0) {
302
+ columns.unshift(children)
303
+ }
304
+ p = p.pid ? this.itemsMap[p.pid] : undefined
305
+ }
306
+ columns.unshift(this.innerItems)
307
+ } else {
308
+ columns = [this.innerItems]
309
+ }
310
+ return columns
311
+ },
312
+ isOnlyColumn() {
313
+ return this.columns.length === 1
314
+ },
315
+ activeIds() {
316
+ return this.pathItems.map(i => i[this.keyField])
317
+ },
318
+ pathItems() {
319
+ const pathItems = []
320
+ if (this.currentItem[this.keyField] !== ROOT_NODE) {
321
+ // 往上找构建完整路径
322
+ let p = this.currentItem
323
+ while (p) {
324
+ pathItems.unshift(p)
325
+ p = this.itemsMap[p.pid]
326
+ }
327
+ }
328
+ return [
329
+ {
330
+ [this.displayField]: '全部',
331
+ [this.keyField]: 'ROOT'
332
+ }
333
+ ].concat(pathItems)
334
+ },
335
+ currentPathItems() {
336
+ const pathItems = []
337
+ if (this.isSingle) {
338
+ // 往上找构建完整路径
339
+ let p = this.itemsMap[this.selectedIds[0]]
340
+ while (p) {
341
+ pathItems.unshift(p)
342
+ p = this.itemsMap[p.pid]
343
+ }
344
+ }
345
+ return pathItems
346
+ }
347
+ },
348
+ watch: {
349
+ items: {
350
+ immediate: true,
351
+ deep: true,
352
+ handler() {
353
+ this.rebuildItems()
354
+ }
355
+ },
356
+ defaultValue: {
357
+ immediate: true,
358
+ handler(vals) {
359
+ this.selectedIds = this.isSingle ? [vals] : vals
360
+ }
361
+ }
362
+ },
363
+
364
+ methods: {
365
+ rebuildItems() {
366
+ console.log('重建innerItems')
367
+ /**
368
+ * 以非递归的方式 深度拷贝items 且建立父子节点关系
369
+ * 目的为了不影响外部传入的prop: items
370
+ * 写成非递归的目的 是为了防止树的层次太深,
371
+ * 递归调用太多次,导致栈溢出
372
+ */
373
+ this.currentItem = this.$pi.lang.cloneDeep(this.rootItem)
374
+ const innerItems = []
375
+ // 初始化堆栈 为items的根节点
376
+ const stack = [...this.items]
377
+ const itemsMap = {}
378
+ while (stack.length > 0) {
379
+ // 将栈顶元素出栈进行处理
380
+ let item = stack.shift()
381
+ if (!item.pid) {
382
+ item = {
383
+ ...item,
384
+ level: 0
385
+ }
386
+ innerItems.push(item)
387
+ }
388
+ const children = item[this.childrenField] || []
389
+ const newChilds = []
390
+ for (let i = children.length - 1; i >= 0; i--) {
391
+ // 浅拷贝子孩子
392
+ const subItem = {
393
+ ...children[i],
394
+ level: item.level + 1
395
+ }
396
+ // 建立父子关系
397
+ subItem.pid = item[this.keyField]
398
+ // 放置到新数组中
399
+ newChilds.unshift(subItem)
400
+ // 入栈 模拟递归效果 等待之后的while循环出栈进行处理
401
+ stack.unshift(subItem)
402
+ }
403
+ // 更新children 为新的数组
404
+ item[this.childrenField] = newChilds
405
+ itemsMap[item[this.keyField]] = item
406
+ }
407
+ // 此时的innerItems无论怎么修改 均不影响items
408
+ this.innerItems = innerItems
409
+ // 方便通过节点的id 为key快速定位到对应的节点dto
410
+ this.itemsMap = itemsMap
411
+ if (this.currentItem[this.keyField] === ROOT_NODE) {
412
+ if (this.isSingle && this.defaultValue) {
413
+ this.currentItem = this.getItemByKeyField(this.defaultValue)
414
+ }
415
+ if (!this.isSingle && this.defaultValue.length > 0) {
416
+ this.currentItem = this.getItemByKeyField(this.defaultValue[0])
417
+ }
418
+ }
419
+ },
420
+ handleRemoveItem(id) {
421
+ this.selectedIds = this.selectedIds.filter(i => i !== id)
422
+ },
423
+ handleClickItem(item) {
424
+ // 点击全部
425
+ if (item[this.keyField] === ROOT_NODE) {
426
+ this.currentItem = this.$pi.lang.cloneDeep(this.rootItem)
427
+ this.$nextTick(this.syncScrollLeft)
428
+ return
429
+ }
430
+ const isLeafNode = !item[this.childrenField] || item[this.childrenField]?.length === 0
431
+ // 点击非叶子节点
432
+ if (item && !isLeafNode && this.currentItem[this.keyField] !== item[this.keyField]) {
433
+ this.currentItem = item
434
+ this.$nextTick(this.syncScrollLeft)
435
+ return
436
+ }
437
+ // 点击的是叶子节点
438
+ if (isLeafNode) {
439
+ if (this.selectedIds.includes(item[this.keyField])) {
440
+ this.handleRemoveItem(item[this.keyField])
441
+ } else {
442
+ // 选中
443
+ if (this.isSingle) {
444
+ this.selectedIds = [item[this.keyField]]
445
+ } else {
446
+ this.selectedIds.push(item[this.keyField])
447
+ }
448
+ }
449
+ }
450
+ },
451
+ handleChangeParentSelect(item, selected) {
452
+ if (this.selectedIds.includes(item[this.keyField])) {
453
+ this.handleRemoveItem(item[this.keyField])
454
+ } else {
455
+ // 选中
456
+ this.selectedIds.push(item[this.keyField])
457
+ }
458
+ },
459
+ handlePopupShow() {
460
+ this.$emit('showd')
461
+ this.syncScrollLeft()
462
+ },
463
+ async syncScrollLeft() {
464
+ // 调用此方法的时候,必须使用$nextTick,因为column是动态变化的,需要等待界面更新渲染后,才能正确设置scrollLeft的位置
465
+ let scrollLeft = 0
466
+ if (this.cascaderWidth === 0) {
467
+ const srollWrapRect = await this.$pi.common.queryRect(this, '.cascader-wrap', false)
468
+ console.log(this, srollWrapRect)
469
+ if (srollWrapRect) {
470
+ this.cascaderWidth = srollWrapRect.width
471
+ }
472
+ }
473
+ if (this.columns.length > 2) {
474
+ scrollLeft = (this.columns.length - 2) * (this.cascaderWidth / 2)
475
+ }
476
+ this.scrollLeft = scrollLeft
477
+ },
478
+ handlePopupClose() {
479
+ this.val = false
480
+ // 关闭弹窗
481
+ this.$emit('close')
482
+ this.handleEmitChange()
483
+ },
484
+ /**
485
+ * @vuese
486
+ * 根据id获取item
487
+ */
488
+ getItemByKeyField(keyField) {
489
+ return this.itemsMap[keyField]
490
+ },
491
+ /**
492
+ * @vuese
493
+ * 取消选择
494
+ */
495
+ handleCancel() {
496
+ this.$emit('cancel')
497
+ this.selectedIds = this.isSingle ? [this.defaultValue] : [...this.defaultValue]
498
+ this.getPopupSelect.onCancelClose && this.handlePopupClose()
499
+ },
500
+ /**
501
+ * @vuese
502
+ * 确认选择
503
+ */
504
+ handleConfirm() {
505
+ this.$emit('confirm', this.isSingle ? this.selectedIds[0] || '' : this.selectedIds)
506
+ this.getPopupSelect.onConfirmClose && this.handlePopupClose()
507
+ }
508
+ }
509
+ }
510
+ </script>
511
+
512
+ <style lang="scss" scoped>
513
+ .cascader-wrap {
514
+ width: 100%;
515
+ height: 100%;
516
+ background: #f4f2f6;
517
+ }
518
+ .scroll-view {
519
+ width: 100%;
520
+ flex: 1;
521
+ white-space: nowrap;
522
+ overflow: auto hidden;
523
+ .column {
524
+ display: inline-block;
525
+ height: 100%;
526
+ width: 50%;
527
+ overflow: hidden auto;
528
+ &:last-child {
529
+ background: #ffffff;
530
+ }
531
+ .column-item {
532
+ position: relative;
533
+ min-height: 100rpx;
534
+ width: 100%;
535
+ white-space: initial;
536
+ padding: 16rpx 32rpx;
537
+ font-size: 28rpx;
538
+ color: #333333;
539
+ overflow: hidden;
540
+ .column-item-inner {
541
+ min-height: 100rpx;
542
+ }
543
+ &.active {
544
+ color: $pi-primary-color;
545
+ background: #ffffff;
546
+ ::v-deep .pi-icon-right {
547
+ color: #333333;
548
+ }
549
+ }
550
+ &.selected {
551
+ color: $pi-primary-color;
552
+ ::v-deep .pi-icon-right {
553
+ color: #333333;
554
+ }
555
+ }
556
+ }
557
+ }
558
+ }
559
+
560
+ .node-breadcrumb {
561
+ width: 100%;
562
+ padding-left: 32rpx;
563
+ padding-right: 32rpx;
564
+ background: #ffffff;
565
+ white-space: nowrap;
566
+ .breadcrumb-item {
567
+ display: inline-flex;
568
+ align-items: center;
569
+ font-size: 14px;
570
+ padding: 32rpx 0;
571
+
572
+ .breadcrumb-item-title.active {
573
+ color: $pi-primary-color;
574
+ }
575
+ }
576
+ }
577
+
578
+ .cascader-area {
579
+ background: #ffffff;
580
+ padding: 22rpx 24rpx;
581
+ color: #333333;
582
+ display: flex;
583
+ align-items: center;
584
+ white-space: nowrap;
585
+
586
+ .scroll-area {
587
+ width: calc(100% - 128rpx);
588
+ flex: 1;
589
+ white-space: nowrap;
590
+ }
591
+ .cascader-item {
592
+ display: inline-flex;
593
+ padding: 14rpx 24rpx;
594
+ background: rgba($pi-primary-color, 0.1);
595
+ align-items: center;
596
+ margin-left: 16rpx;
597
+ border-radius: 8rpx;
598
+ color: $pi-primary-color;
599
+ }
600
+ }
601
+ </style>