forked from verdnatura/salix-front
Merge branch 'dev' into 7648_myEntries_filter
This commit is contained in:
commit
d84fd34c4b
|
@ -5,6 +5,7 @@ import { dashIfEmpty } from 'src/filters';
|
||||||
|
|
||||||
/* basic input */
|
/* basic input */
|
||||||
import VnSelect from 'components/common/VnSelect.vue';
|
import VnSelect from 'components/common/VnSelect.vue';
|
||||||
|
import VnSelectCache from 'components/common/VnSelectCache.vue';
|
||||||
import VnInput from 'components/common/VnInput.vue';
|
import VnInput from 'components/common/VnInput.vue';
|
||||||
import VnInputDate from 'components/common/VnInputDate.vue';
|
import VnInputDate from 'components/common/VnInputDate.vue';
|
||||||
import VnComponent from 'components/common/VnComponent.vue';
|
import VnComponent from 'components/common/VnComponent.vue';
|
||||||
|
@ -41,6 +42,17 @@ const $props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const defaultSelect = {
|
||||||
|
attrs: {
|
||||||
|
row: $props.row,
|
||||||
|
disable: !$props.isEditable,
|
||||||
|
class: 'fit',
|
||||||
|
},
|
||||||
|
forceAttrs: {
|
||||||
|
label: $props.showLabel && $props.column.label,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const defaultComponents = {
|
const defaultComponents = {
|
||||||
input: {
|
input: {
|
||||||
component: markRaw(VnInput),
|
component: markRaw(VnInput),
|
||||||
|
@ -94,14 +106,12 @@ const defaultComponents = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
|
component: markRaw(VnSelectCache),
|
||||||
|
...defaultSelect,
|
||||||
|
},
|
||||||
|
rawSelect: {
|
||||||
component: markRaw(VnSelect),
|
component: markRaw(VnSelect),
|
||||||
attrs: {
|
...defaultSelect,
|
||||||
disable: !$props.isEditable,
|
|
||||||
class: 'fit',
|
|
||||||
},
|
|
||||||
forceAttrs: {
|
|
||||||
label: $props.showLabel && $props.column.label,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
icon: {
|
icon: {
|
||||||
component: markRaw(QIcon),
|
component: markRaw(QIcon),
|
||||||
|
|
|
@ -18,7 +18,7 @@ watchEffect(() => {
|
||||||
(matched) => Object.keys(matched.meta).length
|
(matched) => Object.keys(matched.meta).length
|
||||||
);
|
);
|
||||||
breadcrumbs.value.length = 0;
|
breadcrumbs.value.length = 0;
|
||||||
|
if (!matched.value[0]) return;
|
||||||
if (matched.value[0].name != 'Dashboard') {
|
if (matched.value[0].name != 'Dashboard') {
|
||||||
root.value = useCamelCase(matched.value[0].path.substring(1).toLowerCase());
|
root.value = useCamelCase(matched.value[0].path.substring(1).toLowerCase());
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@ const myOptions = ref([]);
|
||||||
const myOptionsOriginal = ref([]);
|
const myOptionsOriginal = ref([]);
|
||||||
const vnSelectRef = ref();
|
const vnSelectRef = ref();
|
||||||
const dataRef = ref();
|
const dataRef = ref();
|
||||||
|
const lastVal = ref();
|
||||||
|
|
||||||
const value = computed({
|
const value = computed({
|
||||||
get() {
|
get() {
|
||||||
|
@ -85,14 +86,31 @@ const value = computed({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(options, (newValue) => {
|
||||||
|
setOptions(newValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(modelValue, (newValue) => {
|
||||||
|
if (!myOptions.value.some((option) => option[optionValue.value] == newValue))
|
||||||
|
fetchFilter(newValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
setOptions(options.value);
|
||||||
|
if ($props.url && $props.modelValue && !findKeyInOptions())
|
||||||
|
fetchFilter($props.modelValue);
|
||||||
|
if ($props.focusOnMount) setTimeout(() => vnSelectRef.value.showPopup(), 300);
|
||||||
|
});
|
||||||
|
|
||||||
|
function findKeyInOptions() {
|
||||||
|
if (!$props.options) return;
|
||||||
|
return filter($props.modelValue, $props.options)?.length;
|
||||||
|
}
|
||||||
|
|
||||||
function setOptions(data) {
|
function setOptions(data) {
|
||||||
myOptions.value = JSON.parse(JSON.stringify(data));
|
myOptions.value = JSON.parse(JSON.stringify(data));
|
||||||
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
onMounted(() => {
|
|
||||||
setOptions(options.value);
|
|
||||||
if ($props.url && $props.modelValue) fetchFilter($props.modelValue);
|
|
||||||
});
|
|
||||||
|
|
||||||
function filter(val, options) {
|
function filter(val, options) {
|
||||||
const search = val.toString().toLowerCase();
|
const search = val.toString().toLowerCase();
|
||||||
|
@ -125,15 +143,21 @@ async function fetchFilter(val) {
|
||||||
const defaultWhere = $props.useLike
|
const defaultWhere = $props.useLike
|
||||||
? { [key]: { like: `%${val}%` } }
|
? { [key]: { like: `%${val}%` } }
|
||||||
: { [key]: val };
|
: { [key]: val };
|
||||||
const where = { ...defaultWhere, ...$props.where };
|
const where = { ...(val ? defaultWhere : {}), ...$props.where };
|
||||||
const fetchOptions = { where, order: sortBy, limit };
|
const fetchOptions = { where, order: sortBy, limit };
|
||||||
if (fields) fetchOptions.fields = fields;
|
if (fields) fetchOptions.fields = fields;
|
||||||
return dataRef.value.fetch(fetchOptions);
|
return dataRef.value.fetch(fetchOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function filterHandler(val, update) {
|
async function filterHandler(val, update) {
|
||||||
if (!$props.defaultFilter) return update();
|
if (!val && lastVal.value === val) {
|
||||||
|
lastVal.value = val;
|
||||||
|
return update();
|
||||||
|
}
|
||||||
|
lastVal.value = val;
|
||||||
let newOptions;
|
let newOptions;
|
||||||
|
|
||||||
|
if (!$props.defaultFilter) return update();
|
||||||
if ($props.url) {
|
if ($props.url) {
|
||||||
newOptions = await fetchFilter(val);
|
newOptions = await fetchFilter(val);
|
||||||
} else newOptions = filter(val, myOptionsOriginal.value);
|
} else newOptions = filter(val, myOptionsOriginal.value);
|
||||||
|
@ -149,19 +173,6 @@ async function filterHandler(val, update) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(options, (newValue) => {
|
|
||||||
setOptions(newValue);
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(modelValue, (newValue) => {
|
|
||||||
if (!myOptions.value.some((option) => option[optionValue.value] == newValue))
|
|
||||||
fetchFilter(newValue);
|
|
||||||
});
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
if ($props.focusOnMount) setTimeout(() => vnSelectRef.value.showPopup(), 300);
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
<script setup>
|
||||||
|
import { ref, onBeforeMount, useAttrs } from 'vue';
|
||||||
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
|
|
||||||
|
const $props = defineProps({
|
||||||
|
row: {
|
||||||
|
type: [Object],
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
find: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const options = ref([]);
|
||||||
|
onBeforeMount(async () => {
|
||||||
|
const { url } = useAttrs();
|
||||||
|
const findBy = $props.find ?? url?.charAt(0)?.toLocaleLowerCase() + url?.slice(1, -1);
|
||||||
|
if (findBy) options.value = [$props.row[findBy]];
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VnSelect v-bind="$attrs" :options="$attrs.options ?? options" />
|
||||||
|
</template>
|
|
@ -21,9 +21,9 @@ export const useNavigationStore = defineStore('navigationStore', () => {
|
||||||
'route',
|
'route',
|
||||||
'ticket',
|
'ticket',
|
||||||
'worker',
|
'worker',
|
||||||
|
'account',
|
||||||
'wagon',
|
'wagon',
|
||||||
'zone',
|
'zone',
|
||||||
'account',
|
|
||||||
];
|
];
|
||||||
const pinnedModules = ref([]);
|
const pinnedModules = ref([]);
|
||||||
const role = useRole();
|
const role = useRole();
|
||||||
|
|
Loading…
Reference in New Issue