@aochuang/client-sdk 1.0.372 → 1.0.374

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.
@@ -23,7 +23,7 @@
23
23
  ></span>
24
24
  </div>
25
25
  </div>
26
- <div class="sdk-chat-editor-suggestions__body" ref="body">
26
+ <div class="sdk-chat-editor-suggestions__body" ref="body" @scroll="handleBodyScroll">
27
27
  <template v-if="data && data.length">
28
28
  <div class="sdk-chat-editor-suggestions__list">
29
29
  <div
@@ -38,6 +38,9 @@
38
38
  <slot name="item" :data="item"></slot>
39
39
  </div>
40
40
  </div>
41
+ <div class="sdk-chat-editor-suggestions__more" v-if="loadingMore">
42
+ <ui-loading size="mini"></ui-loading>
43
+ </div>
41
44
  </template>
42
45
  </div>
43
46
  <div class="sdk-chat-editor-suggestions__foot">
@@ -68,6 +71,14 @@ export default {
68
71
  type: Boolean,
69
72
  default: false
70
73
  },
74
+ loadingMore: {
75
+ type: Boolean,
76
+ default: false
77
+ },
78
+ hasMore: {
79
+ type: Boolean,
80
+ default: false
81
+ },
71
82
  confirmMethod: {
72
83
  type: Function
73
84
  }
