MinePageUserSimpleInfoUI.ets 4.82 KB
import { Logger, UserDataLocal } from 'wdKit'
import { WDRouterPage, WDRouterRule } from 'wdRouter'
import MinePageDatasModel from '../../model/MinePageDatasModel'
const TAG = "MinePageUserSimpleInfoUI"


@Component
export default struct MinePageUserSimpleInfoUI {
  @Watch('loginStateChange') @Prop isLogin :boolean
  @State userName:string = "登陆注册"
  @State headPhotoUrl:string = ""
  @State levelHead:string = ""
  @State levelId:number = 0


  aboutToAppear(){
    if(this.isLogin){
      this.getUserInfo()
      this.getUserLevel()
    }
  }


  @Consume('isLogin')@Watch('loginChange') loginState:Record<string,string>
  loginChange(){
    Logger.debug("isLogin",'MinePageUserSimpleInfoUI')
    if(this.loginState){
      this.isLogin=true
    }
    if(this.isLogin){
      this.getUserInfo()
      this.getUserLevel()
    }
  }
  loginStateChange(){
    if(this.isLogin){
      this.getUserInfo()
      this.getUserLevel()
    }
  }

  build(){
    Row(){
      //头像
      Stack({alignContent: Alignment.Center}){
        Image(this.headPhotoUrl)
          .alt($r('app.media.default_head'))
          .width('108lpx')
          .height('108lpx')
          .objectFit(ImageFit.Cover)
          .borderRadius(50)
        Image(this.levelHead)
          .width('120lpx')
          .height('120lpx')
          .objectFit(ImageFit.Cover)
          .borderRadius(50)
      }.width('120lpx')
      .height('120lpx')
      .alignContent(Alignment.Center)
      .onClick(()=>{
        this.jumpLogin()
      })

      if(this.isLogin){
        //昵称信息
        Column(){
          Row(){
            Text(this.userName)
              .fontColor($r('app.color.color_222222'))
              .maxLines(1)
              .textOverflow({ overflow: TextOverflow.Ellipsis })
              .fontSize('33lpx')

            Image($r('app.media.mine_user_edit'))
              .width('27lpx')
              .height('27lpx')
              .margin({left:'15lpx'})
              .objectFit(ImageFit.Cover)
            Blank()
          }.width('100%')
          .onClick(()=>{
            this.jumpLogin()
          })

          Stack(){
            Image($r('app.media.mine_grade_bg'))
              .width('84lpx')
              .height('29lpx')
              .objectFit(ImageFit.Auto)
            Text(`等级${this.levelId}`)
              .textAlign(TextAlign.Center)
              .fontColor($r('app.color.white'))
              .fontSize('19lpx')
              .width('50lpx')
              .height('29lpx')
          }.margin({top:'15lpx'})
        }.alignItems(HorizontalAlign.Start)
        .margin({top:'12lpx',left:'17lpx'})
        .width('352lpx')
      }else{
        Row(){
          Text("登录注册")
            .fontColor($r('app.color.color_222222'))
            .textOverflow({ overflow: TextOverflow.Ellipsis })
            .fontSize('33lpx')

          Image($r('app.media.mine_user_edit'))
            .width('11lpx')
            .height('20lpx')
            .margin({left:'15lpx'})
            .objectFit(ImageFit.Cover)
          Blank()
        }.onClick(()=>{
          this.jumpLogin()
        })
        .margin({top:'11lpx',left:'17lpx'})
        .width('352lpx')
      }

      Blank()

      Stack({alignContent:Alignment.Start}){
        Text("签到")
          .textAlign(TextAlign.Start)
          .width('108lpx')
          .height('46lpx')
          .fontColor($r('app.color.color_AD6000'))
          .backgroundColor($r('app.color.color_FFC460'))
          .fontWeight(500)
          .position({x:'23lpx'})
          .padding({left:'35lpx'})
        Image($r("app.media.mine_sign_icon"))
          .width('50lpx')
          .height('50lpx')
      }.width('131lpx')
    }.backgroundColor($r('app.color.white'))
    .setFullWidth()
    .padding({top:'31lpx',left:'46lpx'})
  }

  @Styles setFullWidthAndHeight(){
    .width('100%')
    .height('100%')
  }

  @Styles setFullWidth(){
    .width('100%')
  }

  @Styles setFullHeight(){
    .height('100%')
  }

  getUserInfo(){
    MinePageDatasModel.getUserDetailData(getContext(this)).then((value)=>{
      if(value!=null){
        this.userName = value.userName
        this.headPhotoUrl = value.headPhotoUrl
        UserDataLocal.setUserHeaderUrl(value.headPhotoUrl)
      }
    }).catch((err:Error)=>{
      console.log(TAG,JSON.stringify(err))
    })
  }
  getUserLevel(){
    MinePageDatasModel.getUserLevelData(getContext(this)).then((value)=>{
      if(value!=null){
        this.levelHead = value.levelHead
        this.levelId = value.levelId
        UserDataLocal.setUserLevel(value.levelId)
        UserDataLocal.setUserLevelHeaderUrl(value.levelHead + "")
      }
    }).catch((err:Error)=>{
      console.log(TAG,JSON.stringify(err))
    })
  }

  jumpLogin(){
    if(!this.isLogin){
      WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
    }else {
      WDRouterRule.jumpWithPage(WDRouterPage.mineHomePage)
    }
  }
}