fix bug of add banner

This commit is contained in:
2026-07-05 12:05:18 +02:00
parent bcf7b2f0ae
commit 86e6c3c16f
2 changed files with 16 additions and 16 deletions
+16 -13
View File
@@ -79,10 +79,21 @@ const typeList = ref([
{lable: 'بدون رویداد', value: null},
])
let content = ''
function parseBannerList(value: string | null | undefined): IBenefits[] {
if (!value) return []
try {
const parsed = JSON.parse(value)
return Array.isArray(parsed) ? parsed : []
} catch {
return []
}
}
function addRow() {
benefitsList.value.push({icon: null, show: true, caption: null, link: null, typeClick: null ,modalText:null})
if (!Array.isArray(benefitsList.value)) {
benefitsList.value = []
}
benefitsList.value.push({icon: null, show: true, caption: null, link: null, typeClick: null, modalText: null})
}
function removeRow(index: number) {
@@ -116,17 +127,9 @@ onMounted(async () => {
try {
const res = await getHeaderBannerConst()
if (res) {
if (res.length > 0) {
id = res[0].id || res[0].const_id || null
if (res[0].value) {
benefitsList.value = JSON.parse(res[0].value)
}
} else {
benefitsList.value = JSON.parse(res.value)
}
console.log(benefitsList.value)
if (res?.length > 0) {
id = res[0].id || res[0].const_id || null
benefitsList.value = parseBannerList(res[0].value)
}
} catch (error) {
console.error('خطا در دریافت بنرها:', error)