login.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="container">
  3. <view class="loginTitle">WelcomeLALA</view>
  4. <view class="loginText">请使用您的账号登录</view>
  5. <view class="login-box">
  6. <view class="username">账号</view>
  7. <input class="input-box" type="text" 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. <text @click="navTo('/pages/public/forget')">忘记密码</text>
  15. </view>
  16. <view class="login" @click="toLogin">登录</view>
  17. <view class="login-tip">
  18. 还没有账号?
  19. <text class="register" @click="navTo('/pages/public/register')">立即注册</text>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import { mapMutations } from 'vuex';
  25. import { login } from '@/api/login.js';
  26. import { getUserInfo } from '@/api/user.js';
  27. import { getFileIndex,getFile,writerTxt,getFileText} from '@/utils/fileController.js';
  28. export default {
  29. data() {
  30. return {
  31. phone: '',
  32. password: '',
  33. };
  34. },
  35. onLoad() {
  36. uni.hideLoading();
  37. },
  38. methods: {
  39. ...mapMutations('user', ['setUserInfo', 'login']),
  40. //登录
  41. async toLogin() {
  42. uni.showLoading({
  43. title:'正在登陆中'
  44. });
  45. let obj = this;
  46. obj.logining = true;
  47. if (obj.phone == '') {
  48. obj.$api.msg('请输入账号');
  49. return;
  50. }
  51. if (obj.password == '') {
  52. obj.$api.msg('请输入密码');
  53. return;
  54. }
  55. login({
  56. account: obj.phone,
  57. password: obj.password
  58. })
  59. .then(function(e) {
  60. uni.setStorageSync('token', e.data.token);
  61. getUserInfo({}).then(e => {
  62. obj.login();
  63. //#ifdef APP-PLUS
  64. getFileIndex().then(info => {
  65. getFile(info,'userInfo').then(data =>{
  66. writerTxt(data,e.data)
  67. })
  68. })
  69. //#endif
  70. // 保存返回用户数据
  71. obj.setUserInfo(e.data);
  72. uni.switchTab({
  73. url: '/pages/index/index'
  74. });
  75. });
  76. uni.hideLoading();
  77. })
  78. .catch(function(e) {
  79. console.log(e);
  80. });
  81. },
  82. navTo(url) {
  83. uni.navigateTo({
  84. url
  85. });
  86. },
  87. // 后退
  88. navBack() {
  89. uni.navigateBack();
  90. },
  91. }
  92. };
  93. </script>
  94. <style lang="scss">
  95. page {
  96. min-height: 100%;
  97. background-color: #ffffff;
  98. .container {
  99. width: 100%;
  100. padding: 30% 60rpx;
  101. }
  102. }
  103. .loginTitle {
  104. font-weight: bold;
  105. color: #333333;
  106. font-size: 58rpx;
  107. padding-bottom: 34rpx;
  108. }
  109. .loginText {
  110. font-weight: 500;
  111. color: #333333;
  112. font-size: 34rpx;
  113. padding-bottom: 34rpx;
  114. }
  115. .login-box {
  116. padding-top: 90rpx;
  117. .username {
  118. padding-bottom: 30rpx;
  119. font-weight: 500;
  120. color: #333333;
  121. font-size: 32rpx;
  122. }
  123. }
  124. .forget {
  125. justify-content: flex-end;
  126. text-align: right;
  127. margin: 70rpx 0rpx;
  128. font-weight: 500;
  129. color: #333333;
  130. font-size: 28rpx;
  131. .mui-checkbox{
  132. font-weight: 500;
  133. color: #333333;
  134. font-size: 35rpx;
  135. }
  136. }
  137. .login {
  138. background: linear-gradient(90deg, #60BAB0, #60BAB0, #45969B);
  139. margin-top: 20rpx;
  140. color: #ffffff;
  141. text-align: center;
  142. padding: 26rpx 0rpx;
  143. border-radius: 50rpx;
  144. }
  145. .login-tip {
  146. padding: 60rpx 0rpx;
  147. text-align: center;
  148. font-weight: 500;
  149. color: #333333;
  150. font-size: 28rpx;
  151. .register {
  152. color: #5771df;
  153. }
  154. }
  155. // /* input 样式 */
  156. // .input-placeholder {
  157. // color: #ffffff;
  158. // }
  159. // .placeholder {
  160. // color: #ffffff;
  161. // }
  162. </style>