PageLogin.ets 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { VMLogin } from '../vm/VMLogin'
  2. import { hideKeyboard } from '../utils/SysUtils'
  3. /**
  4. * 登录页面
  5. */
  6. @Entry
  7. @Component
  8. struct PageLogin {
  9. // 登录页面状态管理
  10. @State vm: VMLogin = new VMLogin()
  11. build() {
  12. Column() {
  13. Column() {
  14. Text("博士安全能量隔离系统").fontSize(24).fontColor("#333333").margin({ top: 60 })
  15. Text("温州博士安全科技有限公司").fontSize(14).fontColor("#4B5563").margin({ top: 8, bottom: 30 })
  16. }
  17. .width("100%").backgroundColor($r("app.color.main")).expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  18. Scroll() {
  19. Column() {
  20. Text("欢迎登录").fontSize(20).fontColor("#333333").fontWeight(FontWeight.Bold).margin({ top: 30 })
  21. // 切换短信登录或者密码登录
  22. Row() {
  23. Text("短信登录")
  24. .layoutWeight(1)
  25. .height("100%")
  26. .textAlign(TextAlign.Center)
  27. .fontSize(14)
  28. .fontColor(this.vm.loginType == 0 ? "#FFA500" : "#4B5563")
  29. .backgroundColor(this.vm.loginType == 0 ? "#FFEDD5" : "#FFFFFF")
  30. .onClick(() => {
  31. this.vm.setLoginType(0)
  32. })
  33. Text("密码登录")
  34. .layoutWeight(1)
  35. .height("100%")
  36. .textAlign(TextAlign.Center)
  37. .fontSize(14)
  38. .fontColor(this.vm.loginType == 1 ? "#FFA500" : "#4B5563")
  39. .backgroundColor(this.vm.loginType == 1 ? "#FFEDD5" : "#FFFFFF")
  40. .onClick(() => {
  41. this.vm.setLoginType(1)
  42. })
  43. }.width(335).height(47).border({ width: 1, color: "#D1D5DB", radius: 8 }).margin({ top: 25 })
  44. // 手机号或账号输入框
  45. Row() {
  46. Image(this.vm.loginType == 0 ? $r("app.media.phone") : $r("app.media.user"))
  47. .width(18)
  48. .height(18)
  49. .fillColor("#999999")
  50. TextInput({ placeholder: this.vm.loginType == 0 ? "请输入手机号" : "请输入用户名" })
  51. .placeholderColor("#9CA3AF")
  52. .fontSize(16)
  53. .backgroundColor(Color.Transparent)
  54. .type(this.vm.loginType == 0 ? InputType.PhoneNumber : InputType.Email)
  55. .onChange((value) => {
  56. this.vm.updateAccount(value)
  57. })
  58. }
  59. .width(335)
  60. .height(50)
  61. .border({ width: 1, color: "#D1D5DB", radius: 4 })
  62. .margin({ top: 25 })
  63. .padding({ left: 12, right: 12 })
  64. // 密码或验证码
  65. Row() {
  66. Image(this.vm.loginType == 0 ? $r("app.media.code") : $r("app.media.pwd"))
  67. .width(18)
  68. .height(18)
  69. .fillColor("#999999")
  70. TextInput({ placeholder: this.vm.loginType == 0 ? "请输入验证码" : "请输入密码" })
  71. .placeholderColor("#9CA3AF")
  72. .fontSize(16)
  73. .backgroundColor(Color.Transparent)
  74. .type(this.vm.loginType == 0 ? InputType.PhoneNumber : InputType.Password)
  75. .showPasswordIcon(false)
  76. .onChange((value) => {
  77. this.vm.updateCode(value)
  78. })
  79. }
  80. .width(335)
  81. .height(50)
  82. .border({ width: 1, color: "#D1D5DB", radius: 4 })
  83. .margin({ top: 20 })
  84. .padding({ left: 12, right: 12 })
  85. // 登录按钮
  86. Button("登 录")
  87. .width(335)
  88. .height(52)
  89. .backgroundColor("#FFA500")
  90. .margin({ top: 30 })
  91. .border({ radius: 4 })
  92. .onClick(() => {
  93. this.vm.login(() => {
  94. setTimeout(() => {
  95. this.getUIContext().getRouter().replaceUrl({ url: 'pages/PageHome' })
  96. }, 1500)
  97. })
  98. })
  99. Flex({ wrap: FlexWrap.Wrap, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
  100. Image($r("app.media.tips")).fillColor("#6B7280").width(12).height(12).margin({ right: 5 })
  101. Text("工业安全系统,请妥善保管账号信息").fontSize(12).fontColor("#6B7280")
  102. }.width(335).margin({ top: 16 })
  103. Stack() {
  104. Column().width(335).height(1).backgroundColor("#EEEEEE")
  105. Text("其他登录方式")
  106. .fontColor("#999999")
  107. .fontSize(14)
  108. .backgroundColor(Color.White)
  109. .padding({ left: 6, right: 6 })
  110. }.alignContent(Alignment.Center).margin({ top: 20 })
  111. Row() {
  112. Stack() {
  113. Image($r("app.media.fingerprint")).fillColor("#333333")
  114. }
  115. .width(50)
  116. .height(50)
  117. .padding(12)
  118. .backgroundColor("#F5F5F5")
  119. .borderRadius("50%")
  120. .margin({ left: 10, right: 10 })
  121. Stack() {
  122. Image($r("app.media.qrcode")).fillColor("#333333")
  123. }
  124. .width(50)
  125. .height(50)
  126. .padding(12)
  127. .backgroundColor("#F5F5F5")
  128. .borderRadius("50%")
  129. .margin({ left: 10, right: 10 })
  130. Stack() {
  131. Image($r("app.media.bluetooth")).fillColor("#333333")
  132. }
  133. .width(50)
  134. .height(50)
  135. .padding(14)
  136. .backgroundColor("#F5F5F5")
  137. .borderRadius("50%")
  138. .margin({ left: 10, right: 10 })
  139. }
  140. .width("100%")
  141. .justifyContent(FlexAlign.Center)
  142. .alignItems(VerticalAlign.Center)
  143. .margin({ top: 30, bottom: 30 })
  144. // 分割线
  145. Column().width(335).height(1).backgroundColor("#EEEEEE")
  146. Text("LOTO智能锁控·能量安全隔离").fontSize(14).fontColor("#666666").margin({ top: 20 })
  147. Text("版本 v1.0.0").fontSize(14).fontColor("#666666").margin({ top: 5, bottom: 20 })
  148. }
  149. .width("100%").height("100%")
  150. }.width("100%").height("100%")
  151. }.onClick(() => {
  152. console.log("隐藏键盘")
  153. hideKeyboard()
  154. })
  155. }
  156. }