login.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="wrap">
  3. <view class="login">
  4. <view class="login-title">
  5. <h3>手机号登录/注册</h3>
  6. <p>欢迎来到荆易充</p>
  7. </view>
  8. <view class="login-form">
  9. <view class="login-form-item">
  10. <view class="title">手机号</view>
  11. <view class="input">
  12. <u-input v-model="form.telephone" type="number" placeholder="请输入手机号" placeholder-style="font-size:16px;color:#ccc;"/>
  13. </view>
  14. <view class="tips">未注册的手机号验证后将自动注册</view>
  15. </view>
  16. <view class="login-form-item">
  17. <view class="title">验证码</view>
  18. <view class="input">
  19. <u-input v-model="form.verifyCode" type="number" placeholder="请输入验证码" placeholder-style="font-size:16px;color:#ccc;"/>
  20. <view class="code" @click="getCode">{{codeTips}}</view>
  21. </view>
  22. <u-checkbox-group>
  23. <u-checkbox class="tips" v-model="value" shape="circle" @change="checkboxChange()">
  24. <view v-if="!form.telephone && !value">我已阅读并同意<span>《会员协议》</span>和<span>《隐私协议》</span></view>
  25. <view v-else>我已阅读并同意<span style="color: #000000;">《会员协议》</span>和<span style="color: #000000;">《隐私协议》</span></view>
  26. </u-checkbox>
  27. </u-checkbox-group>
  28. </view>
  29. </view>
  30. <u-button :style="[inputStyle]" class="login-btn" type="success" shape="circle" @click="login">登录</u-button>
  31. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start" change-text="已发送(XS)">
  32. </u-verification-code>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import * as loginApi from '@/apis/login.js'
  38. import {
  39. checkPhone
  40. } from '@/utils'
  41. export default {
  42. data() {
  43. return {
  44. form: {
  45. telephone: '',
  46. verifyCode: '',
  47. },
  48. isSendMsgIng: false,
  49. sendMsgSecond: 60,
  50. codeTips: '',
  51. value: false,
  52. }
  53. },
  54. computed: {
  55. inputStyle() {
  56. let style = {};
  57. if(this.form.telephone) {
  58. style.color = "#fff";
  59. style.backgroundColor = this.$u.color['success'];
  60. }
  61. return style;
  62. }
  63. },
  64. methods: {
  65. codeChange(text) {
  66. this.codeTips = text;
  67. },
  68. start() {
  69. if (!this.isSendMsgIng) {
  70. uni.showLoading({
  71. title: "加载中",
  72. mask: true,
  73. })
  74. loginApi.getVerifyCode(this.form.telephone).then((response) => {
  75. uni.hideLoading();
  76. this.carhelp.set("getvcodetime", new Date().getTime());
  77. if (!"") {
  78. //倒计时
  79. uni.showToast({
  80. title: "发送成功"
  81. })
  82. } else {
  83. uni.showToast({
  84. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  85. })
  86. }
  87. }).catch(error => {
  88. uni.showToast({
  89. title: error,
  90. icon: "none"
  91. })
  92. })
  93. }
  94. },
  95. //倒计时
  96. end() {
  97. this.sendMsgSecond = 60;
  98. this.isSendMsgIng = false;
  99. },
  100. // 获取验证码
  101. getCode() {
  102. if (this.$refs.uCode.canGetCode) {} else {
  103. uni.showToast({
  104. title: '倒计时结束后再发送',
  105. icon: "none"
  106. })
  107. return
  108. }
  109. var checkPhoneResult = checkPhone(this.form.telephone);
  110. if (checkPhoneResult !== true) {
  111. uni.showToast({
  112. title: checkPhoneResult,
  113. })
  114. return;
  115. }
  116. this.$refs.uCode.start();
  117. },
  118. checkboxChange() {
  119. this.value = !this.value;
  120. },
  121. login() {
  122. var checkPhoneResult = checkPhone(this.form.telephone);
  123. if(!this.form.telephone || checkPhoneResult != true) {
  124. uni.showToast({
  125. title: checkPhoneResult,
  126. icon: "none"
  127. })
  128. return;
  129. }
  130. if(!this.form.verifyCode) {
  131. uni.showToast({
  132. title: "请输入验证码",
  133. icon: "none"
  134. })
  135. return
  136. }
  137. if(!this.value) {
  138. uni.showToast({
  139. title: "请勾选协议",
  140. icon: "none"
  141. })
  142. return
  143. }
  144. uni.showLoading({
  145. title: "加载中",
  146. mask: true,
  147. })
  148. loginApi.validateCode({
  149. verifyCode: this.form.verifyCode,
  150. telephone: this.form.telephone,
  151. nickName: this.carhelp.getUserInfo().nickname,
  152. openId: this.carhelp.getOpenId(),
  153. }).then((response) => {
  154. uni.hideLoading();
  155. var token = response ? response.data.token : '';
  156. this.carhelp.setToken(token);
  157. this.carhelp.setPersonInfo(response.data.regUser);
  158. uni.redirectTo({
  159. url: '/pages/index/index'
  160. })
  161. }).catch(error => {
  162. uni.showToast({
  163. title: error,
  164. icon: "none"
  165. })
  166. })
  167. }
  168. }
  169. }
  170. </script>
  171. <style>
  172. page{
  173. background-color: #fff;
  174. }
  175. </style>
  176. <style lang="scss" scoped>
  177. .wrap {
  178. font-size: 28rpx;
  179. .login {
  180. width: 600rpx;
  181. padding-top: 80rpx;
  182. margin: 0 auto;
  183. .login-title {
  184. text-align: left;
  185. h3{
  186. font-size: 48rpx;
  187. font-weight: normal;
  188. }
  189. p{
  190. margin-top: 4px;
  191. color:#777
  192. }
  193. }
  194. .login-form-item{
  195. margin-top: 40px;
  196. .title{
  197. margin-bottom: 8px;
  198. }
  199. .input {
  200. border-bottom: 1px solid #f7f7f7;
  201. position: relative;
  202. }
  203. .code{
  204. position: absolute;
  205. right: 0;
  206. top:7px;
  207. color:#1677FF;
  208. }
  209. .tips {
  210. color: $u-type-info;
  211. margin-top: 12px;
  212. font-size: 12px;
  213. span{
  214. color:#3fbd70;
  215. }
  216. }
  217. }
  218. .login-btn {
  219. margin-top: 40px;
  220. background-color: #a7dbc2;
  221. }
  222. .alternative {
  223. color: $u-tips-color;
  224. display: flex;
  225. justify-content: space-between;
  226. margin-top: 30rpx;
  227. }
  228. }
  229. }
  230. </style>