loginmsg.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="container">
  3. <!-- <view class="cu-form-group" style="margin: 30upx;border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
  4. <view class="title">手机号</view>
  5. <input type="number" :value="mobile" placeholder="请输入手机号" maxlength="11" data-key="mobile" @input="inputChange" />
  6. </view>
  7. <view class="cu-form-group" style="margin: 30upx;border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
  8. <text class="title">验证码</text>
  9. <input type="number" :value="code" placeholder="请输入验证码" maxlength="6" data-key="code" @input="inputChange"
  10. @confirm="toLogin" />
  11. <button class="send-msg" @click="sendMsg" :disabled="sending">{{ sendTime }}</button>
  12. </view> -->
  13. <view class="input-content">
  14. <view class="cu-form-group"
  15. style="border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
  16. <view class="title text-black">手机号</view>
  17. <input type="number" :value="mobile" placeholder="请输入手机号" maxlength="11" data-key="mobile"
  18. @input="inputChange" />
  19. </view>
  20. <view class="cu-form-group" style="border: 2upx solid whitesmoke;border-radius: 30px">
  21. <view class="title text-black">验证码</view>
  22. <input type="number" placeholder="请输入验证码" maxlength="6" :value="code" data-key="code"
  23. @input="inputChange" @confirm="toLogin" />
  24. <button class="send-msg" @click="sendMsg" :disabled="sending">{{ sendTime }}</button>
  25. </view>
  26. </view>
  27. <button class="confirm-btn" @click="toLogin" :disabled="logining">登录</button>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import listCell from '@/components/com-input';
  33. export default {
  34. components: {
  35. listCell
  36. },
  37. data() {
  38. return {
  39. mobile: '',
  40. code: '',
  41. logining: false,
  42. sending: false,
  43. sendTime: '获取验证码',
  44. count: 60,
  45. }
  46. },
  47. methods: {
  48. inputChange(e) {
  49. const key = e.currentTarget.dataset.key;
  50. this[key] = e.detail.value;
  51. },
  52. navBack() {
  53. uni.navigateBack();
  54. },
  55. countDown() {
  56. const {
  57. count
  58. } = this;
  59. if (count === 1) {
  60. this.count = 60;
  61. this.sending = false;
  62. this.sendTime = '获取验证码'
  63. } else {
  64. this.count = count - 1;
  65. this.sending = true;
  66. this.sendTime = count - 1 + '秒后重新获取';
  67. setTimeout(this.countDown.bind(this), 1000);
  68. }
  69. },
  70. sendMsg() {
  71. const {
  72. mobile
  73. } = this;
  74. if (!mobile) {
  75. this.$queue.showToast("请输入手机号");
  76. } else if (mobile.length !== 11) {
  77. this.$queue.showToast("请输入正确的手机号");
  78. } else {
  79. this.$queue.showLoading("正在发送验证码...");
  80. this.$Request.getT('/app/Login/sendMsg/' + mobile + '/gzg').then(res => {
  81. if (res.code === 0) {
  82. this.sending = true;
  83. this.$queue.showToast('验证码发送成功请注意查收');
  84. this.countDown();
  85. uni.hideLoading();
  86. } else {
  87. uni.hideLoading();
  88. uni.showModal({
  89. showCancel: false,
  90. title: '短信发送失败',
  91. content: res.msg ? res.msg : '请一分钟后再获取验证码'
  92. });
  93. }
  94. });
  95. }
  96. },
  97. toLogin() {
  98. const {
  99. mobile,
  100. code
  101. } = this;
  102. let userId = this.$queue.getData("userId");
  103. if (!mobile) {
  104. this.$queue.showToast("请输入手机号");
  105. } else if (mobile.length !== 11) {
  106. this.$queue.showToast("请输入正确的手机号");
  107. } else if (!code) {
  108. this.$queue.showToast("请输入验证码");
  109. } else {
  110. this.$queue.showLoading("正在登录中...");
  111. let openId = this.$queue.getData('openid') ? this.$queue.getData('openid') : '';
  112. let invitation = this.$queue.getData('inviterCode') ? this.$queue.getData('inviterCode') : '';
  113. this.$Request.post(`/app/Login/registerCode`, {
  114. phone: mobile,
  115. openId: openId,
  116. inviterCode: invitation,
  117. msg: code
  118. }).then(res => {
  119. if (res.code === 0) {
  120. this.$queue.setData("token", res.token);
  121. this.$queue.setData('userId', res.user.userId);
  122. this.$queue.setData('userName', res.user.userName);
  123. this.$queue.setData('phone', res.user.phone);
  124. this.$queue.setData('avatar', res.user.avatar?res.user.avatar: '../../static/logo.png');
  125. this.$queue.showToast('登录成功');
  126. setTimeout(function() {
  127. uni.switchTab({
  128. url:'/pages/index/index'
  129. })
  130. },1000)
  131. } else {
  132. uni.showModal({
  133. showCancel: false,
  134. title: '登录失败',
  135. content: res.msg,
  136. });
  137. }
  138. uni.hideLoading();
  139. });
  140. }
  141. },
  142. },
  143. }
  144. </script>
  145. <style lang='scss'>
  146. .send-msg {
  147. border-radius: 30px;
  148. color: #222;
  149. height: 30px;
  150. font-size: 14px;
  151. line-height: 30px;
  152. background: linear-gradient( 143deg, #FFE6EE 0%, #FF9AB2 100%);
  153. }
  154. .container {
  155. top: 0;
  156. padding-top: 32upx;
  157. position: relative;
  158. width: 100%;
  159. height: 100%;
  160. overflow: hidden;
  161. background: #FFFFFF !important;
  162. }
  163. .wrapper {
  164. position: relative;
  165. z-index: 90;
  166. background: #FFFFFF;
  167. padding-bottom: 32upx;
  168. }
  169. .input-content {
  170. /* margin-top: 300upx; */
  171. /* padding-top: 300upx; */
  172. padding: 32upx 80upx;
  173. }
  174. .cu-form-group{
  175. background: #F6F6F6;
  176. }
  177. .confirm-btn {
  178. width: 582rpx;
  179. height: 100rpx;
  180. line-height: 100rpx;
  181. text-aligh:center;
  182. background: linear-gradient( 143deg, #FFE6EE 0%, #FF9AB2 100%);
  183. border-radius: 86rpx 86rpx 86rpx 86rpx;
  184. font-weight: bold;
  185. font-size: 32rpx;
  186. color: #222222;
  187. }
  188. </style>