From 9f9a676f53eb47a627da4076b47b1d7a4cb78601 Mon Sep 17 00:00:00 2001 From: aixianling Date: Tue, 10 Jan 2023 15:17:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wxmp/src/utils/list.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 wxmp/src/utils/list.js diff --git a/wxmp/src/utils/list.js b/wxmp/src/utils/list.js new file mode 100644 index 0000000..196e1d0 --- /dev/null +++ b/wxmp/src/utils/list.js @@ -0,0 +1,36 @@ +import http from "./http"; + +class List { + constructor(action) { + this.action = action + this.current = 1 + this.total = 0 + this.list = [] + } + + getData(params) { + const {action} = this + return http.post(action, null, {params}) + } + + init(params) { + this.getData({...params, current: 1}).then(res => { + if (res?.data) { + this.list = res.data.records + this.total = res.data.total + } + }) + } + + loadMore(params) { + if (this.list.length < this.total) { + this.getData({...params, current: ++this.current}).then(res => { + if (res?.data) { + this.list = [...this.list, ...res.data.records] + } + }) + } + } +} + +export default List