Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
client
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e52005ab
authored
Aug 06, 2025
by
yangchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
因为后端传入的image和homeImage值变成了数组形式,所以对他们两个进行了处理,只显示数组的第一张图片
parent
e77ec803
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
32 deletions
+95
-32
src/views/index.vue
+95
-32
No files found.
src/views/index.vue
View file @
e52005ab
...
...
@@ -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.d
ata[0] : {}
// const arr =
res.data.length ? res.data.slice(1, res.d
ata.length) : []
// informationMainData.value =
sortedData.length ? sortedD
ata[0] : {}
// const arr =
sortedData.length ? sortedData.slice(1, sortedD
ata.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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment