feat: 09, 11 => handle file upload & url on create
This commit is contained in:
parent
684a97cef3
commit
44476f8535
2 changed files with 55 additions and 11 deletions
|
|
@ -59,6 +59,7 @@ const fileData = ref<
|
||||||
loaded: number;
|
loaded: number;
|
||||||
total: number;
|
total: number;
|
||||||
url?: string;
|
url?: string;
|
||||||
|
placeholder?: boolean;
|
||||||
}[]
|
}[]
|
||||||
>([]);
|
>([]);
|
||||||
|
|
||||||
|
|
@ -397,6 +398,11 @@ async function submitForm() {
|
||||||
});
|
});
|
||||||
if (res && currentFormData.value.id) {
|
if (res && currentFormData.value.id) {
|
||||||
await taskOrderFormStore.assignFormData(currentFormData.value.id);
|
await taskOrderFormStore.assignFormData(currentFormData.value.id);
|
||||||
|
|
||||||
|
if (fileList.value) {
|
||||||
|
await uploadFile(currentFormData.value.id, fileList.value);
|
||||||
|
}
|
||||||
|
|
||||||
router.push({
|
router.push({
|
||||||
name: 'TaskOrderView',
|
name: 'TaskOrderView',
|
||||||
params: { id: currentFormData.value.id },
|
params: { id: currentFormData.value.id },
|
||||||
|
|
@ -445,25 +451,29 @@ async function getFileList(taskId: string) {
|
||||||
if (fileList)
|
if (fileList)
|
||||||
fileData.value = await Promise.all(
|
fileData.value = await Promise.all(
|
||||||
fileList.map(async (v) => {
|
fileList.map(async (v) => {
|
||||||
const rse = await taskOrderStore.headAttachment({
|
const res = await taskOrderStore.headAttachment({
|
||||||
parentId: taskId,
|
parentId: taskId,
|
||||||
fileId: v,
|
fileId: v,
|
||||||
});
|
});
|
||||||
|
|
||||||
let contentLength = 0;
|
let contentLength = 0;
|
||||||
if (rse) contentLength = Number(rse['content-length']);
|
if (res) contentLength = Number(res['content-length']);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: v,
|
name: v,
|
||||||
progress: 1,
|
progress: 1,
|
||||||
loaded: contentLength,
|
loaded: contentLength,
|
||||||
total: contentLength,
|
total: contentLength,
|
||||||
url: `/task/${taskId}/attachment/${v}`,
|
url: `/task-order/${taskId}/attachment/${v}`,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fileToUrl(file: File) {
|
||||||
|
return URL.createObjectURL(file);
|
||||||
|
}
|
||||||
|
|
||||||
async function remove(taskId: string, n: string) {
|
async function remove(taskId: string, n: string) {
|
||||||
dialogWarningClose(t, {
|
dialogWarningClose(t, {
|
||||||
message: t('dialog.message.confirmDelete'),
|
message: t('dialog.message.confirmDelete'),
|
||||||
|
|
@ -508,8 +518,18 @@ async function uploadFile(taskId: string, list: FileList) {
|
||||||
);
|
);
|
||||||
fileData?.value.push(data);
|
fileData?.value.push(data);
|
||||||
}
|
}
|
||||||
|
fileList.value = undefined;
|
||||||
|
|
||||||
return await Promise.all(promises);
|
const beforeUnloadHandler = (e: Event) => {
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('beforeunload', beforeUnloadHandler);
|
||||||
|
|
||||||
|
return await Promise.all(promises).then((v) => {
|
||||||
|
window.removeEventListener('beforeunload', beforeUnloadHandler);
|
||||||
|
return v;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function completeValidate() {
|
async function completeValidate() {
|
||||||
|
|
@ -821,8 +841,12 @@ watch([currentFormData.value.taskStatus], () => {
|
||||||
v-model:file-data="fileData"
|
v-model:file-data="fileData"
|
||||||
:transform-url="
|
:transform-url="
|
||||||
async (url: string) => {
|
async (url: string) => {
|
||||||
const result = await api.get<string>(url);
|
if (state.mode === 'create') {
|
||||||
return result.data;
|
return url;
|
||||||
|
} else {
|
||||||
|
const result = await api.get<string>(url);
|
||||||
|
return result.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
@fetch-file-list="
|
@fetch-file-list="
|
||||||
|
|
@ -833,9 +857,21 @@ watch([currentFormData.value.taskStatus], () => {
|
||||||
"
|
"
|
||||||
@upload="
|
@upload="
|
||||||
async (f) => {
|
async (f) => {
|
||||||
if (!currentFormData.id) return;
|
|
||||||
|
|
||||||
fileList = f;
|
fileList = f;
|
||||||
|
fileData = [];
|
||||||
|
|
||||||
|
Array.from(f).forEach((el) => {
|
||||||
|
fileData.push({
|
||||||
|
name: el.name,
|
||||||
|
progress: 1,
|
||||||
|
loaded: 0,
|
||||||
|
total: el.size,
|
||||||
|
placeholder: true,
|
||||||
|
url: fileToUrl(el),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!currentFormData.id) return;
|
||||||
|
|
||||||
await uploadFile(currentFormData.id, f);
|
await uploadFile(currentFormData.id, f);
|
||||||
}
|
}
|
||||||
|
|
@ -997,7 +1033,6 @@ watch([currentFormData.value.taskStatus], () => {
|
||||||
fullTaskOrder?.userTask.find(
|
fullTaskOrder?.userTask.find(
|
||||||
(l) => l.userId === v.responsibleUser.id,
|
(l) => l.userId === v.responsibleUser.id,
|
||||||
)?.userTaskStatus;
|
)?.userTaskStatus;
|
||||||
console.log(_userStatus);
|
|
||||||
return (
|
return (
|
||||||
_userStatus !== UserTaskStatus.Submit &&
|
_userStatus !== UserTaskStatus.Submit &&
|
||||||
_userStatus !== UserTaskStatus.Restart
|
_userStatus !== UserTaskStatus.Restart
|
||||||
|
|
|
||||||
|
|
@ -490,6 +490,10 @@ async function getFileList(creditNoteId: string, slip?: boolean) {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fileToUrl(file: File) {
|
||||||
|
return URL.createObjectURL(file);
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
initTheme();
|
initTheme();
|
||||||
initLang();
|
initLang();
|
||||||
|
|
@ -653,8 +657,12 @@ onMounted(async () => {
|
||||||
v-model:file-data="attachmentData"
|
v-model:file-data="attachmentData"
|
||||||
:transform-url="
|
:transform-url="
|
||||||
async (url: string) => {
|
async (url: string) => {
|
||||||
const result = await api.get<string>(url);
|
if (!creditNoteData?.id) {
|
||||||
return result.data;
|
return url;
|
||||||
|
} else {
|
||||||
|
const result = await api.get<string>(url);
|
||||||
|
return result.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
@fetch-file-list="
|
@fetch-file-list="
|
||||||
|
|
@ -675,6 +683,7 @@ onMounted(async () => {
|
||||||
loaded: 0,
|
loaded: 0,
|
||||||
total: el.size,
|
total: el.size,
|
||||||
placeholder: true,
|
placeholder: true,
|
||||||
|
url: fileToUrl(el),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue