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) { export function moveItem<T extends unknown[]>(
if (index > 0) { arr: T,
const temp = items[index]; idx: number,
items[index] = items[index - 1]; offset: number,
items[index - 1] = temp; ) {
} arr.splice(idx + offset, 0, ...arr.splice(idx, 1));
} }
export function moveItemDown(items: unknown[], index: number) { export function moveItemUp<T extends unknown[]>(items: T, index: number) {
if (index < items.length - 1) { moveItem(items, index, -1);
const temp = items[index]; }
items[index] = items[index + 1];
items[index + 1] = temp; export function moveItemDown<T extends unknown[]>(items: T, index: number) {
} moveItem(items, index, 1);
} }
export function deleteItem(items: unknown[], index: number) { export function deleteItem(items: unknown[], index: number) {
@ -504,4 +504,17 @@ export function calculateDaysUntilExpire(expireDate: Date): number {
return diffInDays; 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; export default useUtilsStore;