refactor: revert catalog changes
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
1346a2e7fd
commit
37b3affdbf
|
@ -185,9 +185,6 @@ async function remove(key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatValue(value) {
|
function formatValue(value) {
|
||||||
if (typeof value === 'object') {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
if (typeof value === 'boolean') return value ? t('Yes') : t('No');
|
if (typeof value === 'boolean') return value ? t('Yes') : t('No');
|
||||||
if (isNaN(value) && !isNaN(Date.parse(value))) return toDate(value);
|
if (isNaN(value) && !isNaN(Date.parse(value))) return toDate(value);
|
||||||
|
|
||||||
|
@ -196,13 +193,6 @@ function formatValue(value) {
|
||||||
|
|
||||||
function sanitizer(params) {
|
function sanitizer(params) {
|
||||||
for (const [key, value] of Object.entries(params)) {
|
for (const [key, value] of Object.entries(params)) {
|
||||||
if (key == 'and') {
|
|
||||||
value.forEach((andValue) => {
|
|
||||||
params = { ...params, ...andValue };
|
|
||||||
});
|
|
||||||
delete params[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value && typeof value === 'object') {
|
if (value && typeof value === 'object') {
|
||||||
const param = Object.values(value)[0];
|
const param = Object.values(value)[0];
|
||||||
if (typeof param == 'string') params[key] = param.replaceAll('%', '');
|
if (typeof param == 'string') params[key] = param.replaceAll('%', '');
|
||||||
|
@ -221,7 +211,7 @@ function sanitizer(params) {
|
||||||
icon="search"
|
icon="search"
|
||||||
@click="search()"
|
@click="search()"
|
||||||
></QBtn>
|
></QBtn>
|
||||||
<QForm @submit="search" id="filterPanelForm" @keyup.enter.prevent="search(true)">
|
<QForm @submit="search" id="filterPanelForm" @keyup.enter="search()">
|
||||||
<QList dense>
|
<QList dense>
|
||||||
<QItem class="q-mt-xs">
|
<QItem class="q-mt-xs">
|
||||||
<QItemSection top>
|
<QItemSection top>
|
||||||
|
|
|
@ -9,7 +9,6 @@ import { useStateStore } from 'src/stores/useStateStore';
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const state = useStateStore();
|
const state = useStateStore();
|
||||||
const emit = defineEmits(['onSearch']);
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
dataKey: {
|
dataKey: {
|
||||||
|
@ -119,7 +118,6 @@ async function search() {
|
||||||
delete filter.params.search;
|
delete filter.params.search;
|
||||||
}
|
}
|
||||||
await arrayData.applyFilter(filter);
|
await arrayData.applyFilter(filter);
|
||||||
emit('onSearch', store.data);
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -86,8 +86,11 @@ function extractValueTags(items) {
|
||||||
<div class="full-width">
|
<div class="full-width">
|
||||||
<VnPaginate
|
<VnPaginate
|
||||||
data-key="OrderCatalogList"
|
data-key="OrderCatalogList"
|
||||||
|
url="Orders/CatalogFilter"
|
||||||
|
:limit="50"
|
||||||
|
:user-params="catalogParams"
|
||||||
|
@on-fetch="extractTags"
|
||||||
:update-router="false"
|
:update-router="false"
|
||||||
@on-change="extractTags"
|
|
||||||
>
|
>
|
||||||
<template #body="{ rows }">
|
<template #body="{ rows }">
|
||||||
<div class="catalog-list">
|
<div class="catalog-list">
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, ref, onMounted, watch } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
|
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
|
||||||
import VnSelect from 'components/common/VnSelect.vue';
|
import VnSelect from 'components/common/VnSelect.vue';
|
||||||
|
import VnFilterPanelChip from 'components/ui/VnFilterPanelChip.vue';
|
||||||
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
import getParamWhere from 'src/filters/getParamWhere';
|
import getParamWhere from 'src/filters/getParamWhere';
|
||||||
import VnFilterPanelChip from 'src/components/ui/VnFilterPanelChip.vue';
|
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
@ -47,19 +48,6 @@ const orderWayList = ref([
|
||||||
const orderBySelected = ref('relevancy DESC, name');
|
const orderBySelected = ref('relevancy DESC, name');
|
||||||
const orderWaySelected = ref('ASC');
|
const orderWaySelected = ref('ASC');
|
||||||
|
|
||||||
const routeQuery = JSON.parse(route?.query.params ?? '{}');
|
|
||||||
const paramsSearch = ref({});
|
|
||||||
const tagData = ref([]);
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
paramsSearch.value = JSON.parse(routeQuery.filter ?? '{}')?.where ?? {};
|
|
||||||
if (Object.keys(paramsSearch.value).length > 0) vnFilterPanelRef.value.search();
|
|
||||||
if (routeQuery.categoryFk && routeQuery.typeFk) {
|
|
||||||
selectedCategoryFk.value = routeQuery.categoryFk;
|
|
||||||
selectedTypeFk.value = routeQuery.typeFk;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const createValue = (val, done) => {
|
const createValue = (val, done) => {
|
||||||
if (val.length > 2) {
|
if (val.length > 2) {
|
||||||
if (!tagOptions.value.includes(val)) {
|
if (!tagOptions.value.includes(val)) {
|
||||||
|
@ -73,21 +61,19 @@ const resetCategory = () => {
|
||||||
typeList.value = null;
|
typeList.value = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectCategory = (category, search) => {
|
const clearFilter = (key) => {
|
||||||
if (!paramsSearch.value?.filter) paramsSearch.value.filter = { where: {} };
|
if (key === 'categoryFk') {
|
||||||
const where = paramsSearch.value.filter.where;
|
|
||||||
if (where.categoryFk === category?.id) {
|
|
||||||
resetCategory();
|
resetCategory();
|
||||||
where.categoryFk = null;
|
}
|
||||||
} else {
|
};
|
||||||
if (where.categoryFk && where.categoryFk !== category?.id) {
|
|
||||||
paramsSearch.value.typeFk = null;
|
|
||||||
selectedTypeFk.value = null;
|
|
||||||
typeList.value = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const selectCategory = (params, category, search) => {
|
||||||
|
if (params.categoryFk === category?.id) {
|
||||||
|
resetCategory();
|
||||||
|
params.categoryFk = null;
|
||||||
|
} else {
|
||||||
selectedCategoryFk.value = category?.id;
|
selectedCategoryFk.value = category?.id;
|
||||||
where.categoryFk = category?.id;
|
params.categoryFk = category?.id;
|
||||||
loadTypes(category?.id);
|
loadTypes(category?.id);
|
||||||
}
|
}
|
||||||
search();
|
search();
|
||||||
|
@ -100,10 +86,6 @@ const loadTypes = async (categoryFk = selectedCategoryFk.value) => {
|
||||||
typeList.value = data;
|
typeList.value = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(selectedTypeFk, (newValue) => {
|
|
||||||
paramsSearch.value.typeFk = newValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
const selectedCategory = computed(() =>
|
const selectedCategory = computed(() =>
|
||||||
(categoryList.value || []).find(
|
(categoryList.value || []).find(
|
||||||
(category) => category?.id === selectedCategoryFk.value
|
(category) => category?.id === selectedCategoryFk.value
|
||||||
|
@ -121,17 +103,26 @@ const selectedType = computed(() => {
|
||||||
return (typeList.value || []).find((type) => type?.id === selectedTypeFk.value);
|
return (typeList.value || []).find((type) => type?.id === selectedTypeFk.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function exprBuilder(param, value) {
|
||||||
|
switch (param) {
|
||||||
|
case 'categoryFk':
|
||||||
|
case 'typeFk':
|
||||||
|
return { [param]: value };
|
||||||
|
case 'search':
|
||||||
|
if (/^\d+$/.test(value)) return { 'i.id': value };
|
||||||
|
else return { 'i.name': { like: `%${value}%` } };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const applyTagFilter = (params, search) => {
|
const applyTagFilter = (params, search) => {
|
||||||
if (!tagValues.value?.length) {
|
if (!tagValues.value?.length) {
|
||||||
params.tagGroups = null;
|
params.tagGroups = null;
|
||||||
search();
|
search();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!params.tagGroups) {
|
||||||
if (!params.tagGroups || typeof params.tagGroups === 'string') {
|
|
||||||
params.tagGroups = [];
|
params.tagGroups = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
params.tagGroups.push(
|
params.tagGroups.push(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
values: tagValues.value.filter((obj) => Object.keys(obj).length > 0),
|
values: tagValues.value.filter((obj) => Object.keys(obj).length > 0),
|
||||||
|
@ -142,29 +133,17 @@ const applyTagFilter = (params, search) => {
|
||||||
tagFk: selectedTag?.value?.tagFk,
|
tagFk: selectedTag?.value?.tagFk,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
tagData.value.push(JSON.parse(params.tagGroups[params.tagGroups.length - 1]));
|
|
||||||
search();
|
search();
|
||||||
selectedTag.value = null;
|
selectedTag.value = null;
|
||||||
tagValues.value = [{}];
|
tagValues.value = [{}];
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeTagChip = (selection, params, search) => {
|
const removeTagChip = (selection, params, search) => {
|
||||||
if (typeof params.tagGroups === 'string') {
|
if (params.tagGroups) {
|
||||||
try {
|
params.tagGroups = (params.tagGroups || []).filter(
|
||||||
params.tagGroups = JSON.parse(params.tagGroups);
|
(value) => value !== selection
|
||||||
} catch (error) {
|
);
|
||||||
console.error('Error parsing tagGroups:', error);
|
|
||||||
params.tagGroups = [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
console.log('params.tagGroups: ', params.tagGroups);
|
|
||||||
console.log('selection: ', selection);
|
|
||||||
|
|
||||||
if (Array.isArray(params.tagGroups)) {
|
|
||||||
params.tagGroups = params.tagGroups.filter((value) => value !== selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -199,12 +178,12 @@ function addOrder(value, field, params) {
|
||||||
<VnFilterPanel
|
<VnFilterPanel
|
||||||
ref="vnFilterPanelRef"
|
ref="vnFilterPanelRef"
|
||||||
:data-key="props.dataKey"
|
:data-key="props.dataKey"
|
||||||
v-model="paramsSearch"
|
:hidden-tags="['orderFk', 'orderBy']"
|
||||||
:redirect="false"
|
:un-removable-params="['orderFk', 'orderBy']"
|
||||||
:hidden-tags="['orderFk', 'orderBy', 'filter', 'search', 'or', 'and']"
|
:expr-builder="exprBuilder"
|
||||||
:custom-tags="['tagGroups']"
|
:custom-tags="['tagGroups']"
|
||||||
:unremovable-params="['orderFk', 'orderBy']"
|
@remove="clearFilter"
|
||||||
:disable-submit-event="true"
|
:redirect="false"
|
||||||
>
|
>
|
||||||
<template #tags="{ tag, formatFn }">
|
<template #tags="{ tag, formatFn }">
|
||||||
<strong v-if="tag.label === 'categoryFk'">
|
<strong v-if="tag.label === 'categoryFk'">
|
||||||
|
@ -222,13 +201,17 @@ function addOrder(value, field, params) {
|
||||||
<template v-for="tag in customTags" :key="tag.label">
|
<template v-for="tag in customTags" :key="tag.label">
|
||||||
<template v-if="tag.label === 'tagGroups'">
|
<template v-if="tag.label === 'tagGroups'">
|
||||||
<VnFilterPanelChip
|
<VnFilterPanelChip
|
||||||
v-for="chip in tagData"
|
v-for="chip in tag.value"
|
||||||
:key="chip"
|
:key="chip"
|
||||||
removable
|
removable
|
||||||
@remove="removeTagChip(chip, params, searchFn)"
|
@remove="removeTagChip(chip, params, searchFn)"
|
||||||
>
|
>
|
||||||
<strong>{{ chip.tagSelection?.name }}: </strong>
|
<strong> {{ JSON.parse(chip).tagSelection?.name }}: </strong>
|
||||||
<span>{{ chip.values[0].value }}</span>
|
<span>{{
|
||||||
|
(JSON.parse(chip).values || [])
|
||||||
|
.map((item) => item.value)
|
||||||
|
.join(' | ')
|
||||||
|
}}</span>
|
||||||
</VnFilterPanelChip>
|
</VnFilterPanelChip>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
@ -243,7 +226,7 @@ function addOrder(value, field, params) {
|
||||||
<QIcon
|
<QIcon
|
||||||
:name="category.icon"
|
:name="category.icon"
|
||||||
class="category-icon"
|
class="category-icon"
|
||||||
@click="selectCategory(category, searchFn)"
|
@click="selectCategory(params, category, searchFn)"
|
||||||
>
|
>
|
||||||
<QTooltip>
|
<QTooltip>
|
||||||
{{ t(category.name) }}
|
{{ t(category.name) }}
|
||||||
|
@ -337,7 +320,7 @@ function addOrder(value, field, params) {
|
||||||
>
|
>
|
||||||
<FetchData
|
<FetchData
|
||||||
v-if="selectedTag"
|
v-if="selectedTag"
|
||||||
:url="`Tags/${selectedTag.id}/filterValue`"
|
:url="`Tags/${selectedTag}/filterValue`"
|
||||||
limit="30"
|
limit="30"
|
||||||
auto-load
|
auto-load
|
||||||
@on-fetch="(data) => (tagOptions = data)"
|
@on-fetch="(data) => (tagOptions = data)"
|
||||||
|
@ -360,7 +343,7 @@ function addOrder(value, field, params) {
|
||||||
@update:model-value="applyTagFilter(params, searchFn)"
|
@update:model-value="applyTagFilter(params, searchFn)"
|
||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
v-else-if="selectedTag.id === 1"
|
v-else-if="selectedTag === 1"
|
||||||
:label="t('params.value')"
|
:label="t('params.value')"
|
||||||
v-model="value.value"
|
v-model="value.value"
|
||||||
:options="tagOptions || []"
|
:options="tagOptions || []"
|
||||||
|
@ -375,7 +358,7 @@ function addOrder(value, field, params) {
|
||||||
@new-value="createValue"
|
@new-value="createValue"
|
||||||
@update:model-value="applyTagFilter(params, searchFn)"
|
@update:model-value="applyTagFilter(params, searchFn)"
|
||||||
/>
|
/>
|
||||||
<QInput
|
<VnInput
|
||||||
v-else
|
v-else
|
||||||
:label="t('params.value')"
|
:label="t('params.value')"
|
||||||
v-model="value.value"
|
v-model="value.value"
|
||||||
|
@ -396,7 +379,6 @@ function addOrder(value, field, params) {
|
||||||
icon="add_circle"
|
icon="add_circle"
|
||||||
shortcut="+"
|
shortcut="+"
|
||||||
flat
|
flat
|
||||||
size="md"
|
|
||||||
class="filter-icon"
|
class="filter-icon"
|
||||||
@click="tagValues.push({})"
|
@click="tagValues.push({})"
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue