Commit e52005ab by yangchen

因为后端传入的image和homeImage值变成了数组形式,所以对他们两个进行了处理,只显示数组的第一张图片

parent e77ec803
......@@ -190,21 +190,36 @@ const dialogTitle = ref('')
const iframeSrc = ref('')
const iframeShow = ref(false)
// function getBanner() {
// banner().then(res => {
// bannerImgList.value = res.data.sort(function (a, b) {
// // 筛选条件:showStatus为1且image字段存在且不为空
// const validData = res.data.filter(item =>
// item.showStatus === 1 &&
// item.image &&
// item.image.trim() !== ''
// );
//
// // 对筛选后的数据进行排序
// bannerImgList.value = validData.sort(function (a, b) {
// return a.orderNum - b.orderNum
// })
// })
// }
function getBanner() {
banner().then(res => {
// 筛选条件:showStatus为1且image字段存在且不为空
const validData = res.data.filter(item =>
item.showStatus === 1 &&
item.image &&
item.image.trim() !== ''
);
// 筛选条件:showStatus为1的数据
const validData = res.data.filter(item => item.showStatus === 1);
// 处理图片字段,只取第一张图片
validData.forEach(item => {
// 注意后台字段名为images(复数),需要取第一张图片
if (Array.isArray(item.images) && item.images.length > 0) {
item.image = item.images[0];
} else {
item.image = ''; // 如果没有图片,设置为空字符串
}
});
// 对筛选后的数据进行排序
bannerImgList.value = validData.sort(function (a, b) {
......@@ -215,18 +230,16 @@ function getBanner() {
getBanner()
// function getAssemblyList() {
// assemblyList({type: 0}).then(res => {
// const data = res.data.sort(function (a, b) {
// return a.orderNum - b.orderNum
// })
// assemblyData.value = data.length > 3 ? data.slice(0, 3) : data
// list.value[1].assemblyData = data.length > 3 ? data.slice(0, 3) : data
// })
// }
// function getAssemblyList() {
// assemblyList({type: 0}).then(res => {
// const data = res.data.sort(function (a, b) {
// // 筛选条件:showStatus为1且description字段存在
// const filteredData = res.data.filter(item =>
// item.showStatus === true &&
// item.description
// );
//
// const data = filteredData.sort(function (a, b) {
// return a.orderNum - b.orderNum
// }).map(item => {
// // 处理description字段,去除<p>标签
......@@ -241,11 +254,8 @@ getBanner()
// }
function getAssemblyList() {
assemblyList({type: 0}).then(res => {
// 筛选条件:showStatus为1且description字段存在
const filteredData = res.data.filter(item =>
item.showStatus === true &&
item.description
);
// 筛选条件:showStatus为true的数据
const filteredData = res.data.filter(item => item.showStatus === true);
const data = filteredData.sort(function (a, b) {
return a.orderNum - b.orderNum
......@@ -254,6 +264,21 @@ function getAssemblyList() {
if (item.description) {
item.description = item.description.replace(/<p>/g, '').replace(/<\/p>/g, '')
}
// 处理images数组,只取第一张图片
if (Array.isArray(item.images) && item.images.length > 0) {
item.image = item.images[0];
} else {
item.image = ''; // 如果没有图片,设置为空字符串
}
// 处理homeImages数组,只取第一张图片
if (Array.isArray(item.homeImages) && item.homeImages.length > 0) {
item.homeImage = item.homeImages[0];
} else {
item.homeImage = ''; // 如果没有图片,设置为空字符串
}
return item
})
assemblyData.value = data.length > 3 ? data.slice(0, 3) : data
......@@ -261,23 +286,43 @@ function getAssemblyList() {
})
}
// 计算自选
// function getResource() {
// informationResourceList().then(res => {
// list.value[0].assemblyData = res.data.length > 3 ? res.data.slice(0, 3) : res.data
// console.log(list.value[0].assemblyData, 'list.value[0].assemblyData')
// })
// // 筛选条件:showStatus为true的数据
// const filteredData = res.data.filter(item => item.showStatus === true);
//
// // 可选:同时处理information字段,去除<p>标签
// const processedData = filteredData.map(item => {
// if (item.information) {
// item.information = item.information.replace(/<p>/g, '').replace(/<\/p>/g, '');
// }
// return item;
// });
//
// list.value[0].assemblyData = processedData.length > 3 ? processedData.slice(0, 3) : processedData;
// console.log(list.value[0].assemblyData, 'list.value[0].assemblyData');
// });
// }
function getResource() {
informationResourceList().then(res => {
// 筛选条件:showStatus为true的数据
const filteredData = res.data.filter(item => item.showStatus === true);
// 可选:同时处理information字段,去除<p>标签
// 处理information字段,去除<p>标签,并处理图片数组
const processedData = filteredData.map(item => {
if (item.information) {
item.information = item.information.replace(/<p>/g, '').replace(/<\/p>/g, '');
}
// 处理images数组,只取第一张图片
if (Array.isArray(item.images) && item.images.length > 0) {
item.image = item.images[0];
} else {
item.image = ''; // 如果没有图片,设置为空字符串
}
return item;
});
......@@ -292,18 +337,30 @@ getResource()
const informationData = ref([])
const informationMainData = ref({})
// function getInformation() {
// informationList().then(res => {
// res.data.forEach(item => {
// // 筛选条件:showStatus为true的数据
// const filteredData = res.data.filter(item => item.showStatus === true);
//
// // 按创建时间降序排序(最新的在前)
// const sortedData = filteredData.sort((a, b) => {
// return new Date(b.createTime) - new Date(a.createTime);
// });
//
// sortedData.forEach(item => {
// item.year = new Date(item.createTime).getFullYear()
// item.month = new Date(item.createTime).getMonth() + 1
// item.month = item.month < 10 ? '0' + item.month : item.month
// item.day = new Date(item.createTime).getDate()
// item.day = item.day < 10 ? '0' + item.day : item.day
// item.description = item.description.replace('<p><br></p>', '')
// // 使用正则表达式去除所有<p></p>标
// if (item.description) {
// item.description = item.description.replace(/<p>/g, '').replace(/<\/p>/g, '')
// }
// })
// informationMainData.value = res.data.length ? res.data[0] : {}
// const arr = res.data.length ? res.data.slice(1, res.data.length) : []
// informationMainData.value = sortedData.length ? sortedData[0] : {}
// const arr = sortedData.length ? sortedData.slice(1, sortedData.length) : []
// informationData.value = arr.length > 3 ? arr.slice(0, 3) : arr
// })
// }
......@@ -327,6 +384,13 @@ function getInformation() {
if (item.description) {
item.description = item.description.replace(/<p>/g, '').replace(/<\/p>/g, '')
}
// 处理images数组,只取第一张图片
if (Array.isArray(item.images) && item.images.length > 0) {
item.image = item.images[0];
} else {
item.image = ''; // 如果没有图片,设置为空字符串
}
})
informationMainData.value = sortedData.length ? sortedData[0] : {}
const arr = sortedData.length ? sortedData.slice(1, sortedData.length) : []
......@@ -334,7 +398,6 @@ function getInformation() {
})
}
getInformation()
function openAssembly(data) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment