使用鸿蒙开发系统,完成一个有滚动条的列表
·
import { MyAiv } from '../componets/MyAiv'
// 定义数据模型
interface ProjectItem {
id: string;
title: string;
deadline: string;
tag: string;
amount: string;
remainingDays: string;
department: string;
isCollected: boolean;
}
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
// 项目数据
@State projectData: ProjectItem[] = [
{
id: '1',
title: '2024年度北京经济技术开发区企业研发机构专项奖励',
deadline: '2025-05-13',
tag: '科技创新',
amount: '最高可申报1000万',
remainingDays: '剩16天',
department: '北京经济技术开发区管理委员会',
isCollected: false
},
{
id: '2',
title: '2024年度国家高新技术企业认定',
deadline: '2025-06-30',
tag: '科技企业',
amount: '税收优惠+补贴',
remainingDays: '剩64天',
department: '国家科技部',
isCollected: true
},
{
id: '3',
title: '中小企业数字化转型专项资金',
deadline: '2025-04-30',
tag: '数字化转型',
amount: '最高补贴500万',
remainingDays: '剩2天',
department: '工业和信息化部',
isCollected: false
},
{
id: '4',
title: '中小企业数字化转型专项资金',
deadline: '2025-04-30',
tag: '数字化转型',
amount: '最高补贴500万',
remainingDays: '剩2天',
department: '工业和信息化部',
isCollected: false
}
];
build() {
Column() {
// Row() {
// Flex({ justifyContent: FlexAlign.SpaceEvenly }) {
// Text('报项目')
// .width('45%')
// .height(60)
// .backgroundColor(0xe4eeff)
// .borderRadius('8')
// .fontColor('#3377fc')
// .fontSize(24)
// .fontWeight(FontWeight.Bold)
// .padding(10)
// Text('读政策')
// .width('45%')
// .height(60)
// .backgroundColor(0xf8eed3)
// .borderRadius('5')
// .fontColor('#c18f65')
// .fontSize(24)
// .fontWeight(FontWeight.Bold)
// .padding(10)
// }
// .width('100%')
// .padding({ top: 10, bottom: 10 })
// }
// 引入组件
Row() {
// MyAiv()
}
// 第三个图形
// Column() {
// Row() {
// Circle()
// .width(50)
// .height(60)
// .fillOpacity(0)
// .strokeWidth(5)
// .stroke(Color.Orange)
// .antiAlias(false)
// .margin({ left: 50, top: 5 })
//
// Path()
// .width(150)
// .height(150)
// .commands('M150 0 L300 300 L0 300 Z')
// .fill("#E87361")
// .strokeWidth(0)
// .scale({ x: 0.50, y: 0.50 })
// .margin({ left: 80, top: 20 })
// }
// .width('94%')
// .height(70)
// .backgroundColor('#fee2cd')
// .borderRadius('8')
// }
// 项目推荐列表 - 使用List实现滚动
List({ space: 10 }) {
ForEach(this.projectData, (item: ProjectItem) => {
ListItem() {
// 项目推荐卡片
Column() {
// 标题
Text(item.title)
.fontSize(18)
.fontWeight(FontWeight.Bold)
.margin({ bottom: 8 })
.width('100%')
// 截止时间
Text(`截止时间:${item.deadline}`)
.fontSize(14)
.fontColor("#666666")
.margin({ bottom: 12 })
.width('100%')
// 标签行
Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
// 标签
Text(item.tag)
.fontSize(14)
.padding(8)
.backgroundColor("#f0f7ff")
.borderRadius(4)
.fontColor("#1890ff")
// 金额信息
Text(item.amount)
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor("#f1aa6c")
.backgroundColor('#fbe9db')
.width(150)
.height(30)
.borderRadius(5)
// 剩余时间
Text(item.remainingDays)
.fontSize(14)
.padding(8)
.borderRadius(4)
.fontColor("#2b2b2b")
}
.width('100%')
.margin({ bottom: 12 })
// 底部信息栏
Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
Text(item.department)
.fontSize(14)
.fontColor("#666666")
// 收藏按钮
Row() {
Text("收藏")
.fontSize(14)
.fontColor(item.isCollected ? '#999' : 'red')
.width(40)
.height(10)
}
.padding(8)
.borderRadius(20)
.backgroundColor("#ffffff")
.border({
width: 1,
color: item.isCollected ? Color.Gray : Color.Red
})
}
.width('100%')
}
.width('90%')
.padding(16)
.backgroundColor(Color.White)
.borderRadius(12)
.shadow({ radius: 8, color: "#19000000", offsetX: 2, offsetY: 2 })
.margin({ top: 20, left: 20 })
}
.onClick(() => {
// 点击项目时的操作
console.log(`点击了项目: ${item.title}`);
})
}, (item: ProjectItem) => item.id)
}
.width('100%')
.height('70%')
.backgroundColor("#f5f5f5")
}
.width('100%')
.height('100%')
}
}

更多推荐


所有评论(0)