LoginPage.ets 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { BarType, YtAvoid, YtButton, yTRequest, yTRouter, yTToast } from 'basic'
  2. import { CodeInputType } from '../models'
  3. import { LoginInput } from '../components/LoginInput'
  4. import { Terms } from '../components/Terms'
  5. import { OtherLoginMethods } from '../components/OtherLoginMethods'
  6. // import { OtherLoginMethods } from '../views/OtherLoginMethods'
  7. @Builder
  8. function LoginBuilder() {
  9. NavDestination() {
  10. LoginPage()
  11. }
  12. .hideTitleBar(true)
  13. }
  14. @Component
  15. struct LoginPage {
  16. @State isAgree: boolean = false
  17. @StorageProp(YtAvoid.safeTopKey) safeTop: number = 0
  18. @StorageProp(YtAvoid.safeBottomKey) safeBottom: number = 0
  19. @State phoneNumber: string = ''
  20. @State Captcha: string = ''
  21. inputPhoneNumberType: CodeInputType = {
  22. txt: '+86',
  23. placeHolder: '请输入手机号'
  24. }
  25. inputCaptchaType: CodeInputType = {
  26. txt: '验证码',
  27. placeHolder: '请输入验证码'
  28. }
  29. loginMethodArr: BarType<undefined>[] = [
  30. // {
  31. // src: $r('app.media.wechat'),
  32. // txt: '微信登入',
  33. // click: () => {
  34. // //使用微信sdk实现微信登录
  35. //
  36. // }
  37. // },
  38. {
  39. // src: $r('app.media.hua_wei'),
  40. text: '华为登录',
  41. click: () => {
  42. if (!this.isAgree) {
  43. // yTToast.agreePrivacy({ text: '华为登录' })
  44. return
  45. }
  46. yTRequest.huaweiLogin()
  47. }
  48. }
  49. ]
  50. aboutToAppear(): void {
  51. }
  52. build() {
  53. Column() {
  54. Image($r('[basic].media.ic_back'))
  55. .width(24)
  56. .aspectRatio(1)
  57. .margin({ bottom: 66 })
  58. .onClick(() => {
  59. yTRouter.routerBack()
  60. })
  61. Text('使用电话号码访问')
  62. .fontSize($r('[basic].float.page_text_font_size_10'))
  63. .margin({ bottom: 39 })
  64. LoginInput({ item: this.inputPhoneNumberType, inputData: this.phoneNumber, needCode: false })
  65. LoginInput({ item: this.inputCaptchaType, inputData: this.Captcha, phoneNumber: this.phoneNumber })
  66. Terms({ isAgree: this.isAgree, mg: 13 })
  67. .margin({ bottom: 74 })
  68. YtButton({
  69. btContent: '登录', click: () => {
  70. if (!this.isAgree) {
  71. AppStorage.setOrCreate<Record<string, string>>('captchaLogin',
  72. {
  73. 'phonenumber': this.phoneNumber,
  74. 'captcha': this.Captcha
  75. })
  76. // yTToast.agreePrivacy({ text: '验证码登录' })
  77. return
  78. }
  79. yTRequest.phonenumberLogin({
  80. 'phonenumber': this.phoneNumber,
  81. 'captcha': this.Captcha
  82. })
  83. }
  84. })
  85. .margin({ bottom: 81 })
  86. // LoginButton('登录', () => {
  87. // if (!this.isAgree) {
  88. // PromptActionClass.openAgreePrivacy({})
  89. // return
  90. // }
  91. // const code = AppStorage.get<CodeType>('smsCode')
  92. // const askCodeNum: AskCodeNum = {
  93. // phonenumber: this.phoneNumber,
  94. // smsCode: this.Captcha,
  95. // uuid: code?.uuid
  96. // }
  97. //
  98. // yTRequest.post<TokenType, AskCodeNum>('/api/friendcase/member/phoneLogin', askCodeNum)
  99. // .then(res => {
  100. // AppStorage.setOrCreate(AppstorageKey.TOKEN, res.token)
  101. // yTRequest.refreshUserInfo()
  102. // yTRouter.routerBack()
  103. // AppStorage.setOrCreate<string>(AppstorageKey.PHONE_NUMBER, this.phoneNumber)
  104. // IBestToast.show('登录成功')
  105. // })
  106. // .catch((err: Error) => {
  107. // YTLog.error(err)
  108. //
  109. // })
  110. //
  111. // })
  112. OtherLoginMethods({ loginMethodArr: this.loginMethodArr })
  113. }
  114. .padding({
  115. top: 10 + this.safeTop,
  116. left: 16,
  117. right: 16,
  118. bottom: this.safeBottom
  119. })
  120. .alignItems(HorizontalAlign.Start)
  121. }
  122. }