This commit is contained in:
parent
8c13ceb3fe
commit
3476b4807f
|
@ -86,6 +86,10 @@ const $props = defineProps({
|
|||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
sortByWeight: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
const { validations } = useValidator();
|
||||
const requiredFieldRule = (val) => validations().required($attrs.required, val);
|
||||
|
@ -186,11 +190,24 @@ async function fetchFilter(val) {
|
|||
$props.exprBuilder && Object.assign(where, $props.exprBuilder(key, val));
|
||||
const fetchOptions = { where, include, limit };
|
||||
if (fields) fetchOptions.fields = fields;
|
||||
if (sortBy) fetchOptions.order = sortBy;
|
||||
if (sortBy) {
|
||||
let sort = sortBy;
|
||||
if (typeof sort === 'string') sort = [getOrderCaseString(key, val), sortBy];
|
||||
else sort = [getOrderCaseString(key, val), ...sortBy];
|
||||
fetchOptions.order = sort;
|
||||
}
|
||||
|
||||
return dataRef.value.fetch(fetchOptions);
|
||||
}
|
||||
|
||||
function getOrderCaseString(prop, value) {
|
||||
return `CASE
|
||||
WHEN ${prop} LIKE '${value}%' THEN 1
|
||||
WHEN ${prop} LIKE '%${value}%' THEN 2
|
||||
ELSE 3
|
||||
END, ${prop} DESC`;
|
||||
}
|
||||
|
||||
async function filterHandler(val, update) {
|
||||
if (!val && lastVal.value === val) {
|
||||
lastVal.value = val;
|
||||
|
|
Loading…
Reference in New Issue