Commit 30f3acec by huangqy

列表刷新

parent c5d621ee
...@@ -8,6 +8,7 @@ import {UnitList} from'./UnitList' ...@@ -8,6 +8,7 @@ import {UnitList} from'./UnitList'
export struct Unit { export struct Unit {
@State dataSource: Gldw[] = [] @State dataSource: Gldw[] = []
@State offsetNumber: number = 0 @State offsetNumber: number = 0
@State finished: boolean = false
controller: SearchController = new SearchController() controller: SearchController = new SearchController()
aboutToAppear(){ aboutToAppear(){
...@@ -15,9 +16,17 @@ export struct Unit { ...@@ -15,9 +16,17 @@ export struct Unit {
} }
async getUnitList(dwmc?: string) { async getUnitList(dwmc?: string) {
Logger.info('-------DEBUG-------: 起始' + this.offsetNumber)
const res = await gldwModal.query(this.offsetNumber * 20, dwmc) const res = await gldwModal.query(this.offsetNumber * 20, dwmc)
if (res.length == 0) { // 如果数据库查到的数据是空数组,则告诉后面不需要再调了
this.finished = true
}
this.dataSource = [...this.dataSource, ...res] this.dataSource = [...this.dataSource, ...res]
this.offsetNumber++ }
scrollEvent() {
this.getUnitList()
Logger.info('-------DEBUG-------: 开始滑动' + this.offsetNumber)
} }
...@@ -36,7 +45,7 @@ export struct Unit { ...@@ -36,7 +45,7 @@ export struct Unit {
.borderRadius(5) .borderRadius(5)
}.width('100%') }.width('100%')
Column() { Column() {
UnitList({ dataSource: $dataSource,onScrollEdge: this.getUnitList }) UnitList({ dataSource: $dataSource, finished: $finished,offsetNumber: $offsetNumber, onScrollEdge: this.getUnitList })
}.margin({top:20}).borderRadius(2) }.margin({top:20}).borderRadius(2)
} }
}.linearGradient({ }.linearGradient({
......
import { Gldw } from '@ohos/common' import { Gldw, Logger } from '@ohos/common'
@Component @Component
export struct UnitList { export struct UnitList {
@Link dataSource: Gldw[] @Link dataSource: Gldw[]
@Link finished: boolean
@Link offsetNumber: number
@Styles commonPadding() { @Styles commonPadding() {
.padding({top:4, bottom:4}) .padding({top:4, bottom:4})
.alignSelf(ItemAlign.Start) .alignSelf(ItemAlign.Start)
} }
onScrollEdge: () => void onScrollEdge: () => void
scroller: Scroller = new Scroller()
@Builder renderList() { @Builder renderList() {
Column() { Column() {
Scroll() { List({ space: 2, scroller: this.scroller }){
List(){
ForEach(this.dataSource, (item, index) => { ForEach(this.dataSource, (item, index) => {
ListItem(){ ListItem(){
Row() { Row() {
...@@ -31,10 +34,16 @@ export struct UnitList { ...@@ -31,10 +34,16 @@ export struct UnitList {
} }
}.width('45%') }.width('45%')
}.commonPadding() }.commonPadding()
} }.borderRadius(4)
}) })
}.divider({strokeWidth:1,color:'505050'}) }.divider({strokeWidth:1,color:'505050'})
}.onScrollEdge(() => this.onScrollEdge()) .onScrollIndex((firstIndex: number, lastIndex: number) => {
if (!this.finished && this.dataSource.length == (lastIndex + 1) ) {
// 如果没完成并且划到最底部则调刷新数据接口
this.offsetNumber ++
this.onScrollEdge()
}
})
}.width('100%').height('100%').backgroundColor('#fff') }.width('100%').height('100%').backgroundColor('#fff')
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论