Добавление скачивания файла
This commit is contained in:
BIN
src/assets/word.png
Normal file
BIN
src/assets/word.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 875 B |
@@ -130,7 +130,6 @@
|
||||
{{ task.finished_at }}
|
||||
</td>
|
||||
<td
|
||||
class=""
|
||||
>
|
||||
<button class="text-red-500 p-1 rounded-full hover:text-red-700 cursor-pointer" @click="delete_row(task.id)">x</button>
|
||||
</td>
|
||||
|
||||
@@ -46,6 +46,42 @@ const viewed_b = async () => {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
const download = async () => {
|
||||
try {
|
||||
const rez = await axios.get("http://127.0.0.1:8001/file_download", {
|
||||
params: {
|
||||
path: props.article_date.split(" ")[0],
|
||||
title: props.title,
|
||||
},
|
||||
responseType: "blob",
|
||||
});
|
||||
const blobUrl = window.URL.createObjectURL(new Blob([rez.data], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }));
|
||||
const link = document.createElement("a");
|
||||
// Принудительно добавляем .docx к имени файла
|
||||
let filename = props.title + ".docx";
|
||||
try {
|
||||
const disposition = rez.headers && rez.headers["content-disposition"];
|
||||
if (disposition) {
|
||||
const match = disposition.match(/filename\*?=([^;\n]+)/i);
|
||||
if (match) {
|
||||
let name = match[1].replace(/UTF-8''/, "").replace(/"/g, "");
|
||||
if (!name.endsWith(".docx")) name += ".docx";
|
||||
filename = name;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
/* ignore */
|
||||
}
|
||||
link.href = blobUrl;
|
||||
link.setAttribute("download", filename);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener("click", handleClickOutside);
|
||||
@@ -57,26 +93,24 @@ onBeforeUnmount(() => {
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="bg-white dark:bg-gray-800 hover:-translate-y-2 hover:shadow-2xl rounded-xl transition pb-1 mb-3"
|
||||
:class="{ 'opacity-50': props.viewed }"
|
||||
><!--:class="{ 'opacity-50': props.viewed }" обработчик прочитанности-->
|
||||
class="bg-white dark:bg-gray-800 hover:-translate-y-2 hover:shadow-2xl rounded-xl transition pb-1 mb-3"
|
||||
:class="{ 'opacity-50': props.viewed }"
|
||||
>
|
||||
<!--:class="{ 'opacity-50': props.viewed }" обработчик прочитанности-->
|
||||
<div ref="cardRef" class="cursor-pointer" @click="toggle">
|
||||
<div class="flex justify-between p-3">
|
||||
<div class="flex justify-between p-3">
|
||||
<p>{{ article_date }}</p>
|
||||
<a
|
||||
:href="url"
|
||||
class="max-w-100 text-blue-600 dark:text-gray-400 hover:text-blue-800 underline flex"
|
||||
style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis"
|
||||
>
|
||||
<img
|
||||
src="/src/assets/href.webp"
|
||||
class="w-5 h-6 mr-2"
|
||||
/>
|
||||
<img src="/src/assets/href.webp" class="w-5 h-6 mr-2" />
|
||||
{{ url }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="m-3 dark:bg-gray-900 shadow rounded-xl p-3">
|
||||
<div class="m-3 dark:bg-gray-900 shadow rounded-xl p-3">
|
||||
<p>{{ title }}</p>
|
||||
</div>
|
||||
|
||||
@@ -96,11 +130,19 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
class="ml-4 shadow mb-5 bg-lime-500 dark:bg-orange-500 hover:dark:bg-orange-600 hover:dark:text-neutral-50 hover:bg-lime-300 hover:text-stone-900 rounded-xl w-40 h-10 text-white cursor-pointer"
|
||||
@click="viewed_b"
|
||||
>
|
||||
Прочитано
|
||||
</button>
|
||||
<div class="flex justify-between">
|
||||
<button
|
||||
class="ml-4 shadow mb-5 bg-lime-500 dark:bg-orange-500 hover:dark:bg-orange-600 hover:dark:text-neutral-50 hover:bg-lime-300 hover:text-stone-900 rounded-xl w-40 h-10 text-white cursor-pointer"
|
||||
@click="viewed_b"
|
||||
>
|
||||
Прочитано
|
||||
</button>
|
||||
<button
|
||||
class="hover:opacity-75 mr-10 rounded-xl cursor-pointer"
|
||||
@click="download"
|
||||
>
|
||||
<img src="/src/assets/word.png" class="h-10 mb-2" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user