login.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. success: res => {
  72. uni.showToast({ title: '登陆成功' });
  73. uni.setStorageSync('user', res.data.data.user);
  74. uni.$emit('update');
  75. uni.navigateBack();
  76. }
  77. });
  78. }
  79. }
  80. };
  81. </script>
  82. <style lang="scss">
  83. page {
  84. background-color: $theme-color;
  85. text-align: center;
  86. }
  87. .login {
  88. padding: 15px;
  89. .logo {
  90. width: 150px;
  91. height: 150px;
  92. }
  93. .item {
  94. background-color: white;
  95. padding: 15px;
  96. margin-top: 15px;
  97. border-radius: 3px;
  98. overflow: hidden;
  99. text-align: left;
  100. font-size: 14px;
  101. .icon {
  102. float: left;
  103. font-size: 24px;
  104. }
  105. input {
  106. float: left;
  107. padding-left: 10px;
  108. width: 50%;
  109. }
  110. .code {
  111. float: right;
  112. color: #565656;
  113. }
  114. }
  115. button {
  116. margin-top: 36px;
  117. width: 85%;
  118. background-color: #ebb827;
  119. color: white;
  120. }
  121. .divider {
  122. color: white;
  123. font-size: 13px;
  124. margin-top: 76px;
  125. }
  126. .third {
  127. margin-top: 20px;
  128. .weixin {
  129. width: 50px;
  130. height: 50px;
  131. margin: 0 auto;
  132. border: 1px solid white;
  133. border-radius: 50%;
  134. color: white;
  135. .icon {
  136. font-size: 33px;
  137. line-height: 50px;
  138. }
  139. }
  140. }
  141. }
  142. </style>