sadais-piui 1.2.7-beta85 → 1.2.7-beta87

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.
@@ -16,6 +16,7 @@
16
16
  @close="handlePopupClose"
17
17
  @cancel="handleCancel"
18
18
  @confirm="handleConfirm"
19
+ @showed="handlePopupShow"
19
20
  >
20
21
  <view
21
22
  class="pi-cascader pi-h-100P pi-flex-column"
@@ -27,7 +28,7 @@
27
28
  <!-- 顶部面包屑 -->
28
29
  <scroll-view class="node-breadcrumb pi-solid-bottom-1" scroll-x>
29
30
  <view
30
- v-for="(item, index) in pathItems"
31
+ v-for="(item, index) in allPathItems"
31
32
  :key="index"
32
33
  class="breadcrumb-item"
33
34
  @click="handleClickItem(item)"
@@ -92,7 +93,7 @@
92
93
  </scroll-view>
93
94
  </scroll-view>
94
95
  <!-- 已选区域 -->
95
- <view class="cascader-area">
96
+ <view v-if="!isSingle" class="cascader-area">
96
97
  <text>{{ `已选(${selectedIds.length})` }}</text>
97
98
  <scroll-view class="scroll-area" scroll-x>
98
99
  <view
@@ -108,6 +109,31 @@
108
109
  </view>
109
110
  </scroll-view>
110
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 pathItems"
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
+ :class="{
129
+ active: currentItem && currentItem[keyField] === item[keyField]
130
+ }"
131
+ >
132
+ {{ item[displayField] }}
133
+ </view>
134
+ </view>
135
+ </scroll-view>
136
+ </view>
111
137
  </view>
112
138
  <slot name="footer" />
113
139
  </view>
@@ -116,7 +142,6 @@
116
142
 
117
143
  <script>
118
144
  import ValueSync from '../../mixin/value-sync'
119
- import cloneDeep from 'lodash/cloneDeep'
120
145
  import { getConfig } from '../../config'
121
146
 
122
147
  const TAG = 'PiCascader'
@@ -227,11 +252,11 @@ export default {
227
252
  }
228
253
  return {
229
254
  rootItem,
230
- currentItem: cloneDeep(rootItem),
255
+ currentItem: this.$pi.lang.cloneDeep(rootItem),
231
256
  innerItems: [],
232
257
  itemsMap: {}, // 已选数据id索引
233
258
  selectedIds: [], // 已选数据
234
- cascaderWidth: 0, // 容器宽度
259
+ cascaderWidth: this.$pi.system.systemInfo.screenWidth, // 容器宽度
235
260
  scrollLeft: 0 // 视图左侧滚动区域,自动对齐到选择的栏目
236
261
  }
237
262
  },
@@ -303,12 +328,15 @@ export default {
303
328
  p = this.itemsMap[p.pid]
304
329
  }
305
330
  }
331
+ return pathItems
332
+ },
333
+ allPathItems() {
306
334
  return [
307
335
  {
308
336
  [this.displayField]: '全部',
309
337
  [this.keyField]: 'ROOT'
310
338
  }
311
- ].concat(pathItems)
339
+ ].concat(this.pathItems)
312
340
  }
313
341
  },
314
342
  watch: {
@@ -386,7 +414,7 @@ export default {
386
414
  handleClickItem(item) {
387
415
  // 点击全部
388
416
  if (item[this.keyField] === ROOT_NODE) {
389
- this.currentItem = cloneDeep(this.rootItem)
417
+ this.currentItem = this.$pi.lang.cloneDeep(this.rootItem)
390
418
  this.$nextTick(this.syncScrollLeft)
391
419
  return
392
420
  }
@@ -419,11 +447,16 @@ export default {
419
447
  this.selectedIds.push(item[this.keyField])
420
448
  }
421
449
  },
450
+ handlePopupShow() {
451
+ this.$emit('showd')
452
+ this.syncScrollLeft()
453
+ },
422
454
  async syncScrollLeft() {
423
455
  // 调用此方法的时候,必须使用$nextTick,因为column是动态变化的,需要等待界面更新渲染后,才能正确设置scrollLeft的位置
424
456
  let scrollLeft = 0
425
457
  if (this.cascaderWidth === 0) {
426
- const srollWrapRect = await this.$pi.common.queryRect(this, '.pi-cascader', false)
458
+ const srollWrapRect = await this.$pi.common.queryRect(this, '.cascader-wrap', false)
459
+ console.log(this, srollWrapRect)
427
460
  if (srollWrapRect) {
428
461
  this.cascaderWidth = srollWrapRect.width
429
462
  }
@@ -515,6 +548,7 @@ export default {
515
548
  .node-breadcrumb {
516
549
  width: 100%;
517
550
  padding-left: 32rpx;
551
+ padding-right: 32rpx;
518
552
  background: #ffffff;
519
553
  white-space: nowrap;
520
554
  .breadcrumb-item {
@@ -14,7 +14,6 @@
14
14
  'animation-duration': getDuration.css
15
15
  }
16
16
  ]"
17
-
18
17
  @tap.stop.prevent="handleCloseMask"
19
18
  >
20
19
  <view
@@ -15,6 +15,7 @@
15
15
  :z-index="getPopup.zIndex"
16
16
  :background="getPopup.background"
17
17
  @show="$emit('show')"
18
+ @showed="$emit('showed')"
18
19
  @close="handlePopupClose"
19
20
  >
20
21
  <view class="pi-popup-select pi-flex-column" :style="[customStyle]" :class="[customClass]">
@@ -17,7 +17,7 @@
17
17
  @cancel="handleCancel"
18
18
  @confirm="handleConfirm"
19
19
  @closed="$emit('closed', $event)"
20
- @show="$emit('show', $event)"
20
+ @show="handleShowEvent"
21
21
  @showed="$emit('showed', $event)"
22
22
  >
23
23
  <view class="pi-select pi-h-100P pi-flex-column" :style="[customStyle]" :class="[customClass]">
@@ -39,11 +39,23 @@
39
39
  />
40
40
  </view>
41
41
  </view>
42
+ <view v-if="getRemoteSearchConfig.enable && getRemoteSearchConfig.filter" class="pi-pd-lr-24">
43
+ <pi-search
44
+ v-model="keyword"
45
+ :placeholder="getRemoteSearchConfig.filterPlaceholder"
46
+ show-action
47
+ :action-text="getRemoteSearchConfig.filterAction"
48
+ @search="handleKeywordSearch"
49
+ @clear="handleKeywordSearch"
50
+ @action="handleKeywordSearch"
51
+ />
52
+ </view>
42
53
  <scroll-view
43
54
  scroll-y
44
55
  class="pi-scroll"
45
56
  :scroll-into-view="getFirstSelectedId"
46
57
  scroll-with-animation
58
+ @scrolltolower="handleScrolltolower"
47
59
  >
48
60
  <view
49
61
  v-for="item in getItems"
@@ -116,6 +128,8 @@ import { getConfig } from '../../config'
116
128
  const TAG = 'PiSelect'
117
129
  const { select } = getConfig()
118
130
 
131
+ const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
132
+
119
133
  export default {
120
134
  name: 'PiSelect',
121
135
  // 混入v-model
@@ -267,12 +281,34 @@ export default {
267
281
  // 参照popup
268
282
  return select.popup
269
283
  }
284
+ },
285
+ // 远程搜索配置
286
+ remoteSearchConfig: {
287
+ type: Object,
288
+ default() {
289
+ return select.remoteSearchConfig
290
+ }
291
+ },
292
+ // 远程搜索结果解析钩子
293
+ parseRemoteSearchResult: {
294
+ type: [Object, Function],
295
+ default() {
296
+ return {
297
+ [PI_DEFAULT_FN_FLAG]: true,
298
+ fn: select.parseRemoteSearchResult
299
+ }
300
+ }
270
301
  }
271
302
  },
272
303
  data() {
273
304
  return {
274
305
  // 当前选中的值
275
- selected: {}
306
+ selected: {},
307
+ keyword: '',
308
+ remoteItems: [],
309
+ remoteLoading: false,
310
+ pageNo: 1,
311
+ isEnd: false
276
312
  }
277
313
  },
278
314
  computed: {
@@ -282,6 +318,9 @@ export default {
282
318
  getSelectedCheckbox() {
283
319
  return this.$pi.lang.mergeDeep(select.selectedCheckbox, this.selectedCheckbox)
284
320
  },
321
+ getRemoteSearchConfig() {
322
+ return this.$pi.lang.mergeDeep(select.remoteSearchConfig, this.remoteSearchConfig)
323
+ },
285
324
  getPopupSelect() {
286
325
  const popupSelect = this.$pi.lang.mergeDeep(select.popupSelect, this.popupSelect)
287
326
  if (!this.singleCancel && this.singleConfirm) {
@@ -310,7 +349,8 @@ export default {
310
349
  }
311
350
  },
312
351
  getItems() {
313
- return this.items.map(item => {
352
+ const targetItems = this.remoteSearchConfig.enable ? this.remoteItems : this.items
353
+ return targetItems.map(item => {
314
354
  let isSelected = false
315
355
  if (this.isMulti) {
316
356
  isSelected =
@@ -487,6 +527,55 @@ export default {
487
527
  if (this.isMulti) {
488
528
  this.selected = this.isSelectAll ? [] : [...this.items]
489
529
  }
530
+ },
531
+ handleShowEvent() {
532
+ console.log('打开窗口', this.getRemoteSearchConfig.enable)
533
+ this.$emit('show')
534
+ if (!this.getRemoteSearchConfig.enable) return
535
+ this.keyword = ''
536
+ this.handleResetRemoteSearch()
537
+ this.handleRemoteSearch()
538
+ },
539
+ handleResetRemoteSearch() {
540
+ this.pageNo = 1
541
+ this.isEnd = false
542
+ this.remoteItems = []
543
+ },
544
+ handleKeywordSearch() {
545
+ this.handleResetRemoteSearch()
546
+ this.handleRemoteSearch()
547
+ },
548
+ handleScrolltolower() {
549
+ console.log('滚动触底了', this.getRemoteSearchConfig.enable, this.isEnd)
550
+ if (!this.getRemoteSearchConfig.enable) return
551
+ if (this.isEnd) return
552
+ this.handleRemoteSearch()
553
+ },
554
+ async handleRemoteSearch() {
555
+ if (this.remoteLoading) return
556
+ const parseRemoteSearchResult = this.parseRemoteSearchResult[PI_DEFAULT_FN_FLAG]
557
+ ? this.parseRemoteSearchResult.fn
558
+ : this.parseRemoteSearchResult
559
+ this.remoteLoading = true
560
+ this.$loading()
561
+ const items = await parseRemoteSearchResult(
562
+ this.pageNo,
563
+ this.getRemoteSearchConfig.pageSize,
564
+ this.keyword
565
+ )
566
+ this.remoteLoading = false
567
+ this.$hideLoading()
568
+ if (!this.$pi.lang.isArray(items)) {
569
+ console.error(TAG, items, '远程搜索结果必须为数组类型')
570
+ return
571
+ }
572
+ console.log('远程搜索结果', items)
573
+ this.pageNo++
574
+ // 判断页码
575
+ if (items?.length < this.getRemoteSearchConfig.pageSize) {
576
+ this.isEnd = true
577
+ }
578
+ this.remoteItems = this.remoteItems.concat(items)
490
579
  }
491
580
  }
492
581
  }
@@ -1,10 +1,10 @@
1
1
  <!--
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2022-05-18 11:08:49
4
- * @LastEditTime: 2023-09-02 11:40:02
4
+ * @LastEditTime: 2023-12-05 09:41:08
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 选择输入
7
- * @FilePath: \piui-awesome\src\piui\components\pi-select-input\index.vue
7
+ * @FilePath: /piui-awesome/src/piui/components/pi-select-input/index.vue
8
8
  -->
9
9
 
10
10
  <template>
@@ -48,6 +48,7 @@
48
48
 
49
49
  <!-- 选择弹出框 -->
50
50
  <pi-select
51
+ ref="pi-select"
51
52
  v-model="show"
52
53
  :default-value="val"
53
54
  :key-default-value="getSelect.keyDefaultValue"
@@ -68,6 +69,8 @@
68
69
  :popup="getSelect.popup"
69
70
  :confirm-btn="getSelect.confirmBtn"
70
71
  :cancel-btn="getSelect.cancelBtn"
72
+ :remote-search-config="getSelect.remoteSearchConfig"
73
+ :parse-remote-search-result="getSelect.parseRemoteSearchResult"
71
74
  @confirm="handleSelectConfirm"
72
75
  @close="$emit('close', $event)"
73
76
  @closed="$emit('closed', $event)"
@@ -165,27 +168,28 @@ export default {
165
168
  return parseValue
166
169
  }
167
170
  if (this.$pi.lang.isEmpty(this.val)) return ''
171
+ const getItems = this.$refs['pi-select']?.getItems || this.getSelect.items
168
172
  if (this.getSelect.keyDefaultValue) {
169
173
  if (this.getSelect.isMulti) {
170
- return this.getSelect.items
174
+ return getItems
171
175
  .filter(item => this.val.includes(item[this.getSelect.keyField]))
172
176
  .map(item => item[this.getSelect.displayField])
173
177
  .join(this.rangeSplit)
174
178
  } else {
175
- const val = this.getSelect.items.find(item => item[this.getSelect.keyField] === this.val)
179
+ const val = getItems.find(item => item[this.getSelect.keyField] === this.val)
176
180
  return val ? val[this.getSelect.displayField] : ''
177
181
  }
178
182
  } else {
179
183
  // 这里需要从items再次获取,防止用户设置的默认值没有设置displayField的情况
180
184
  if (this.getSelect.isMulti) {
181
- return this.getSelect.items
185
+ return getItems
182
186
  .filter(item =>
183
187
  this.val.some(v => v[this.getSelect.keyField] === item[this.getSelect.keyField])
184
188
  )
185
189
  .map(item => item[this.getSelect.displayField])
186
190
  .join(this.rangeSplit)
187
191
  } else {
188
- const val = this.getSelect.items.find(
192
+ const val = getItems.find(
189
193
  item => item[this.getSelect.keyField] === this.val[this.getSelect.keyField]
190
194
  )
191
195
  return val ? val[this.getSelect.displayField] : ''
package/config/select.js CHANGED
@@ -27,5 +27,15 @@ export default {
27
27
  popupSelect: popupSelect, // popupSelect配置
28
28
  popup: popupSelect.popup, // 弹窗的配置,默认选项请参照popup
29
29
  confirmBtn: popupSelect.confirmBtn, // 确认按钮配置
30
- cancelBtn: popupSelect.cancelBtn // 取消按钮配置
30
+ cancelBtn: popupSelect.cancelBtn, // 取消按钮配置
31
+ remoteSearchConfig: {
32
+ // 远程搜索配置
33
+ enable: false, // 是否开启远程搜索
34
+ filter: false, // 是否支持筛选
35
+ filterPlaceholder: '请输入关键字', // 筛选框占位符
36
+ filterAction: '搜索',
37
+ filterKey: 'name', // 筛选字段
38
+ pageSize: 20 // 每页数量
39
+ },
40
+ parseRemoteSearchResult: null // 远程搜索结果解析钩子
31
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta85",
3
+ "version": "1.2.7-beta87",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {