|
|
@@ -1,9 +1,12 @@
|
|
|
<template>
|
|
|
- <div :class="gridClass">
|
|
|
+ <div
|
|
|
+ :class="gridClass"
|
|
|
+ @scroll="handleScroll"
|
|
|
+ >
|
|
|
<template v-if="hasData">
|
|
|
<component
|
|
|
:is="cardComponent"
|
|
|
- v-for="item in filterList"
|
|
|
+ v-for="item in cacheItems"
|
|
|
:key="item.id"
|
|
|
:device="item"
|
|
|
:flag="item.flag"
|
|
|
@@ -39,20 +42,48 @@ export default {
|
|
|
default: -1
|
|
|
}
|
|
|
},
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ maxLength: 0,
|
|
|
+ locked: false
|
|
|
+ }
|
|
|
+ },
|
|
|
computed: {
|
|
|
groupItems () {
|
|
|
return [...this.groupOptions.list]
|
|
|
+ },
|
|
|
+ cacheItems () {
|
|
|
+ const length = this.filterList.length
|
|
|
+ return this.maxLength < length
|
|
|
+ ? this.filterList.slice(0, this.maxLength)
|
|
|
+ : this.filterList
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
|
path () {
|
|
|
- this.refreshGroups(true)
|
|
|
+ this.onResetGroupOptions()
|
|
|
},
|
|
|
total () {
|
|
|
- this.refreshGroups(true)
|
|
|
+ this.onResetGroupOptions()
|
|
|
+ },
|
|
|
+ status () {
|
|
|
+ this.maxLength = 100
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ handleScroll (event) {
|
|
|
+ if (this.locked) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const { scrollTop, scrollHeight, clientHeight } = event.target
|
|
|
+ if (this.maxLength < this.filterList.length && Math.ceil(scrollTop + clientHeight + 1) >= scrollHeight) {
|
|
|
+ this.locked = true
|
|
|
+ this.maxLength += 100
|
|
|
+ setTimeout(() => {
|
|
|
+ this.locked = false
|
|
|
+ }, 500)
|
|
|
+ }
|
|
|
+ },
|
|
|
refreshGroups (force) {
|
|
|
if (!this.path || !force && this.groupOptions.loading) {
|
|
|
return
|
|
|
@@ -64,6 +95,7 @@ export default {
|
|
|
? { loaded: true }
|
|
|
: { loading: true }
|
|
|
)
|
|
|
+ this.maxLength = 100
|
|
|
this.groupOptions = groupOptions
|
|
|
this.onChanged()
|
|
|
if (this.total <= 0) {
|
|
|
@@ -73,6 +105,7 @@ export default {
|
|
|
getDevicesByQuery({
|
|
|
pageNum: 1,
|
|
|
pageSize: this.total,
|
|
|
+ orderFlag: 1,
|
|
|
activate: 1,
|
|
|
org: this.path
|
|
|
}, { custom: true }).then(
|
|
|
@@ -82,12 +115,12 @@ export default {
|
|
|
}
|
|
|
const map = {}
|
|
|
const topics = []
|
|
|
- groupOptions.list = data.map(device => {
|
|
|
+ groupOptions.list = Object.freeze(data.map(device => {
|
|
|
const item = this.transformDevice(device)
|
|
|
map[device.id] = item
|
|
|
topics.push(...this.createTopics(item))
|
|
|
return item
|
|
|
- })
|
|
|
+ }))
|
|
|
groupOptions.map = map
|
|
|
groupOptions.loaded = true
|
|
|
this.onChanged()
|