ytBuildComp.ets 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { EmitterKeyCollection, UserInfo, userInfo, yTRouter } from "basic"
  2. import { emitter } from "@kit.BasicServicesKit"
  3. import { AppStorageV2 } from "@kit.ArkUI"
  4. @ComponentV2
  5. export struct ytBuildComp {
  6. // 主体内容
  7. @BuilderParam main: () => void
  8. // 是否登录
  9. @Local isLogin: boolean = true
  10. // 用户信息
  11. @Local userInfo: UserInfo = AppStorageV2.connect<UserInfo>(UserInfo, 'UserInfo', () => userInfo)!
  12. // 是否校验登录
  13. @Local checkLogin: boolean = true
  14. toLogin = () => {
  15. yTRouter.router2LoginPage(false)
  16. }
  17. LoginStatusChange(){
  18. this.isLogin = this.userInfo.checkLogin()
  19. }
  20. aboutToAppear(): void {
  21. emitter.on(EmitterKeyCollection.LOGIN, () => {
  22. this.LoginStatusChange()
  23. })
  24. emitter.on(EmitterKeyCollection.LOGOUT, () => {
  25. this.LoginStatusChange()
  26. })
  27. // 防止横幅闪烁
  28. setTimeout(() => {
  29. this.LoginStatusChange()
  30. }, 300)
  31. }
  32. build() {
  33. RelativeContainer(){
  34. Column(){
  35. this.main()
  36. }
  37. .width("100%")
  38. .height("100%")
  39. .alignRules({
  40. top: { anchor: "__container__", align: VerticalAlign.Top},
  41. left: { anchor: "__container__", align: HorizontalAlign.Start},
  42. })
  43. if(!this.isLogin && this.checkLogin){
  44. Column(){
  45. Row() {
  46. Text("登录使用更多功能")
  47. .fontSize(18)
  48. .fontWeight(400)
  49. .fontColor(Color.Black)
  50. Text("马上登录")
  51. .fontSize(14)
  52. .fontWeight(500)
  53. .borderRadius(10)
  54. .onClick(this.toLogin)
  55. .fontColor(Color.White)
  56. .backgroundColor('#95C50A')
  57. .padding({ top: 5, bottom: 5, left: 10, right: 10 })
  58. }
  59. .width("100%")
  60. .borderRadius(8)
  61. .alignItems(VerticalAlign.Center)
  62. .backgroundColor('rgba(255, 255, 255, 1)')
  63. .justifyContent(FlexAlign.SpaceBetween)
  64. .padding({ left: 20, right: 20, top: 18, bottom: 18 })
  65. }
  66. .width('100%')
  67. .height('100%')
  68. .padding({left: 20, right: 20, bottom: 10})
  69. .justifyContent(FlexAlign.End)
  70. .alignItems(HorizontalAlign.Center)
  71. .backgroundColor('rgba(0, 0, 0, 0.2)')
  72. .alignRules({
  73. top: { anchor: "__container__", align: VerticalAlign.Top},
  74. left: { anchor: "__container__", align: HorizontalAlign.Start},
  75. })
  76. }
  77. }
  78. .width("100%")
  79. .height("100%")
  80. }
  81. }