56 lines
1.1 KiB
Vue
56 lines
1.1 KiB
Vue
|
|
<template>
|
||
|
|
<k-box>
|
||
|
|
<k-button
|
||
|
|
theme="positive"
|
||
|
|
icon="download"
|
||
|
|
:disabled="loading"
|
||
|
|
@click="exportEpub"
|
||
|
|
>
|
||
|
|
Exporter en EPUB
|
||
|
|
</k-button>
|
||
|
|
|
||
|
|
<k-text v-if="loading">Génération en cours…</k-text>
|
||
|
|
<k-text v-if="error" theme="negative">{{ error }}</k-text>
|
||
|
|
</k-box>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
export default {
|
||
|
|
props: {
|
||
|
|
pageId: String
|
||
|
|
},
|
||
|
|
data() {
|
||
|
|
return {
|
||
|
|
loading: false,
|
||
|
|
error: null,
|
||
|
|
}
|
||
|
|
},
|
||
|
|
methods: {
|
||
|
|
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()
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
// Télécharger le fichier
|
||
|
|
const url = window.URL.createObjectURL(blob)
|
||
|
|
const a = document.createElement('a')
|
||
|
|
a.href = url
|
||
|
|
a.download = this.pageId + '.epub'
|
||
|
|
a.click()
|
||
|
|
|
||
|
|
} catch (e) {
|
||
|
|
this.error = "Erreur : " + e.message
|
||
|
|
} finally {
|
||
|
|
this.loading = false
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</script>
|