login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="container">
  3. <view class="container_text">
  4. <image class="banner-img" src="/static/img/img001.png" mode="scaleToFill"></image>
  5. </view>
  6. <view class="loginTitle"><text>登录</text></view>
  7. <view class="login_text">
  8. <view class="login_input flex">
  9. <view class="login_img"><image src="/static/icon/img03.png"></image></view>
  10. <view class="login_name"><input class="uni-input" v-model="username" focus placeholder="请输入手机号" /></view>
  11. </view>
  12. <view class="login_input flex">
  13. <view class="login_img"><image src="/static/icon/img04.png"></image></view>
  14. <view class="login_name"><input class="uni-input" type="password" v-model="passward" focus placeholder="请输入密码" /></view>
  15. </view>
  16. <view><button type="green" class="uni-button uni-button-green" @click="toLogin">登录</button></view>
  17. <view><button type="green" class="uni-button uni-button-green uni-button-green-plain" plain="true" hover-class="none" @click="register">注册</button></view>
  18. <navigator url="./forget"><view class="forget">忘记密码</view></navigator>
  19. <!-- <view class="flex other">
  20. <view class="fenge"></view>
  21. <view class="qita">其他方式登录</view>
  22. <view class="fenge"></view>
  23. </view>
  24. <view class="weixin" @click="wecahtLogin"><image src="/static/img/img05.png"></image></view> -->
  25. <!-- <view class="weixin_text">微信登录</view> -->
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import { mapMutations } from 'vuex';
  31. import { login } from '@/api/login.js';
  32. export default {
  33. data() {
  34. return {
  35. username: '',
  36. passward: '',
  37. // #ifdef APP-PLUS
  38. // 保存当前是否为微信浏览器
  39. weixinB:false,
  40. // #endif
  41. };
  42. },
  43. onLoad() {
  44. console.log(this.$store.state.hasLogin)
  45. this.weixinB=uni.getStorageSync('weichatBrowser')
  46. },
  47. methods: {
  48. ...mapMutations(['setUserInfo','login']),
  49. //登录
  50. async toLogin() {
  51. let obj = this;
  52. obj.logining = true;
  53. if (obj.username == '') {
  54. obj.$api.msg('请输入手机号');
  55. return;
  56. }
  57. if (obj.passward == '') {
  58. obj.$api.msg('请输入密码');
  59. return;
  60. }
  61. login({
  62. account:obj.username,
  63. password:obj.passward
  64. })
  65. .then(function(e) {
  66. obj.login();
  67. obj.$store.state.hasLogin = true;
  68. uni.setStorageSync('token',e.data.userinfo.token);
  69. obj.setUserInfo(e.data.userinfo);
  70. //调用注册接口,成功跳转首页
  71. uni.switchTab({
  72. url: '/pages/index/index'
  73. });
  74. })
  75. .catch(function(e) {
  76. console.log(e);
  77. });
  78. },
  79. //跳转注册页
  80. register() {
  81. uni.navigateTo({
  82. url: `/pages/public/register`
  83. });
  84. },
  85. //跳转忘记密码
  86. forget() {
  87. uni.navigateTo({
  88. url: `/pages/public/forget`
  89. });
  90. },
  91. // 后退
  92. navBack() {
  93. uni.navigateBack();
  94. }
  95. }
  96. };
  97. </script>
  98. <style lang="scss">
  99. page {
  100. height: 100%;
  101. }
  102. .container {
  103. width: 100%;
  104. height: 100%;
  105. background-size: 100%;
  106. }
  107. .container_text {
  108. width: 100%;
  109. height: 500rpx;
  110. top: 0rpx;
  111. .banner-img {
  112. width: 100%;
  113. height: 100%;
  114. }
  115. }
  116. .login_text {
  117. margin: auto 30rpx;
  118. position: relative;
  119. padding: 100rpx 102rpx;
  120. background-color: #ffffff;
  121. margin-top: -180rpx;
  122. border-radius: 20rpx;
  123. .login_input {
  124. border-bottom: 1px solid #f0f0f0;
  125. margin-bottom: 65rpx;
  126. .login_img image {
  127. height: 35rpx;
  128. width: 29rpx;
  129. margin-right: 20rpx;
  130. }
  131. .uni-input {
  132. text-align: left;
  133. width: 470rpx;
  134. font-size: 28rpx !important;
  135. }
  136. .login_name {
  137. color: #333333;
  138. }
  139. }
  140. .other {
  141. margin-top: 60rpx;
  142. .fenge {
  143. width: 30%;
  144. height: 2rpx;
  145. background-color: #eeeeee;
  146. }
  147. .qita {
  148. font-size: 28rpx;
  149. color: #999999;
  150. }
  151. }
  152. .weixin {
  153. width: 75rpx;
  154. height: 75rpx;
  155. margin: 25rpx auto;
  156. }
  157. .weixin image {
  158. width: 100%;
  159. height: 100%;
  160. }
  161. .weixin_text {
  162. text-align: center;
  163. font-size: 28rpx;
  164. color: #999999;
  165. }
  166. .forget {
  167. font-size: 28rpx;
  168. width: 100%;
  169. text-align: right;
  170. color: #999999;
  171. }
  172. .uni-button-green {
  173. color: #ffffff;
  174. background-color: #5dbc7c;
  175. margin: 40rpx 10rpx;
  176. border-radius: 50rpx;
  177. }
  178. .uni-button-green-plain {
  179. border: 1px solid #5dbc7c;
  180. margin: 40rpx 10rpx;
  181. border-radius: 50rpx;
  182. color: #5dbc7c;
  183. background-color: #ffffff;
  184. }
  185. .uni-button {
  186. height: 85rpx;
  187. line-height: 85rpx;
  188. }
  189. }
  190. .loginTitle {
  191. position: absolute;
  192. top: 250rpx;
  193. width: 100%;
  194. text-align: center;
  195. color: white;
  196. font-size: 40rpx;
  197. }
  198. </style>