@mypui/myp-ui
Version:
第一个高效且强悍的nvue开源组件库。做最好、最顺手的nvue组件库
138 lines (135 loc) • 3.23 kB
JavaScript
export default {
methods: {
// #ifdef APP-NVUE
mypResetLoadMore() {
this.$refs['myp-scroller'].resetLoadmore()
},
mypScroll(e) {
this.$emit("scroll", e)
},
mypMoreLoad() {
if (!this.mypUp.use) {
return
}
if (this.useLoading) {
return
}
this.mypLoad()
},
mypRefresh() {
this.mypPrePage = this.mypCurrentPage
this.mypCurrentPage = 1
if (this.mypDown.use) {
this.mypIsDownLoading = true
}
this.mypGetContentList('refresh')
},
mypLoad() {
if (!this.mypUp.use) return;
if (this.mypIsDownLoading) {
if (this.platform === 'ios') {
this.$refs['myp-loader'] && this.$refs['myp-loader'].cancel()
return
}
const that = this
setTimeout(()=>{
that.$refs['myp-loader'] && that.$refs['myp-loader'].cancel()
}, 0)
return
}
if (this.mypIsUpLoading) {
return
}
if (!this.mypHasMore) {
if (this.platform === 'ios') {
this.$refs['myp-loader'] && this.$refs['myp-loader'].cancel()
return
}
const that = this
setTimeout(()=>{
that.$refs['myp-loader'] && that.$refs['myp-loader'].cancel()
}, 0)
return
}
this.mypPrePage = this.mypCurrentPage
this.mypCurrentPage += 1
if (this.mypUp.use) {
this.mypIsUpLoading = true
}
this.mypGetContentList('load')
},
mypReload() {
if (!this.mypUp.use) return;
if (this.mypIsDownLoading) {
if (this.platform === 'ios') {
this.$refs['myp-loader'] && this.$refs['myp-loader'].cancel()
return
}
const that = this
setTimeout(()=>{
that.$refs['myp-loader'] && that.$refs['myp-loader'].cancel()
}, 0)
return
}
if (this.mypIsUpLoading) {
return
}
this.mypPrePage = this.mypCurrentPage
this.mypCurrentPage = 1
if (this.mypUp.use) {
this.mypIsUpLoading = true
}
this.mypGetContentList('load')
},
// default has no more
// ref method: call when refresh/load success
mypEndSuccess(hasMore=false) {
this.mypHasMore = hasMore
if (this.mypIsDownLoading) {
this.$refs['myp-refresher'] && this.$refs['myp-refresher'].cancel()
this.mypIsDownLoading = false
// 重置 loadMore
this.mypResetLoadMore()
}
if (this.mypIsUpLoading) {
this.$refs['myp-loader'] && this.$refs['myp-loader'].cancel()
this.mypIsUpLoading = false
// 重置 loadMore
// this.mypResetLoadMore()
}
},
// ref method: call when refresh/load fail
mypEndError() {
this.mypCurrentPage = this.mypPrePage
if (this.mypIsDownLoading) {
this.$refs['myp-refresher'] && this.$refs['myp-refresher'].cancel()
this.mypIsDownLoading = false
}
if (this.mypIsUpLoading) {
this.$refs['myp-loader'] && this.$refs['myp-loader'].cancel()
this.mypIsUpLoading = false
}
},
mypInitContentList() {
this.mypPrePage = 0
this.mypCurrentPage = 1
if (this.mypDown.use) {
this.mypIsDownLoading = true
this.mypGetContentList('refresh')
} else {
if (this.mypUp.use) {
this.mypIsUpLoading = true
this.mypGetContentList('load')
}
}
},
mypGetContentList(type='refresh') {
if (type === 'refresh') {
this.$emit('down')
} else {
this.$emit('up')
}
}
// #endif
}
}