refs #6772: Improve FetchData
This commit is contained in:
parent
31d9c00ce0
commit
38e3e1c004
|
@ -79,22 +79,18 @@ async function paginate() {
|
||||||
pagination.value.page += 1;
|
pagination.value.page += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetch(fetchFilter = {}, options = { append: false }) {
|
async function fetch(fetchFilter = {}) {
|
||||||
try {
|
try {
|
||||||
const filter = Object.assign(fetchFilter, $props.filter); // eslint-disable-line vue/no-dupe-keys
|
const filter = Object.assign(fetchFilter, $props.filter, $props.params); // eslint-disable-line vue/no-dupe-keys
|
||||||
if ($props.where && !fetchFilter.where) filter.where = $props.where;
|
if ($props.where && !fetchFilter.where) filter.where = $props.where;
|
||||||
if ($props.sortBy) filter.order = $props.sortBy;
|
if ($props.sortBy) filter.order = $props.sortBy;
|
||||||
if ($props.limit) filter.limit = $props.limit;
|
if ($props.limit) filter.limit = $props.limit;
|
||||||
if ($props.skip) filter.skip = $props.skip;
|
if ($props.skip) filter.skip = $props.skip;
|
||||||
|
|
||||||
const { data } = await axios.get($props.url, {
|
await arrayData.applyFilter(filter);
|
||||||
params: { filter: JSON.stringify(filter), ...$props.params },
|
|
||||||
});
|
|
||||||
pagination.value.hasMoreData = data.length === pagination.value.rowsPerPage;
|
|
||||||
|
|
||||||
if (options.append) {
|
const { data } = store;
|
||||||
store.data.push(...data);
|
pagination.value.hasMoreData = data.length === pagination.value.rowsPerPage;
|
||||||
} else store.data = data;
|
|
||||||
|
|
||||||
emit('onFetch', data);
|
emit('onFetch', data);
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ const $props = defineProps({
|
||||||
},
|
},
|
||||||
limit: {
|
limit: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: '4',
|
default: '30',
|
||||||
},
|
},
|
||||||
fetchRef: {
|
fetchRef: {
|
||||||
type: Object,
|
type: Object,
|
||||||
|
@ -161,9 +161,8 @@ watch(modelValue, (newValue) => {
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
|
|
||||||
async function onScroll(scrollEv) {
|
async function onScroll(scrollEv) {
|
||||||
const { to, ref, direction } = scrollEv;
|
const { to, direction } = scrollEv;
|
||||||
const lastIndex = myOptions.value.length - 1;
|
const lastIndex = myOptions.value.length - 1;
|
||||||
const optionIndex = ref.getOptionIndex();
|
|
||||||
|
|
||||||
if (!$props.url && !$props.fetchRef) return;
|
if (!$props.url && !$props.fetchRef) return;
|
||||||
if (direction === 'decrease') return;
|
if (direction === 'decrease') return;
|
||||||
|
|
|
@ -80,8 +80,7 @@ export function useArrayData(key, userOptions) {
|
||||||
exprFilter = where ? { where } : null;
|
exprFilter = where ? { where } : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(filter, store.userFilter, exprFilter);
|
Object.assign(store.filter, filter, store.userFilter, exprFilter);
|
||||||
Object.assign(store.filter, filter);
|
|
||||||
const params = {
|
const params = {
|
||||||
filter: JSON.stringify(store.filter),
|
filter: JSON.stringify(store.filter),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue