forget.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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[3|4|5|7|8][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. obj.login();
  70. // 保存返回用户数据
  71. obj.setUserInfo(e.data);
  72. //成功跳转首页
  73. uni.switchTab({
  74. url: '/pages/index/index'
  75. });
  76. });
  77. }).catch((e) => {
  78. console.log(e);
  79. });
  80. },
  81. //发送验证码
  82. verification() {
  83. let obj = this;
  84. if (this.phone == '') {
  85. this.$api.msg('请输入电话号码');
  86. return;
  87. }
  88. if (this.phone.length < 11) {
  89. this.$api.msg('请输入正确的手机号');
  90. return;
  91. }
  92. // 判断是否在倒计时
  93. if (obj.countDown > 0) {
  94. return false;
  95. } else {
  96. obj.countDown = 60;
  97. obj.time = setInterval(() => {
  98. obj.countDown--;
  99. }, 1000);
  100. //调用验证码接口
  101. verify({
  102. phone: obj.phone,
  103. type: 'login'
  104. })
  105. .then(({ data }) => {})
  106. .catch(err => {
  107. console.log(err);
  108. });
  109. }
  110. },
  111. login() {
  112. //返回登录
  113. uni.navigateTo({
  114. url: '/pages/public/login'
  115. });
  116. }
  117. }
  118. };
  119. </script>
  120. <style lang="scss">
  121. page {
  122. height: 100%;
  123. }
  124. .container {
  125. width: 100%;
  126. height: 100%;
  127. background-size: 100%;
  128. }
  129. .container_text {
  130. width: 100%;
  131. height: 500rpx;
  132. top: 0rpx;
  133. .banner-img {
  134. width: 100%;
  135. height: 100%;
  136. }
  137. }
  138. .login_text {
  139. margin: auto 30rpx;
  140. position: relative;
  141. padding: 100rpx 102rpx;
  142. background-color: #ffffff;
  143. margin-top: -180rpx;
  144. border-radius: 20rpx;
  145. .login_input {
  146. border-bottom: 1px solid #f0f0f0;
  147. margin-bottom: 65rpx;
  148. .login_img image {
  149. height: 35rpx;
  150. width: 29rpx;
  151. margin-right: 20rpx;
  152. }
  153. .uni-input {
  154. text-align: left;
  155. width: 470rpx;
  156. font-size: 28rpx !important;
  157. }
  158. .login_name {
  159. color: #333333;
  160. .width {
  161. width: 325rpx !important;
  162. }
  163. .code {
  164. color: #5dbc7c;
  165. font-size: 23rpx;
  166. border-left: 1px solid #eeeeee;
  167. width: 150rpx;
  168. flex-shrink: 0;
  169. text-align: center;
  170. }
  171. }
  172. }
  173. .uni-button-green {
  174. color: #ffffff;
  175. background-color: #5dbc7c;
  176. margin: 40rpx 10rpx;
  177. border-radius: 50rpx;
  178. }
  179. .uni-button {
  180. height: 85rpx;
  181. line-height: 85rpx;
  182. }
  183. }
  184. .loginTitle {
  185. position: absolute;
  186. top: 250rpx;
  187. width: 100%;
  188. text-align: center;
  189. color: white;
  190. font-size: 40rpx;
  191. }
  192. uni-button {
  193. height: 80rpx !important;
  194. line-height: 80rpx !important;
  195. }
  196. </style>