feat: abstract function

This commit is contained in:
Methapon Metanipat 2024-10-30 11:26:27 +07:00
parent f149aa15ed
commit 8e8e29941f

View file

@ -96,20 +96,20 @@ export function notify(
}
}
export function moveItemUp(items: unknown[], index: number) {
if (index > 0) {
const temp = items[index];
items[index] = items[index - 1];
items[index - 1] = temp;
}
export function moveItem<T extends unknown[]>(
arr: T,
idx: number,
offset: number,
) {
arr.splice(idx + offset, 0, ...arr.splice(idx, 1));
}
export function moveItemDown(items: unknown[], index: number) {
if (index < items.length - 1) {
const temp = items[index];
items[index] = items[index + 1];
items[index + 1] = temp;
}
export function moveItemUp<T extends unknown[]>(items: T, index: number) {
moveItem(items, index, -1);
}
export function moveItemDown<T extends unknown[]>(items: T, index: number) {
moveItem(items, index, 1);
}
export function deleteItem(items: unknown[], index: number) {
@ -504,4 +504,17 @@ export function calculateDaysUntilExpire(expireDate: Date): number {
return diffInDays;
}
export function createDataRefBase<T>(
defaultPage = 1,
defaultPageMax = 1,
defaultPageSize = 30,
) {
return {
data: ref<T[]>(),
page: ref<number>(defaultPage),
pageMax: ref<number>(defaultPageMax),
pageSize: ref<number>(defaultPageSize),
};
}
export default useUtilsStore;