1@Extend(Text) 2function textStyle() { 3 .fontSize(16) 4 .fontColor($r('app.color.add_title_color')) 5 .margin({ 6 top: 10, 7 bottom: 10 8 }) 9} 10 11@Extend(TextInput) 12function inputStyle() { 13 .borderRadius(0) 14 .backgroundColor('#f1f3f5') 15 .placeholderColor($r('app.color.title_color')) 16} 17 18@Extend(Line) 19function lineStyle(value: string = '100%') { 20 .width(value) 21 .height(1) 22 .backgroundColor($r('app.color.add_title_color')) 23} 24 25@Entry 26@Component 27struct Page02_TaskList { 28 @State currentState1: boolean = false 29 @State currentState2: boolean = false 30 @State currentState3: boolean = false 31 @State currentState4: boolean = false 32 private selectedDate: Date = new Date() 33 calendarChange = () => { 34 CalendarPickerDialog.show({ 35 selected: this.selectedDate, 36 onChange: (value) => { 37 console.log("CalendarPickerDialog:" + JSON.stringify(value)) 38 } 39 }) 40 } 41 timePickerChange = () => { 42 TimePickerDialog.show({ 43 selected: this.selectedDate, 44 useMilitaryTime: true, 45 disappearTextStyle: { 46 color: Color.Brown, 47 font: { 48 size: 15, 49 weight: FontWeight.Bold 50 } 51 }, 52 textStyle: { 53 color: Color.Orange 54 }, 55 selectedTextStyle: { 56 color: Color.Blue, 57 font: { 58 size: 18, 59 weight: FontWeight.Bold 60 } 61 }, 62 onAccept: (value: TimePickerResult) => { 63 console.log(JSON.stringify(value)) 64 } 65 }) 66 } 67 68 // 组件内部提取公共样式 69 build() { 70 Column() { 71 // 标题模块 72 Text('新建任务') 73 .fontSize(26) 74 .fontWeight(FontWeight.Bold) 75 .fontColor($r('app.color.title_color')) 76 .margin({ 77 bottom: 20 78 }) 79 80 // 主体内容 81 Column({ 82 space: 10 83 }) { 84 // 标题模块 85 Column() { 86 Text('标题') 87 .textStyle() 88 TextInput({ 89 placeholder: '请输入任务标题' 90 }).inputStyle() 91 92 Line().lineStyle() 93 } 94 .width('100%') 95 .alignItems(HorizontalAlign.Start) 96 97 // 日期选择 98 Column() { 99 Text('日期') 100 .textStyle() 101 Column() { 102 TextInput({ 103 placeholder: '请选择日期' 104 }) 105 .inputStyle() 106 .onClick(this.calendarChange) 107 Line().lineStyle() 108 } 109 } 110 .width('100%') 111 .alignItems(HorizontalAlign.Start) 112 113 // 时间选择 114 Column() { 115 Text('日期') 116 .textStyle() 117 Row() { 118 Column() { 119 TextInput({ 120 placeholder: '请选择开始时间' 121 }) 122 .inputStyle() 123 .onClick(this.timePickerChange) 124 Line().lineStyle('90%') 125 } 126 .width('48%') 127 128 Column() { 129 TextInput({ 130 placeholder: '请选择完成时间' 131 }) 132 .inputStyle() 133 .onClick(this.timePickerChange) 134 Line().lineStyle('90%') 135 } 136 .width('48%') 137 } 138 } 139 .width('100%') 140 .alignItems(HorizontalAlign.Start) 141 142 Column() { 143 Text('描述') 144 .textStyle() 145 TextInput({ 146 placeholder: '请输入任务描述' 147 }).inputStyle() 148 149 Line().lineStyle() 150 } 151 .width('100%') 152 .alignItems(HorizontalAlign.Start) 153 154 Column() { 155 Text('类型') 156 .textStyle() 157 Row() { 158 Row() { 159 Radio({ 160 value: '1', 161 group: 'type' 162 }) 163 .width(24) 164 .height(24) 165 .radioStyle({ 166 checkedBackgroundColor: '#5b67ca' 167 }) 168 .onChange((isChecked: boolean) => { 169 console.log(`isChecked`) 170 }) 171 172 Text('生活任务') 173 .fontColor('#10275a') 174 .fontWeight(FontWeight.Bold) 175 } 176 177 Row() { 178 Radio({ 179 value: '1', 180 group: 'type' 181 }) 182 .width(24) 183 .height(24) 184 .radioStyle({ 185 checkedBackgroundColor: '#5b67ca' 186 }) 187 .onChange((isChecked: boolean) => { 188 console.log(`isChecked`) 189 }) 190 191 Text('工作任务') 192 .fontColor('#10275a') 193 .fontWeight(FontWeight.Bold) 194 } 195 196 } 197 .width('100%') 198 .justifyContent(FlexAlign.SpaceBetween) 199 } 200 .width('100%') 201 .alignItems(HorizontalAlign.Start) 202 203 Column() { 204 Text('标签') 205 .textStyle() 206 Row({ 207 space: 20 208 }) { 209 Column() { 210 Text('工作') 211 .fontSize(18) 212 .fontColor(Color.White) 213 } 214 .width(60) 215 .height(30) 216 .backgroundColor(Color.Brown) 217 .alignItems(HorizontalAlign.Center) 218 .justifyContent(FlexAlign.Center) 219 .border({ 220 width: 2, 221 color: this.currentState1 ? Color.Yellow : Color.Transparent 222 }) 223 .onClick(() => { 224 this.currentState1 = !this.currentState1 225 }) 226 227 Column() { 228 Text('生活') 229 .fontSize(18) 230 .fontColor(Color.White) 231 } 232 .width(60) 233 .height(30) 234 .backgroundColor(Color.Orange) 235 .alignItems(HorizontalAlign.Center) 236 .justifyContent(FlexAlign.Center) 237 .border({ 238 width: 2, 239 color: this.currentState2 ? Color.Yellow : Color.Transparent 240 }) 241 .onClick(() => { 242 this.currentState2 = !this.currentState2 243 }) 244 245 Column() { 246 Text('学习') 247 .fontSize(18) 248 .fontColor(Color.White) 249 } 250 .width(60) 251 .height(30) 252 .backgroundColor(Color.Grey) 253 .alignItems(HorizontalAlign.Center) 254 .justifyContent(FlexAlign.Center) 255 .border({ 256 width: 2, 257 color: this.currentState3 ? Color.Yellow : Color.Transparent 258 }) 259 .onClick(() => { 260 this.currentState3 = !this.currentState3 261 }) 262 263 Column() { 264 Text('娱乐') 265 .fontSize(18) 266 .fontColor(Color.White) 267 } 268 .width(60) 269 .height(30) 270 .backgroundColor(Color.Pink) 271 .alignItems(HorizontalAlign.Center) 272 .justifyContent(FlexAlign.Center) 273 .border({ 274 width: 2, 275 color: this.currentState4 ? Color.Yellow : Color.Transparent 276 }) 277 .onClick(() => { 278 this.currentState4 = !this.currentState4 279 }) 280 } 281 } 282 .width('100%') 283 .alignItems(HorizontalAlign.Start) 284 } 285 } 286 .height('100%') 287 .width('100%') 288 .padding(10) 289 .backgroundColor('#f1f3f5') 290 } 291}
Copyright ©2010-2022 比特日记 All Rights Reserved.
Powered By 可尔物语