login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view class="container">
  3. <view class="container_box" v-if="!weixinB"></view>
  4. <view class="loginTitle" v-if="!weixinB"><text>请登录。</text></view>
  5. <view class="login_text" v-if="!weixinB">
  6. <view class="login_input flex">
  7. <!-- <view class="login_img"><image src="/static/icon/img03.png"></image></view> -->
  8. <view class="login_name"><input class="uni-input" v-model="username" focus placeholder="请输入用户名" /></view>
  9. </view>
  10. <view class="login_input flex" style="margin-bottom: 75rpx;">
  11. <!-- <view class="login_img"><image src="/static/icon/img04.png"></image></view> -->
  12. <view class="login_name"><input class="uni-input" type="password" v-model="passward" focus placeholder="请输入密码" /></view>
  13. </view>
  14. <view><button type="green" class="uni-button uni-button-red" @click="toLogin">登录</button></view>
  15. <!-- <view><button type="green" class="uni-button uni-button-green uni-button-green-plain" plain="true" hover-class="none" @click="register">注册</button></view> -->
  16. <view class="forget" @click="forget">忘记密码?</view>
  17. <!-- <view class="forget" @click="register">没有账号?立即创建一个。</view> -->
  18. <!-- <view class="flex other">
  19. <view class="fenge"></view>
  20. <view class="qita">其他方式登录</view>
  21. <view class="fenge"></view>
  22. </view>
  23. <view class="weixin"><image src="https://37shop.liuniu946.com/front/img/img05.png"></image></view>
  24. <view class="weixin_text">微信登录</view> -->
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { mapMutations } from 'vuex';
  30. import { login,getUserInfo } from '@/api/login.js';
  31. export default {
  32. data() {
  33. return {
  34. username: '',
  35. passward: '',
  36. // #ifdef APP-PLUS
  37. // 保存当前是否为微信浏览器
  38. weixinB:false,
  39. // #endif
  40. };
  41. },
  42. onLoad() {
  43. this.weixinB=uni.getStorageSync('weichatBrowser')
  44. },
  45. methods: {
  46. ...mapMutations(['setUserInfo','login']),
  47. //登录
  48. async toLogin() {
  49. let obj = this;
  50. obj.logining = true;
  51. if (obj.username == '') {
  52. obj.$api.msg('请输入手机号');
  53. return;
  54. }
  55. if (obj.passward == '') {
  56. obj.$api.msg('请输入密码');
  57. return;
  58. }
  59. login({
  60. account:obj.username,
  61. password:obj.passward,
  62. })
  63. .then(function(e) {
  64. uni.setStorageSync('token',e.data.token);
  65. getUserInfo({}).then((e)=> {
  66. obj.login();
  67. // 保存返回用户数据
  68. obj.setUserInfo(e.data);
  69. })
  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>
  99. page {
  100. height: 100%;
  101. background-color: #FFFFFF;
  102. }
  103. .container {
  104. width: 100%;
  105. height: 100%;
  106. background-size: 100%;
  107. }
  108. .container_box {
  109. width: 100%;
  110. height: 200rpx;
  111. }
  112. .login_text {
  113. margin: auto 30rpx;
  114. position: relative;
  115. margin-top: 150rpx !important;
  116. }
  117. .login_input {
  118. border: 1px solid #f0f0f0;
  119. padding: 35rpx 25rpx;
  120. margin-bottom: 45rpx;
  121. border-radius: 15rpx;
  122. }
  123. .login_img image {
  124. height: 35rpx;
  125. width: 29rpx;
  126. margin-right: 20rpx;
  127. }
  128. .uni-input {
  129. text-align: left;
  130. width: 470rpx;
  131. font-size: 28rpx !important;
  132. }
  133. .login_name {
  134. color: #333333;
  135. }
  136. .fenge {
  137. width: 30%;
  138. height: 2rpx;
  139. background-color: #eeeeee;
  140. }
  141. .qita {
  142. font-size: 28rpx;
  143. color: #999999;
  144. }
  145. .other {
  146. margin-top: 60rpx;
  147. }
  148. .weixin {
  149. width: 75rpx;
  150. height: 75rpx;
  151. margin: 25rpx auto;
  152. }
  153. .weixin image {
  154. width: 100%;
  155. height: 100%;
  156. }
  157. .weixin_text {
  158. text-align: center;
  159. font-size: 28rpx;
  160. color: #999999;
  161. }
  162. .forget {
  163. font-size: 28rpx;
  164. width: 100%;
  165. text-align: left;
  166. color: #313131;
  167. margin-bottom: 25rpx;
  168. }
  169. .forget:hover{
  170. cursor: pointer;
  171. }
  172. .loginTitle {
  173. position: absolute;
  174. width: 100%;
  175. text-align: left;
  176. color: #333333;
  177. font-size: 56rpx;
  178. padding-left: 25rpx;
  179. font-weight: bold;
  180. }
  181. .uni-button-red {
  182. color: #FFFFFF;
  183. background-color: #BC253A;
  184. margin: 40rpx 10rpx;
  185. border-radius: 15rpx;
  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: 100rpx;
  196. line-height: 100rpx;
  197. background-color: #1CC7C7;
  198. }
  199. </style>