forget.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. background-color: #ff4c4c;
  133. top: 0rpx;
  134. .banner-img {
  135. width: 100%;
  136. height: 100%;
  137. }
  138. }
  139. .login_text {
  140. margin: auto 30rpx;
  141. position: relative;
  142. padding: 100rpx 102rpx;
  143. background-color: #ffffff;
  144. margin-top: -180rpx;
  145. border-radius: 20rpx;
  146. .login_input {
  147. border-bottom: 1px solid #f0f0f0;
  148. margin-bottom: 65rpx;
  149. .login_img image {
  150. height: 35rpx;
  151. width: 29rpx;
  152. margin-right: 20rpx;
  153. }
  154. .uni-input {
  155. text-align: left;
  156. width: 470rpx;
  157. font-size: 28rpx !important;
  158. }
  159. .login_name {
  160. color: #333333;
  161. .width {
  162. width: 325rpx !important;
  163. }
  164. .code {
  165. color: #ff4c4c;
  166. font-size: 23rpx;
  167. border-left: 1px solid #eeeeee;
  168. width: 150rpx;
  169. flex-shrink: 0;
  170. text-align: center;
  171. }
  172. }
  173. }
  174. .uni-button-green {
  175. color: #ffffff;
  176. background-color: #ff4c4c;
  177. margin: 40rpx 10rpx;
  178. border-radius: 50rpx;
  179. }
  180. .uni-button {
  181. height: 85rpx;
  182. line-height: 85rpx;
  183. }
  184. }
  185. .loginTitle {
  186. position: absolute;
  187. top: 250rpx;
  188. width: 100%;
  189. text-align: center;
  190. color: white;
  191. font-size: 40rpx;
  192. }
  193. uni-button {
  194. height: 80rpx !important;
  195. line-height: 80rpx !important;
  196. }
  197. </style>