Переработка бэкэнда под задачи №99, 88

This commit is contained in:
Alex committed 2024-04-19 16:15:12 +03:00
1 parent 2aeb3ef513
commit 18c0042729
1 file changed
+115 -128
+115 -128
View File
@@ -1,71 +1,65 @@
<template> <template>
<v-row no-gutters class="flex-column h-100 gap pa-1"> <v-row no-gutters class="flex-column h-100 gap pa-1">
<v-col class="w100 h-100 flex-grow-0"> <v-col class="w100 h-100 flex-grow-0">
<v-card> <v-card>
<v-tabs <v-tabs v-model="tab" bg-color="bg_tab" slider-color="slider_tab" selected-class="isActiveTab" :grow="true">
v-model="tab" <v-tab value="mainInfo">Основная информация</v-tab>
bg-color="bg_tab" <v-tab value="document">Документация</v-tab>
slider-color="slider_tab" <v-tab value="testings">Тестирование</v-tab>
selected-class="isActiveTab" </v-tabs>
:grow="true"> </v-card>
<v-tab value="mainInfo">Основная информация</v-tab> </v-col>
<v-tab value="document">Документация</v-tab> <v-col class="w100 h-100">
<v-tab value="testings">Тестирование</v-tab> <v-window v-model="tab" class="h-100">
</v-tabs> <v-window-item no-gutters class="gap h-100" value="mainInfo">
</v-card> <MainInfoSafety :formainpage="formainpage"></MainInfoSafety>
</v-col> </v-window-item>
<v-col class="w100 h-100"> <v-window-item value="document" class="h-100">
<v-window v-model="tab" class="h-100"> <v-row no-gutters class="gap h-100 ">
<v-window-item no-gutters class="gap h-100" value="mainInfo"> <v-col lg="6">
<MainInfoSafety :formainpage="formainpage"></MainInfoSafety> <v-card class="h-100 flex-column d-flex gap ">
</v-window-item> <v-row class="ma-0 overflow-auto pb-1 ">
<v-window-item value="document" class="h-100">
<v-row no-gutters class="gap h-100 ">
<v-col lg="6">
<v-card class="h-100 flex-column d-flex gap ">
<v-row class="ma-0 my-3 overflow-auto h-0 pb-1">
<v-card class="overflow-y-auto flex-grow-1 flex-shrink-1 h-100"> <v-card class="overflow-y-auto flex-grow-1 flex-shrink-1 h-100">
<v-card-title>{{ safetyData.name }}</v-card-title> <v-card-title>{{ safetyData.name }}</v-card-title>
<v-expansion-panels <v-expansion-panels
multiple
flat>
flat <v-expansion-panel elevation=0 v-for="category in safetyData.categories"
> :key="category.id" class="py-0">
<v-expansion-panel-title class="font-weight-medium">{{
category.category__name }}</v-expansion-panel-title>
<v-expansion-panel <v-expansion-panel-text>
elevation=0
v-for="category in safetyData.categories"
:key="category.id"
class="py-0">
<v-expansion-panel-title class="font-weight-medium">{{ category.category__name }}</v-expansion-panel-title>
<v-expansion-panel-text>
<div v-for="file in category.files" :key="file.id" class="overflow-y-auto d-flex justify-space-between"> <div v-for="file in category.files" :key="file.id"
<div class="overflow-y-auto d-flex justify-space-between">
class="cursor-pointer" <div class="cursor-pointer"
@click="openPDF(file.url), loading=true"> @click="openPDF(file.url), loading = true">
{{ file.name }} {{ file.name }}
</div> </div>
<div> <div>
<v-btn size="small" variant="text" icon="mdi-file-pdf-box" color="red" @click="openPDF(file.url), loading=true"></v-btn> <v-btn size="small" variant="text" icon="mdi-file-pdf-box"
<v-btn size="small" variant="text" icon='mdi-file-download-outline' color="green" @click="downloadItem(burl + file.url, file.name)"></v-btn> color="red"
</div> @click="openPDF(file.url), loading = true"></v-btn>
</div> <v-btn size="small" variant="text"
icon='mdi-file-download-outline' color="green"
@click="downloadItem(burl + file.url, file.name)"></v-btn>
</div>
</div>
</v-expansion-panel-text> </v-expansion-panel-text>
<!-- <v-card-actions v-if="category.id != 'evacuation_plan'"> <!-- <v-card-actions v-if="category.id != 'evacuation_plan'">
<v-btn <v-btn
@click="showMore[ category.id] = !showMore[category.id]" @click="showMore[ category.id] = !showMore[category.id]"
variant="text"> variant="text">
@@ -76,7 +70,7 @@
@click="showMore[category.id] = !showMore[ category.id]"> @click="showMore[category.id] = !showMore[ category.id]">
</v-btn> </v-btn>
</v-card-actions>--> </v-card-actions>-->
<!-- <v-expand-transition> <!-- <v-expand-transition>
<div v-show="showMore[ category.id]"> <div v-show="showMore[ category.id]">
<v-card-actions v-for="file in category.files" :key="file.id" class="overflow-y-auto"> <v-card-actions v-for="file in category.files" :key="file.id" class="overflow-y-auto">
<v-card-text <v-card-text
@@ -89,62 +83,54 @@
</v-card-actions> </v-card-actions>
</div> </div>
</v-expand-transition> --> </v-expand-transition> -->
</v-expansion-panel> </v-expansion-panel>
</v-expansion-panels> </v-expansion-panels>
</v-card> </v-card>
</v-row> </v-row>
<v-row class="ma-0 overflow-auto h-0"> <v-row class="ma-0 overflow-auto bg-yellow ">
<v-card class="overflow-y-auto flex-grow-1 h-100"> <v-card class="overflow-y-auto flex-grow-1 h-100">
<v-card-title>{{ responsibilityData.name }}</v-card-title> <v-card-title>{{ responsibilityData.name }}</v-card-title>
<v-container <v-container v-for="file in responsibilityData.files" :fluid="true" class="py-0">
v-for="file in responsibilityData.files" <v-card-actions :key="file.id">
:fluid="true" <v-card-text class="cursor-pointer"
class="py-0"> @click="openPDF(checkNameFiles(file)), loading = true">
<v-card-actions :key="file.id"> {{ get_name(decodeURI(file.file_name.replace(/\.[^/.]+$/, ""))) }}
<v-card-text </v-card-text>
class="cursor-pointer" <v-btn icon="mdi-file-pdf-box" color="red"
@click="openPDF(checkNameFiles(file)), loading=true"> @click="openPDF(checkNameFiles(file)), loading = true"></v-btn>
{{ get_name(decodeURI(file.file_name.replace(/\.[^/.]+$/, ""))) }} <v-btn icon='mdi-file-download-outline' color="green"
</v-card-text> @click="downloadItem(burl + checkNameFiles(file), get_name(decodeURI(file.file_name)))"></v-btn>
<v-btn icon="mdi-file-pdf-box" color="red" @click="openPDF(checkNameFiles(file)), loading=true"></v-btn> </v-card-actions>
<v-btn icon='mdi-file-download-outline' color="green" @click="downloadItem(burl + checkNameFiles(file), get_name(decodeURI(file.file_name)))"></v-btn> </v-container>
</v-card>
</v-row>
</v-card>
</v-col>
<v-col>
<v-card class="h-100 flex-column d-flex gap">
<v-row class="ma-0 overflow-auto h-0">
<v-card v-show="showFile"
class="mr-2 flex-grow-1 flex-shrink-1 h-100 pa-2 overflow-auto">
<v-container v-if="loading">
<v-progress-linear :rounded="5" indeterminate color="teal">
</v-progress-linear>
</v-container>
<VuePdfEmbed :source="pdfSource" width="720" @rendered="loading = false" />
</v-card>
</v-row>
<v-card-actions v-show="showFile">
<v-btn position="sticky" block @click="showFile = false">Закрыть</v-btn>
</v-card-actions> </v-card-actions>
</v-container> </v-card>
</v-card> </v-col>
</v-row> </v-row>
</v-card> </v-window-item>
</v-col> <v-window-item value="testings" no-gutters class="gap h-100 ">
<v-col> <TestSafety></TestSafety>
<v-card class="h-100 flex-column d-flex gap"> </v-window-item>
<v-row class="ma-0 overflow-auto h-0"> </v-window>
<v-card v-show="showFile" class="mr-2 flex-grow-1 flex-shrink-1 h-100 pa-2 overflow-auto"> </v-col>
<v-container v-if="loading"> </v-row>
<v-progress-linear
:rounded="5"
indeterminate
color="teal">
</v-progress-linear>
</v-container>
<VuePdfEmbed :source="pdfSource" width="720" @rendered="loading = false"/>
</v-card>
</v-row>
<v-card-actions v-show="showFile">
<v-btn
position="sticky"
block
@click="showFile = false">Закрыть</v-btn>
</v-card-actions>
</v-card>
</v-col>
</v-row>
</v-window-item>
<v-window-item value="testings" no-gutters class="gap h-100 ">
<TestSafety></TestSafety>
</v-window-item>
</v-window>
</v-col>
</v-row>
</template> </template>
<script setup> <script setup>
@@ -160,14 +146,14 @@ import MainInfoSafety from './MainInfoSafety.vue';
pagecounter(); pagecounter();
const safetyData = ref([]); const safetyData = ref({categories:[]});
const responsibilityData = ref(); const responsibilityData = ref();
const showMore = ref(false); const showMore = ref(false);
const showFile = ref(true); const showFile = ref(true);
let pdfSource = ref(""); let pdfSource = ref("");
const loading = ref(false); const loading = ref(false);
const tab = ref(''); const tab = ref('');
const burl = baseURL.slice(0,-1); const burl = baseURL.slice(0, -1);
const route = useRoute(); const route = useRoute();
// Вынес запрос в отдельную функцию, чтобы избежать дублирования одного и того же запроса на сервер. // Вынес запрос в отдельную функцию, чтобы избежать дублирования одного и того же запроса на сервер.
@@ -175,23 +161,24 @@ function getSafety() {
axiosApiInstance.get(`api/safety/files/?chapter=${route.params.chapter}`).then(result => { axiosApiInstance.get(`api/safety/files/?chapter=${route.params.chapter}`).then(result => {
safetyData.value = result.data safetyData.value = result.data
// console.log(safetyData.value); // console.log(safetyData.value);
loading.value=true loading.value = true
pdfSource.value =burl + safetyData.value.categories[0].files[0].url pdfSource.value = burl + safetyData.value.categories[0].files[0].url
// console.log(safetyData.value); // console.log(safetyData.value);
}) })
} }
const formainpage = computed({ const formainpage = computed({
get() { get() {
let arr=[] let arr = []
if(safetyData.value.length>0){
safetyData.value.categories.forEach(element => { safetyData.value.categories.forEach(element => {
element.files.forEach((e)=>{ element.files.forEach((e) => {
if(e.formainpage==true){ if (e.formainpage == true) {
arr.push(e)} arr.push(e)
}
}) })
}) })
}
return arr return arr
} }
}) })
@@ -213,20 +200,20 @@ onBeforeMount(() => getSafety());
// }, {}); // }, {});
const downloadItem = (url, fileName) => { const downloadItem = (url, fileName) => {
axiosApiInstance.get(url, {responseType: 'blob'}) axiosApiInstance.get(url, { responseType: 'blob' })
.then(response => { .then(response => {
saveAs(response.data, fileName) saveAs(response.data, fileName)
}) })
}; };
function openPDF(url) { function openPDF(url) {
pdfSource.value = burl+url pdfSource.value = burl + url
showFile.value = true showFile.value = true
}; };
function get_name(namestr){ function get_name(namestr) {
let arr= namestr.split("/") let arr = namestr.split("/")
return arr[arr.length-1] return arr[arr.length - 1]
} }
function checkNameFiles(obj) { function checkNameFiles(obj) {