@aochuang/client-sdk 1.0.372 → 1.0.373

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
  },
@@ -180,7 +200,7 @@ export default {
180
200
  checkAutoFocus () {
181
201
  if (!this.data || !this.data.length) {
182
202
  this.focusId = null
183
- } else {
203
+ } else if (!this.focusId || !this.data.some(item => item.id === this.focusId)) {
184
204
  this.focusId = this.data[0].id
185
205
  }
186
206
  },
@@ -341,4 +361,10 @@ export default {
341
361
  .sdk-chat-editor-suggestions__item.is-focus:after {
342
362
  opacity: 1;
343
363
  }
364
+ .sdk-chat-editor-suggestions__more {
365
+ height: 32px;
366
+ display: flex;
367
+ align-items: center;
368
+ justify-content: center;
369
+ }
344
370
  </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,8 @@ 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
266
278
  this.suggestionsKeyword = keyword
267
279
  this.popoverActive = true
268
280
  clearTimeout(this._loadSuggestionsTimer)
@@ -274,13 +286,60 @@ export default {
274
286
  if (requestId !== this._suggestionsRequestId) {
275
287
  return
276
288
  }
277
- this.suggestionsData = rs || []
289
+ const result = this.normalizeSuggestionsResult(rs)
290
+ this.suggestionsData = result.items
291
+ this.suggestionsHasMore = result.hasMore
278
292
  }).finally(() => {
279
293
  if (requestId === this._suggestionsRequestId) {
280
294
  this.suggestioning = false
281
295
  }
282
296
  })
283
297
  },
298
+ handleSuggestionsLoadMore () {
299
+ if (!this.fetchMoreSuggestionsMethod || !this.suggestionsHasMore || this.suggestionsLoadingMore) {
300
+ return
301
+ }
302
+ const requestId = this._suggestionsRequestId
303
+ const keyword = this.suggestionsKeyword
304
+ const nearestInfo = this.suggestionsNearsetInfo
305
+ this.suggestionsLoadingMore = true
306
+ return Promise.resolve(this.fetchMoreSuggestionsMethod({
307
+ keyword,
308
+ nearestInfo,
309
+ isAtContext: !!(nearestInfo && nearestInfo.isAtContext),
310
+ data: this.suggestionsData.slice()
311
+ })).then(rs => {
312
+ if (requestId !== this._suggestionsRequestId || keyword !== this.suggestionsKeyword) {
313
+ return
314
+ }
315
+ const result = this.normalizeSuggestionsResult(rs)
316
+ const ids = new Set(this.suggestionsData.map(item => item && item.id))
317
+ this.suggestionsData = this.suggestionsData.concat(result.items.filter(item => {
318
+ if (!item || ids.has(item.id)) {
319
+ return false
320
+ }
321
+ ids.add(item.id)
322
+ return true
323
+ }))
324
+ this.suggestionsHasMore = result.hasMore
325
+ }).finally(() => {
326
+ if (requestId === this._suggestionsRequestId) {
327
+ this.suggestionsLoadingMore = false
328
+ }
329
+ })
330
+ },
331
+ normalizeSuggestionsResult (result) {
332
+ if (Array.isArray(result)) {
333
+ return {
334
+ items: result,
335
+ hasMore: false
336
+ }
337
+ }
338
+ return {
339
+ items: result && Array.isArray(result.items) ? result.items : [],
340
+ hasMore: !!(result && result.hasMore)
341
+ }
342
+ },
284
343
  normalizeSuggestionsKeyword (nearestInfo, keyword) {
285
344
  const nearest = keyword === undefined
286
345
  ? (nearestInfo && nearestInfo.nearest) || ''
@@ -294,6 +353,8 @@ export default {
294
353
  this._suggestionsRequestId = (this._suggestionsRequestId || 0) + 1
295
354
  this.$refs.suggestions && this.$refs.suggestions.close()
296
355
  this.suggestioning = false
356
+ this.suggestionsLoadingMore = false
357
+ this.suggestionsHasMore = false
297
358
  this.popoverActive = false
298
359
  },
299
360
  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.373",
4
4
  "description": "",
5
5
  "files": [
6
6
  "common",