je ne sais plus se que contient se commit
This commit is contained in:
parent
c4892e919c
commit
309111c23a
6 changed files with 102 additions and 13 deletions
|
|
@ -7,9 +7,11 @@ Kirby::plugin('tonnom/epub-export', [
|
|||
'pattern' => 'epub-export/(:any)',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
|
||||
$pageId = get('id');
|
||||
$page = page($pageId);
|
||||
throw new Exception($page);
|
||||
|
||||
throw new Exception($pageId);
|
||||
if (!$page) {
|
||||
throw new Exception("Page introuvable");
|
||||
}
|
||||
|
|
@ -37,14 +39,13 @@ Kirby::plugin('tonnom/epub-export', [
|
|||
]
|
||||
],
|
||||
|
||||
'sections' => [
|
||||
'fields' => [
|
||||
'epubexport' => [
|
||||
'props' => [
|
||||
'computed' => [
|
||||
'pageId' => function () {
|
||||
return $this->model()->id();
|
||||
},
|
||||
],
|
||||
'component' => 'export-button'
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
</k-box>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<!-- <script>
|
||||
export default {
|
||||
props: {
|
||||
pageId: String
|
||||
|
|
@ -29,8 +29,7 @@
|
|||
async exportEpub() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
console.log(this.pageId)
|
||||
|
||||
try {
|
||||
const response = await this.$api.post(`epub-export/${this.pageId}`);
|
||||
const blob = await response.blob()
|
||||
|
|
@ -52,4 +51,42 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
</script> -->
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
|
||||
// Props
|
||||
const { pageId } = defineProps({
|
||||
pageId: String
|
||||
})
|
||||
|
||||
// State
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
// Methods
|
||||
async function exportEpub() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
|
||||
try {
|
||||
// Appel API
|
||||
const response = await $api.post(`epub-export/${pageId}`)
|
||||
const blob = await response.blob()
|
||||
|
||||
// Création du téléchargement
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = pageId + '.epub'
|
||||
a.click()
|
||||
|
||||
} catch (e) {
|
||||
error.value = 'Erreur : ' + e.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import ExportButton from "./components/ExportButton.vue";
|
||||
|
||||
window.panel.plugin("tonnom/epub-export", {
|
||||
sections: {
|
||||
fields: {
|
||||
epubexport: ExportButton
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue