Refactor TabPiyangoTalihliListesi.vue to improve file upload handling and validation. Remove unused SignalR imports, enhance error handling for file uploads, and integrate dialog and toast notifications for user feedback on upload results. Update table header to include sorting for 'İkramiyesi'.
This commit is contained in:
@ -71,7 +71,6 @@
|
||||
import { useUsersStore } from '@/stores/usersStore'
|
||||
import PanelWrapper from '@/components/PanelWrapper.vue'
|
||||
import PanelTalihliDocument from '@/module/cekilisler/components/panel/PanelTalihliDocument.vue'
|
||||
import { connectToHub, onCompleted, onProgress } from '@/module/cekilisler/service/signalrService'
|
||||
const usersStore = useUsersStore()
|
||||
const tableHeader = ref<Record<string, any>>([
|
||||
{
|
||||
@ -111,7 +110,8 @@
|
||||
style: { width: '20%' }
|
||||
},{
|
||||
name: 'ikramiye',
|
||||
title: 'İkramiyesi'
|
||||
title: 'İkramiyesi',
|
||||
sort: true
|
||||
},{
|
||||
name: '',
|
||||
title: 'Talihli',
|
||||
@ -191,53 +191,118 @@
|
||||
import { usePiyangoTalihliStore } from '../stores/piyangoTalihliStore'
|
||||
|
||||
const piyangoTalihliStore = usePiyangoTalihliStore()
|
||||
import { usePiyangoKatilimciValidationStore } from '../validation/piyangoKatilimciValidationStore'
|
||||
import { usePiyangoTalihliValidationStore } from '../validation/piyangoTalihliValidationStore'
|
||||
import { useToastStore } from '@/components/global/toastStore'
|
||||
import { useDialogStore } from '@/components/global/dialogStore'
|
||||
|
||||
const piyangoTalihliValidationStore = usePiyangoTalihliValidationStore()
|
||||
const toastStore = useToastStore()
|
||||
const dialogStore = useDialogStore()
|
||||
|
||||
const escapeHtml = (value: string) =>
|
||||
String(value)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
|
||||
const showTalihliUploadDialog = (
|
||||
title: string,
|
||||
mesaj: string,
|
||||
detaylar: string[] = []
|
||||
) => {
|
||||
const details = (Array.isArray(detaylar) ? detaylar : []).filter((x) => !!x)
|
||||
const items = details
|
||||
.map((x) => `<li style="margin-bottom:6px;">${escapeHtml(String(x))}</li>`)
|
||||
.join('')
|
||||
|
||||
// Detay listesi varsa özet içinde aynı satırları tekrar gösterme
|
||||
let summary = mesaj || ''
|
||||
if (details.length > 0) {
|
||||
for (const d of details) {
|
||||
summary = summary.split(String(d)).join(' ').replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
summary = summary.replace(/\.\s*\./g, '.').trim()
|
||||
if (!summary) {
|
||||
summary = 'Talihli listesi yüklenemedi. Aşağıdaki satır hatalarını kontrol ediniz.'
|
||||
}
|
||||
}
|
||||
|
||||
const contentHtml = `
|
||||
<p style="margin:0 0 12px; line-height:1.45;">${escapeHtml(summary)}</p>
|
||||
${
|
||||
items
|
||||
? `<ul style="margin:0; padding-left:18px; max-height:280px; overflow:auto; line-height:1.4;">${items}</ul>`
|
||||
: ''
|
||||
}
|
||||
`
|
||||
|
||||
dialogStore.CreateDialog({
|
||||
id: 'talihli-upload-result',
|
||||
title,
|
||||
contentHtml,
|
||||
closeText: 'Tamam',
|
||||
showClose: true
|
||||
})
|
||||
}
|
||||
|
||||
const piyangoKatilimciValidationStore = usePiyangoKatilimciValidationStore()
|
||||
const AddNewDocument = () => {
|
||||
dataStore.panelData = {
|
||||
title: '',
|
||||
file: ''
|
||||
}
|
||||
piyangoTalihliStore.RestoreFileFormData()
|
||||
talihliFilePanel.value = true
|
||||
}
|
||||
const FileUpload = async () => {
|
||||
// const connectionId = await connectToHub()
|
||||
if (!piyangoTalihliValidationStore.FileFormCheck()) {
|
||||
return
|
||||
}
|
||||
|
||||
// Progress modal'ı aç
|
||||
uploadProgressValue.value = 0
|
||||
uploadProgressPanel.value = true
|
||||
|
||||
// onProgress((data) => {
|
||||
// uploadProgressValue.value = data.Percent
|
||||
// console.log('Progress:', data.Percent)
|
||||
// })
|
||||
//
|
||||
// onCompleted((data) => {
|
||||
// console.log('Tamamlandı:', data)
|
||||
// uploadProgressPanel.value = false
|
||||
// refreshList.value = true
|
||||
// talihliFilePanel.value = false
|
||||
// })
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append('file', piyangoTalihliStore.piyangoTalihliFileFormData.excelFile)
|
||||
console.log( dataStore.panelData)
|
||||
const response = await dataStore.dataPost(
|
||||
`Katilimci/talihli-yukle/${piyangoStore.selectedLottery}`,
|
||||
{
|
||||
data: formData,
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
skipErrorForStatuses: [400]
|
||||
}
|
||||
)
|
||||
|
||||
if (response.data !== 'errorfalse') {
|
||||
uploadProgressPanel.value = false
|
||||
refreshList.value = true
|
||||
talihliFilePanel.value = false
|
||||
} else {
|
||||
// Hata olursa paneli kapat
|
||||
uploadProgressPanel.value = false
|
||||
uploadProgressPanel.value = false
|
||||
|
||||
if (response?._error && response.status === 400) {
|
||||
const errData = response.data || {}
|
||||
const hata =
|
||||
typeof errData === 'string'
|
||||
? errData
|
||||
: errData.hata || errData.Hata || 'Talihli listesi yüklenemedi.'
|
||||
const detaylar = errData.detaylar || errData.Detaylar || []
|
||||
showTalihliUploadDialog('Talihli Yükleme Hatası', hata, detaylar)
|
||||
return
|
||||
}
|
||||
|
||||
if (response === 'errorfalse') {
|
||||
showTalihliUploadDialog(
|
||||
'Talihli Yükleme Hatası',
|
||||
'Talihli listesi yüklenirken bir hata oluştu. Lütfen dosyayı kontrol edip tekrar deneyiniz.'
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const mesaj = response?.Mesaj || response?.mesaj || 'Talihli listesi yüklendi.'
|
||||
const detaylar = response?.Detaylar || response?.detaylar || []
|
||||
if (Array.isArray(detaylar) && detaylar.length > 0) {
|
||||
showTalihliUploadDialog('Talihli Yükleme Uyarıları', mesaj, detaylar)
|
||||
} else {
|
||||
toastStore.AddToast(mesaj, 'ok', 5000)
|
||||
}
|
||||
|
||||
refreshList.value = true
|
||||
talihliFilePanel.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user