otherPhoneLogin.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="other-box">
  3. <en-nav @navHeight="setNavHeight" :right-show="true" right-text="密码登录" @rightClick="goToPass"></en-nav>
  4. <view class="login-box" :style="{'height':'calc(100vh - '+navHeight+'px)'}">
  5. <view class="login-top">
  6. <view class="login-title">
  7. <text class="title-item sys-color-black sys-weight-600">验证登录</text>
  8. </view>
  9. <view class="login-from">
  10. <view class="from-text" :class="{'apply-shake':phoneShake}">
  11. <input type="tel" class="from-input sys-color-gray-3" max="11" v-model="phone" placeholder="请输入手机号"></input>
  12. </view>
  13. <view class="from-code" :class="{'apply-shake':codeShake}">
  14. <view class="from-text">
  15. <input type="tel" class="from-input sys-color-gray-3" v-model="code" placeholder="请输入验证码"></input>
  16. </view>
  17. <view class="code-text">
  18. <text class="sys-color-gray-3" v-if="time<=0" @click="senCode">获取验证码</text>
  19. <text class="sys-color-gray-3" v-else>{{time}} s</text>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="login-but sys-color-white sys-background-black sys-selected-but" @click="login" :class="{'sys-unselected-but':!isLogin}">登录</view>
  24. <view class="local-txt sys-color-gray-9">若长时间未收到验证码,请使用以下方式快速登录</view>
  25. </view>
  26. </view>
  27. <view class="login-bottom">
  28. <other-login></other-login>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import EnNav from "@/components/en-utils/en-nav/en-nav";
  34. import tools from "@/service/tools";
  35. import OtherLogin from "@/pages/login/model/otherLogin";
  36. import {forgetPassword, login} from "@/api/login";
  37. export default {
  38. name:'otherPhoneLogin',
  39. components: {OtherLogin, EnNav},
  40. data() {
  41. return {
  42. navHeight:40,
  43. isLogin:false,
  44. phoneShake:false,
  45. codeShake:false,
  46. phone:'',
  47. code:'',
  48. time:0,
  49. }
  50. },
  51. watch:{
  52. 'phone':function (){
  53. this.verifyIsLogin()
  54. },
  55. 'code':function (){
  56. this.verifyIsLogin()
  57. },
  58. },
  59. methods: {
  60. login(){
  61. if(this.phone.length !== 11){
  62. tools.error('请输入手机号码')
  63. this.setShake(1)
  64. tools.vibrate()
  65. return false
  66. }
  67. if(this.code ===''){
  68. tools.error('请输入验证码')
  69. this.setShake(2)
  70. tools.vibrate()
  71. return false
  72. }
  73. this.oneClickLogin(this.phone)
  74. // forgetPassword({'mobile':this.phone,'code':this.code}).then((res)=>{
  75. // if(res.code===0){
  76. // tools.success('登陆成功')
  77. // setTimeout(()=>{
  78. // uni.switchTab({
  79. // 'url':'/pages/index/index'
  80. // })
  81. // },1500)
  82. // }else {
  83. // tools.error(res.msg)
  84. // }
  85. // })
  86. },
  87. oneClickLogin(mobile){
  88. login({'mobile':mobile,'grant_type':'mobile','scope':'server'}).then((res)=>{
  89. tools.setLoginData(res)
  90. if(res.isNewUser){
  91. uni.switchTab({
  92. 'url':'/pages/index/index'
  93. })
  94. }else {
  95. setTimeout(()=>{
  96. uni.navigateTo({
  97. 'url':'/pages/perfect/sexAndAge'
  98. })
  99. },1500)
  100. }
  101. }).catch((e)=>{
  102. console.log(e)
  103. })
  104. },
  105. setShake(type){
  106. if(type===1){
  107. this.phoneShake=true
  108. }else {
  109. this.codeShake=true
  110. }
  111. setTimeout(()=>{
  112. this.phoneShake=false
  113. this.codeShake=false
  114. },500)
  115. },
  116. setNavHeight(navHeight){
  117. this.navHeight=navHeight
  118. },
  119. verifyIsLogin(){
  120. this.isLogin = this.phone.length === 11 && this.code !== '';
  121. },
  122. senCode(){
  123. if(this.phone.length !== 11){
  124. tools.error('请输入手机号码')
  125. this.setShake(1)
  126. tools.vibrate()
  127. return false
  128. }
  129. this.time=60
  130. let timeServe=setInterval(()=>{
  131. --this.time
  132. if(this.time<=0){
  133. clearInterval(timeServe)
  134. }
  135. },1000)
  136. },
  137. goToPass(){
  138. uni.navigateTo({
  139. 'url':'/pages/login/passLogin'
  140. })
  141. }
  142. }
  143. }
  144. </script>
  145. <style scoped lang="scss">
  146. .other-box{
  147. padding: 82rpx 80rpx 0 80rpx;
  148. box-sizing: border-box;
  149. position: relative;
  150. .login-top{
  151. .login-title{
  152. padding-bottom: 60rpx;
  153. .title-item{
  154. font-size: 48rpx;
  155. }
  156. }
  157. .login-from{
  158. .from-text{
  159. width: 100%;
  160. padding-bottom: 40rpx;
  161. border-bottom: 1rpx solid #E0E0E0;
  162. .from-input{
  163. font-size: 32rpx;
  164. height: 44rpx;
  165. line-height: 44rpx;
  166. }
  167. .from-input::placeholder{
  168. color: #999999;
  169. }
  170. }
  171. .from-code{
  172. margin-top: 60rpx;
  173. display: flex;
  174. justify-content: space-between;
  175. .from-text{
  176. width: 344rpx;
  177. }
  178. .code-text{
  179. width: 180rpx;
  180. height: 44rpx;
  181. line-height: 44rpx;
  182. text-align: center;
  183. text{
  184. font-size: 32rpx;
  185. }
  186. }
  187. }
  188. }
  189. .login-but{
  190. margin-top: 120rpx;
  191. }
  192. .local-txt{
  193. padding-top: 32rpx;
  194. font-size: 24rpx;
  195. text-align: center;
  196. }
  197. }
  198. .login-bottom{
  199. padding-bottom: calc(186rpx + env(safe-area-inset-bottom));
  200. position: absolute;
  201. bottom: 0;
  202. left: 80rpx;
  203. width:calc(100vw - 160rpx);
  204. }
  205. }
  206. </style>