Merge branch 'dev' into VnTable_fix
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
commit
47fe9b25e9
|
@ -112,9 +112,7 @@ async function search(evt) {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
const filter = { ...userParams.value };
|
const filter = { ...userParams.value };
|
||||||
store.userParamsChanged = true;
|
store.userParamsChanged = true;
|
||||||
store.filter.skip = 0;
|
arrayData.reset(['skip', 'filter.skip', 'page']);
|
||||||
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;
|
||||||
|
|
||||||
|
@ -138,9 +136,7 @@ async function reload() {
|
||||||
async function clearFilters() {
|
async function clearFilters() {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
store.userParamsChanged = true;
|
store.userParamsChanged = true;
|
||||||
store.filter.skip = 0;
|
arrayData.reset(['skip', 'filter.skip', 'page']);
|
||||||
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)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, ref, watch } from 'vue';
|
import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useArrayData } from 'composables/useArrayData';
|
import { useArrayData } from 'composables/useArrayData';
|
||||||
|
|
||||||
|
@ -95,6 +95,8 @@ onMounted(async () => {
|
||||||
mounted.value = true;
|
mounted.value = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => arrayData.reset());
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.data,
|
() => props.data,
|
||||||
() => {
|
() => {
|
||||||
|
@ -118,8 +120,7 @@ const addFilter = async (filter, params) => {
|
||||||
|
|
||||||
async function fetch(params) {
|
async function fetch(params) {
|
||||||
useArrayData(props.dataKey, params);
|
useArrayData(props.dataKey, params);
|
||||||
store.filter.skip = 0;
|
arrayData.reset(['filter.skip', 'skip']);
|
||||||
store.skip = 0;
|
|
||||||
await arrayData.fetch({ append: false });
|
await arrayData.fetch({ append: false });
|
||||||
if (!store.hasMoreData) {
|
if (!store.hasMoreData) {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
|
|
|
@ -103,8 +103,7 @@ async function search() {
|
||||||
const staticParams = Object.entries(store.userParams).filter(
|
const staticParams = Object.entries(store.userParams).filter(
|
||||||
([key, value]) => value && (props.staticParams || []).includes(key)
|
([key, value]) => value && (props.staticParams || []).includes(key)
|
||||||
);
|
);
|
||||||
store.skip = 0;
|
arrayData.reset(['skip', 'page']);
|
||||||
store.page = 1;
|
|
||||||
|
|
||||||
if (props.makeFetch)
|
if (props.makeFetch)
|
||||||
await arrayData.applyFilter({
|
await arrayData.applyFilter({
|
||||||
|
|
|
@ -18,7 +18,8 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
setOptions();
|
setOptions();
|
||||||
store.skip = 0;
|
arrayDataStore.reset(['skip']);
|
||||||
|
|
||||||
const query = route.query;
|
const query = route.query;
|
||||||
const searchUrl = store.searchUrl;
|
const searchUrl = store.searchUrl;
|
||||||
if (query[searchUrl]) {
|
if (query[searchUrl]) {
|
||||||
|
@ -128,6 +129,10 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
||||||
delete store[option];
|
delete store[option];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reset(opts = []) {
|
||||||
|
if (arrayDataStore.get(key)) arrayDataStore.reset(key, opts);
|
||||||
|
}
|
||||||
|
|
||||||
function cancelRequest() {
|
function cancelRequest() {
|
||||||
if (canceller) {
|
if (canceller) {
|
||||||
canceller.abort();
|
canceller.abort();
|
||||||
|
@ -151,9 +156,8 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
||||||
userParams = sanitizerParams(userParams, store?.exprBuilder);
|
userParams = sanitizerParams(userParams, store?.exprBuilder);
|
||||||
|
|
||||||
store.userParams = userParams;
|
store.userParams = userParams;
|
||||||
store.skip = 0;
|
arrayDataStore.reset(['skip', 'filter.skip', 'page']);
|
||||||
store.filter.skip = 0;
|
|
||||||
store.page = 1;
|
|
||||||
await fetch({ append: false });
|
await fetch({ append: false });
|
||||||
return { filter, params };
|
return { filter, params };
|
||||||
}
|
}
|
||||||
|
@ -242,5 +246,6 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
||||||
updateStateParams,
|
updateStateParams,
|
||||||
isLoading,
|
isLoading,
|
||||||
deleteOption,
|
deleteOption,
|
||||||
|
reset,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,37 +3,56 @@ import { defineStore } from 'pinia';
|
||||||
|
|
||||||
export const useArrayDataStore = defineStore('arrayDataStore', () => {
|
export const useArrayDataStore = defineStore('arrayDataStore', () => {
|
||||||
const state = ref({});
|
const state = ref({});
|
||||||
|
const defaultOpts = {
|
||||||
|
filter: {},
|
||||||
|
userFilter: {},
|
||||||
|
userParams: {},
|
||||||
|
url: '',
|
||||||
|
limit: 10,
|
||||||
|
skip: 0,
|
||||||
|
order: '',
|
||||||
|
isLoading: false,
|
||||||
|
userParamsChanged: false,
|
||||||
|
exprBuilder: null,
|
||||||
|
searchUrl: 'params',
|
||||||
|
navigate: null,
|
||||||
|
page: 1,
|
||||||
|
};
|
||||||
|
|
||||||
function get(key) {
|
function get(key) {
|
||||||
return state.value[key];
|
return state.value[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
function set(key) {
|
function set(key) {
|
||||||
state.value[key] = {
|
state.value[key] = getDefaultState();
|
||||||
filter: {},
|
|
||||||
userFilter: {},
|
|
||||||
userParams: {},
|
|
||||||
url: '',
|
|
||||||
limit: 10,
|
|
||||||
skip: 0,
|
|
||||||
order: '',
|
|
||||||
data: ref(),
|
|
||||||
isLoading: false,
|
|
||||||
userParamsChanged: false,
|
|
||||||
exprBuilder: null,
|
|
||||||
searchUrl: 'params',
|
|
||||||
navigate: null,
|
|
||||||
page: 1,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear(key) {
|
function clear(key) {
|
||||||
delete state.value[key];
|
delete state.value[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reset(key, opts = []) {
|
||||||
|
if (!opts.length) state.value[key] = getDefaultState();
|
||||||
|
else
|
||||||
|
opts.forEach((opt) => {
|
||||||
|
if (opt.includes('.')) {
|
||||||
|
const [parent, child] = opt.split('.');
|
||||||
|
state.value[key][parent][child] = defaultOpts[child];
|
||||||
|
} else if (Object.hasOwn(state.value[key], opt))
|
||||||
|
state.value[key][opt] = defaultOpts[opt];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDefaultState() {
|
||||||
|
return Object.assign(JSON.parse(JSON.stringify(defaultOpts)), {
|
||||||
|
data: ref(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
get,
|
get,
|
||||||
set,
|
set,
|
||||||
clear,
|
clear,
|
||||||
|
reset,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue