refactor: util fn
This commit is contained in:
parent
19428bef81
commit
77bc4973a9
1 changed files with 15 additions and 10 deletions
|
|
@ -4,6 +4,7 @@ import axios, { AxiosInstance, AxiosProgressEvent } from 'axios';
|
||||||
import { ComposerTranslation } from 'vue-i18n';
|
import { ComposerTranslation } from 'vue-i18n';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
|
import arr from 'src/utils/arr';
|
||||||
import { getRole } from 'src/services/keycloak';
|
import { getRole } from 'src/services/keycloak';
|
||||||
|
|
||||||
import GlobalDialog from 'components/GlobalDialog.vue';
|
import GlobalDialog from 'components/GlobalDialog.vue';
|
||||||
|
|
@ -96,20 +97,12 @@ export function notify(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveItem<T extends unknown[]>(
|
|
||||||
arr: T,
|
|
||||||
idx: number,
|
|
||||||
offset: number,
|
|
||||||
) {
|
|
||||||
arr.splice(idx + offset, 0, ...arr.splice(idx, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function moveItemUp<T extends unknown[]>(items: T, index: number) {
|
export function moveItemUp<T extends unknown[]>(items: T, index: number) {
|
||||||
moveItem(items, index, -1);
|
arr.move(items, index, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveItemDown<T extends unknown[]>(items: T, index: number) {
|
export function moveItemDown<T extends unknown[]>(items: T, index: number) {
|
||||||
moveItem(items, index, 1);
|
arr.move(items, index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteItem(items: unknown[], index: number) {
|
export function deleteItem(items: unknown[], index: number) {
|
||||||
|
|
@ -266,6 +259,12 @@ export function manageAttachment(
|
||||||
if (res.status >= 400) return false;
|
if (res.status >= 400) return false;
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
|
headAttachment: async (opts: { parentId: string; fileId: string }) => {
|
||||||
|
const url = `/${base}/${opts.parentId}/attachment/${opts.fileId}`;
|
||||||
|
const res = await api.head(url);
|
||||||
|
if (res.status < 400) return res.headers;
|
||||||
|
return false;
|
||||||
|
},
|
||||||
getAttachment: async (opts: {
|
getAttachment: async (opts: {
|
||||||
parentId: string;
|
parentId: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -337,6 +336,12 @@ export function manageFile<T extends string>(
|
||||||
if (res.status >= 400) return false;
|
if (res.status >= 400) return false;
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
|
headFile: async (opts: { group: T; parentId: string; fileId: string }) => {
|
||||||
|
const url = `/${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`;
|
||||||
|
const res = await api.head(url);
|
||||||
|
if (res.status < 400) return res.headers;
|
||||||
|
return false;
|
||||||
|
},
|
||||||
getFile: async (opts: {
|
getFile: async (opts: {
|
||||||
group: T;
|
group: T;
|
||||||
parentId: string;
|
parentId: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue