login.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="content">
  3. <view class="login-head d-flex a-center j-end">
  4. <view class="circle yellow"></view>
  5. <view class="circle blue"></view>
  6. <view class="circle green"></view>
  7. </view>
  8. <view class="login-body d-flex a-center j-center">
  9. <view class="login-content d-flex flex-column">
  10. <view class="d-flex j-sb">
  11. <image src="../../static/biguser.png" style="width:166rpx;height:166rpx" mode=""></image>
  12. <view>
  13. <u-input class="login-input" :border-color="borderColor" :clearable="false" height="52" v-model="userData.username"
  14. border placeholder="请输入账号" placeholder-style="font-size:23rpx;font-family: Segoe UI;" trim />
  15. <u-input class="login-input u-m-t-16" type="password" :password-icon="false" :clearable="false" :border-color="borderColor"
  16. height="52" v-model="userData.password" border placeholder="请输入密码" placeholder-style="font-size:23rpx;font-family: Segoe UI;"
  17. trim />
  18. <u-checkbox class="login-check u-m-t-10" v-model="checked">记住密码</u-checkbox>
  19. </view>
  20. </view>
  21. <view class="login-button u-m-t-20" @click="loginY">登录</view>
  22. </view>
  23. </view>
  24. <u-toast ref="uToast" />
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. mapGetters,
  30. mapMutations
  31. } from "vuex"
  32. import {
  33. loginApp
  34. } from "@/common/api.js"
  35. export default {
  36. data() {
  37. return {
  38. userData: {
  39. username: '',
  40. password: '',
  41. client: 'APP'
  42. },
  43. borderColor: 'transparent',
  44. checked: false
  45. }
  46. },
  47. onShow() {
  48. this.init()
  49. },
  50. methods: {
  51. ...mapMutations(['login']),
  52. init() {
  53. // 是否记住密码
  54. let status = uni.getStorageSync('checked')
  55. if(status) {
  56. this.userData.username = uni.getStorageSync("userinfo").username
  57. this.userData.password = uni.getStorageSync("userinfo").password
  58. this.checked = status
  59. }
  60. },
  61. loginY() {
  62. if (!this.userData.username) {
  63. this.$refs.uToast.show({
  64. title: '请输入账号',
  65. type: 'error'
  66. })
  67. return
  68. }
  69. if (!this.userData.password) {
  70. this.$refs.uToast.show({
  71. title: '请输入密码',
  72. type: 'error'
  73. })
  74. return
  75. }
  76. loginApp(this.userData).then(res => {
  77. if (res.status === '20000') {
  78. res.data.username = this.userData.username
  79. res.data.password = this.userData.password
  80. // 存储用户信息
  81. if (this.checked) {
  82. uni.setStorageSync('checked', this.checked);
  83. this.login(res.data)
  84. } else {
  85. this.userData.username = ''
  86. this.userData.password = ''
  87. }
  88. // 存储token
  89. uni.setStorageSync('token', res.data.token);
  90. // uni.setStorageSync('token', res.data.token);
  91. // 跳转
  92. uni.navigateTo({
  93. url: '/pages/index/index'
  94. })
  95. }
  96. })
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .content {
  103. width: 100%;
  104. height: 100%;
  105. min-height: 100vh;
  106. background-color: $uni-color-blue;
  107. .login-head {
  108. height: 42rpx;
  109. background-color: $uni-color-deep-blue;
  110. padding-right: 14rpx;
  111. .circle {
  112. width: 19rpx;
  113. height: 19rpx;
  114. border-radius: 50%;
  115. margin-right: 12rpx;
  116. }
  117. .yellow {
  118. background-color: #FADB50;
  119. }
  120. .blue {
  121. background-color: #1A6CD6;
  122. }
  123. .green {
  124. background-color: #7AE376;
  125. }
  126. }
  127. .login-body {
  128. height: calc(100vh - 42rpx);
  129. .login-content {
  130. width: 64.8%;
  131. height: 50%;
  132. .login-button {
  133. width: 100%;
  134. height: 52rpx;
  135. background-color: $uni-color-deep-blue;
  136. color: #fff;
  137. font-size: 23rpx;
  138. text-align: center;
  139. line-height: 52rpx;
  140. }
  141. .login-input {
  142. width: 307rpx;
  143. background-color: #fff;
  144. }
  145. }
  146. }
  147. }
  148. /deep/ .u-checkbox__label {
  149. color: #FFF;
  150. font-size: 23rpx;
  151. }
  152. </style>