This commit is contained in:
iriska-gri committed 2024-05-22 12:22:39 +03:00
commit 4cd8f88a7e
4 files changed
+106 -49

No files matched your search

+10 -3
View File
@@ -20,9 +20,13 @@ class SafetyTypeSerializer(serializers.ModelSerializer):
class Committee1FilesSerializer(serializers.ModelSerializer):
typeoffile = serializers.SerializerMethodField('typeoffiledef', read_only=True)
parent = serializers.IntegerField(source = 'id_committee1.id')
def typeoffiledef(self,obj):
return 'comm'
class Meta:
model = Committee1Files
fields = ['id','file_name','is_actual']
fields = ['id','file_name','is_actual', 'typeoffile','parent']
@@ -63,10 +67,13 @@ class Commettee1Serializer(serializers.ModelSerializer):
class OrderResponsibilityFilesSerializer(serializers.ModelSerializer):
typeoffile = serializers.SerializerMethodField('typeoffiledef', read_only=True)
parent = serializers.IntegerField(source = 'id_order_responsibility.id')
def typeoffiledef(self,obj):
return 'resp'
class Meta:
model = Committee1Files
fields = ['id','file_name','is_actual']
fields = ['id','file_name','is_actual','typeoffile','parent']
class OrderResponsibilitySerializer(serializers.ModelSerializer):
employee = serializers.SerializerMethodField('get_respons')
@@ -9,7 +9,7 @@
></MainInfoSafety>
</v-window-item>
<v-window-item class="gap h-100" value="document">
<documentation-safety />
<documentation-safety :docSections = "safetyData" />
</v-window-item>
<v-window-item class="gap h-100" value="testings">
<TestSafety></TestSafety>
@@ -1,10 +1,5 @@
<template>
<v-row
no-gutters
class="h-100 gap"
>
<!-- v-if="Object.keys(docSections).length > 0" -->
<v-row no-gutters class="h-100 gap">
<v-col class="d-flex">
<v-row no-gutters class="flex-column gap">
<v-col lg="6" class="w100 d-flex flex-column">
@@ -37,7 +32,7 @@
color="primary"
density="compact"
@click="
openPDF(file.file_name, file.id), (loading = true)
openPDF(file)
"
>
<span class="text-body-2 text-wrap">
@@ -53,10 +48,7 @@
<v-icon
icon="mdi-file-download-outline"
@click="
downloadItem(
burl + file.file_name,
get_name(decodeURI(file.file_name))
)
downloadItem(file)
"
/></v-col>
</v-row>
@@ -96,7 +88,7 @@
color="primary"
density="compact"
@click="
openPDF(file.file_name, file.id), (loading = true)
openPDF(file)
"
>
<span class="text-body-2 text-wrap">
@@ -112,10 +104,7 @@
<v-icon
icon="mdi-file-download-outline"
@click="
downloadItem(
burl + file.file_name,
get_name(decodeURI(file.file_name))
)
downloadItem(file)
"
/></v-col>
</v-row>
@@ -127,29 +116,36 @@
</v-row>
</v-col>
<v-col class="d-flex flex-column">
<v-card class="flex-column h-100 d-flex rounded-0">
<v-row no-gutters class="h-0 overflow-auto">
<v-col class="align-self-center text-center">
<v-col class="d-flex flex-column "
:class="!loading?'align-center align-self-center':''">
<v-container v-if="loading">
<v-progress-linear :rounded="5" indeterminate color="teal">
</v-progress-linear>
<v-progress-linear :rounded="5" indeterminate color="teal" />
</v-container>
<VuePdfEmbed
v-show="showFile"
:source="pdfSource"
width="720"
@rendered="loading = false"
@loading-failed="handlePdfError"
/>
{{err}}
<v-card-text v-show="!showFile" >
<span class="text-h5 text-grey"
>
{{ err }}
</span>
</v-card-text>
</v-col>
</v-row>
<v-divider />
<v-card-actions v-show="showFile">
<v-btn position="sticky" block @click="closeFile">Закрыть</v-btn>
@@ -157,14 +153,14 @@
</v-card>
</v-col>
</v-row>
<!-- <v-row v-else>{{ Object.keys(docSections).length > 0 }}</v-row> -->
</template>
<script>
import { ref } from "vue";
import { axiosApiInstance, baseURL } from "@/utils/axios-api";
import { ref, computed } from "vue";
import { axiosApiInstance, baseURL, spravURLBase } from "@/utils/axios-api";
import { saveAs } from "file-saver";
import VuePdfEmbed from "vue-pdf-embed";
import { triggerRef } from "vue";
export default {
props: {
@@ -180,40 +176,62 @@ export default {
VuePdfEmbed,
},
setup() {
const loading = ref(false);
setup(props, { emit }) {
const loading = ref(true);
const burl = baseURL.slice(0, -1);
const pdfSource = ref("");
const burl = baseURL.slice(0, -1);
const showFile = ref(false);
const showFile = ref(true);
const filId = ref(null);
const err = ref('s')
const err = ref("Файл не выбран");
const downloadItem = (url, fileName) => {
const downloadItem = (file) => {
let url = development.value ? burl + file.file_name : spravURLBase + `files/${file.typeoffile == 'comm' ? 'committee1_docs' : 'order_responsibility_docs'}/${file.parent}/${file.name}`
console.log(burl + file.file_name);
axiosApiInstance.get(url, { responseType: "blob" }).then((response) => {
saveAs(response.data, fileName);
saveAs(response.data, get_name(decodeURI(file.file_name)));
});
};
const openPDF = (url, id) => {
pdfSource.value = burl + url;
const openPDF = (file) => {
console.log(file, "fil");
let source =development.value ? burl + file.file_name : spravURLBase + `files/${file.typeoffile == 'comm' ? 'committee1_docs' : 'order_responsibility_docs'}/${file.parent}/${file.name}`
if(source!=pdfSource.value){
loading.value = true
pdfSource.value = source
}
showFile.value = true;
filId.value = id;
filId.value = file.id;
};
const development = computed({
get() {
return process.env.NODE_ENV == "development" ? true : false;
}
})
// process.env.NODE_ENV == "development" ? true : false;
const get_name = (namestr) => {
let arr = namestr.split("/");
return arr[arr.length - 1];
};
const closeFile = () => {
err.value = "Файл не выбран"
showFile.value = false;
filId.value = null;
};
const handlePdfError = (error) => {
err.value = "Файл не найден"
loading.value = false
const handlePdfError = (error) => {
showFile.value=false
err.value = "Файл не найден";
loading.value = false;
// if (error.status === 404) {
// console.error('PDF file not found');
@@ -221,7 +239,33 @@ export default {
// } else {
// console.error('An error occurred while loading the PDF:', error);
// }
}
};
const firstFile = () => {
loading.value = false;
let files = []
props.docSections.type_comm.forEach(el => {
// console.log(el);
files.push(...el.comm.comitee_files)
});
props.docSections.type_resp.forEach(el => {
files.push(...el.resp.get_resp_files)
});
pdfSource.value =development.value ? burl + files[0].file_name : spravURLBase + `files/${files[0].typeoffile == 'comm' ? 'committee1_docs' : 'order_responsibility_docs'}/${files[0].parent}/${files[0].name}`
// = source
// pdfSource.value =
// burl + files[0].file_name;
filId.value = files[0].id;
console.log(pdfSource.value, "-------------------------------");
};
firstFile();
return {
downloadItem,
@@ -234,10 +278,15 @@ export default {
burl,
showFile,
closeFile,
err
err,
};
},
};
// http://10.252.44.33/accounting6/index.php?controller=OrderResponsibility&action=DownloadFile&fld_file=222&fld_order_responsibility=11
// http://10.252.44.33/accounting6/index.php?controller=Committee&action=DownloadFile&fld_file=412&fld_committee=29
// \\10.252.44.33\Webserver\data\htdocs\accounting6\files\committee1_docs\2
// \\10.252.44.33\Webserver\data\htdocs\accounting6\files\order_responsibility_docs\12
</script>
<style></style>
@@ -87,7 +87,7 @@
</v-col>
</v-row>
<!-- <v-dialog v-model="openFirstPlan" :width="900" height="100%">
<v-dialog v-model="openFirstPlan" :width="900" height="100%">
<v-row class="ma-0 overflow-auto h-0">
<v-card class="h-100 w-100 pa-0">
<v-card-actions class="d-flex justify-space-between">
@@ -101,6 +101,7 @@
@click="downloadFile(urlschema)">
</v-btn>
</v-card-actions>
<VuePdfEmbed v-if="urlschema.endsWith('.pdf')"
:source="urlschema"
width="500"
@@ -115,7 +116,7 @@
</v-img>
</v-card>
</v-row>
</v-dialog> -->
</v-dialog>
</template>
<script setup>