perf :包含分页数据页面代码优化

This commit is contained in:
kele
2023-02-07 15:45:02 +08:00
parent 447ece1a49
commit 29131a3af7
10 changed files with 67 additions and 82 deletions
+14 -15
View File
@@ -144,6 +144,13 @@
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
import { reactive } from 'vue';
import _ from 'lodash';
const pagination = {
data: [],
current_page: 1,
total: 1,
last_page: 1,
};
const state = reactive({
list: {},
couponId: 0,
@@ -182,12 +189,7 @@
});
function onTabsChange(e) {
state.pagination = {
data: [],
current_page: 1,
total: 1,
last_page: 1,
};
state.pagination = pagination;
state.currentTab = e.index;
state.categoryId = e.value;
getGoodsList(state.categoryId);
@@ -201,15 +203,11 @@
is_category_deep: false,
});
if (res.error === 0) {
if (page >= 2) {
let couponlist = _.concat(state.pagination.data, res.data.data);
state.pagination = {
...res.data,
data: couponlist,
};
} else {
state.pagination = res.data;
}
let couponlist = _.concat(state.pagination.data, res.data.data);
state.pagination = {
...res.data,
data: couponlist,
};
if (state.pagination.current_page < state.pagination.last_page) {
state.loadStatus = 'more';
} else {
@@ -234,6 +232,7 @@
data.items_value.forEach((i) => {
state.tabMaps.push({ name: i.name, value: i.id });
});
state.pagination = pagination
getGoodsList(state.tabMaps[0].value);
}
// 加载更多
+13 -15
View File
@@ -91,6 +91,12 @@
import { computed, reactive } from 'vue';
import _ from 'lodash';
const pagination = {
data: [],
current_page: 1,
total: 1,
last_page: 1,
};
// 数据
const state = reactive({
currentTab: 0,
@@ -123,12 +129,7 @@
},
];
function onTabsChange(e) {
state.pagination = {
data: [],
current_page: 1,
total: 1,
last_page: 1,
};
state.pagination = pagination
state.currentTab = e.index;
state.type = e.value;
if (state.currentTab == 0) {
@@ -141,15 +142,11 @@
state.loadStatus = 'loading';
const res = await sheep.$api.coupon.list({ list_rows, page });
if (res.error === 0) {
if (page >= 2) {
let couponlist = _.concat(state.pagination.data, res.data.data);
state.pagination = {
...res.data,
data: couponlist,
};
} else {
state.pagination = res.data;
}
let couponlist = _.concat(state.pagination.data, res.data.data);
state.pagination = {
...res.data,
data: couponlist,
};
if (state.pagination.current_page < state.pagination.last_page) {
state.loadStatus = 'more';
} else {
@@ -189,6 +186,7 @@
title: msg,
});
setTimeout(() => {
state.pagination = pagination
getData();
}, 1000);
}