phone-login.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <!-- 手机登录 -->
  3. <view class="page-container">
  4. <!-- 顶部标题区域 -->
  5. <image class="bg-image " src="@/static/images/bg.png" mode="aspectFill"></image>
  6. <!-- 登录表单区域 -->
  7. <view class="login-form">
  8. <!-- 账号输入框 -->
  9. <view class="input-group">
  10. <text class="input-label">账号</text>
  11. <u-input v-model="account" placeholder="请输入手机号码" :border="false" class="input-field" type="number"
  12. maxlength="11"></u-input>
  13. </view>
  14. <!-- 密码输入框 -->
  15. <view class="input-group">
  16. <text class="input-label">密码</text>
  17. <u-input v-model="password" placeholder="请输入密码" :border="false" class="input-field" type="password"
  18. :password-icon="true"></u-input>
  19. </view>
  20. <!-- 登录按钮 -->
  21. <button class="login-btn" @tap="handleLogin">
  22. <text>确定</text>
  23. </button>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. phoneLogin
  30. } from '@/config/api.js';
  31. export default {
  32. data() {
  33. return {
  34. account: '',
  35. password: ''
  36. }
  37. },
  38. methods: {
  39. // 处理登录
  40. handleLogin() {
  41. if (!this.account) {
  42. uni.showToast({
  43. title: '请输入账号',
  44. icon: 'none'
  45. });
  46. return;
  47. }
  48. if (!this.password) {
  49. uni.showToast({
  50. title: '请输入密码',
  51. icon: 'none'
  52. });
  53. return;
  54. }
  55. console.log('登录信息:', {
  56. account: this.account,
  57. password: this.password
  58. });
  59. let params = {
  60. "username": this.account,
  61. "password": this.password,
  62. "wxid": "3"
  63. }
  64. phoneLogin(params).then((res) => {
  65. console.log(res, "登陆成功")
  66. uni.setStorageSync('access_token', res.token);
  67. // 保存用户信息到缓存
  68. if (res.user) {
  69. uni.setStorageSync('user', res.user);
  70. }
  71. this.$store.commit('isLogin', true);
  72. uni.showToast({
  73. title: '登录成功',
  74. icon: 'success',
  75. duration: 1000
  76. });
  77. // 登录成功后的跳转
  78. setTimeout(() => {
  79. uni.switchTab({
  80. url: '/pages/index/index'
  81. });
  82. }, 1000);
  83. uni.hideLoading();
  84. })
  85. }
  86. },
  87. }
  88. </script>
  89. <style>
  90. .page-container {
  91. min-height: 100vh;
  92. background: #F5F5F5;
  93. }
  94. /* 背景图片 */
  95. .bg-image {
  96. top: 0;
  97. left: 0;
  98. width: 100%;
  99. height: 300rpx;
  100. z-index: 0;
  101. }
  102. .login-form {
  103. background: #FFFFFF;
  104. border-radius: 24rpx;
  105. padding: 32rpx;
  106. margin: 32rpx;
  107. box-shadow: 0 4rpx 16rpx rgba(41, 44, 53, 0.1);
  108. .input-group {
  109. margin-bottom: 32rpx;
  110. .input-label {
  111. display: block;
  112. font-size: 28rpx;
  113. color: #292C35;
  114. margin-bottom: 16rpx;
  115. }
  116. .input-field {
  117. background: #F5F5F5;
  118. border-radius: 12rpx;
  119. height: 88rpx;
  120. padding: 0 24rpx;
  121. font-size: 28rpx;
  122. }
  123. }
  124. .login-btn {
  125. width: 100%;
  126. height: 88rpx;
  127. background: linear-gradient(135deg, #FF5B05 0%, #FF8E3C 100%);
  128. border-radius: 44rpx;
  129. color: #FFFFFF;
  130. font-size: 32rpx;
  131. font-weight: 500;
  132. display: flex;
  133. align-items: center;
  134. justify-content: center;
  135. margin-top: 48rpx;
  136. border: none;
  137. box-shadow: 0 4rpx 16rpx rgba(255, 91, 5, 0.3);
  138. &:active {
  139. transform: translateY(2rpx);
  140. box-shadow: 0 2rpx 8rpx rgba(255, 91, 5, 0.4);
  141. }
  142. }
  143. }
  144. </style>