@@ -108,6 +119,15 @@ export default {
108
119
  handleCloseClick () {
109
120
  this.closed = true
110
121
  },
122
+ handleBodyScroll (evt) {
123
+ if (!this.hasMore || this.loadingMore) {
124
+ return
125
+ }
126
+ const target = evt.target
127
+ if (target.scrollHeight - target.scrollTop - target.clientHeight <= 20) {
128
+ this.$emit('load-more')
129
+ }
130
+ },
111
131
  handleItemMouseEnter (item) {
112
132
  this.focusId = item.id
113
133
  },
@@ -163,6 +183,12 @@ export default {
163
183
  // 向下
164
184
  if (evt.keyCode === 40) {
165
185
  evt.preventDefault()
186
+ if (this.hasMore && !this.loadingMore && index >= this.data.length - 2) {
187
+ this.$emit('load-more')
188
+ }
189
+ if (this.hasMore && index === this.data.length - 1) {
190
+ return
191
+ }
166
192
  const nextIndex = index + 1 > this.data.length - 1 ? 0 : index + 1
167
193
  this.focusId = this.data[nextIndex].id
168
194
  this.scrollTo(this.focusId)
@@ -180,7 +206,7 @@ export default {
180
206
  checkAutoFocus () {
181
207
  if (!this.data || !this.data.length) {
182
208
  this.focusId = null
183
- } else {
209
+ } else if (!this.focusId || !this.data.some(item => item.id === this.focusId)) {
184
210
  this.focusId = this.data[0].id
185
211
  }
186
212
  },
@@ -341,4 +367,10 @@ export default {
341
367
  .sdk-chat-editor-suggestions__item.is-focus:after {
342
368
  opacity: 1;
343
369
  }
370
+ .sdk-chat-editor-suggestions__more {
371
+ height: 32px;
372
+ display: flex;
373
+ align-items: center;
374
+ justify-content: center;
375
+ }
344
376
  </style>
@@ -46,9 +46,12 @@
46
46
  ref="suggestions"
47
47
  :keyword="suggestionsKeyword"
48
48
  :loading="suggestioning"
49
+ :loading-more="suggestionsLoadingMore"
50
+ :has-more="suggestionsHasMore"
49
51
  :data="suggestionsData"
50
52
  :confirm-method="handleSuggestionsConfirmMethod"
51
53
  @closed="handleSuggestionsClosed"
54
+ @load-more="handleSuggestionsLoadMore"
52
55
  >
53
56
  <template slot="item" slot-scope="scope">
54
57
  <slot name="suggestions-item" v-bind="scope"></slot>
@@ -83,6 +86,9 @@ export default {
83
86
  fetchSuggestionsMethod: {
84
87
  type: Function
85
88
  },
89
+ fetchMoreSuggestionsMethod: {
90
+ type: Function
91
+ },
86
92
  confirmSuggestionsMethod: {
87
93
  type: Function
88
94
  },
@@ -99,6 +105,8 @@ export default {
99
105
  sending: false,
100
106
  popoverActive: false,
101
107
  suggestioning: false,
108
+ suggestionsLoadingMore: false,
109
+ suggestionsHasMore: false,
102
110
  suggestionsData: [],
103
111
  suggestionsKeyword: null,
104
112
  inputValue: this.value || ''
@@ -127,6 +135,8 @@ export default {
127
135
  },
128
136
  handleSuggestionsClosed () {
129
137
  this.suggestionsData = []
138
+ this.suggestionsHasMore = false
139
+ this.suggestionsLoadingMore = false
130
140
  },
131
141
  handleSuggestionsConfirmMethod ({ item }) {
132
142
  const next = () => {
@@ -263,6 +273,9 @@ export default {
263
273
  const requestId = (this._suggestionsRequestId || 0) + 1
264
274
  this._suggestionsRequestId = requestId
265
275
  this.suggestioning = true
276
+ this.suggestionsLoadingMore = false
277
+ this.suggestionsHasMore = false
278
+ this.suggestionsData = []
266
279
  this.suggestionsKeyword = keyword
267
280
  this.popoverActive = true
268
281
  clearTimeout(this._loadSuggestionsTimer)
@@ -274,13 +287,60 @@ export default {
274
287
  if (requestId !== this._suggestionsRequestId) {
275
288
  return
276
289
  }
277
- this.suggestionsData = rs || []
290
+ const result = this.normalizeSuggestionsResult(rs)
291
+ this.suggestionsData = result.items
292
+ this.suggestionsHasMore = result.hasMore
278
293
  }).finally(() => {
279
294
  if (requestId === this._suggestionsRequestId) {
280
295
  this.suggestioning = false
281
296
  }
282
297
  })
283
298
  },
299
+ handleSuggestionsLoadMore () {
300
+ if (!this.fetchMoreSuggestionsMethod || !this.suggestionsHasMore || this.suggestionsLoadingMore) {
301
+ return
302
+ }
303
+ const requestId = this._suggestionsRequestId
304
+ const keyword = this.suggestionsKeyword
305
+ const nearestInfo = this.suggestionsNearsetInfo
306
+ this.suggestionsLoadingMore = true
307
+ return Promise.resolve(this.fetchMoreSuggestionsMethod({
308
+ keyword,
309
+ nearestInfo,
310
+ isAtContext: !!(nearestInfo && nearestInfo.isAtContext),
311
+ data: this.suggestionsData.slice()
312
+ })).then(rs => {
313
+ if (requestId !== this._suggestionsRequestId || keyword !== this.suggestionsKeyword) {
314
+ return
315
+ }
316
+ const result = this.normalizeSuggestionsResult(rs)
317
+ const ids = new Set(this.suggestionsData.map(item => item && item.id))
318
+ this.suggestionsData = this.suggestionsData.concat(result.items.filter(item => {
319
+ if (!item || ids.has(item.id)) {
320
+ return false
321
+ }
322
+ ids.add(item.id)
323
+ return true
324
+ }))
325
+ this.suggestionsHasMore = result.hasMore
326
+ }).finally(() => {
327
+ if (requestId === this._suggestionsRequestId) {
328
+ this.suggestionsLoadingMore = false
329
+ }
330
+ })
331
+ },
332
+ normalizeSuggestionsResult (result) {
333
+ if (Array.isArray(result)) {
334
+ return {
335
+ items: result,
336
+ hasMore: false
337
+ }
338
+ }
339
+ return {
340
+ items: result && Array.isArray(result.items) ? result.items : [],
341
+ hasMore: !!(result && result.hasMore)
342
+ }
343
+ },
284
344
  normalizeSuggestionsKeyword (nearestInfo, keyword) {
285
345
  const nearest = keyword === undefined
286
346
  ? (nearestInfo && nearestInfo.nearest) || ''
@@ -294,6 +354,8 @@ export default {
294
354
  this._suggestionsRequestId = (this._suggestionsRequestId || 0) + 1
295
355
  this.$refs.suggestions && this.$refs.suggestions.close()
296
356
  this.suggestioning = false
357
+ this.suggestionsLoadingMore = false
358
+ this.suggestionsHasMore = false
297
359
  this.popoverActive = false
298
360
  },
299
361
  hasCurrentSuggestionsContext () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/client-sdk",
3
- "version": "1.0.372",
3
+ "version": "1.0.374",
4
4
  "description": "",
5
5
  "files": [
6
6
  "common",