sadais-piui 1.2.7-beta85 → 1.2.7-beta86

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.
@@ -116,7 +116,6 @@
116
116
 
117
117
  <script>
118
118
  import ValueSync from '../../mixin/value-sync'
119
- import cloneDeep from 'lodash/cloneDeep'
120
119
  import { getConfig } from '../../config'
121
120
 
122
121
  const TAG = 'PiCascader'
@@ -227,7 +226,7 @@ export default {
227
226
  }
228
227
  return {
229
228
  rootItem,
230
- currentItem: cloneDeep(rootItem),
229
+ currentItem: this.$pi.lang.cloneDeep(rootItem),
231
230
  innerItems: [],
232
231
  itemsMap: {}, // 已选数据id索引
233
232
  selectedIds: [], // 已选数据
@@ -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-beta86",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {