fix: order when is string #1279

Merged
alexm merged 2 commits from hotFix_fixOrderStringArray into master 2025-01-24 07:32:59 +00:00
1 changed files with 14 additions and 9 deletions
Showing only changes of commit 5b448e5bb3 - Show all commits

View File

@ -93,8 +93,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
Object.assign(params, userParams);
if (params.filter) params.filter.skip = store.skip;
if (store?.order && typeof store?.order == 'string') store.order = [store.order];
if (store.order?.length) params.filter.order = [...store.order];
if (store.order?.length) params.filter.order = [...toArray(store.order)];
else delete params.filter.order;
store.currentFilter = JSON.parse(JSON.stringify(params));
@ -191,10 +190,9 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
async function addOrder(field, direction = 'ASC') {
const newOrder = field + ' ' + direction;
let order = store.order || [];
if (typeof order == 'string') order = [order];
const order = toArray(store.order);
let index = order.findIndex((o) => o.split(' ')[0] === field);
let index = getOrderIndex(order, field);
if (index > -1) {
order[index] = newOrder;
} else {
@ -211,16 +209,23 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
}
async function deleteOrder(field) {
let order = store.order ?? [];
if (typeof order == 'string') order = [order];
const index = order.findIndex((o) => o.split(' ')[0] === field);
const order = toArray(store.order);
const index = getOrderIndex(order, field);
if (index > -1) order.splice(index, 1);
store.order = order;
fetch({});
}
function getOrderIndex(order, field) {
return order.findIndex((o) => o.split(' ')[0] === field);
}
function toArray(str = []) {
if (Array.isArray(str)) return str;
if (typeof str === 'string') return str.split(',').map((item) => item.trim());
}
function sanitizerParams(params, exprBuilder) {
for (const param in params) {
if (params[param] === '' || params[param] === null) {