fix: fix pagination issue & skip url query param
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
731169053c
commit
9b7ffbf3d2
|
@ -10,7 +10,7 @@ const { t } = useI18n();
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => {}
|
default: () => {},
|
||||||
},
|
},
|
||||||
dataKey: {
|
dataKey: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -67,9 +67,9 @@ const arrayData = useArrayData($props.dataKey, {
|
||||||
});
|
});
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const store = arrayData.store;
|
const store = arrayData.store;
|
||||||
const userParams = ref({})
|
const userParams = ref({});
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
userParams.value = $props.modelValue ?? {}
|
userParams.value = $props.modelValue ?? {};
|
||||||
emit('init', { params: userParams.value });
|
emit('init', { params: userParams.value });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -102,6 +102,7 @@ async function search(evt) {
|
||||||
store.userParamsChanged = true;
|
store.userParamsChanged = true;
|
||||||
store.filter.skip = 0;
|
store.filter.skip = 0;
|
||||||
store.skip = 0;
|
store.skip = 0;
|
||||||
|
store.page = 1;
|
||||||
const { params: newParams } = await arrayData.addFilter({ params: userParams.value });
|
const { params: newParams } = await arrayData.addFilter({ params: userParams.value });
|
||||||
userParams.value = newParams;
|
userParams.value = newParams;
|
||||||
|
|
||||||
|
@ -114,7 +115,8 @@ async function search(evt) {
|
||||||
async function reload() {
|
async function reload() {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
const params = Object.values(userParams.value).filter((param) => param);
|
const params = Object.values(userParams.value).filter((param) => param);
|
||||||
|
store.skip = 0;
|
||||||
|
store.page = 1;
|
||||||
await arrayData.fetch({ append: false });
|
await arrayData.fetch({ append: false });
|
||||||
if (!$props.showAll && !params.length) store.data = [];
|
if (!$props.showAll && !params.length) store.data = [];
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
|
@ -126,6 +128,7 @@ async function clearFilters() {
|
||||||
store.userParamsChanged = true;
|
store.userParamsChanged = true;
|
||||||
store.filter.skip = 0;
|
store.filter.skip = 0;
|
||||||
store.skip = 0;
|
store.skip = 0;
|
||||||
|
store.page = 1;
|
||||||
// Filtrar los params no removibles
|
// Filtrar los params no removibles
|
||||||
const removableFilters = Object.keys(userParams.value).filter((param) =>
|
const removableFilters = Object.keys(userParams.value).filter((param) =>
|
||||||
$props.unremovableParams.includes(param)
|
$props.unremovableParams.includes(param)
|
||||||
|
|
|
@ -104,6 +104,7 @@ async function search() {
|
||||||
([key, value]) => value && (props.staticParams || []).includes(key)
|
([key, value]) => value && (props.staticParams || []).includes(key)
|
||||||
);
|
);
|
||||||
store.skip = 0;
|
store.skip = 0;
|
||||||
|
store.page = 1;
|
||||||
|
|
||||||
if (props.makeFetch)
|
if (props.makeFetch)
|
||||||
await arrayData.applyFilter({
|
await arrayData.applyFilter({
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { onMounted, ref, computed } from 'vue';
|
import { onMounted, computed } from 'vue';
|
||||||
import { useRouter, useRoute } from 'vue-router';
|
import { useRouter, useRoute } from 'vue-router';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { useArrayDataStore } from 'stores/useArrayDataStore';
|
import { useArrayDataStore } from 'stores/useArrayDataStore';
|
||||||
|
@ -16,8 +16,6 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
let canceller = null;
|
let canceller = null;
|
||||||
|
|
||||||
const page = ref(1);
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
setOptions();
|
setOptions();
|
||||||
store.skip = 0;
|
store.skip = 0;
|
||||||
|
@ -87,13 +85,13 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(filter, store.userFilter, exprFilter);
|
Object.assign(filter, store.userFilter, exprFilter);
|
||||||
Object.assign(store.filter, { ...filter, skip: store.skip });
|
Object.assign(store.filter, filter);
|
||||||
const params = {
|
const params = { filter: store.filter };
|
||||||
filter: JSON.stringify(store.filter),
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.assign(params, userParams);
|
Object.assign(params, userParams);
|
||||||
|
params.filter.skip = store.skip;
|
||||||
|
|
||||||
|
params.filter = JSON.stringify(params.filter);
|
||||||
store.currentFilter = params;
|
store.currentFilter = params;
|
||||||
store.isLoading = true;
|
store.isLoading = true;
|
||||||
const response = await axios.get(store.url, {
|
const response = await axios.get(store.url, {
|
||||||
|
@ -154,8 +152,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
||||||
store.userParams = userParams;
|
store.userParams = userParams;
|
||||||
store.skip = 0;
|
store.skip = 0;
|
||||||
store.filter.skip = 0;
|
store.filter.skip = 0;
|
||||||
page.value = 1;
|
store.page = 1;
|
||||||
|
|
||||||
await fetch({ append: false });
|
await fetch({ append: false });
|
||||||
return { filter, params };
|
return { filter, params };
|
||||||
}
|
}
|
||||||
|
@ -187,10 +184,11 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
||||||
async function loadMore() {
|
async function loadMore() {
|
||||||
if (!store.hasMoreData) return;
|
if (!store.hasMoreData) return;
|
||||||
|
|
||||||
store.skip = store.limit * page.value;
|
store.skip = store.limit * store.page;
|
||||||
page.value += 1;
|
store.page += 1;
|
||||||
|
|
||||||
await fetch({ append: true });
|
await fetch({ append: true });
|
||||||
|
updateStateParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refresh() {
|
async function refresh() {
|
||||||
|
|
|
@ -23,6 +23,7 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => {
|
||||||
exprBuilder: null,
|
exprBuilder: null,
|
||||||
searchUrl: 'params',
|
searchUrl: 'params',
|
||||||
navigate: null,
|
navigate: null,
|
||||||
|
page: 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue