ilk
This commit is contained in:
51
ui/src/stores/downloadstpdfStore.js
Normal file
51
ui/src/stores/downloadstpdfStore.js
Normal file
@@ -0,0 +1,51 @@
|
||||
// src/stores/downloadstpdfStore.js
|
||||
import { defineStore } from 'pinia'
|
||||
import { download } from 'src/services/api'
|
||||
|
||||
export const useDownloadstpdfStore = defineStore('downloadstpdf', {
|
||||
actions: {
|
||||
/* ==========================================================
|
||||
📄 PDF İNDİR / AÇ
|
||||
========================================================== */
|
||||
async downloadPDF(accountCode, startDate, endDate, parislemler = []) {
|
||||
try {
|
||||
// 🔹 Query params
|
||||
const params = {
|
||||
accountcode: accountCode,
|
||||
startdate: startDate,
|
||||
enddate: endDate
|
||||
}
|
||||
|
||||
if (Array.isArray(parislemler) && parislemler.length > 0) {
|
||||
params.parislemler = parislemler.filter(
|
||||
p => p !== undefined && p !== null && p !== ''
|
||||
)
|
||||
}
|
||||
|
||||
// 🔥 MERKEZİ API — BLOB
|
||||
const blob = await download('/export-pdf', params)
|
||||
|
||||
// 🔹 Blob → URL
|
||||
const pdfUrl = window.URL.createObjectURL(
|
||||
new Blob([blob], { type: 'application/pdf' })
|
||||
)
|
||||
|
||||
// 🔹 Yeni sekmede aç
|
||||
window.open(pdfUrl, '_blank')
|
||||
|
||||
console.log('✅ PDF yeni sekmede açıldı')
|
||||
return { ok: true, message: '📄 PDF hazırlandı' }
|
||||
|
||||
} catch (err) {
|
||||
console.error('❌ PDF açma hatası:', err)
|
||||
|
||||
return {
|
||||
ok: false,
|
||||
message:
|
||||
err?.message ||
|
||||
'❌ PDF alınamadı'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user