fix(frontend): tweak MkPagination behaviouyr
This commit is contained in:
parent
4f9f625e65
commit
c032dd1214
@ -163,21 +163,22 @@ async function init(): Promise<void> {
|
|||||||
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
||||||
await os.api(props.pagination.endpoint, {
|
await os.api(props.pagination.endpoint, {
|
||||||
...params,
|
...params,
|
||||||
limit: props.pagination.noPaging ? (props.pagination.limit || 10) : (props.pagination.limit || 10) + 1,
|
limit: props.pagination.limit ?? 10,
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
for (let i = 0; i < res.length; i++) {
|
for (let i = 0; i < res.length; i++) {
|
||||||
const item = res[i];
|
const item = res[i];
|
||||||
if (i === 3) item._shouldInsertAd_ = true;
|
if (i === 3) item._shouldInsertAd_ = true;
|
||||||
}
|
}
|
||||||
if (!props.pagination.noPaging && (res.length > (props.pagination.limit || 10))) {
|
|
||||||
res.pop();
|
if (res.length === 0 || props.pagination.noPaging) {
|
||||||
|
items.value = res;
|
||||||
|
more.value = false;
|
||||||
|
} else {
|
||||||
if (props.pagination.reversed) moreFetching.value = true;
|
if (props.pagination.reversed) moreFetching.value = true;
|
||||||
items.value = res;
|
items.value = res;
|
||||||
more.value = true;
|
more.value = true;
|
||||||
} else {
|
|
||||||
items.value = res;
|
|
||||||
more.value = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
offset.value = res.length;
|
offset.value = res.length;
|
||||||
error.value = false;
|
error.value = false;
|
||||||
fetching.value = false;
|
fetching.value = false;
|
||||||
@ -198,7 +199,7 @@ const fetchMore = async (): Promise<void> => {
|
|||||||
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
||||||
await os.api(props.pagination.endpoint, {
|
await os.api(props.pagination.endpoint, {
|
||||||
...params,
|
...params,
|
||||||
limit: SECOND_FETCH_LIMIT + 1,
|
limit: SECOND_FETCH_LIMIT,
|
||||||
...(props.pagination.offsetMode ? {
|
...(props.pagination.offsetMode ? {
|
||||||
offset: offset.value,
|
offset: offset.value,
|
||||||
} : {
|
} : {
|
||||||
@ -227,28 +228,26 @@ const fetchMore = async (): Promise<void> => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (res.length > SECOND_FETCH_LIMIT) {
|
if (res.length === 0) {
|
||||||
res.pop();
|
|
||||||
|
|
||||||
if (props.pagination.reversed) {
|
if (props.pagination.reversed) {
|
||||||
reverseConcat(res).then(() => {
|
reverseConcat(res).then(() => {
|
||||||
more.value = true;
|
more.value = false;
|
||||||
moreFetching.value = false;
|
moreFetching.value = false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
items.value = items.value.concat(res);
|
items.value = items.value.concat(res);
|
||||||
more.value = true;
|
more.value = false;
|
||||||
moreFetching.value = false;
|
moreFetching.value = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (props.pagination.reversed) {
|
if (props.pagination.reversed) {
|
||||||
reverseConcat(res).then(() => {
|
reverseConcat(res).then(() => {
|
||||||
more.value = false;
|
more.value = true;
|
||||||
moreFetching.value = false;
|
moreFetching.value = false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
items.value = items.value.concat(res);
|
items.value = items.value.concat(res);
|
||||||
more.value = false;
|
more.value = true;
|
||||||
moreFetching.value = false;
|
moreFetching.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,20 +263,19 @@ const fetchMoreAhead = async (): Promise<void> => {
|
|||||||
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
||||||
await os.api(props.pagination.endpoint, {
|
await os.api(props.pagination.endpoint, {
|
||||||
...params,
|
...params,
|
||||||
limit: SECOND_FETCH_LIMIT + 1,
|
limit: SECOND_FETCH_LIMIT,
|
||||||
...(props.pagination.offsetMode ? {
|
...(props.pagination.offsetMode ? {
|
||||||
offset: offset.value,
|
offset: offset.value,
|
||||||
} : {
|
} : {
|
||||||
sinceId: items.value[items.value.length - 1].id,
|
sinceId: items.value[items.value.length - 1].id,
|
||||||
}),
|
}),
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.length > SECOND_FETCH_LIMIT) {
|
if (res.length === 0) {
|
||||||
res.pop();
|
|
||||||
items.value = items.value.concat(res);
|
|
||||||
more.value = true;
|
|
||||||
} else {
|
|
||||||
items.value = items.value.concat(res);
|
items.value = items.value.concat(res);
|
||||||
more.value = false;
|
more.value = false;
|
||||||
|
} else {
|
||||||
|
items.value = items.value.concat(res);
|
||||||
|
more.value = true;
|
||||||
}
|
}
|
||||||
offset.value += res.length;
|
offset.value += res.length;
|
||||||
moreFetching.value = false;
|
moreFetching.value = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user