login.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view>
  3. <view class="login">
  4. <image src="../../static/images/logo.jpg" class="logo"></image>
  5. <view class="item">
  6. <text class="icon">&#xe6c9;</text>
  7. <input type="number" placeholder="输入手机号" v-model="item.mobile" />
  8. </view>
  9. <view class="item">
  10. <text class="icon">&#xe7a1;</text>
  11. <input type="number" placeholder="输入短信验证码" v-model="item.captcha" />
  12. <text class="code" @click="captchaSend()">{{ msg }}</text>
  13. </view>
  14. <button type="warn" @click="login()">登陆</button>
  15. <view class="divider"><view>第三方登陆</view></view>
  16. <view class="third">
  17. <view class="weixin"><text class="icon">&#xe622;</text></view>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. item: {},
  27. msg: '获取短信',
  28. flag: true,
  29. time: 60
  30. };
  31. },
  32. methods: {
  33. //发送验证码
  34. captchaSend() {
  35. if (!this.flag) {
  36. return;
  37. }
  38. this.$http.request({
  39. url: this.$http.urls.captchaSend,
  40. data: { mobile: this.item.mobile, type: 2 },
  41. success: res => {
  42. uni.showToast({ title: '发送成功' });
  43. //一分钟倒计时
  44. var countdown = setInterval(() => {
  45. this.time--;
  46. if (this.time == 0) {
  47. this.flag = true;
  48. this.msg = '获取短信';
  49. this.time = 60;
  50. clearInterval(countdown);
  51. } else {
  52. this.flag = false;
  53. this.msg = '重新获取(' + this.time + ')';
  54. }
  55. }, 1000);
  56. }
  57. });
  58. },
  59. //登陆
  60. login() {
  61. //数据校验
  62. let rule = [{ name: 'mobile', checkType: 'phoneno', errorMsg: '请输入正确的手机号' }, { name: 'captcha', checkType: 'notnull', errorMsg: '输入短信验证码' }];
  63. let checkRes = this.$verify.check(this.item, rule);
  64. if (!checkRes) {
  65. uni.showToast({ title: this.$verify.error, icon: 'none' });
  66. return;
  67. }
  68. this.$http.request({
  69. url: this.$http.urls.login,
  70. data:this.item,
  71. method: 'POST',
  72. success: res => {
  73. uni.showToast({ title: '登陆成功' });
  74. uni.setStorageSync('user', res.data.data.user);
  75. uni.$emit('update');
  76. uni.navigateBack();
  77. }
  78. });
  79. }
  80. }
  81. };
  82. </script>
  83. <style lang="scss">
  84. page {
  85. background-color: $theme-color;
  86. text-align: center;
  87. }
  88. .login {
  89. padding: 15px;
  90. .logo {
  91. width: 150px;
  92. height: 150px;
  93. }
  94. .item {
  95. background-color: white;
  96. padding: 15px;
  97. margin-top: 15px;
  98. border-radius: 3px;
  99. overflow: hidden;
  100. text-align: left;
  101. font-size: 14px;
  102. .icon {
  103. float: left;
  104. font-size: 24px;
  105. }
  106. input {
  107. float: left;
  108. padding-left: 10px;
  109. width: 50%;
  110. }
  111. .code {
  112. float: right;
  113. color: #565656;
  114. }
  115. }
  116. button {
  117. margin-top: 36px;
  118. width: 85%;
  119. background-color: #ebb827;
  120. color: white;
  121. }
  122. .divider {
  123. color: white;
  124. font-size: 13px;
  125. margin-top: 76px;
  126. }
  127. .third {
  128. margin-top: 20px;
  129. .weixin {
  130. width: 50px;
  131. height: 50px;
  132. margin: 0 auto;
  133. border: 1px solid white;
  134. border-radius: 50%;
  135. color: white;
  136. .icon {
  137. font-size: 33px;
  138. line-height: 50px;
  139. }
  140. }
  141. }
  142. }
  143. </style>