login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="container">
  3. <view class="loginTitle">Welcome鲲鹏云矿</view>
  4. <view class="loginText">请使用您的账号登录</view>
  5. <view class="login-box">
  6. <view class="username">账号</view>
  7. <input class="input-box" type="number" v-model="phone" placeholder="请输入账号" />
  8. </view>
  9. <view class="login-box">
  10. <view class="username">密码</view>
  11. <input class="input-box" type="password" v-model="password" placeholder="请输入密码" />
  12. </view>
  13. <view class="forget flex">
  14. <view class="mui-checkbox ">
  15. <!-- <input id="chkRem" type="checkbox" checked="checked" class="RememberCheck"  @change="checkboxChange" /> -->
  16. <checkbox-group @change="checkboxChange">
  17. <checkbox id="chkRem" type="checkbox" :checked="rememberPsw" @tap="rememberPsw = !rememberPsw" style="transform:scale(0.8)" >记住密码</checkbox>
  18. </checkbox-group>
  19. </view>
  20. <text @click="navTo('/pages/public/forget')">忘记密码</text>
  21. </view>
  22. <view class="login" @click="toLogin">登录</view>
  23. <view class="login-tip">
  24. 还没有账号?
  25. <text class="register" @click="navTo('/pages/public/register')">立即注册</text>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import { mapMutations } from 'vuex';
  31. import { login } from '@/api/login.js';
  32. import { getUserInfo } from '@/api/user.js';
  33. export default {
  34. data() {
  35. return {
  36. phone: '',
  37. password: '',
  38. rememberPsw: true
  39. };
  40. },
  41. onLoad() {},
  42. mounted() {
  43. let that = this;
  44. //缓存的密码
  45. const HCuname = uni.getStorageSync('HCuname');
  46. //缓存的密码
  47. const HCpassw = uni.getStorageSync('HCpassw');
  48. //有缓存就赋值给文本没有就清空
  49. if (HCuname && HCpassw) {
  50. that.phone = HCuname;
  51. that.password = HCpassw;
  52. } else {
  53. that.phone = '';
  54. that.password = '';
  55. }
  56. },
  57. methods: {
  58. ...mapMutations('user', ['setUserInfo', 'login']),
  59. //登录
  60. async toLogin() {
  61. let obj = this;
  62. obj.logining = true;
  63. if (obj.phone == '') {
  64. obj.$api.msg('请输入手机号');
  65. return;
  66. }
  67. if (obj.password == '') {
  68. obj.$api.msg('请输入密码');
  69. return;
  70. }
  71. login({
  72. account: obj.phone,
  73. password: obj.password
  74. })
  75. .then(function(e) {
  76. if (obj.rememberPsw) {
  77. uni.setStorageSync('HCuname', obj.phone);
  78. uni.setStorageSync('HCpassw', obj.password);
  79. } else {
  80. uni.removeStorageSync('HCuname');
  81. uni.removeStorageSync('HCpassw');
  82. obj.phone = '';
  83. obj.password = '';
  84. }
  85. uni.setStorageSync('token', e.data.token);
  86. getUserInfo({}).then(e => {
  87. obj.login();
  88. // 保存返回用户数据
  89. obj.setUserInfo(e.data);
  90. uni.switchTab({
  91. url: '/pages/index/index'
  92. });
  93. });
  94. })
  95. .catch(function(e) {
  96. console.log(e);
  97. });
  98. },
  99. navTo(url) {
  100. uni.navigateTo({
  101. url
  102. });
  103. },
  104. // 后退
  105. navBack() {
  106. uni.navigateBack();
  107. },
  108. checkboxChange: function(e) {
  109. console.log(e.detail.value.length);
  110. if (e.detail.value.length == 1) {
  111. //获取缓存的账号
  112. uni.getStorageSync('HCuname', this.phone);
  113. uni.getStorageSync('HCpassw', this.password);
  114. } else {
  115. uni.removeStorageSync('HCuname');
  116. uni.removeStorageSync('HCpassw');
  117. }
  118. },
  119. rember(){
  120. this.rememberPsw = ! this.rememberPsw
  121. }
  122. }
  123. };
  124. </script>
  125. <style lang="scss">
  126. page {
  127. min-height: 100%;
  128. background-color: #ffffff;
  129. .container {
  130. width: 100%;
  131. padding: 30% 60rpx;
  132. }
  133. }
  134. .loginTitle {
  135. font-weight: bold;
  136. color: #333333;
  137. font-size: 58rpx;
  138. padding-bottom: 34rpx;
  139. }
  140. .loginText {
  141. font-weight: 500;
  142. color: #333333;
  143. font-size: 34rpx;
  144. padding-bottom: 34rpx;
  145. }
  146. .login-box {
  147. padding-top: 90rpx;
  148. .username {
  149. padding-bottom: 30rpx;
  150. font-weight: 500;
  151. color: #333333;
  152. font-size: 32rpx;
  153. }
  154. }
  155. .forget {
  156. text-align: right;
  157. margin: 70rpx 0rpx;
  158. font-weight: 500;
  159. color: #333333;
  160. font-size: 28rpx;
  161. .mui-checkbox{
  162. font-weight: 500;
  163. color: #333333;
  164. font-size: 35rpx;
  165. }
  166. }
  167. .login {
  168. background-color: #5771df;
  169. margin-top: 20rpx;
  170. color: #ffffff;
  171. text-align: center;
  172. padding: 26rpx 0rpx;
  173. border-radius: 50rpx;
  174. }
  175. .login-tip {
  176. padding: 60rpx 0rpx;
  177. text-align: center;
  178. font-weight: 500;
  179. color: #333333;
  180. font-size: 28rpx;
  181. .register {
  182. color: #5771df;
  183. }
  184. }
  185. // /* input 样式 */
  186. // .input-placeholder {
  187. // color: #ffffff;
  188. // }
  189. // .placeholder {
  190. // color: #ffffff;
  191. // }
  192. </style>