scinote-web/app/javascript/vue/reports/renderers/pdf.vue

85 lines
2.3 KiB
Vue
Raw Normal View History

2024-01-11 02:56:01 +08:00
<template>
<div class="group w-full h-full">
2024-01-11 02:56:01 +08:00
<template v-if="pdf.error">
<span class="flex items-center gap-1 text-sn-delete-red">
<i class="fas fa-exclamation-triangle"></i>
{{ i18n.t('projects.reports.index.error') }}
<span v-if="pdf.preview_url" class="text-sn-black">|</span>
<a v-if="pdf.preview_url" href="#"
class="file-preview-link flex items-center gap-1
pdf hover:no-underline whitespace-nowrap"
:data-preview-url="pdf.preview_url">
{{ i18n.t('projects.reports.index.previous_pdf') }}
</a>
</span>
</template>
<span v-else-if="pdf.processing" class="processing pdf">
{{ i18n.t('projects.reports.index.generating') }}
</span>
2024-01-11 02:56:01 +08:00
<template v-else-if="pdf.preview_url">
<a v-if="pdf.preview_url" href="#"
class="file-preview-link flex items-center gap-1
pdf hover:no-underline whitespace-nowrap"
:data-preview-url="pdf.preview_url">
<i class="sn-icon sn-icon-file-word"></i>
{{ i18n.t('projects.reports.index.pdf') }}
</a>
</template>
<a v-else class="hidden group-hover:!block" href="#" @click.prevent="generate">
2024-01-11 02:56:01 +08:00
{{ i18n.t('projects.reports.index.generate') }}
</a>
</div>
</template>
<script>
import axios from '../../../packs/custom_axios.js';
export default {
name: 'PdfRenderer',
2024-01-11 02:56:01 +08:00
props: {
params: {
required: true
}
},
data() {
return {
pdf: this.params.data.pdf_file
};
},
mounted() {
if (this.pdf.processing) {
setTimeout(this.checkStatus, 3000);
}
},
watch: {
'params.data.pdf_file': {
handler: function (val) {
this.pdf = val;
if (val?.processing) {
setTimeout(this.checkStatus, 3000);
}
},
deep: true
}
},
2024-01-11 02:56:01 +08:00
methods: {
generate() {
axios.post(this.params.data.urls.generate_pdf)
.then(() => {
this.pdf.processing = true;
this.checkStatus();
});
},
checkStatus() {
axios.get(this.params.data.urls.status)
.then((response) => {
this.pdf = response.data.data.attributes.pdf_file;
if (this.pdf.processing) {
setTimeout(this.checkStatus, 3000);
}
});
}
}
};
</script>