Merge branch 'feature/fix' into 'feature/grassV2'
fix updateHeight error See merge request !9
Showing
10 changed files
with
157 additions
and
153 deletions
@@ -10,9 +10,7 @@ | @@ -10,9 +10,7 @@ | ||
10 | :name="`route-view-${yoho.direction}`"> | 10 | :name="`route-view-${yoho.direction}`"> |
11 | <router-view v-if="!$route.meta.keepAlive"></router-view> | 11 | <router-view v-if="!$route.meta.keepAlive"></router-view> |
12 | </transition> | 12 | </transition> |
13 | - <div class="fps" v-if="showFps"> | ||
14 | - {{fps}} | ||
15 | - </div> | 13 | + <div id="fps" class="fps" v-if="showFps"></div> |
16 | </div> | 14 | </div> |
17 | </template> | 15 | </template> |
18 | 16 | ||
@@ -52,7 +50,7 @@ export default { | @@ -52,7 +50,7 @@ export default { | ||
52 | } | 50 | } |
53 | if (now - this.time >= 1000) { | 51 | if (now - this.time >= 1000) { |
54 | this.time = now; | 52 | this.time = now; |
55 | - this.fps = this.fpsTick; | 53 | + document.getElementById('fps').innerText = this.fpsTick; |
56 | this.fpsTick = 0; | 54 | this.fpsTick = 0; |
57 | } | 55 | } |
58 | this.fpsTick++; | 56 | this.fpsTick++; |
@@ -18,6 +18,11 @@ export default { | @@ -18,6 +18,11 @@ export default { | ||
18 | }, | 18 | }, |
19 | share: Boolean | 19 | share: Boolean |
20 | }, | 20 | }, |
21 | + data() { | ||
22 | + return { | ||
23 | + posting: false | ||
24 | + }; | ||
25 | + }, | ||
21 | methods: { | 26 | methods: { |
22 | ...mapActions(['postComment']), | 27 | ...mapActions(['postComment']), |
23 | ...articleMapActions(['fetchArticleUpdate']), | 28 | ...articleMapActions(['fetchArticleUpdate']), |
@@ -53,6 +58,10 @@ export default { | @@ -53,6 +58,10 @@ export default { | ||
53 | } | 58 | } |
54 | }, | 59 | }, |
55 | async comment(content) { | 60 | async comment(content) { |
61 | + if (this.posting) { | ||
62 | + return; | ||
63 | + } | ||
64 | + this.posting = true; | ||
56 | const result = await this.postComment({ | 65 | const result = await this.postComment({ |
57 | content: content, | 66 | content: content, |
58 | destId: this.addType === 0 ? this.destId : void 0, | 67 | destId: this.addType === 0 ? this.destId : void 0, |
@@ -61,6 +70,7 @@ export default { | @@ -61,6 +70,7 @@ export default { | ||
61 | columnType: this.columnType | 70 | columnType: this.columnType |
62 | }); | 71 | }); |
63 | 72 | ||
73 | + this.posting = false; | ||
64 | if (result.code === 200) { | 74 | if (result.code === 200) { |
65 | const waitData = this.addType === 0 ? this.fetchArticleUpdate({articleId: this.destId}) : Promise.resolve(); | 75 | const waitData = this.addType === 0 ? this.fetchArticleUpdate({articleId: this.destId}) : Promise.resolve(); |
66 | 76 |
@@ -18,6 +18,12 @@ export default { | @@ -18,6 +18,12 @@ export default { | ||
18 | resize(index) { | 18 | resize(index) { |
19 | this.$refs.scroll.resize(index); | 19 | this.$refs.scroll.resize(index); |
20 | }, | 20 | }, |
21 | + unlockHight(params) { | ||
22 | + this.$refs.scroll.unlockHight(params); | ||
23 | + }, | ||
24 | + delete(params) { | ||
25 | + this.$refs.scroll.delete(params); | ||
26 | + }, | ||
21 | init() { | 27 | init() { |
22 | this.$refs.scroll.init(); | 28 | this.$refs.scroll.init(); |
23 | } | 29 | } |
1 | <template> | 1 | <template> |
2 | <div class="cube-recycle-list"> | 2 | <div class="cube-recycle-list"> |
3 | <div class="cube-recycle-list-main"> | 3 | <div class="cube-recycle-list-main"> |
4 | - <div class="cube-recycle-list-items" :style="{height: heights + 'px'}"> | 4 | + <div ref="items" class="cube-recycle-list-items"> |
5 | <div | 5 | <div |
6 | - v-for="(item, index) in visibleItems" | ||
7 | - :key="index" | 6 | + v-for="item in visibleItems" |
7 | + :key="item.index" | ||
8 | class="cube-recycle-list-item" | 8 | class="cube-recycle-list-item" |
9 | :class="thumbClass" | 9 | :class="thumbClass" |
10 | - :ref="'loads'+index" | ||
11 | - :style="getItemStyle(item, index)" | ||
12 | - > | ||
13 | - <div | ||
14 | - v-if="infinite" | ||
15 | - :class="{'cube-recycle-list-transition': infinite}" | ||
16 | - :style="{opacity: +!item.loaded}" | ||
17 | - > | ||
18 | - <slot name="tombstone"></slot> | ||
19 | - </div> | ||
20 | - <div | ||
21 | - v-if="!item.placeholder" | ||
22 | - :class="{'cube-recycle-list-transition': infinite}" | ||
23 | - :style="{opacity: item.loaded}" | ||
24 | - > | ||
25 | - <slot name="item" :data="{data: item.data, index}"></slot> | 10 | + :ref="'loads'+item.index" |
11 | + :style="getItemStyle(item)"> | ||
12 | + <div v-if="!item.placeholder || !item.height"> | ||
13 | + <slot name="item" :data="item"></slot> | ||
26 | </div> | 14 | </div> |
27 | </div> | 15 | </div> |
28 | </div> | 16 | </div> |
29 | - <div | ||
30 | - v-if="!infinite" | ||
31 | - class="cube-recycle-list-loading"> | 17 | + <div class="cube-recycle-list-loading"> |
32 | <slot name="spinner"> | 18 | <slot name="spinner"> |
33 | <div class="cube-recycle-list-loading-content" v-show="!noMore" :style="{visibility: loadings.length ? 'visible' : 'hidden'}"> | 19 | <div class="cube-recycle-list-loading-content" v-show="!noMore" :style="{visibility: loadings.length ? 'visible' : 'hidden'}"> |
34 | <cube-loading class="spinner"></cube-loading> | 20 | <cube-loading class="spinner"></cube-loading> |
@@ -54,7 +40,6 @@ export default { | @@ -54,7 +40,6 @@ export default { | ||
54 | data() { | 40 | data() { |
55 | return { | 41 | return { |
56 | items: [], | 42 | items: [], |
57 | - list: [], | ||
58 | heights: this.thumbs.length ? 1000 : 0, | 43 | heights: this.thumbs.length ? 1000 : 0, |
59 | startIndex: 0, | 44 | startIndex: 0, |
60 | currentIndex: 0, | 45 | currentIndex: 0, |
@@ -91,14 +76,19 @@ export default { | @@ -91,14 +76,19 @@ export default { | ||
91 | computed: { | 76 | computed: { |
92 | visibleItems() { | 77 | visibleItems() { |
93 | if (this.thumbsList.length) { | 78 | if (this.thumbsList.length) { |
94 | - return this.thumbsList.map(item => { | ||
95 | - return { | ||
96 | - data: item | ||
97 | - }; | ||
98 | - }).concat(this.items.slice(this.thumbsList.length, this.items.length)); | 79 | + return this.thumbItems.concat(this.items.slice(this.thumbsList.length, this.items.length)); |
99 | } | 80 | } |
100 | return this.items; | 81 | return this.items; |
101 | }, | 82 | }, |
83 | + thumbItems() { | ||
84 | + return this.thumbsList.map((item, index) => { | ||
85 | + return { | ||
86 | + data: item, | ||
87 | + isThumb: true, | ||
88 | + index | ||
89 | + }; | ||
90 | + }); | ||
91 | + }, | ||
102 | tombHeight() { | 92 | tombHeight() { |
103 | return this.infinite ? this.$refs.tomb && this.$refs.tomb.offsetHeight : 0; | 93 | return this.infinite ? this.$refs.tomb && this.$refs.tomb.offsetHeight : 0; |
104 | }, | 94 | }, |
@@ -114,21 +104,6 @@ export default { | @@ -114,21 +104,6 @@ export default { | ||
114 | }; | 104 | }; |
115 | } | 105 | } |
116 | }, | 106 | }, |
117 | - watch: { | ||
118 | - list(newV) { | ||
119 | - if (newV.length) { | ||
120 | - this.loadings.pop(); | ||
121 | - if (!this.loadings.length) { | ||
122 | - this.loadItems(); | ||
123 | - } | ||
124 | - } | ||
125 | - }, | ||
126 | - items(newV) { | ||
127 | - if (newV.length > this.list.length) { | ||
128 | - this.getItems(); | ||
129 | - } | ||
130 | - } | ||
131 | - }, | ||
132 | mounted() { | 107 | mounted() { |
133 | this.scrollEvent = throttle(this._onScroll.bind(this), 100); | 108 | this.scrollEvent = throttle(this._onScroll.bind(this), 100); |
134 | let supportsPassive = false; | 109 | let supportsPassive = false; |
@@ -153,71 +128,68 @@ export default { | @@ -153,71 +128,68 @@ export default { | ||
153 | init() { | 128 | init() { |
154 | this.load(true); | 129 | this.load(true); |
155 | }, | 130 | }, |
156 | - getItemStyle(item, index) { | 131 | + getItemStyle(item) { |
157 | const style = {}; | 132 | const style = {}; |
158 | 133 | ||
159 | - if (!this.isThumb) { | ||
160 | - style.transform = `translate3d(0, ${item.top}px, 0)`; | ||
161 | - } | ||
162 | - if (item.placeholder) { | 134 | + if (item.height) { |
135 | + if (!item.unlockHight) { | ||
163 | style.height = `${item.height}px`; | 136 | style.height = `${item.height}px`; |
164 | - } else { | ||
165 | - style['z-index'] = this.visibleItems.length - index; | ||
166 | } | 137 | } |
167 | - if (!item.height && !this.isThumb) { | 138 | + } else if (item.willchange) { |
139 | + style.transition = 'height 300ms cubic-bezier(0.165, 0.84, 0.44, 1)'; | ||
140 | + style['will-change'] = 'height'; | ||
141 | + style.height = `${item.height}px`; | ||
142 | + style.opacity = 0; | ||
143 | + } else if (!item.isThumb) { | ||
144 | + style.position = 'absolute'; | ||
168 | style.top = `${-1000}px`; | 145 | style.top = `${-1000}px`; |
169 | style.visibility = 'hidden'; | 146 | style.visibility = 'hidden'; |
170 | } | 147 | } |
171 | return style; | 148 | return style; |
172 | }, | 149 | }, |
173 | load(reload) { | 150 | load(reload) { |
174 | - if (this.infinite) { | ||
175 | - // increase capacity of items to display tombstone | ||
176 | - this.items.length += this.size; | ||
177 | - this.loadItems(); | ||
178 | - } else if ((!this.loadings.length && !this.noMore) || reload) { | 151 | + if ((!this.loadings.length && !this.noMore) || reload) { |
179 | this.getItems(reload); | 152 | this.getItems(reload); |
180 | } | 153 | } |
181 | }, | 154 | }, |
182 | getItems(reload) { | 155 | getItems(reload) { |
183 | if (reload) { | 156 | if (reload) { |
184 | this.noMore = false; | 157 | this.noMore = false; |
185 | - this.list = []; | ||
186 | this.items = []; | 158 | this.items = []; |
187 | } | 159 | } |
188 | this.loadings.push('pending'); | 160 | this.loadings.push('pending'); |
189 | this.onFetch().then((res) => { | 161 | this.onFetch().then((res) => { |
190 | - /* istanbul ignore if */ | ||
191 | if (!res) { | 162 | if (!res) { |
192 | this.noMore = true; | 163 | this.noMore = true; |
193 | this.loadings.pop(); | 164 | this.loadings.pop(); |
194 | } else { | 165 | } else { |
195 | - this.list = this.list.concat(res); | 166 | + this.loadItems(res); |
196 | } | 167 | } |
197 | }); | 168 | }); |
198 | }, | 169 | }, |
199 | - async loadItems() { | ||
200 | - let end = this.infinite ? this.items.length : this.list.length; | ||
201 | - let item; | 170 | + async loadItems(list) { |
171 | + const lastItem = this.items[this.items.length - 1]; | ||
172 | + const start = lastItem ? lastItem.index + 1 : 0; | ||
202 | 173 | ||
203 | - for (let i = this.items.length; i < end; i++) { | ||
204 | - item = this.items[i]; | ||
205 | - /* istanbul ignore if */ | ||
206 | - if (item && item.loaded) { | ||
207 | - continue; | 174 | + for (let i = 0; i < list.length; i++) { |
175 | + await this.loadItem(i + start, list[i]); | ||
208 | } | 176 | } |
209 | - await this.loadItem(i); | 177 | + if (this.loadings.length) { |
178 | + this.loadings.pop(); | ||
210 | } | 179 | } |
211 | if (this.thumbsList.length) { | 180 | if (this.thumbsList.length) { |
212 | this.thumbsList = []; | 181 | this.thumbsList = []; |
213 | } | 182 | } |
214 | }, | 183 | }, |
215 | - loadItem(i) { | 184 | + loadItem(i, item) { |
216 | return new Promise(r => { | 185 | return new Promise(r => { |
217 | - this.setItem(i, this.list[i]); | 186 | + const insertIndex = this.setItem(i, item); |
187 | + | ||
218 | this.$nextTick(() => { | 188 | this.$nextTick(() => { |
219 | - this.updateItemHeight(i); | 189 | + setTimeout(() => { |
190 | + this.updateItemHeight(insertIndex); | ||
220 | r(); | 191 | r(); |
192 | + }, 100); | ||
221 | }); | 193 | }); |
222 | }); | 194 | }); |
223 | }, | 195 | }, |
@@ -226,14 +198,18 @@ export default { | @@ -226,14 +198,18 @@ export default { | ||
226 | this.thumbsList[index] = data; | 198 | this.thumbsList[index] = data; |
227 | this.thumbsList = this.thumbsList.map(item => item); | 199 | this.thumbsList = this.thumbsList.map(item => item); |
228 | } | 200 | } |
229 | - this.$set(this.items, index, { | 201 | + const insertIndex = this.items.length; |
202 | + | ||
203 | + this.$set(this.items, insertIndex, { | ||
230 | data: data || {}, | 204 | data: data || {}, |
231 | height: 0, | 205 | height: 0, |
232 | top: -1000, | 206 | top: -1000, |
233 | - isTombstone: !data, | ||
234 | - loaded: data ? 1 : 0, | ||
235 | - placeholder: false | 207 | + placeholder: false, |
208 | + unlockHight: false, | ||
209 | + willchange: false, | ||
210 | + index | ||
236 | }); | 211 | }); |
212 | + return insertIndex; | ||
237 | }, | 213 | }, |
238 | updateItemHeight(index, resize) { | 214 | updateItemHeight(index, resize) { |
239 | if (index === 0 && !resize) { | 215 | if (index === 0 && !resize) { |
@@ -243,7 +219,7 @@ export default { | @@ -243,7 +219,7 @@ export default { | ||
243 | // update item height | 219 | // update item height |
244 | let increHeight = 0; | 220 | let increHeight = 0; |
245 | let cur = this.items[index]; | 221 | let cur = this.items[index]; |
246 | - let dom = this.$refs[`loads${index}`]; | 222 | + let dom = this.$refs[`loads${cur.index}`]; |
247 | 223 | ||
248 | try { | 224 | try { |
249 | if (dom && dom[0]) { | 225 | if (dom && dom[0]) { |
@@ -266,18 +242,8 @@ export default { | @@ -266,18 +242,8 @@ export default { | ||
266 | 242 | ||
267 | return increHeight; | 243 | return increHeight; |
268 | }, | 244 | }, |
269 | - updateItemTop(startIndex, increHeight) { | ||
270 | - // loop all items to update item top and list height | ||
271 | - for (let i = startIndex; i < this.items.length; i++) { | ||
272 | - let pre = this.items[i - 1]; | ||
273 | - | ||
274 | - this.items[i].top = pre ? pre.top + pre.height : 0; | ||
275 | - } | ||
276 | - this.heights += increHeight; | ||
277 | - }, | ||
278 | - updateIndex() { | ||
279 | - // update visible items start index | ||
280 | - let top = this.$el.scrollTop; | 245 | + updateIndex(scrollTop) { |
246 | + let top = scrollTop; | ||
281 | let hasTopItem = false; | 247 | let hasTopItem = false; |
282 | 248 | ||
283 | for (let i = 0; i < this.items.length; i++) { | 249 | for (let i = 0; i < this.items.length; i++) { |
@@ -292,26 +258,65 @@ export default { | @@ -292,26 +258,65 @@ export default { | ||
292 | } | 258 | } |
293 | } | 259 | } |
294 | if (hasTopItem) { | 260 | if (hasTopItem) { |
295 | - this.currentIndex = this.startIndex; | 261 | + this.currentIndex = this.items[this.startIndex].index; |
296 | } else { | 262 | } else { |
297 | - this.currentIndex = this.items.length - 1; | 263 | + this.currentIndex = this.items[this.items.length - 1].index; |
298 | } | 264 | } |
299 | }, | 265 | }, |
300 | _onScroll() { | 266 | _onScroll() { |
301 | const scrollTop = this.$el.scrollTop; | 267 | const scrollTop = this.$el.scrollTop; |
268 | + const heights = this.$refs.items.offsetHeight; | ||
302 | 269 | ||
303 | // trigger load | 270 | // trigger load |
304 | - if (scrollTop + this.$el.offsetHeight > this.heights - this.offset) { | 271 | + if (scrollTop + this.$el.offsetHeight > heights - this.offset) { |
305 | this.load(); | 272 | this.load(); |
306 | } | 273 | } |
307 | - this.updateIndex(); | 274 | + this.updateIndex(scrollTop); |
308 | 275 | ||
309 | this.$emit('scroll', {scrollTop, startIndex: this.currentIndex, item: this.items[this.currentIndex]}); | 276 | this.$emit('scroll', {scrollTop, startIndex: this.currentIndex, item: this.items[this.currentIndex]}); |
310 | }, | 277 | }, |
311 | - resize(index) { | ||
312 | - const increHeight = this.updateItemHeight(index, true); | 278 | + findItemIndex(itemIndex) { |
279 | + return this.items.findIndex(item => item.index === itemIndex); | ||
280 | + }, | ||
281 | + resize(itemIndex) { | ||
282 | + const findItemIndex = this.findItemIndex(itemIndex); | ||
313 | 283 | ||
314 | - this.updateItemTop(index, increHeight); | 284 | + if (findItemIndex >= 0) { |
285 | + this.updateItemHeight(findItemIndex, true); | ||
286 | + } | ||
287 | + }, | ||
288 | + delete(itemIndex) { | ||
289 | + const findItemIndex = this.findItemIndex(itemIndex); | ||
290 | + | ||
291 | + if (findItemIndex >= 0) { | ||
292 | + this.items[findItemIndex].willchange = true; | ||
293 | + let dom = this.$refs[`loads${itemIndex}`]; | ||
294 | + | ||
295 | + dom && dom[0].addEventListener('transitionend', () => { | ||
296 | + this.items.splice(findItemIndex, 1); | ||
297 | + this._onScroll(); | ||
298 | + }, { | ||
299 | + once: true | ||
300 | + }); | ||
301 | + this.$nextTick(() => { | ||
302 | + this.items[findItemIndex].height = 0; | ||
303 | + }); | ||
304 | + } | ||
305 | + }, | ||
306 | + unlockHight({index, promise}) { | ||
307 | + const findItemIndex = this.findItemIndex(index); | ||
308 | + | ||
309 | + if (findItemIndex >= 0) { | ||
310 | + const cur = this.items[findItemIndex]; | ||
311 | + | ||
312 | + if (cur) { | ||
313 | + cur.unlockHight = true; | ||
314 | + promise.then(() => { | ||
315 | + this.updateItemHeight(findItemIndex, true); | ||
316 | + cur.unlockHight = false; | ||
317 | + }); | ||
318 | + } | ||
319 | + } | ||
315 | } | 320 | } |
316 | }, | 321 | }, |
317 | components: { | 322 | components: { |
@@ -336,7 +341,6 @@ export default { | @@ -336,7 +341,6 @@ export default { | ||
336 | visibility: hidden | 341 | visibility: hidden |
337 | .cube-recycle-list-item | 342 | .cube-recycle-list-item |
338 | width: 100% | 343 | width: 100% |
339 | - position: absolute | ||
340 | box-sizing: border-box | 344 | box-sizing: border-box |
341 | &.thumb | 345 | &.thumb |
342 | position relative | 346 | position relative |
@@ -6,14 +6,16 @@ | @@ -6,14 +6,16 @@ | ||
6 | <ImageFormat :lazy="lazy" class="product-image" :src="product.productImage" :width="136" :height="180"></ImageFormat> | 6 | <ImageFormat :lazy="lazy" class="product-image" :src="product.productImage" :width="136" :height="180"></ImageFormat> |
7 | <div class="product-info"> | 7 | <div class="product-info"> |
8 | <p class="product-name">{{product.productName}}</p> | 8 | <p class="product-name">{{product.productName}}</p> |
9 | - <p class="price">¥{{product.salesPrice}}</p> | ||
10 | - </div> | ||
11 | - </div> | 9 | + <div class="price"> |
10 | + ¥{{product.salesPrice}} | ||
12 | <AuthComponent | 11 | <AuthComponent |
13 | class="btn-fav hover-opacity" | 12 | class="btn-fav hover-opacity" |
14 | @click="onFav" | 13 | @click="onFav" |
15 | :class="favClass">{{favText}}</AuthComponent> | 14 | :class="favClass">{{favText}}</AuthComponent> |
16 | </div> | 15 | </div> |
16 | + </div> | ||
17 | + </div> | ||
18 | + </div> | ||
17 | </template> | 19 | </template> |
18 | 20 | ||
19 | <script> | 21 | <script> |
@@ -128,7 +130,6 @@ export default { | @@ -128,7 +130,6 @@ export default { | ||
128 | 130 | ||
129 | <style lang="scss" scoped> | 131 | <style lang="scss" scoped> |
130 | .product-item { | 132 | .product-item { |
131 | - position: relative; | ||
132 | margin-top: 20px; | 133 | margin-top: 20px; |
133 | margin-right: 20px; | 134 | margin-right: 20px; |
134 | margin-left: 30px; | 135 | margin-left: 30px; |
@@ -182,9 +183,8 @@ export default { | @@ -182,9 +183,8 @@ export default { | ||
182 | } | 183 | } |
183 | 184 | ||
184 | .btn-fav { | 185 | .btn-fav { |
185 | - position: absolute; | ||
186 | - bottom: 20px; | ||
187 | - right: -20px; | 186 | + float: right; |
187 | + margin-right: -40px; | ||
188 | width: 120px; | 188 | width: 120px; |
189 | height: 50px; | 189 | height: 50px; |
190 | padding: 0; | 190 | padding: 0; |
@@ -117,7 +117,7 @@ export default { | @@ -117,7 +117,7 @@ export default { | ||
117 | methods: { | 117 | methods: { |
118 | ...mapMutations(['CHANGE_ARTICLE_LIST_INTRO_HEIGHT', 'CHANGE_ARTICLE_LIST_INTRO']), | 118 | ...mapMutations(['CHANGE_ARTICLE_LIST_INTRO_HEIGHT', 'CHANGE_ARTICLE_LIST_INTRO']), |
119 | init() { | 119 | init() { |
120 | - if (this.data.introHeight === 0) { | 120 | + if (this.data.introHeight === 0 && this.isEllipsis) { |
121 | this.CHANGE_ARTICLE_LIST_INTRO_HEIGHT({ | 121 | this.CHANGE_ARTICLE_LIST_INTRO_HEIGHT({ |
122 | articleId: this.data.articleId, | 122 | articleId: this.data.articleId, |
123 | introHeight: get(this.$refs, 'introPool.scrollHeight', 0) + 20, | 123 | introHeight: get(this.$refs, 'introPool.scrollHeight', 0) + 20, |
@@ -189,7 +189,6 @@ export default { | @@ -189,7 +189,6 @@ export default { | ||
189 | margin-top: 20px; | 189 | margin-top: 20px; |
190 | 190 | ||
191 | .intro { | 191 | .intro { |
192 | - touch-action: none; | ||
193 | font-size: 28px; | 192 | font-size: 28px; |
194 | color: #4a4a4a; | 193 | color: #4a4a4a; |
195 | letter-spacing: 0.06PX; | 194 | letter-spacing: 0.06PX; |
@@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
10 | </template> | 10 | </template> |
11 | 11 | ||
12 | <script> | 12 | <script> |
13 | -import {get, first, debounce} from 'lodash'; | 13 | +import {get, first} from 'lodash'; |
14 | import ArticleItemHeader from './article-item-header'; | 14 | import ArticleItemHeader from './article-item-header'; |
15 | import ArticleItemSlide from './article-item-slide'; | 15 | import ArticleItemSlide from './article-item-slide'; |
16 | import ArticleItemIntro from './article-item-intro'; | 16 | import ArticleItemIntro from './article-item-intro'; |
@@ -31,9 +31,6 @@ export default { | @@ -31,9 +31,6 @@ export default { | ||
31 | type: String, | 31 | type: String, |
32 | thumb: Boolean | 32 | thumb: Boolean |
33 | }, | 33 | }, |
34 | - mounted() { | ||
35 | - this.expandEvent = debounce(this.onExpandEvent.bind(this), 200); | ||
36 | - }, | ||
37 | computed: { | 34 | computed: { |
38 | articleState() { | 35 | articleState() { |
39 | return this.articleStates[this.data.articleId] || this.data; | 36 | return this.articleStates[this.data.articleId] || this.data; |
@@ -88,34 +85,21 @@ export default { | @@ -88,34 +85,21 @@ export default { | ||
88 | }, | 85 | }, |
89 | methods: { | 86 | methods: { |
90 | onExpand() { | 87 | onExpand() { |
91 | - this.expandEvent(); | ||
92 | - }, | ||
93 | - onExpandEvent() { | ||
94 | - const $phItem = document.getElementById(`ph${this.index}`); | ||
95 | - | ||
96 | - $phItem.innerHTML = ''; | ||
97 | - $phItem.status = 0; | ||
98 | - this.$nextTick(() => { | ||
99 | - this.onResize(); | ||
100 | - }); | 88 | + this.changeResolve && this.changeResolve(); |
101 | }, | 89 | }, |
102 | onResize() { | 90 | onResize() { |
103 | - this.$emit('on-resize', this.index); | 91 | + this.$emit('on-unlock-height', { |
92 | + index: this.index, | ||
93 | + promise: Promise.resolve() | ||
94 | + }); | ||
104 | }, | 95 | }, |
105 | onExpanding() { | 96 | onExpanding() { |
106 | - const $phItem = document.getElementById(`ph${this.index}`); | ||
107 | - | ||
108 | - if ($phItem.status === 1) { | ||
109 | - return; | ||
110 | - } | ||
111 | - | ||
112 | - const $nextItem = document.getElementById(`item${this.index + 1}`); | ||
113 | - | ||
114 | - if ($nextItem) { | ||
115 | - $phItem.innerHTML = $nextItem.outerHTML; | ||
116 | - } | ||
117 | - $phItem.style.zIndex = 999; | ||
118 | - $phItem.status = 1; | 97 | + this.$emit('on-unlock-height', { |
98 | + index: this.index, | ||
99 | + promise: new Promise(r => { | ||
100 | + this.changeResolve = r; | ||
101 | + }) | ||
102 | + }); | ||
119 | }, | 103 | }, |
120 | onFollow(follow) { | 104 | onFollow(follow) { |
121 | this.$emit('on-follow', follow); | 105 | this.$emit('on-follow', follow); |
@@ -127,7 +111,7 @@ export default { | @@ -127,7 +111,7 @@ export default { | ||
127 | this.$emit('on-show-comment', {articleId: this.data.articleId, index: this.index}); | 111 | this.$emit('on-show-comment', {articleId: this.data.articleId, index: this.index}); |
128 | }, | 112 | }, |
129 | onShowMore() { | 113 | onShowMore() { |
130 | - this.$emit('on-show-more', this.data); | 114 | + this.$emit('on-show-more', {article: this.data, index: this.index}); |
131 | } | 115 | } |
132 | }, | 116 | }, |
133 | components: {ArticleItemHeader, ArticleItemSlide, ArticleItemIntro, ArticleItemComment} | 117 | components: {ArticleItemHeader, ArticleItemSlide, ArticleItemIntro, ArticleItemComment} |
1 | <template> | 1 | <template> |
2 | <div> | 2 | <div> |
3 | <Layout class="article"> | 3 | <Layout class="article"> |
4 | - <LayoutHeader theme="white" slot='header' :title="title"> | 4 | + <LayoutHeader v-if="!noHeader" theme="white" slot='header' :title="title"> |
5 | <template v-if="showHeader"> | 5 | <template v-if="showHeader"> |
6 | <div class="avatar-wrapper" @click="toUserPage"> | 6 | <div class="avatar-wrapper" @click="toUserPage"> |
7 | <WidgetAvatar class="widget-avatar" :src="currentAuthor.authorHeadIco" :width="70" :height="70"></WidgetAvatar> | 7 | <WidgetAvatar class="widget-avatar" :src="currentAuthor.authorHeadIco" :width="70" :height="70"></WidgetAvatar> |
@@ -12,21 +12,19 @@ | @@ -12,21 +12,19 @@ | ||
12 | <WidgetFollow :share="share" class="widget-follow" :author-uid="currentAuthor.authorUid" :follow="currentAuthor.hasAttention === 'Y'" @on-follow="follow => onFollow(currentAuthor, follow)"></WidgetFollow> | 12 | <WidgetFollow :share="share" class="widget-follow" :author-uid="currentAuthor.authorUid" :follow="currentAuthor.hasAttention === 'Y'" @on-follow="follow => onFollow(currentAuthor, follow)"></WidgetFollow> |
13 | </template> | 13 | </template> |
14 | </LayoutHeader> | 14 | </LayoutHeader> |
15 | - <LayoutRecycleList :size="10" :thumbs="thumbs" :remove="deleteArticle" ref="scroll" @scroll="onScroll" :offset="2000" :on-fetch="onFetch"> | ||
16 | - <template class="article-item" #item="{ data: {data, index} }"> | 15 | + <LayoutRecycleList :size="10" :thumbs="thumbs" ref="scroll" @scroll="onScroll" :offset="2000" :on-fetch="onFetch"> |
16 | + <template class="article-item" #item="{ data }"> | ||
17 | <ArticleItem | 17 | <ArticleItem |
18 | - :id="`item${index}`" | ||
19 | :type="type" | 18 | :type="type" |
20 | - :index="index" | ||
21 | - :data="data" | ||
22 | - :data-id="data.articleId" | 19 | + :index="data.index" |
20 | + :data="data.data" | ||
23 | :share="share" | 21 | :share="share" |
24 | - @on-follow="follow => onFollow(data, follow)" | 22 | + @on-follow="follow => onFollow(data.data, follow)" |
25 | @on-resize="onResize" | 23 | @on-resize="onResize" |
24 | + @on-unlock-height="onUnlockHeight" | ||
26 | @on-show-guang="onShowGuang" | 25 | @on-show-guang="onShowGuang" |
27 | @on-show-comment="onShowComment" | 26 | @on-show-comment="onShowComment" |
28 | @on-show-more="onShowMore"></ArticleItem> | 27 | @on-show-more="onShowMore"></ArticleItem> |
29 | - <div :id="`ph${index}`"></div> | ||
30 | </template> | 28 | </template> |
31 | </LayoutRecycleList> | 29 | </LayoutRecycleList> |
32 | </Layout> | 30 | </Layout> |
@@ -61,6 +59,7 @@ export default { | @@ -61,6 +59,7 @@ export default { | ||
61 | share: Boolean, | 59 | share: Boolean, |
62 | type: String, | 60 | type: String, |
63 | onFetch: Function, | 61 | onFetch: Function, |
62 | + noHeader: Boolean, | ||
64 | thumbs: { | 63 | thumbs: { |
65 | type: Array, | 64 | type: Array, |
66 | default() { | 65 | default() { |
@@ -91,7 +90,6 @@ export default { | @@ -91,7 +90,6 @@ export default { | ||
91 | isShare: false, | 90 | isShare: false, |
92 | authorType: 1 | 91 | authorType: 1 |
93 | }, | 92 | }, |
94 | - deleteArticle: {} | ||
95 | }; | 93 | }; |
96 | }, | 94 | }, |
97 | activated() { | 95 | activated() { |
@@ -128,17 +126,17 @@ export default { | @@ -128,17 +126,17 @@ export default { | ||
128 | this.$refs.comment.init(); | 126 | this.$refs.comment.init(); |
129 | }); | 127 | }); |
130 | }, | 128 | }, |
131 | - async onShowMore(article) { | 129 | + async onShowMore({article, index}) { |
132 | if (this.yoho && this.yoho.context.isLogin && !this._uid) { | 130 | if (this.yoho && this.yoho.context.isLogin && !this._uid) { |
133 | let user = await this.$sdk.getUser(); | 131 | let user = await this.$sdk.getUser(); |
134 | 132 | ||
135 | this._uid = user.uid; | 133 | this._uid = user.uid; |
136 | } | 134 | } |
137 | 135 | ||
138 | - this.$refs.moreAction.show(article, this._uid); | 136 | + this.$refs.moreAction.show(article, this._uid, index); |
139 | }, | 137 | }, |
140 | - onDelete(articleId) { | ||
141 | - this.deleteArticle = {articleId}; | 138 | + onDelete(index) { |
139 | + this.$refs.scroll.delete(index); | ||
142 | }, | 140 | }, |
143 | onPageReady({success}) { | 141 | onPageReady({success}) { |
144 | if (success && this.showCommentAction) { | 142 | if (success && this.showCommentAction) { |
@@ -150,6 +148,9 @@ export default { | @@ -150,6 +148,9 @@ export default { | ||
150 | this.showCommentActioning = false; | 148 | this.showCommentActioning = false; |
151 | } | 149 | } |
152 | }, | 150 | }, |
151 | + onUnlockHeight(params) { | ||
152 | + this.$refs.scroll.unlockHight(params); | ||
153 | + }, | ||
153 | onClose() { | 154 | onClose() { |
154 | this.$refs.commentAction.hide(); | 155 | this.$refs.commentAction.hide(); |
155 | }, | 156 | }, |
@@ -45,7 +45,8 @@ export default { | @@ -45,7 +45,8 @@ export default { | ||
45 | methods: { | 45 | methods: { |
46 | ...articleStore.mapActions(['reportArticle', 'deleteArticle']), | 46 | ...articleStore.mapActions(['reportArticle', 'deleteArticle']), |
47 | ...userStore.mapActions(['followUser']), | 47 | ...userStore.mapActions(['followUser']), |
48 | - show(params, uid) { | 48 | + show(params, uid, index) { |
49 | + this.index = index; | ||
49 | params = params || {}; | 50 | params = params || {}; |
50 | 51 | ||
51 | this.list[0].hide = params.hasAttention !== 'Y'; | 52 | this.list[0].hide = params.hasAttention !== 'Y'; |
-
Please register or login to post a comment