ytBuildComp.ets 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 = false
  10. // 用户信息
  11. @Local userInfo: UserInfo = AppStorageV2.connect<UserInfo>(UserInfo, 'UserInfo', () => userInfo)!
  12. // 是否校验登录
  13. @Local checkLogin: boolean = false
  14. toLogin = () => {
  15. yTRouter.router2LoginPage(false)
  16. }
  17. LoginStatusChange(){
  18. this.isLogin = this.userInfo.checkLogin()
  19. this.userInfo.setUserInfoAndLogin(userInfo, false)
  20. }
  21. aboutToAppear(): void {
  22. emitter.on(EmitterKeyCollection.LOGIN, () => {
  23. this.LoginStatusChange()
  24. })
  25. emitter.on(EmitterKeyCollection.LOGOUT, () => {
  26. this.LoginStatusChange()
  27. })
  28. this.LoginStatusChange()
  29. }
  30. build() {
  31. RelativeContainer(){
  32. Column(){
  33. this.main()
  34. }
  35. .width("100%")
  36. .height("100%")
  37. .alignRules({
  38. top: { anchor: "__container__", align: VerticalAlign.Top},
  39. left: { anchor: "__container__", align: HorizontalAlign.Start},
  40. })
  41. if(!this.isLogin && this.checkLogin){
  42. Row() {
  43. Text("登录使用更多功能")
  44. .fontSize(20)
  45. .fontWeight(400)
  46. .fontColor(Color.White)
  47. Text("马上登录")
  48. .fontSize(14)
  49. .fontWeight(500)
  50. .borderRadius(20)
  51. .padding({ top: 5, bottom: 5, left: 10, right: 10 })
  52. .linearGradient({
  53. colors: [['#30E3CE', 0.5], ['#91F1FF', 1]]
  54. })
  55. .onClick(this.toLogin)
  56. }
  57. .width("100%")
  58. .alignItems(VerticalAlign.Center)
  59. .justifyContent(FlexAlign.SpaceBetween)
  60. .padding({ left: 20, right: 20, top: 18, bottom: 18 })
  61. .backgroundColor('rgba(0, 0, 0, 0.5)')
  62. .alignRules({
  63. bottom: { anchor: "__container__", align: VerticalAlign.Bottom},
  64. left: { anchor: "__container__", align: HorizontalAlign.Start},
  65. })
  66. }
  67. }
  68. .width("100%")
  69. .height("100%")
  70. }
  71. }