Files
app-govern/common/js/list.js

84 lines
2.9 KiB
JavaScript
Raw Normal View History

2023-01-11 16:33:13 +08:00
export default {
2023-04-04 08:47:19 +08:00
onPullDownRefresh() {
2023-01-11 16:33:13 +08:00
this.store && this.store.reload();
this.store.loadedCallback = () => {
uni.stopPullDownRefresh();
};
},
2023-04-04 08:47:19 +08:00
onReachBottom() {
if (this.store.status != 'noMore') {
2023-01-11 16:33:13 +08:00
this.store.next && this.store.next();
}
},
2023-04-04 08:47:19 +08:00
data() {
2023-01-11 16:33:13 +08:00
return {
store: {},
};
},
methods: {
2023-04-04 08:47:19 +08:00
DataSource(url) {
2023-01-11 16:33:13 +08:00
var me = this;
return {
data: [],
2023-04-04 08:47:19 +08:00
status: 'more',
2023-01-11 16:33:13 +08:00
empty: false,
total: 0,
2023-03-30 09:04:07 +08:00
header: {
2023-04-04 08:47:19 +08:00
'Content-Type': 'application/json;charset=UTF-8',
2023-03-30 09:04:07 +08:00
},
2023-01-11 16:33:13 +08:00
params: {
2023-03-30 09:04:07 +08:00
currentPage: 1,
pageSize: 20,
2023-01-11 16:33:13 +08:00
},
2023-04-04 08:47:19 +08:00
reload() {
2023-01-11 16:33:13 +08:00
this.data = [];
2023-04-04 08:47:19 +08:00
this.status = 'loading';
2023-01-11 16:33:13 +08:00
this.empty = false;
2023-03-30 09:04:07 +08:00
this.params.currentPage = 1;
2023-01-11 16:33:13 +08:00
this.next();
},
callBack: null,
firstCallBack: null,
loadedCallback: null,
2023-04-04 08:47:19 +08:00
next() {
2023-01-11 16:33:13 +08:00
me.$request({
url: url,
2023-03-30 09:04:07 +08:00
data: this.params,
2023-01-11 16:33:13 +08:00
header: this.header,
2023-04-04 08:47:19 +08:00
method: 'POST',
2023-01-11 16:33:13 +08:00
}).then((res) => {
console.warn(res);
2023-04-04 08:47:19 +08:00
let resultData =
2023-04-12 18:39:52 +08:00
res.data?.list || res.data?.records || [];
2023-03-30 09:04:07 +08:00
if (this.params.currentPage == 1) {
2023-01-11 16:33:13 +08:00
this.data = resultData;
if (resultData.length == 0 || resultData == 0) {
this.empty = true;
2023-04-04 08:47:19 +08:00
} else if (
resultData.length < this.params.pageSize
) {
this.status = 'noMore';
2023-01-11 16:33:13 +08:00
} else if (res.total == resultData.length) {
2023-04-04 08:47:19 +08:00
this.status = 'noMore';
2023-01-11 16:33:13 +08:00
}
} else {
this.data.push(...resultData);
2023-03-30 09:04:07 +08:00
if (resultData.length < this.params.pageSize) {
2023-04-04 08:47:19 +08:00
this.status = 'noMore';
2023-01-11 16:33:13 +08:00
}
}
2023-03-30 09:04:07 +08:00
if (this.params.currentPage == 1) {
2023-01-11 16:33:13 +08:00
this.firstCallBack && this.firstCallBack();
}
this.loadedCallback && this.loadedCallback();
2023-03-30 09:04:07 +08:00
this.params.currentPage++;
2023-01-11 16:33:13 +08:00
this.total = res.total;
this.loading = false;
});
},
};
},
},
};