Fix product performance grouped JSON build

This commit is contained in:
M_Kececi
2026-07-05 05:16:31 +03:00
parent 48bde09c2c
commit 27934bccdf
5 changed files with 486 additions and 162 deletions
+45 -19
View File
@@ -15,27 +15,46 @@ function normalizeUploadsPath (storagePath) {
}
function resolveProductImageUrl (item) {
if (!item || typeof item !== 'object') return ''
return resolveProductImageUrls(item)[0] || ''
}
const thumbURL = String(item.thumb_url || item.thumbUrl || '').trim()
if (thumbURL) return thumbURL
const fullURL = String(item.full_url || item.fullUrl || '').trim()
if (fullURL) return fullURL
const uploadsPath = normalizeUploadsPath(item.storage_path || item.storage || '')
if (uploadsPath) return uploadsPath
const fileName = String(item.file_name || item.FileName || '').trim()
if (fileName) return `/uploads/image/${fileName}`
function resolveProductImageUrls (item) {
if (!item || typeof item !== 'object') return []
const urls = []
const addURL = value => {
const url = String(value || '').trim()
if (url && !urls.includes(url)) urls.push(url)
}
const contentURL = String(item.content_url || item.ContentURL || '').trim()
if (contentURL.startsWith('/api/')) return contentURL
if (contentURL.startsWith('/')) return `/api${contentURL}`
if (contentURL.startsWith('/api/')) addURL(contentURL)
else if (contentURL.startsWith('/')) addURL(`/api${contentURL}`)
const imageId = Number(item.id || item.ID || 0)
if (Number.isFinite(imageId) && imageId > 0) return `/api/product-images/${imageId}/content`
return ''
if (Number.isFinite(imageId) && imageId > 0) addURL(`/api/product-images/${imageId}/content`)
const thumbURL = String(item.thumb_url || item.thumbUrl || '').trim()
addURL(thumbURL)
const fullURL = String(item.full_url || item.fullUrl || '').trim()
addURL(fullURL)
const uploadsPath = normalizeUploadsPath(item.storage_path || item.storage || '')
addURL(uploadsPath)
const fileName = String(item.file_name || item.FileName || '').trim()
if (fileName) addURL(`/uploads/image/${fileName}`)
return urls
}
function normalizedFilterMap (filters = {}) {
return Object.fromEntries(Object.entries(filters || {})
.map(([key, values]) => [
String(key || '').trim(),
normalizedList(values, true)
])
.filter(([key, values]) => key && values.length)
.sort((a, b) => a[0].localeCompare(b[0], 'tr')))
}
function normalizedList (value, sort = false) {
@@ -69,6 +88,8 @@ export const useProductPerformanceStore = defineStore('product-performance-store
mainGroup: String(params.urunAnaGrubu || params.urun_ana_grubu || ''),
groupLevels: normalizedList(params.groupLevels),
expandedKeys: normalizedList(params.expandedKeys, true),
expandThroughLevel: Number(params.expandThroughLevel ?? params.expand_through_level ?? -1),
filters: normalizedFilterMap(params.filters),
limit: Number(params.limit || 0)
})
},
@@ -91,7 +112,8 @@ export const useProductPerformanceStore = defineStore('product-performance-store
console.info(`${logPrefix} in-flight reuse`, {
mode: params.mode,
groupLevels: normalizedList(params.groupLevels),
expandedKeys: normalizedList(params.expandedKeys, true).length
expandedKeys: normalizedList(params.expandedKeys, true).length,
expandThroughLevel: Number(params.expandThroughLevel ?? params.expand_through_level ?? -1)
})
return this.groupedInFlightByKey[key]
}
@@ -102,6 +124,7 @@ export const useProductPerformanceStore = defineStore('product-performance-store
mode: params.mode,
groupLevels: normalizedList(params.groupLevels),
expandedKeys: normalizedList(params.expandedKeys, true).length,
expandThroughLevel: Number(params.expandThroughLevel ?? params.expand_through_level ?? -1),
limit: params.limit
})
const request = api.post('/pricing/product-performance/grouped', {
@@ -109,12 +132,15 @@ export const useProductPerformanceStore = defineStore('product-performance-store
urun_ana_grubu: params.urunAnaGrubu || params.urun_ana_grubu || '',
group_levels: Array.isArray(params.groupLevels) ? params.groupLevels : String(params.groupLevels || '').split(',').filter(Boolean),
expanded_keys: Array.isArray(params.expandedKeys) ? params.expandedKeys : String(params.expandedKeys || '').split(',').filter(Boolean),
expand_through_level: Number(params.expandThroughLevel ?? params.expand_through_level ?? -1),
filters: normalizedFilterMap(params.filters),
limit: params.limit
}, {
params: {
mode: params.mode,
limit: params.limit,
urun_ana_grubu: params.urunAnaGrubu || params.urun_ana_grubu || ''
urun_ana_grubu: params.urunAnaGrubu || params.urun_ana_grubu || '',
expand_through_level: Number(params.expandThroughLevel ?? params.expand_through_level ?? -1)
},
timeout: 90000
}).then(resp => {
@@ -190,7 +216,7 @@ export const useProductPerformanceStore = defineStore('product-performance-store
const key = String(item?.key || '').trim()
if (!key) continue
returned.add(key)
const urls = (Array.isArray(item.images) ? item.images : []).map(resolveProductImageUrl).filter(Boolean)
const urls = (Array.isArray(item.images) ? item.images : []).flatMap(resolveProductImageUrls).filter(Boolean)
this.setImageCache(key, urls)
lists[key] = urls
urlsByKey[key] = urls[0] || ''