RMCalendarCell.ets
4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { RMCalendarBean } from './RMCalendarBean';
import { ToastUtils, NetworkUtil } from 'wdKit/Index';
@Component
export struct RMCalenderCell {
private selectOpacity: number = 0.15
itemFontSize: Length = 0
itemFontColor: ResourceColor = {} as ResourceColor
itemFontWeight: FontWeight = FontWeight.Normal
selectDayFontColor: ResourceColor = {} as ResourceColor
selectFontColor: ResourceColor = {} as ResourceColor
selectItemBgColor: ResourceColor = {} as ResourceColor
disabledFontColor: ResourceColor = {} as ResourceColor
nowFontColor: ResourceColor = {} as ResourceColor
// 今日时间戳
selectDay: number = 0
@Link selectItem: RMCalendarBean
@Link selectedDates: Array<RMCalendarBean>
@Prop hasPre: boolean
@Prop hasNext: boolean
@ObjectLink item: RMCalendarBean
// 自定义每一项布局
cellLayout?: (item: RMCalendarBean) => void
selectDayLayout?: (item: RMCalendarBean) => void
cellClick?: (item: RMCalendarBean) => void
disableClick?: (item: RMCalendarBean) => void
/**
* 检测是否包含在数组中
*/
checkInArrays() {
for (let index = 0; index < this.selectedDates.length; index++) {
if (this.item.time == this.selectedDates[index].time) {
return index
}
}
return -1
}
getItemColor() {
if (!NetworkUtil.isNetConnected()) {
if (this.selectItem && this.selectItem.time == this.item.time) {
return this.selectFontColor
}
return this.disabledFontColor
}
if (!this.isShowSelectBg() && this.item.isNow) {
return this.nowFontColor
} else if (this.item.isPre) {
return this.disabledFontColor
} else if (this.item.isNext) {
return this.disabledFontColor
} else if (this.selectItem && this.selectItem.time == this.item.time) {
return this.selectFontColor
}
return this.itemFontColor
}
getBorder() {
if (this.selectItem && this.selectItem.time == this.item.time) {
return this.border({
width: 1,
color: this.getItemColor()
})
} else {
return this.border({
width: 0,
}
)
}
}
/**
* 获取选中项背景颜色
*/
getSelectItemBg() {
return this.selectItemBgColor
}
/**
* 获取选中项背景透明度
* @returns
*/
getSelectItemBgOpa() {
return this.item.isPre || this.item.isNext ? this.selectOpacity : 1
}
/**
* 是否需要显示选项背景
*/
isShowSelectBg() {
return this.selectItem && this.selectItem.time == this.item.time
}
build() {
Column() {
Stack() {
if (!this.item.isPre) {
if (this.isShowSelectBg()) {
Column()// .position({ x: "10%", y: "10%" })
.height("80%")
.aspectRatio(1)// .borderRadius(999)
.backgroundColor(this.getSelectItemBg())
.opacity(this.getSelectItemBgOpa())
.borderRadius(2)
.transition({ type: TransitionType.Insert, opacity: 1 })
.transition({ type: TransitionType.Delete, opacity: 0 })
}
Text(this.item.date + '')
.fontSize(this.itemFontSize)
.fontColor(this.getItemColor())
.fontWeight(this.itemFontWeight)
.fontFamily('BebasNeueBold')
}
}
// .justifyContent(FlexAlign.Center)
.aspectRatio(1)
// .border(this.getBorder())
.width("80%")
}
.justifyContent(FlexAlign.Center)
// .width("100%")
// .aspectRatio(1)
.onClick(() => {
// animateTo({ duration: 200 }, () => {
//
// })
if (this.item.isNext) {
if (!this.hasNext) {
if (this.disableClick) {
this.disableClick(this.item)
}
return
}
}
if (this.item.isPre) {
// if (!this.hasPre) {
if (this.disableClick) {
this.disableClick(this.item)
}
return
// }
}
if (NetworkUtil.isNetConnected()) {
this.selectItem = this.item
if (this.cellClick) {
this.cellClick(this.item)
}
}
})
}
}