forget.vue 4.0 KB

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