forget.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="container">
  3. <view class="container_text">
  4. <!-- <image class="banner-img" src="/static/img/img01.png" mode=" scaleToFill"></image> -->
  5. <view class="banner-img" style="background-color: #f63332;">
  6. </view>
  7. </view>
  8. <view class="loginTitle"><text>手机号登录</text></view>
  9. <view class="login_text">
  10. <view class="login_input flex">
  11. <view class="login_img"><image src="/static/icon/img03.png"></image></view>
  12. <view class="login_name"><input class="uni-input" v-model="phone" focus placeholder="请输入手机号" /></view>
  13. </view>
  14. <view class="login_input flex">
  15. <view class="login_img"><image src="/static/icon/img06.png"></image></view>
  16. <view class="login_name flex">
  17. <input class="uni-input width" v-model="code" focus placeholder="请输入验证码" />
  18. <view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
  19. </view>
  20. </view>
  21. <view>
  22. <button type="green" @click="register" class="uni-button uni-button-green">登录</button>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import { mapMutations } from 'vuex';
  29. import { verify, loginMobile, getUserInfo } from '@/api/login.js';
  30. export default {
  31. data() {
  32. return {
  33. phone: '', //用户
  34. code: '', //验证码
  35. time: '', //保存倒计时对象
  36. countDown: 0 //倒计时
  37. };
  38. },
  39. onLoad() {},
  40. watch: {
  41. // 监听倒计时
  42. countDown(i) {
  43. if (i == 0) {
  44. clearInterval(this.time);
  45. }
  46. }
  47. },
  48. methods: {
  49. ...mapMutations('user', ['setUserInfo', 'login']),
  50. // 手机登录
  51. register() {
  52. let obj = this;
  53. if (obj.phone == '') {
  54. obj.$api.msg('请输入电话号码');
  55. return;
  56. }
  57. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.phone)) {
  58. obj.$api.msg('请输入正确的手机号');
  59. return;
  60. }
  61. if (obj.code == '') {
  62. obj.$api.msg('请输入验证码');
  63. return;
  64. }
  65. loginMobile({
  66. phone: obj.phone, //账号
  67. captcha: obj.code
  68. }).then(function(e) {
  69. uni.setStorageSync('token', e.data.token);
  70. getUserInfo({}).then(e => {
  71. obj.login();
  72. // 保存返回用户数据
  73. obj.setUserInfo(e.data);
  74. //成功跳转首页
  75. uni.switchTab({
  76. url: '/pages/index/index'
  77. });
  78. });
  79. }).catch((e) => {
  80. console.log(e);
  81. });
  82. },
  83. //发送验证码
  84. verification() {
  85. let obj = this;
  86. if (this.phone == '') {
  87. this.$api.msg('请输入电话号码');
  88. return;
  89. }
  90. if (this.phone.length < 11) {
  91. this.$api.msg('请输入正确的手机号');
  92. return;
  93. }
  94. // 判断是否在倒计时
  95. if (obj.countDown > 0) {
  96. return false;
  97. } else {
  98. obj.countDown = 60;
  99. obj.time = setInterval(() => {
  100. obj.countDown--;
  101. }, 1000);
  102. //调用验证码接口
  103. verify({
  104. phone: obj.phone,
  105. type: 'login'
  106. })
  107. .then(({ data }) => {})
  108. .catch(err => {
  109. console.log(err);
  110. });
  111. }
  112. }
  113. }
  114. };
  115. </script>
  116. <style lang="scss">
  117. page {
  118. height: 100%;
  119. }
  120. .container {
  121. width: 100%;
  122. height: 100%;
  123. background-size: 100%;
  124. }
  125. .container_text {
  126. width: 100%;
  127. height: 500rpx;
  128. top: 0rpx;
  129. .banner-img {
  130. width: 100%;
  131. height: 100%;
  132. }
  133. }
  134. .login_text {
  135. margin: auto 30rpx;
  136. position: relative;
  137. padding: 100rpx 102rpx;
  138. background-color: #ffffff;
  139. margin-top: -180rpx;
  140. border-radius: 20rpx;
  141. .login_input {
  142. border-bottom: 1px solid #f0f0f0;
  143. margin-bottom: 65rpx;
  144. .login_img image {
  145. height: 35rpx;
  146. width: 29rpx;
  147. margin-right: 20rpx;
  148. }
  149. .uni-input {
  150. text-align: left;
  151. width: 470rpx;
  152. font-size: 28rpx !important;
  153. }
  154. .login_name {
  155. color: #333333;
  156. .width {
  157. width: 325rpx !important;
  158. }
  159. .code {
  160. color: #f63332;
  161. font-size: 23rpx;
  162. border-left: 1px solid #eeeeee;
  163. width: 150rpx;
  164. flex-shrink: 0;
  165. text-align: center;
  166. }
  167. }
  168. }
  169. .uni-button-green {
  170. color: #ffffff;
  171. background-color: #f63332;
  172. margin: 40rpx 10rpx;
  173. border-radius: 50rpx;
  174. }
  175. .uni-button {
  176. height: 85rpx;
  177. line-height: 85rpx;
  178. }
  179. }
  180. .loginTitle {
  181. position: absolute;
  182. top: 250rpx;
  183. width: 100%;
  184. text-align: center;
  185. color: white;
  186. font-size: 40rpx;
  187. }
  188. uni-button {
  189. height: 80rpx !important;
  190. line-height: 80rpx !important;
  191. }
  192. </style>