login.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template >
  2. <view>
  3. <view class="logo">
  4. <image class="img" src="@/assets/img/logo/logo1.png" mode=""></image>
  5. </view>
  6. <!-- <view class="logoText">
  7. e家能源
  8. </view> -->
  9. <!-- 手机号/密码 -->
  10. <!-- 手机号/密码 -->
  11. <view class="input-box">
  12. <u-input v-model="phone" style="padding: 0 20px" class="tel-input" type="text" placeholder="请输入手机号码" />
  13. <u-input v-model="password" style="padding: 0 20px" class="password-input" type="password" placeholder="请输入密码" :password-icon="true" />
  14. </view>
  15. <button class="login-disable" :class="{
  16. login:password.length&&phone.length
  17. }" @click="submit" >登录</button>
  18. <view class="reset" @click="gotoUrl('/pages/mine/findBackPassword')" >
  19. 忘记密码? <span style="color:#387aea ;">点击找回</span>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import * as API from '@/apis/pagejs/user.js'
  25. import {
  26. checkPhone
  27. } from '@/apis/utils'
  28. export default {
  29. data() {
  30. return {
  31. phone:"",
  32. password:"",
  33. }
  34. },
  35. onLoad(){
  36. this.query()
  37. },
  38. methods: {
  39. loginset(response){
  40. var token = response ? response.data.token : '';
  41. this.carhelp.setToken(token);
  42. this.carhelp.setPersonInfo(response.data.regUser);
  43. this.carhelp.setPersonInfoPlus(response.data)
  44. //this.gotoUrl("pages/user/index")
  45. uni.redirectTo({
  46. url: '/pages/statistics/statistics'
  47. })
  48. },
  49. query(){
  50. uni.showLoading({
  51. title: "加载中",
  52. mask: true,
  53. })
  54. API.findByOpenId({
  55. noerror:true,
  56. openId: this.carhelp.getOpenId(),
  57. }).then((response) => {
  58. if(response.message){
  59. uni.hideLoading();
  60. if(response.message=='没有权限'){
  61. uni.showModal({
  62. title:"提示",
  63. showCancel:false,
  64. content:"没有权限"
  65. })
  66. }
  67. }else{
  68. this.loginset(response)
  69. }
  70. }).catch(error => {
  71. uni.hideLoading();
  72. })
  73. },
  74. submit(){
  75. if(!(this.phone.length&&this.password.length)){
  76. return
  77. }
  78. var checkPhoneResult = checkPhone(this.phone);
  79. if (checkPhoneResult !== true) {
  80. uni.showToast({
  81. icon: "none",
  82. title: checkPhoneResult,
  83. })
  84. return;
  85. }
  86. if(!this.password.length){
  87. uni.showToast({
  88. icon: "none",
  89. title: "请输入密码"
  90. })
  91. return
  92. }
  93. uni.showLoading({
  94. title: "加载中",
  95. mask: true,
  96. })
  97. API.login({
  98. password:this.password,
  99. phone:this.phone,
  100. openId: this.carhelp.getOpenId(),
  101. noerror:true,
  102. }).then((response) => {
  103. if(response.message){
  104. uni.hideLoading();
  105. if(response.message=='没有权限'){
  106. uni.showModal({
  107. title:"提示",
  108. showCancel:false,
  109. content:"没有权限"
  110. })
  111. }else{
  112. uni.showToast({
  113. icon: "none",
  114. title: response.message?response.message:"登录失败"
  115. })
  116. }
  117. }else{
  118. this.loginset(response)
  119. }
  120. }).catch(error => {
  121. uni.hideLoading();
  122. uni.showToast({
  123. icon: "none",
  124. title: error?error:"登录失败"
  125. })
  126. })
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. page{
  133. background-color: #fff;
  134. padding-top: 160rpx;
  135. }
  136. .logoText{
  137. width: 160rpx;
  138. margin: 0 auto;
  139. line-height: 46rpx;
  140. color: rgba(16,16,16,1);
  141. font-size: 32rpx;
  142. margin-top: 20rpx;
  143. }
  144. .logo{
  145. margin: 0 auto;
  146. //width: 160rpx;
  147. border-radius: 16px;
  148. //background: linear-gradient(180deg, rgba(31,85,255,1) 0%,rgba(39,171,255,1) 100%);
  149. display: flex;
  150. align-items: center;
  151. justify-content: center;
  152. .img{
  153. width: 282rpx;
  154. height: 66rpx;
  155. }
  156. }
  157. .input-box{
  158. padding: 0 58rpx;
  159. margin-top: 112rpx;
  160. .tel-input,.password-input{
  161. display: flex;align-items: center;
  162. border-radius: 50px;
  163. background-color: rgba(248,248,248,1);
  164. color: rgba(16,16,16,1);
  165. height: 100rpx;
  166. line-height: 100rpx;
  167. padding: 0 48rpx;
  168. margin-bottom: 40rpx;
  169. }
  170. }
  171. .login-disable{
  172. margin: 80rpx 56rpx 40rpx;
  173. border-radius: 100rpx;
  174. background-color: rgba(223,223,223,1);
  175. color: rgba(255, 255, 255, 1);
  176. }
  177. .login{
  178. background-color: rgba(27,119,251,1);
  179. }
  180. .reset{
  181. color: rgba(119,119,119,1);
  182. text-align: center;
  183. }
  184. </style>