login.vue 4.2 KB

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