1 Star 1 Fork 0

matchZhou/HarmonyDemos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CalendarDemo.ets 2.78 KB
一键复制 编辑 原始数据 按行查看 历史
matchZhou 提交于 2024-01-18 09:25 . 将日历demo的list改为swiper
//日历demo
@Entry
@Component
struct CalendarDemo {
@State isShow: boolean = false;
@State selectNumber: number = 0;
@State currentIndex: number = 0;
build() {
Column() {
Stack() {
SwiperComp({ currentIndex: $currentIndex, selectDate: $selectNumber })
if (this.isShow) {
GridComp({ currentIndex: $currentIndex, selectDate: $selectNumber })
.backgroundColor('#fff')
.transition(TransitionEffect.OPACITY.animation({ duration: 600 })
)
}
}
Row()
.width('20%')
.height(8)
.backgroundColor('#ccc')
.borderRadius(10)
.onClick(() => {
animateTo({ duration: 600 }, () => {
this.isShow = !this.isShow;
})
})
}
}
}
@Component
struct SwiperComp {
@State data: number[][] = [];
@State rowsTemplate: string = '1fr 1fr 1fr 1fr 1fr';
@State count: number = 5;
// @State swiperIndex: number = 0;
@Link currentIndex: number
@Link selectDate: number
controller: SwiperController = new SwiperController()
aboutToAppear(): void {
let tempArr: number[] = [];
for (let i = 1; i < 32; i++) {
tempArr.push(i);
if (i % 7 === 0) {
this.data.push(tempArr);
tempArr = [];
}
}
}
build() {
Column() {
Swiper() {
ForEach(this.data, (itemArr: number[], index: number) => {
Grid() {
ForEach(itemArr, (item: number, subIndex: number) => {
GridItem() {
Text(item.toString()).height(50).onClick(() => {
this.currentIndex = index * 7 + subIndex;
this.selectDate = item;
})
}.backgroundColor(this.currentIndex === index * 7 + subIndex ? '#33ff00ff' : '#fff')
})
}.columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr')
.rowsTemplate('1fr')
.width('100%')
.height(50)
})
}.width('100%').index(Math.floor(this.currentIndex / 7)).indicator(false)
}
}
}
@Component
struct GridComp {
@State data: number[] = [];
@Link currentIndex: number;
@Link selectDate: number
aboutToAppear(): void {
for (let i = 1; i < 32; i++) {
this.data.push(i);
}
}
build() {
Column() {
Grid() {
ForEach(this.data, (item: number, index: number) => {
GridItem() {
Text(item.toString()).onClick(() => {
this.currentIndex = index;
this.selectDate = item;
})
}.width('100%').height('100%')
.backgroundColor(this.currentIndex === index ? '#33ff00ff' : '#fff')
})
}
.rowsTemplate('1fr 1fr 1fr 1fr 1fr')
.columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr')
.height(5 * 50)
.width('100%')
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/matchzhou/harmony-demos.git
git@gitee.com:matchzhou/harmony-demos.git
matchzhou
harmony-demos
HarmonyDemos
3784a99b4cf300fafeee6884312e4f3cd219f63d

搜索帮助

344bd9b3 5694891 D2dac590 5694891