P-28-feat:create display card img/pdf with download
This commit is contained in:
1 parent
58372282fb
commit
60e8c08ba4
3 files changed
+50
-62
No files matched your search
@@ -12,19 +12,14 @@ from userauth.models import *
|
|||||||
|
|
||||||
class SafetyTypeAPIView(ListAPIView):
|
class SafetyTypeAPIView(ListAPIView):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
print("sdfsdssssssssssssssssssssssssss")
|
|
||||||
chapters = SafetyType.objects.annotate(Count("mainpage_file")).filter(mainpage_file__count__gt=0)
|
chapters = SafetyType.objects.annotate(Count("mainpage_file")).filter(mainpage_file__count__gt=0)
|
||||||
return Response(SafetyTypeSerializer(chapters, many=True).data)
|
return Response(SafetyTypeSerializer(chapters, many=True).data)
|
||||||
|
|
||||||
class SafetyAPIView(APIView):
|
class SafetyAPIView(APIView):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
||||||
chapters = self.request.query_params.get('chapter', "fire")
|
chapters = self.request.query_params.get('chapter', "fire")
|
||||||
|
|
||||||
safety_group = SafetyType.objects.get(path=chapters)
|
safety_group = SafetyType.objects.get(path=chapters)
|
||||||
# print(safety_group)
|
|
||||||
return Response(SafetySerializer(safety_group).data)
|
return Response(SafetySerializer(safety_group).data)
|
||||||
# return Response("d")
|
|
||||||
|
|
||||||
# class SafetyResponsebilityAPIView(APIView):
|
# class SafetyResponsebilityAPIView(APIView):
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<v-col class="w100 h-100">
|
<v-col class="w100 h-100">
|
||||||
<v-window v-model="tab" class="h-100">
|
<v-window v-model="tab" class="h-100">
|
||||||
<v-window-item no-gutters class="gap h-100" value="mainInfo">
|
<v-window-item no-gutters class="gap h-100" value="mainInfo">
|
||||||
<MainInfoSafety :formainpage="formainpage"></MainInfoSafety>
|
<MainInfoSafety :formainpage="safetyData.mainpage_file"></MainInfoSafety>
|
||||||
</v-window-item>
|
</v-window-item>
|
||||||
<v-window-item value="document" class="h-100">
|
<v-window-item value="document" class="h-100">
|
||||||
<v-row no-gutters class="gap h-100 ">
|
<v-row no-gutters class="gap h-100 ">
|
||||||
@@ -59,9 +59,11 @@
|
|||||||
{{ get_name(decodeURI(file.file_name.replace(/\.[^/.]+$/, ""))) }}
|
{{ get_name(decodeURI(file.file_name.replace(/\.[^/.]+$/, ""))) }}
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-btn icon="mdi-file-pdf-box" color="red"
|
<v-btn icon="mdi-file-pdf-box" color="red"
|
||||||
@click="openPDF(checkNameFiles(file)), loading = true"></v-btn>
|
@click="openPDF(checkNameFiles(file)), loading = true">
|
||||||
|
</v-btn>
|
||||||
<v-btn icon='mdi-file-download-outline' color="green"
|
<v-btn icon='mdi-file-download-outline' color="green"
|
||||||
@click="downloadItem(burl + checkNameFiles(file), get_name(decodeURI(file.file_name)))"></v-btn>
|
@click="downloadItem(burl + checkNameFiles(file), get_name(decodeURI(file.file_name)))">
|
||||||
|
</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-container>
|
</v-container>
|
||||||
</v-card>
|
</v-card>
|
||||||
@@ -96,9 +98,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onBeforeMount, computed } from 'vue';
|
import { ref, onBeforeMount } from 'vue';
|
||||||
import { pagecounter } from '@/utils/universal_functions';
|
import { pagecounter } from '@/utils/universal_functions';
|
||||||
import { axiosApiInstance, baseURL, spravURLBase } from '@/utils/axios-api';
|
import { axiosApiInstance, baseURL } from '@/utils/axios-api';
|
||||||
import { saveAs } from 'file-saver';
|
import { saveAs } from 'file-saver';
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
@@ -108,7 +110,7 @@ import MainInfoSafety from './MainInfoSafety.vue';
|
|||||||
|
|
||||||
pagecounter();
|
pagecounter();
|
||||||
|
|
||||||
const safetyData = ref({categories:[]});
|
const safetyData = ref({});
|
||||||
const responsibilityData = ref();
|
const responsibilityData = ref();
|
||||||
const showMore = ref(false);
|
const showMore = ref(false);
|
||||||
const showFile = ref(true);
|
const showFile = ref(true);
|
||||||
@@ -120,45 +122,21 @@ const route = useRoute();
|
|||||||
|
|
||||||
// Вынес запрос в отдельную функцию, чтобы избежать дублирования одного и того же запроса на сервер.
|
// Вынес запрос в отдельную функцию, чтобы избежать дублирования одного и того же запроса на сервер.
|
||||||
function getSafety() {
|
function getSafety() {
|
||||||
console.log(route.params);
|
|
||||||
axiosApiInstance.get(`api/safety/?chapter=${route.params.chapter}`).then(result => {
|
axiosApiInstance.get(`api/safety/?chapter=${route.params.chapter}`).then(result => {
|
||||||
safetyData.value = result.data
|
safetyData.value = result.data
|
||||||
// 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({
|
|
||||||
get() {
|
|
||||||
let arr = []
|
|
||||||
safetyData.value.categories.forEach(element => {
|
|
||||||
element.files.forEach((e) => {
|
|
||||||
if (e.formainpage == true) {
|
|
||||||
arr.push(e)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// function getResponsibility() {
|
|
||||||
// axiosApiInstance.get(`api/safety/committee_files/`).then(result => {
|
|
||||||
// responsibilityData.value = result.data
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
// getResponsibility()
|
|
||||||
|
|
||||||
onBeforeMount(() => getSafety());
|
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) {
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
<v-col cols="9" class="flex-column" >
|
<v-col cols="9" class="flex-column" >
|
||||||
<v-row no-gutters class="h-100 justify-center">
|
<v-row no-gutters class="h-100 justify-center">
|
||||||
<v-col lg="6" class="meheight" v-for="schema in formainpage" :key="schema.id">
|
<v-col lg="6" class="meheight" v-for="schema in formainpage" :key="schema.id">
|
||||||
<VuePdfEmbed v-if="schema.url.endsWith('.pdf')" :source="burl + schema.url" width="500" />
|
<VuePdfEmbed v-if="schema.url.endsWith('.pdf')"
|
||||||
|
:source="burl + schema.url"
|
||||||
|
width="500"
|
||||||
|
@click="openFirstPlan_opener(schema)"/>
|
||||||
<v-img v-else
|
<v-img v-else
|
||||||
class="cursor-pointer"
|
class="cursor-pointer"
|
||||||
:src="burl + schema.url"
|
:src="burl + schema.url"
|
||||||
@@ -29,20 +32,31 @@
|
|||||||
<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-row class="ma-0 overflow-auto h-0">
|
||||||
<v-card class="h-100 w-100 pa-0 flex-grow-0">
|
<v-card class="h-100 w-100 pa-0 flex-grow-0">
|
||||||
<v-btn
|
<v-card-actions class="d-flex justify-space-between">
|
||||||
density="compact"
|
<v-btn
|
||||||
variant="text"
|
density="compact"
|
||||||
icon="mdi-close"
|
variant="text"
|
||||||
@click="openFirstPlan = false">
|
icon="mdi-close"
|
||||||
</v-btn>
|
@click="openFirstPlan = false">
|
||||||
<v-img
|
</v-btn>
|
||||||
:src="urlschema"
|
<v-btn class="d-flex align-center" icon='mdi-file-download-outline' color="green"
|
||||||
class="cursor-pointer"
|
@click="downloadFile(urlschema)">
|
||||||
height="100%"
|
</v-btn>
|
||||||
width="100%"
|
</v-card-actions>
|
||||||
@click="openFirstPlan = false">
|
<VuePdfEmbed v-if="urlschema.endsWith('.pdf')"
|
||||||
</v-img>
|
:source="urlschema"
|
||||||
</v-card>
|
width="500"
|
||||||
|
@click="openFirstPlan = false"/>
|
||||||
|
<v-img
|
||||||
|
v-else
|
||||||
|
:src="urlschema"
|
||||||
|
class="cursor-pointer"
|
||||||
|
height="100%"
|
||||||
|
width="100%"
|
||||||
|
@click="openFirstPlan = false">
|
||||||
|
</v-img>
|
||||||
|
</v-card>
|
||||||
|
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -53,7 +67,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { baseURL, axiosApiInstance } from '@/utils/axios-api'
|
import { baseURL, axiosApiInstance } from '@/utils/axios-api'
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import VuePdfEmbed from 'vue-pdf-embed';
|
import VuePdfEmbed from 'vue-pdf-embed';
|
||||||
|
import { saveAs } from 'file-saver';
|
||||||
|
|
||||||
defineProps(
|
defineProps(
|
||||||
{
|
{
|
||||||
@@ -62,23 +78,22 @@ defineProps(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const downloadFile = (url, fileName) => {
|
||||||
|
axiosApiInstance.get(url, { responseType: 'blob' })
|
||||||
|
.then(response => {
|
||||||
|
saveAs(response.data, fileName)
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
const urlschema=ref(null)
|
const urlschema=ref(null)
|
||||||
const burl = baseURL.slice(0,-1)
|
const burl = baseURL.slice(0,-1)
|
||||||
const openFirstPlan = ref(false)
|
const openFirstPlan = ref(false)
|
||||||
const responsibility = ref([])
|
|
||||||
function openFirstPlan_opener(schema){
|
function openFirstPlan_opener(schema){
|
||||||
urlschema.value = burl + schema.url
|
urlschema.value = burl + schema.url
|
||||||
openFirstPlan.value = true
|
openFirstPlan.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// function getResponsibility() {
|
|
||||||
// axiosApiInstance.get(`api/safety/responsibility/`).then(result => {
|
|
||||||
// responsibility.value = result.data.users
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
// getResponsibility()
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
Reference in new issue
Block a user