forget.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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">
  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. login() {
  114. //返回登录
  115. uni.navigateTo({
  116. url: '/pages/public/login'
  117. });
  118. }
  119. }
  120. };
  121. </script>
  122. <style lang="scss">
  123. page {
  124. height: 100%;
  125. }
  126. .container {
  127. width: 100%;
  128. height: 100%;
  129. background-size: 100%;
  130. }
  131. .container_text {
  132. width: 100%;
  133. height: 500rpx;
  134. top: 0rpx;
  135. .banner-img {
  136. width: 100%;
  137. height: 100%;
  138. background-color: $base-color;
  139. }
  140. }
  141. .login_text {
  142. margin: auto 30rpx;
  143. position: relative;
  144. padding: 100rpx 102rpx;
  145. background-color: #ffffff;
  146. margin-top: -180rpx;
  147. border-radius: 20rpx;
  148. .login_input {
  149. border-bottom: 1px solid #f0f0f0;
  150. margin-bottom: 65rpx;
  151. .login_img image {
  152. height: 35rpx;
  153. width: 29rpx;
  154. margin-right: 20rpx;
  155. }
  156. .uni-input {
  157. text-align: left;
  158. width: 470rpx;
  159. font-size: 28rpx !important;
  160. }
  161. .login_name {
  162. color: #333333;
  163. .width {
  164. width: 325rpx !important;
  165. }
  166. .code {
  167. color: $base-color;
  168. font-size: 23rpx;
  169. border-left: 1px solid #eeeeee;
  170. width: 150rpx;
  171. flex-shrink: 0;
  172. text-align: center;
  173. }
  174. }
  175. }
  176. .uni-button-green {
  177. color: #ffffff;
  178. background-color: $base-color;
  179. margin: 40rpx 10rpx;
  180. border-radius: 50rpx;
  181. }
  182. .uni-button {
  183. height: 85rpx;
  184. line-height: 85rpx;
  185. }
  186. }
  187. .loginTitle {
  188. position: absolute;
  189. top: 250rpx;
  190. width: 100%;
  191. text-align: center;
  192. color: white;
  193. font-size: 40rpx;
  194. }
  195. uni-button {
  196. height: 80rpx !important;
  197. line-height: 80rpx !important;
  198. }
  199. </style>