login.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="container">
  3. <view class="container_text">
  4. <image class="banner-img" src="http://shicai.liuniu946.com/static/img/img11.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,getUserInfo } 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. this.weixinB=uni.getStorageSync('weichatBrowser')
  45. },
  46. methods: {
  47. ...mapMutations('user',['setUserInfo','login']),
  48. //登录
  49. async toLogin() {
  50. let obj = this;
  51. obj.logining = true;
  52. if (obj.username == '') {
  53. obj.$api.msg('请输入手机号');
  54. return;
  55. }
  56. if (obj.passward == '') {
  57. obj.$api.msg('请输入密码');
  58. return;
  59. }
  60. login({
  61. account:obj.username,
  62. password:obj.passward
  63. })
  64. .then(function(e) {
  65. uni.setStorageSync('token',e.data.token);
  66. getUserInfo({}).then((e)=> {
  67. obj.login();
  68. // 保存返回用户数据
  69. obj.setUserInfo(e.data);
  70. })
  71. let address = uni.getStorageSync('addressData')||'';
  72. console.log(address,'address')
  73. if(address == ''){
  74. uni.navigateTo({
  75. url: '/pages/index/address'
  76. });
  77. }else{
  78. //调用注册接口,成功跳转首页
  79. uni.switchTab({
  80. url: '/pages/index/index'
  81. });
  82. }
  83. })
  84. .catch(function(e) {
  85. console.log(e);
  86. });
  87. },
  88. //跳转注册页
  89. register() {
  90. uni.navigateTo({
  91. url: `/pages/public/register`
  92. });
  93. },
  94. //跳转忘记密码
  95. forget() {
  96. uni.navigateTo({
  97. url: `/pages/public/forget`
  98. });
  99. },
  100. // 后退
  101. navBack() {
  102. uni.navigateBack();
  103. }
  104. }
  105. };
  106. </script>
  107. <style lang="scss">
  108. page {
  109. height: 100%;
  110. }
  111. .container {
  112. width: 100%;
  113. height: 100%;
  114. background-size: 100%;
  115. }
  116. .container_text {
  117. width: 100%;
  118. height: 500rpx;
  119. top: 0rpx;
  120. .banner-img {
  121. width: 100%;
  122. height: 100%;
  123. }
  124. }
  125. .login_text {
  126. margin: auto 30rpx;
  127. position: relative;
  128. padding: 100rpx 102rpx;
  129. background-color: #ffffff;
  130. margin-top: -180rpx;
  131. border-radius: 20rpx;
  132. .login_input {
  133. border-bottom: 1px solid #f0f0f0;
  134. margin-bottom: 65rpx;
  135. .login_img image {
  136. height: 35rpx;
  137. width: 29rpx;
  138. margin-right: 20rpx;
  139. }
  140. .uni-input {
  141. text-align: left;
  142. width: 470rpx;
  143. font-size: 28rpx !important;
  144. }
  145. .login_name {
  146. color: #333333;
  147. }
  148. }
  149. .other {
  150. margin-top: 60rpx;
  151. .fenge {
  152. width: 30%;
  153. height: 2rpx;
  154. background-color: #eeeeee;
  155. }
  156. .qita {
  157. font-size: 28rpx;
  158. color: #999999;
  159. }
  160. }
  161. .weixin {
  162. width: 75rpx;
  163. height: 75rpx;
  164. margin: 25rpx auto;
  165. }
  166. .weixin image {
  167. width: 100%;
  168. height: 100%;
  169. }
  170. .weixin_text {
  171. text-align: center;
  172. font-size: 28rpx;
  173. color: #999999;
  174. }
  175. .forget {
  176. font-size: 28rpx;
  177. width: 100%;
  178. text-align: right;
  179. color: #999999;
  180. }
  181. .uni-button-green {
  182. color: #ffffff;
  183. background-color: #5dbc7c;
  184. margin: 40rpx 10rpx;
  185. border-radius: 50rpx;
  186. }
  187. .uni-button-green-plain {
  188. border: 1px solid #5dbc7c;
  189. margin: 40rpx 10rpx;
  190. border-radius: 50rpx;
  191. color: #5dbc7c;
  192. background-color: #ffffff;
  193. }
  194. .uni-button {
  195. height: 85rpx;
  196. line-height: 85rpx;
  197. }
  198. }
  199. .loginTitle {
  200. position: absolute;
  201. top: 250rpx;
  202. width: 100%;
  203. text-align: center;
  204. color: white;
  205. font-size: 40rpx;
  206. }
  207. </style>