Files
front/src/components/Setings_downloads.vue
admin bf9d63e635
Some checks failed
continuous-integration/drone Build is failing
add
2026-04-07 11:15:50 +10:00

82 lines
2.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div
class="dark:bg-gray-800 mt-5 sm:m-5 bg-white p-4 hover:-translate-y-2 hover:shadow-2xl border-slate-100 rounded-xl transition"
>
<div class="flex flex-wrap items-center gap-2 w-full justify-between">
<!-- Поля ввода дат в одной строке -->
<div class="flex items-center gap-2 flex-grow max-w-130">
<span class="dark:text-neutral-300 whitespace-nowrap">с</span>
<DatePicker v-model="data_start" />
<span class="dark:text-neutral-300 whitespace-nowrap">по</span>
<DatePicker v-model="data_finish" />
</div>
<!-- Кнопка выгрузки -->
<button
class="dark:bg-orange-500 hover:dark:bg-orange-600 shadow text-white bg-sky-700 hover:bg-sky-900 rounded-xl px-2 min-h-11 cursor-pointer w-full sm:w-auto sm:min-w-40 flex-shrink-0"
@click="downloadAll"
>
Выгрузить
</button>
</div>
</div>
</template>
<script setup>
import { ref } from "vue";
import axios from "axios";
import DatePicker from "./DatePicker.vue";
// Переменные для выгрузки с датами по умолчанию
const data_start = ref(getYesterdayDate());
const data_finish = ref(getTodayDate());
// Функция для получения вчерашней даты в формате YYYY-MM-DD
function getYesterdayDate() {
const date = new Date();
date.setDate(date.getDate() - 1);
return date.toISOString().split("T")[0];
}
// Функция для получения сегодняшней даты в формате YYYY-MM-DD
function getTodayDate() {
return new Date().toISOString().split("T")[0];
}
// Выгрузка
const downloadAll = async () => {
try {
const response = await axios.post(
// "http://127.0.0.1:8001/download_all",
"https://allowlgroup.ru/api/8001/download_all",
{
data_start: data_start.value,
data_finish: data_finish.value,
},
{
responseType: "blob",
},
);
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement("a");
link.href = url;
link.setAttribute(
"download",
`documents_${data_start.value}_${data_finish.value}.zip`,
);
document.body.appendChild(link);
link.click();
link.remove();
window.URL.revokeObjectURL(url);
} catch (error) {
console.error("Ошибка при выгрузке:", error);
}
};
</script>