优化非遗传承页面

This commit is contained in:
Qi 2025-08-10 20:59:42 +08:00
parent 29fd6a779b
commit 08bdd86007

View File

@ -30,7 +30,8 @@
<div v-for="item in currentHeritageList" :key="item.id" class="heritage-item card"> <div v-for="item in currentHeritageList" :key="item.id" class="heritage-item card">
<div class="heritage-image"> <div class="heritage-image">
<div class="image-placeholder"> <div class="image-placeholder">
<svg viewBox="0 0 200 150" width="100%" height="150"> <img v-if="item.coverImage" :src="getFileAccessHttpUrl(item.coverImage)" :alt="item.name" class="heritage-cover-image" />
<svg v-else viewBox="0 0 200 150" width="100%" height="150">
<rect width="200" height="150" :fill="item.color" opacity="0.2"/> <rect width="200" height="150" :fill="item.color" opacity="0.2"/>
<circle cx="100" cy="75" r="30" :fill="item.color" opacity="0.5"/> <circle cx="100" cy="75" r="30" :fill="item.color" opacity="0.5"/>
<text x="100" y="85" text-anchor="middle" :fill="item.color" <text x="100" y="85" text-anchor="middle" :fill="item.color"
@ -597,11 +598,6 @@ const protectionStats = ref({
const getProtectionStats = async () => { const getProtectionStats = async () => {
console.log('=== 开始获取保护现状统计数据 ===') console.log('=== 开始获取保护现状统计数据 ===')
try { try {
//
console.log('调用API: getLevelStats')
const statsResponse = await heritageApi.getLevelStats()
console.log('级别统计数据完整响应:', JSON.stringify(statsResponse, null, 2))
// //
protectionStats.value = { protectionStats.value = {
national: 0, national: 0,
@ -610,57 +606,90 @@ const getProtectionStats = async () => {
inheritors: 0 inheritors: 0
} }
// - result //
let dataArray = null const [nationalResponse, provincialResponse, municipalResponse] = await Promise.all([
if (statsResponse?.result && Array.isArray(statsResponse.result)) { heritageApi.getProjectsByLevel('国家级'),
// resultAPI heritageApi.getProjectsByLevel('省级'),
dataArray = statsResponse.result heritageApi.getProjectsByLevel('市级')
console.log('响应包含result字段数组长度:', dataArray.length) ])
} else if (Array.isArray(statsResponse)) {
// console.log('=== API响应详情 ===')
dataArray = statsResponse console.log('国家级项目完整响应:', JSON.stringify(nationalResponse, null, 2))
console.log('响应是直接数组,长度:', dataArray.length) console.log('省级项目完整响应:', JSON.stringify(provincialResponse, null, 2))
} else { console.log('市级项目完整响应:', JSON.stringify(municipalResponse, null, 2))
console.log('API响应格式不正确:', statsResponse)
console.log('statsResponse?.result:', statsResponse?.result) //
console.log('Array.isArray(statsResponse):', Array.isArray(statsResponse)) const extractData = (response: any) => {
console.log('提取数据,响应类型:', typeof response)
console.log('响应内容:', response)
//
if (response?.result && Array.isArray(response.result)) {
console.log('使用 response.result长度:', response.result.length)
return response.result
}
if (response?.data?.result && Array.isArray(response.data.result)) {
console.log('使用 response.data.result长度:', response.data.result.length)
return response.data.result
}
if (response?.data?.records && Array.isArray(response.data.records)) {
console.log('使用 response.data.records长度:', response.data.records.length)
return response.data.records
}
if (response?.data && Array.isArray(response.data)) {
console.log('使用 response.data长度:', response.data.length)
return response.data
}
if (Array.isArray(response)) {
console.log('直接使用响应数组,长度:', response.length)
return response
}
console.log('未找到有效数据数组,返回空数组')
return []
} }
if (dataArray && Array.isArray(dataArray)) { const nationalProjects = extractData(nationalResponse)
// - count const provincialProjects = extractData(provincialResponse)
dataArray.forEach((item: any, index: number) => { const municipalProjects = extractData(municipalResponse)
console.log(`处理统计项 [${index}]:`, JSON.stringify(item, null, 2))
const level = item.heritage_level || item.heritageLevel console.log('=== 提取的项目数据 ===')
const count = item.count || 0 console.log('国家级项目数据:', nationalProjects)
console.log('项目级别:', level, '数量:', count) console.log('省级项目数据:', provincialProjects)
console.log('市级项目数据:', municipalProjects)
if (level === '国家级') { //
protectionStats.value.national = count protectionStats.value.national = nationalProjects.length
console.log('设置国家级数量:', count) protectionStats.value.provincial = provincialProjects.length
} else if (level === '省级') { protectionStats.value.municipal = municipalProjects.length
protectionStats.value.provincial = count
console.log('设置省级数量:', count) console.log('=== 统计结果 ===')
} else if (level === '市级') { console.log('国家级项目数量:', protectionStats.value.national)
protectionStats.value.municipal = count console.log('省级项目数量:', protectionStats.value.provincial)
console.log('设置市级数量:', count) console.log('市级项目数量:', protectionStats.value.municipal)
} else {
console.log('未识别的级别:', level)
}
})
}
// //
console.log('调用API: getInheritorList') console.log('=== 获取传承人数据 ===')
const inheritorResponse = await heritageApi.getInheritorList({ const inheritorResponse = await heritageApi.getInheritorList({
pageNo: 1, pageNo: 1,
pageSize: 1000 pageSize: 1000
}) })
console.log('传承人API完整响应:', JSON.stringify(inheritorResponse, null, 2))
if (inheritorResponse?.total) { if (inheritorResponse?.total) {
protectionStats.value.inheritors = inheritorResponse.total protectionStats.value.inheritors = inheritorResponse.total
console.log('使用total字段传承人数量:', inheritorResponse.total)
} else if (inheritorResponse?.records) { } else if (inheritorResponse?.records) {
protectionStats.value.inheritors = inheritorResponse.records.length //
const activeInheritors = inheritorResponse.records.filter((inheritor: any) => inheritor.status === 1)
protectionStats.value.inheritors = activeInheritors.length
console.log('使用records字段过滤后传承人数量:', activeInheritors.length)
console.log('所有传承人记录数:', inheritorResponse.records.length)
} else if (inheritorResponse?.data?.records) {
const activeInheritors = inheritorResponse.data.records.filter((inheritor: any) => inheritor.status === 1)
protectionStats.value.inheritors = activeInheritors.length
console.log('使用data.records字段过滤后传承人数量:', activeInheritors.length)
} }
console.log('=== 最终保护现状统计 ===:', protectionStats.value) console.log('=== 最终保护现状统计 ===:', protectionStats.value)
@ -900,6 +929,7 @@ const getHeritageItems = async () => {
currentStatus: project.currentStatus || '保护良好', currentStatus: project.currentStatus || '保护良好',
viewCount: project.viewCount || 0, viewCount: project.viewCount || 0,
likeCount: project.likeCount || 0, likeCount: project.likeCount || 0,
year: project.approvalYear || '未知',
craftProcess: project.craftProcess && project.craftProcess.trim() !== '' ? craftProcess: project.craftProcess && project.craftProcess.trim() !== '' ?
(typeof project.craftProcess === 'string' ? JSON.parse(project.craftProcess) : project.craftProcess) : (typeof project.craftProcess === 'string' ? JSON.parse(project.craftProcess) : project.craftProcess) :
[], [],
@ -1124,6 +1154,13 @@ const closeImagePreview = () => {
gap: 2rem; gap: 2rem;
} }
.heritage-cover-image {
width: 100%;
height: 150px;
object-fit: cover;
border-radius: 8px;
}
.heritage-item { .heritage-item {
overflow: hidden; overflow: hidden;
transition: all 0.3s ease; transition: all 0.3s ease;