MainView.ets 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { BackgroundPageModifier, DateOption, YTAddressSelectorDialog, YTDateUtil,
  2. YtProgressComp,
  3. yTRouter } from 'basic'
  4. import { UnitType } from 'basic/src/main/ets/datepicker/DatePickerEnums'
  5. import { promptAction } from '@kit.ArkUI'
  6. @Component
  7. export struct MainView {
  8. @State point:number = 40
  9. build() {
  10. Column() {
  11. Text('打开日历')
  12. .onClick(() => {
  13. //以下内容都可以不传 有默认值
  14. const date: Date = new Date()
  15. const yTDateDialog = new YTAddressSelectorDialog(this.getUIContext())
  16. let dateOption = new DateOption() //选项配置类
  17. dateOption.date = date //当前日期 默认今天
  18. dateOption.minDate = new Date(2000, 0, 1) //最小选择的日期 默认10年前的今天
  19. dateOption.maxDate = new Date(2048, 12, 30) //最大选择的日期 默认10年后的今天
  20. dateOption.unitType = UnitType.YEAR_MONTH_DAY //日期单位 默认年月日 可选年月、月日等组合
  21. dateOption.confirm = (date: Date) => { //确认选择回调函数
  22. console.log('确认', YTDateUtil.formatDate(date))
  23. promptAction.openToast({ message: YTDateUtil.formatDate(date) })
  24. }
  25. dateOption.headerLeftBuilder = wrapBuilder(headerLeftBuilder) //头部左侧按钮 默认返回按钮
  26. dateOption.headerRightBuilder = wrapBuilder(headerRightBuilder) //头部右侧按钮 默认确认按钮
  27. dateOption.highlightBackgroundColor = Color.Pink //选中高亮背景色
  28. dateOption.highlightBorderColor = Color.Red //选中高亮边框色
  29. dateOption.textStyle = {
  30. //日期文字样式
  31. font: { size: 20, weight: 400 },
  32. color: Color.Gray
  33. }
  34. dateOption.selectedTextStyle = {
  35. //选中日期文字样式
  36. font: { size: 25, weight: 400 },
  37. color: Color.Yellow
  38. }
  39. yTDateDialog.show(dateOption) //设置好配置之后打开日历的函数
  40. })
  41. Button('跳转页面测试')
  42. .onClick(()=>{
  43. yTRouter.pushPathByName('TestRouterPage',null)
  44. })
  45. YtProgressComp({
  46. growPoint:this.point,
  47. v1Point:{
  48. point:100,
  49. position:4
  50. },
  51. v2Point:{
  52. point:200,
  53. position:10,
  54. topImage:$r('app.media.app_icon'),
  55. }
  56. })
  57. Row(){
  58. Button('+10')
  59. .onClick(()=>{
  60. this.point += 10
  61. })
  62. Button('-10')
  63. .onClick(()=>{
  64. this.point -= 10
  65. })
  66. }
  67. }
  68. .attributeModifier(new BackgroundPageModifier(true))
  69. }
  70. }
  71. @Builder
  72. function headerLeftBuilder() {
  73. Image($r('app.media.app_icon'))
  74. .width(24)
  75. }
  76. @Builder
  77. function headerRightBuilder() {
  78. Image($r("app.media.app_icon"))
  79. .width(24)
  80. }