Commit e52005ab by yangchen

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

parent e77ec803
...@@ -190,21 +190,36 @@ const dialogTitle = ref('') ...@@ -190,21 +190,36 @@ const dialogTitle = ref('')
const iframeSrc = ref('') const iframeSrc = ref('')
const iframeShow = ref(false) const iframeShow = ref(false)
// function getBanner() { // function getBanner() {
// banner().then(res => { // 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 // return a.orderNum - b.orderNum
// }) // })
// }) // })
// } // }
function getBanner() { function getBanner() {
banner().then(res => { banner().then(res => {
// 筛选条件:showStatus为1且image字段存在且不为空 // 筛选条件:showStatus为1的数据
const validData = res.data.filter(item => const validData = res.data.filter(item => item.showStatus === 1);
item.showStatus === 1 &&
item.image && // 处理图片字段,只取第一张图片
item.image.trim() !== '' 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) { bannerImgList.value = validData.sort(function (a, b) {
...@@ -215,18 +230,16 @@ function getBanner() { ...@@ -215,18 +230,16 @@ function getBanner() {
getBanner() getBanner()
// function getAssemblyList() { // function getAssemblyList() {
// assemblyList({type: 0}).then(res => { // assemblyList({type: 0}).then(res => {
// const data = res.data.sort(function (a, b) { // // 筛选条件:showStatus为1且description字段存在
// return a.orderNum - b.orderNum // const filteredData = res.data.filter(item =>
// }) // item.showStatus === true &&
// assemblyData.value = data.length > 3 ? data.slice(0, 3) : data // item.description
// list.value[1].assemblyData = data.length > 3 ? data.slice(0, 3) : data // );
// }) //
// } // const data = filteredData.sort(function (a, b) {
// function getAssemblyList() {
// assemblyList({type: 0}).then(res => {
// const data = res.data.sort(function (a, b) {
// return a.orderNum - b.orderNum // return a.orderNum - b.orderNum
// }).map(item => { // }).map(item => {
// // 处理description字段,去除<p>标签 // // 处理description字段,去除<p>标签
...@@ -241,11 +254,8 @@ getBanner() ...@@ -241,11 +254,8 @@ getBanner()
// } // }
function getAssemblyList() { function getAssemblyList() {
assemblyList({type: 0}).then(res => { assemblyList({type: 0}).then(res => {
// 筛选条件:showStatus为1且description字段存在 // 筛选条件:showStatus为true的数据
const filteredData = res.data.filter(item => const filteredData = res.data.filter(item => item.showStatus === true);
item.showStatus === true &&
item.description
);
const data = filteredData.sort(function (a, b) { const data = filteredData.sort(function (a, b) {
return a.orderNum - b.orderNum return a.orderNum - b.orderNum
...@@ -254,6 +264,21 @@ function getAssemblyList() { ...@@ -254,6 +264,21 @@ function getAssemblyList() {
if (item.description) { if (item.description) {
item.description = item.description.replace(/<p>/g, '').replace(/<\/p>/g, '') 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 return item
}) })
assemblyData.value = data.length > 3 ? data.slice(0, 3) : data assemblyData.value = data.length > 3 ? data.slice(0, 3) : data
...@@ -261,23 +286,43 @@ function getAssemblyList() { ...@@ -261,23 +286,43 @@ function getAssemblyList() {
}) })
} }
// 计算自选
// function getResource() { // function getResource() {
// informationResourceList().then(res => { // informationResourceList().then(res => {
// list.value[0].assemblyData = res.data.length > 3 ? res.data.slice(0, 3) : res.data // // 筛选条件:showStatus为true的数据
// console.log(list.value[0].assemblyData, 'list.value[0].assemblyData') // 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() { function getResource() {
informationResourceList().then(res => { informationResourceList().then(res => {
// 筛选条件:showStatus为true的数据 // 筛选条件:showStatus为true的数据
const filteredData = res.data.filter(item => item.showStatus === true); const filteredData = res.data.filter(item => item.showStatus === true);
// 可选:同时处理information字段,去除<p>标签 // 处理information字段,去除<p>标签,并处理图片数组
const processedData = filteredData.map(item => { const processedData = filteredData.map(item => {
if (item.information) { if (item.information) {
item.information = item.information.replace(/<p>/g, '').replace(/<\/p>/g, ''); 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; return item;
}); });
...@@ -292,18 +337,30 @@ getResource() ...@@ -292,18 +337,30 @@ getResource()
const informationData = ref([]) const informationData = ref([])
const informationMainData = ref({}) const informationMainData = ref({})
// function getInformation() { // function getInformation() {
// informationList().then(res => { // 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.year = new Date(item.createTime).getFullYear()
// item.month = new Date(item.createTime).getMonth() + 1 // item.month = new Date(item.createTime).getMonth() + 1
// item.month = item.month < 10 ? '0' + item.month : item.month // item.month = item.month < 10 ? '0' + item.month : item.month
// item.day = new Date(item.createTime).getDate() // item.day = new Date(item.createTime).getDate()
// item.day = item.day < 10 ? '0' + item.day : item.day // 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] : {} // informationMainData.value = sortedData.length ? sortedData[0] : {}
// const arr = res.data.length ? res.data.slice(1, res.data.length) : [] // const arr = sortedData.length ? sortedData.slice(1, sortedData.length) : []
// informationData.value = arr.length > 3 ? arr.slice(0, 3) : arr // informationData.value = arr.length > 3 ? arr.slice(0, 3) : arr
// }) // })
// } // }
...@@ -327,6 +384,13 @@ function getInformation() { ...@@ -327,6 +384,13 @@ function getInformation() {
if (item.description) { if (item.description) {
item.description = item.description.replace(/<p>/g, '').replace(/<\/p>/g, '') 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] : {} informationMainData.value = sortedData.length ? sortedData[0] : {}
const arr = sortedData.length ? sortedData.slice(1, sortedData.length) : [] const arr = sortedData.length ? sortedData.slice(1, sortedData.length) : []
...@@ -334,7 +398,6 @@ function getInformation() { ...@@ -334,7 +398,6 @@ function getInformation() {
}) })
} }
getInformation() getInformation()
function openAssembly(data) { 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