自动签页面
这个提交包含在:
父节点
2a93b85895
当前提交
c76be01096
@ -5,57 +5,76 @@ type ItemType = (string | number | Object)
|
|||||||
@Preview
|
@Preview
|
||||||
@Component
|
@Component
|
||||||
export struct RefreshView {
|
export struct RefreshView {
|
||||||
@Prop isLoading: boolean
|
@Link isLoading: boolean
|
||||||
@Prop data: ItemType[]
|
@Prop data: Array<object>
|
||||||
loadMore(){}
|
onLoadMore?: () => void
|
||||||
refresh(){}
|
onRefresh?: () => void
|
||||||
|
private startY: number = 0
|
||||||
|
private endY: number = 0
|
||||||
|
private lastNum: number = 0
|
||||||
|
private _openMore: boolean = false
|
||||||
|
|
||||||
aboutToAppear(): void {
|
aboutToAppear(): void {
|
||||||
this.refresh()
|
// this.onRefresh && this.onRefresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用父组件@Builder装饰的方法初始化子组件@BuilderParam
|
// 使用父组件@Builder装饰的方法初始化子组件@BuilderParam
|
||||||
@BuilderParam customBuilderParam: (item:string) => void
|
@BuilderParam customBuilderParam: (item: ESObject, index: number) => void
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
|
|
||||||
Refresh({ refreshing: $$this.isLoading }) {
|
Refresh({ refreshing: $$this.isLoading }) {
|
||||||
|
if (this.data && this.data.length > 0) {
|
||||||
List() {
|
List() {
|
||||||
ForEach(this.data ?? [], (item: string) => {
|
ForEach(this.data ?? [], (item: ESObject, index: number) => {
|
||||||
ListItem() {
|
ListItem() {
|
||||||
this.customBuilderParam(item)
|
this.customBuilderParam(item, index)
|
||||||
}
|
}
|
||||||
.backgroundColor('blue')
|
|
||||||
}, (index: number) => index.toString())
|
}, (index: number) => index.toString())
|
||||||
}
|
}
|
||||||
.onScrollStart(() => {
|
|
||||||
ToolsHelper.log('onScrollStart')
|
|
||||||
})
|
|
||||||
.onScrollStop(() => {
|
|
||||||
ToolsHelper.log('onScrollStop')
|
|
||||||
})
|
|
||||||
.onTouch((event: TouchEvent) => {
|
.onTouch((event: TouchEvent) => {
|
||||||
const e1 = event.touches[0]
|
const e1 = event.touches[0]
|
||||||
ToolsHelper.log(`onTouch ${event.type}-${e1.x.toString()}-${e1.y.toString()}`)
|
switch (event.type) {
|
||||||
|
case TouchType.Down:
|
||||||
|
this._openMore = this.data && this.lastNum >= this.data.length && !this.isLoading
|
||||||
|
this.startY = e1.y
|
||||||
|
break
|
||||||
|
// case TouchType.Move:
|
||||||
|
// this.endY = e1.y
|
||||||
|
// if (this.endY - this.startY < -100) {
|
||||||
|
// this.loadMore&&this.loadMore()
|
||||||
|
// }
|
||||||
|
// break
|
||||||
|
case TouchType.Up:
|
||||||
|
this.endY = e1.y
|
||||||
|
if (this.endY - this.startY < -100 && this._openMore) {
|
||||||
|
this.onLoadMore && this.onLoadMore()
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.onScrollIndex((first: number, last: number) => {
|
.onScrollIndex((first: number, last: number) => {
|
||||||
ToolsHelper.log(`${first.toString()}-${last.toString()}`)
|
this.lastNum = last
|
||||||
})
|
})
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.height('100%')
|
.height('100%')
|
||||||
.alignListItem(ListItemAlign.Center)
|
.alignListItem(ListItemAlign.Center)
|
||||||
.scrollBar(BarState.Off)
|
.scrollBar(BarState.Off)
|
||||||
}.width('100%')
|
} else {
|
||||||
.backgroundColor('red')
|
Text('暂无数据')
|
||||||
|
.width('100%')
|
||||||
|
.height('100%')
|
||||||
|
.textAlign(TextAlign.Center)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
.height('100%')
|
.height('100%')
|
||||||
.onStateChange((refreshStatus: RefreshStatus) => {
|
.onStateChange((refreshStatus: RefreshStatus) => {
|
||||||
ToolsHelper.log('Refresh onStatueChange state is ' + refreshStatus)
|
ToolsHelper.log('Refresh onStatueChange state is ' + refreshStatus)
|
||||||
})
|
})
|
||||||
.onRefreshing(() => {
|
.onRefreshing(() => {
|
||||||
setTimeout(() => {
|
this.onRefresh && this.onRefresh()
|
||||||
this.isLoading = false
|
|
||||||
}, 2000)
|
|
||||||
ToolsHelper.log('onRefreshing test')
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
正在加载...
在新工单中引用
屏蔽一个用户