feat: abstract function
This commit is contained in:
parent
f149aa15ed
commit
8e8e29941f
1 changed files with 25 additions and 12 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue