mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
fix csv export
This commit is contained in:
@@ -43,11 +43,11 @@ const creatingCsv = ref<boolean>(false);
|
|||||||
async function downloadCSV() {
|
async function downloadCSV() {
|
||||||
creatingCsv.value = true;
|
creatingCsv.value = true;
|
||||||
const result = await $fetch(`/api/project/generate_csv?mode=events&slice=${options.indexOf(selectedTimeFrom.value)}`, signHeaders());
|
const result = await $fetch(`/api/project/generate_csv?mode=events&slice=${options.indexOf(selectedTimeFrom.value)}`, signHeaders());
|
||||||
const blob = new Blob([result], { type: 'text/csv' });
|
const blob = new Blob([result as any], { type: 'text/csv' });
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = url;
|
a.href = url;
|
||||||
a.download = 'ReportVisits.csv';
|
a.download = 'ReportEvents.csv';
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
|
|||||||
@@ -47,12 +47,9 @@ onMounted(async () => {
|
|||||||
|
|
||||||
const creatingCsv = ref<boolean>(false);
|
const creatingCsv = ref<boolean>(false);
|
||||||
|
|
||||||
async function downloadCSV(isGoogle: boolean) {
|
async function downloadCSV() {
|
||||||
creatingCsv.value = true;
|
creatingCsv.value = true;
|
||||||
const result = await $fetch(`/api/project/generate_csv?mode=visits&slice=${options.indexOf(selectedTimeFrom.value)}`,
|
const result = await $fetch(`/api/project/generate_csv?mode=visits&slice=${options.indexOf(selectedTimeFrom.value)}`, signHeaders());
|
||||||
signHeaders({ 'x-google-export': isGoogle ? 'true' : 'false' })
|
|
||||||
);
|
|
||||||
if (!isGoogle) {
|
|
||||||
const blob = new Blob([result as any], { type: 'text/csv' });
|
const blob = new Blob([result as any], { type: 'text/csv' });
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
@@ -62,9 +59,6 @@ async function downloadCSV(isGoogle: boolean) {
|
|||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
window.URL.revokeObjectURL(url);
|
window.URL.revokeObjectURL(url);
|
||||||
} else {
|
|
||||||
alert(result);
|
|
||||||
}
|
|
||||||
creatingCsv.value = false;
|
creatingCsv.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,21 +101,16 @@ function goToUpgrade() {
|
|||||||
<USelectMenu v-model="selectedTimeFrom" :options="options"></USelectMenu>
|
<USelectMenu v-model="selectedTimeFrom" :options="options"></USelectMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="isPremium" @click="downloadCSV(false)"
|
<div v-if="isPremium" @click="downloadCSV()"
|
||||||
class="bg-[#57c78fc0] hover:bg-[#57c78fab] cursor-pointer text-text poppins font-semibold px-8 py-2 rounded-lg">
|
class="bg-[#57c78fc0] hover:bg-[#57c78fab] cursor-pointer text-text poppins font-semibold px-8 py-2 rounded-lg">
|
||||||
Download CSV
|
Download CSV
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="isPremium" @click="downloadCSV(true)"
|
<div v-if="!isPremium" @click="goToUpgrade()"
|
||||||
class="bg-[#57c78fc0] hover:bg-[#57c78fab] cursor-pointer text-text poppins font-semibold px-8 py-2 rounded-lg">
|
|
||||||
Export CSV to Google Sheets
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- <div v-if="!isPremium" @click="goToUpgrade()"
|
|
||||||
class="bg-[#57c78f46] hover:bg-[#57c78f42] flex gap-4 items-center cursor-pointer text-text poppins font-semibold px-8 py-2 rounded-lg">
|
class="bg-[#57c78f46] hover:bg-[#57c78f42] flex gap-4 items-center cursor-pointer text-text poppins font-semibold px-8 py-2 rounded-lg">
|
||||||
<i class="far fa-lock"></i>
|
<i class="far fa-lock"></i>
|
||||||
Upgrade plan for CSV
|
Upgrade plan for CSV
|
||||||
</div> -->
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user