Добавлен функционал скачивания файлов

This commit is contained in:
Alex committed 2024-01-25 10:41:18 +03:00
1 parent 8885fa0949
commit 68e0c717e5
4 files changed
+48 -10

No files matched your search

+6
View File
@@ -15,6 +15,7 @@
"chart.js": "^4.4.1",
"date-fns": "^2.30.0",
"express-vue": "^5.12.0",
"file-saver": "^2.0.5",
"moment": "^2.29.4",
"pinia": "^2.0.23",
"roboto-fontface": "*",
@@ -10568,6 +10569,11 @@
"node": "^10.12.0 || >=12.0.0"
}
},
"node_modules/file-saver": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
"integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
},
"node_modules/file-system-cache": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/file-system-cache/-/file-system-cache-2.3.0.tgz",
+1
View File
@@ -17,6 +17,7 @@
"chart.js": "^4.4.1",
"date-fns": "^2.30.0",
"express-vue": "^5.12.0",
"file-saver": "^2.0.5",
"moment": "^2.29.4",
"pinia": "^2.0.23",
"roboto-fontface": "*",
+2 -1
View File
@@ -6,6 +6,7 @@ const spravURL = 'http://10.252.44.33/accounting6/images/photo/'
// const baseWS = process.env.NODE_ENV == 'development'? 'ws://127.0.0.1:8000/': `ws://${window.location.host}/`;
const baseURL = process.env.NODE_ENV == 'development'? 'http://127.0.0.1:8000/': `http://10.252.44.60:9965/`;
const baseWS = process.env.NODE_ENV == 'development'? 'ws://127.0.0.1:8000/': `ws://10.252.44.60:9966/`;
const safetyURL = process.env.NODE_ENV == 'development'? 'http://127.0.0.1:8000': `http://10.252.44.60:9965`;
// для релизного меняем 'http://ukd/'
// const baseURL = 'http://127.0.0.1:8000/';
@@ -89,4 +90,4 @@ async error => {
})
export { axiosApiInstance, clearAxios, baseURL,spravURL,baseWS }
export { axiosApiInstance, clearAxios, baseURL,spravURL,baseWS, safetyURL }
+39 -9
View File
@@ -8,11 +8,13 @@
<!-- Безопасность -->
<!-- {{ safetyData }} -->
<v-row class="bg-red">
<v-col>
<v-col cols="6">
<v-card v-for="item in safetyData" :key="item.id">
<v-card-title>{{ item.name }}</v-card-title>
<v-card-actions v-for="category in item.categories" :key="item.id + category.id" >
<v-btn>{{ category.name }}</v-btn>
<!-- <v-card-actions
v-for="category in item.categories"
:key="item.id + category.id">
<v-btn variant="text">{{ category.name }}</v-btn>
<v-btn
:icon="showMore[item.id + category.id] ? 'mdi-chevron-up' : 'mdi-chevron-down'"
@click="showMore[item.id + category.id] = !showMore[item.id + category.id]">
@@ -25,9 +27,30 @@
<v-btn icon='mdi-cloud-download' color="grey"></v-btn>
</v-card-actions>
</div>
</v-expand-transition>
</v-card-actions>
</v-expand-transition>
</v-card-actions> -->
<v-container
v-for="category in item.categories"
:key="item.id + category.id"
:fluid="true"
class="py-0">
<v-card-actions>
<v-btn variant="text">{{ category.name }}</v-btn>
<v-btn
:icon="showMore[item.id + category.id] ? 'mdi-chevron-up' : 'mdi-chevron-down'"
@click="showMore[item.id + category.id] = !showMore[item.id + category.id]">
</v-btn>
</v-card-actions>
<v-expand-transition>
<div v-show="showMore[item.id + category.id]">
<v-card-actions v-for="file in category.files" :key="file.id">
<v-card-text>{{ file.name }}</v-card-text>
<v-btn icon="mdi-eye" color="grey"></v-btn>
<v-btn icon='mdi-cloud-download' color="grey" @click="downloadItem(safetyURL + file.url, file.name)"></v-btn>
</v-card-actions>
</div>
</v-expand-transition>
</v-container>
</v-card>
</v-col>
</v-row>
@@ -36,7 +59,9 @@
<script setup>
import { ref, onBeforeMount } from 'vue';
import { pagecounter } from '@/utils/universal_functions'
import { axiosApiInstance } from '@/utils/axios-api';
import { axiosApiInstance, safetyURL } from '@/utils/axios-api';
import { saveAs } from 'file-saver'
import axios from 'axios';
pagecounter();
@@ -47,15 +72,20 @@ onBeforeMount(() => {
axiosApiInstance.get(`api/safety/files/`).then(result => {
safetyData.value = result.data
})
console.log(safetyData);
});
// Проверяем по ID на какой категории срабатывает клик на раскрытии/скрытии, чтобы избежать срабатывания у всех категорий одновременно
showMore.value = safetyData.value.reduce((acc, value) => {
acc[value.id] = false
return acc
}, {});
const downloadItem = (url, fileName) => {
axios.get(url, {responseType: 'blob'})
.then(response => {
saveAs(response.data, fileName)
})
}
</script>
<style>