loginInput.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <view class="login-container">
  3. <navBar title="登录" color="#000" />
  4. <view class="login-content">
  5. <!-- 标题 -->
  6. <view class="login-header">
  7. <view text="登录" size="36rpx" color="#333" bold></view>
  8. </view>
  9. <!-- 表单区域 -->
  10. <view class="login-form">
  11. <!-- 手机号码输入 -->
  12. <view class="form-item">
  13. <view class="item-label"> 手机号码 </view>
  14. <u-input
  15. placeholder="请输入登录的手机号码"
  16. v-model="phoneNumber"
  17. clearable
  18. class="custom-input"
  19. :customStyle="{ padding: '8rpx 24rpx ' }"
  20. >
  21. <template #prefix>
  22. <u-icon name="phone" size="36rpx" color="#999" marginRight="20rpx"></u-icon>
  23. </template>
  24. </u-input>
  25. </view>
  26. <!-- 密码输入 -->
  27. <view class="form-item">
  28. <view class="item-label"> 登录密码 </view>
  29. <u-input
  30. placeholder="请输入密码"
  31. v-model="password"
  32. clearable
  33. type="password"
  34. class="custom-input"
  35. :customStyle="{ padding: '8rpx 24rpx ' }"
  36. >
  37. <template #prefix>
  38. <u-icon name="lock" size="36rpx" color="#999" marginRight="20rpx"></u-icon>
  39. </template>
  40. </u-input>
  41. <!-- 忘记密码 -->
  42. <view class="forgot-password">
  43. <view @click="forgotPassword">忘记密码</view>
  44. </view>
  45. </view>
  46. <!-- 登录按钮 -->
  47. <u-button
  48. type="primary"
  49. @click="handleLogin"
  50. :customStyle="{
  51. marginTop: '80rpx',
  52. height: '90rpx',
  53. fontSize: '32rpx',
  54. borderRadius: '100rpx',
  55. }"
  56. :disabled="!canLogin"
  57. >登录</u-button
  58. >
  59. <!-- 注册链接 -->
  60. <view class="register-section">
  61. <view @click="goToRegister">注册</view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import navBar from "@/components/nav-bar/index.vue";
  69. export default {
  70. data() {
  71. return {
  72. phoneNumber: "", // 手机号码
  73. password: "", // 密码
  74. };
  75. },
  76. components: {
  77. navBar,
  78. },
  79. computed: {
  80. // 判断是否可以登录
  81. canLogin() {
  82. return this.phoneNumber.length >= 11 && this.password.length >= 6;
  83. },
  84. },
  85. methods: {
  86. // 处理登录
  87. handleLogin() {
  88. if (!this.validateForm()) {
  89. return;
  90. }
  91. uni.showLoading({
  92. title: "登录中...",
  93. });
  94. // 模拟登录请求
  95. setTimeout(() => {
  96. uni.hideLoading();
  97. uni.showToast({
  98. title: "登录成功",
  99. icon: "success",
  100. });
  101. // 登录成功后的操作,比如跳转到首页
  102. setTimeout(() => {
  103. uni.switchTab({
  104. url: "/pages/index/index",
  105. });
  106. }, 1500);
  107. }, 2000);
  108. },
  109. // 表单验证
  110. validateForm() {
  111. if (!this.phoneNumber) {
  112. uni.showToast({
  113. title: "请输入手机号码",
  114. icon: "none",
  115. });
  116. return false;
  117. }
  118. if (!/^1[3-9]\d{9}$/.test(this.phoneNumber)) {
  119. uni.showToast({
  120. title: "请输入正确的手机号码",
  121. icon: "none",
  122. });
  123. return false;
  124. }
  125. if (!this.password) {
  126. uni.showToast({
  127. title: "请输入密码",
  128. icon: "none",
  129. });
  130. return false;
  131. }
  132. if (this.password.length < 6) {
  133. uni.showToast({
  134. title: "密码长度不能少于6位",
  135. icon: "none",
  136. });
  137. return false;
  138. }
  139. return true;
  140. },
  141. // 忘记密码
  142. forgotPassword() {
  143. uni.navigateTo({
  144. url: "/pages/forgot-password/forgot-password",
  145. });
  146. },
  147. // 跳转到注册页面
  148. goToRegister() {
  149. uni.navigateTo({
  150. url: "/pages/register/register",
  151. });
  152. },
  153. // 微信登录
  154. wechatLogin() {
  155. uni.showToast({
  156. title: "微信登录",
  157. icon: "none",
  158. });
  159. },
  160. // QQ登录
  161. qqLogin() {
  162. uni.showToast({
  163. title: "QQ登录",
  164. icon: "none",
  165. });
  166. },
  167. },
  168. };
  169. </script>
  170. <style scoped lang="scss">
  171. .login-container {
  172. background: #fff;
  173. position: absolute;
  174. left: 0;
  175. right: 0;
  176. top: 0;
  177. bottom: 0;
  178. .login-content {
  179. padding: 32rpx;
  180. box-sizing: border-box;
  181. }
  182. }
  183. .login-header {
  184. text-align: center;
  185. margin-bottom: 100rpx;
  186. margin-top: 60rpx;
  187. }
  188. .login-form {
  189. }
  190. .form-item {
  191. margin-bottom: 32rpx;
  192. }
  193. .item-label {
  194. color: rgba(18, 26, 44, 1);
  195. font-family: Roboto;
  196. font-size: 32rpx;
  197. font-weight: 400;
  198. line-height: 51.2rpx;
  199. letter-spacing: 0px;
  200. text-align: left;
  201. padding-bottom: 6rpx;
  202. }
  203. .custom-input {
  204. box-sizing: border-box;
  205. border: 2rpx solid rgba(158, 161, 168, 1);
  206. border-radius: 24rpx;
  207. background: rgba(255, 255, 255, 1);
  208. padding: 8rpx 24rpx !important;
  209. }
  210. .forgot-password {
  211. text-align: left;
  212. margin-top: 8rpx;
  213. color: rgba(102, 112, 133, 1);
  214. font-family: Inter;
  215. font-size: 24rpx;
  216. font-weight: 400;
  217. line-height: 40rpx;
  218. }
  219. .register-section {
  220. display: flex;
  221. justify-content: center;
  222. align-items: center;
  223. margin-top: 32rpx;
  224. color: #016bf6;
  225. font-family: Inter;
  226. font-size: 12px;
  227. font-weight: 400;
  228. line-height: 20px;
  229. letter-spacing: 0%;
  230. text-align: right;
  231. text-decoration-line: underline;
  232. }
  233. .other-login {
  234. margin-top: 100rpx;
  235. }
  236. .divider-line {
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. margin-bottom: 60rpx;
  241. }
  242. .line {
  243. flex: 1;
  244. height: 1rpx;
  245. background: #e0e0e0;
  246. }
  247. ::v-deep .u-input {
  248. text-align: left !important;
  249. }
  250. </style>