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) {
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue