fix: order when is string #1279
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue