login.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view class="zai-box">
  3. <image src="../../static/img/login.png" mode='aspectFit' class="zai-logo"></image>
  4. <!-- <view style="height: 300rpx;"></view> -->
  5. <view class="zai-title">潘黄楼宇</view>
  6. <form>
  7. <view class="cu-form-group">
  8. <view class="title">用户名</view>
  9. <input placeholder="请输入账号" v-model="account" name="input"></input>
  10. </view>
  11. <view class="cu-form-group">
  12. <view class="title">密码</view>
  13. <input placeholder="请输入密码" type="password" displayable v-model="password" name="input"></input>
  14. </view>
  15. <view class="cu-form-group">
  16. <image @click="getCaptcha" style="height: 50rpx;width: 160rpx;" :src="captchaImg" mode="aspectFill"></image>
  17. <input placeholder="请输入验证码" v-model="code" name="input"></input>
  18. </view>
  19. </form>
  20. <view class="zai-label" @click="gotoNewPass">忘记密码?</view>
  21. <button @click="bindLogin" class="bg-gradual-blue shadow-blur round cu-btn block lg " >立即登录</button>
  22. </view>
  23. </template>
  24. <script>
  25. import * as $auth from "@/common/auth.js"
  26. import loginService from "@/api/auth/loginService"
  27. import {mapActions} from 'vuex'
  28. export default {
  29. data() {
  30. return {
  31. captchaImg: '',
  32. account: '',
  33. password: '',
  34. code: '',
  35. uuid: ''
  36. }
  37. },
  38. created() {
  39. this.getCaptcha()
  40. },
  41. methods: {
  42. ...mapActions(['refreshUserInfo']),
  43. gotoNewPass() {
  44. uni.navigateTo({
  45. url: '/pages/newPass/newPass'
  46. })
  47. },
  48. // 登录
  49. bindLogin() {
  50. /**
  51. * 客户端对账号信息进行一些必要的校验。
  52. * 实际开发中,根据业务需要进行处理,这里仅做示例。
  53. */
  54. if (this.account.length < 1) {
  55. uni.showToast({
  56. icon: 'none',
  57. title: '账号不能为空'
  58. });
  59. return;
  60. }
  61. if (this.password.length < 1) {
  62. uni.showToast({
  63. icon: 'none',
  64. title: '密码不能为空'
  65. });
  66. return;
  67. }
  68. const inputForm ={
  69. 'username': this.account,
  70. 'password': this.password,
  71. 'code': this.code,
  72. 'uuid': this.uuid
  73. }
  74. loginService.login(inputForm).then(({data}) => {
  75. this.$store.commit('SET_TOKEN',data.token);
  76. this.refreshUserInfo();
  77. setTimeout(function() {
  78. uni.reLaunch({
  79. url: '../index/index',
  80. });
  81. },1000)
  82. }).catch(e => {
  83. this.getCaptcha()
  84. console.error(e)
  85. })
  86. },
  87. // 获取验证码
  88. getCaptcha () {
  89. loginService.getCode().then(({data}) => {
  90. this.captchaImg = 'data:image/gif;base64,' + data.codeImg
  91. this.uuid = data.uuid
  92. })
  93. }
  94. }
  95. }
  96. </script>
  97. <style>
  98. .zai-box{
  99. padding: 0 50upx;
  100. position: relative;
  101. }
  102. .zai-logo{
  103. width: 100%;
  104. width: 100%;
  105. margin-top: 100upx;
  106. margin-bottom: 100upx;
  107. padding: 20px;
  108. height: 310upx;
  109. overflow: hidden;
  110. }
  111. .zai-title{
  112. position: absolute;
  113. top: 0;
  114. margin-top: 100upx;
  115. margin-bottom: 100upx;
  116. line-height: 340upx;
  117. font-size: 68upx;
  118. color: #fff;
  119. text-align: center;
  120. width: 100%;
  121. margin-left: -50upx;
  122. }
  123. .zai-form{
  124. margin-top: 300upx;
  125. }
  126. .zai-input{
  127. background: #e2f5fc;
  128. margin-top: 30upx;
  129. border-radius: 100upx;
  130. padding: 20upx 40upx;
  131. font-size: 36upx;
  132. }
  133. .input-placeholder, .zai-input{
  134. color: #94afce;
  135. }
  136. .zai-label{
  137. padding: 60upx 0;
  138. text-align: center;
  139. font-size: 30upx;
  140. color: #a7b6d0;
  141. }
  142. .zai-btn{
  143. background: #ff65a3;
  144. color: #fff;
  145. border: 0;
  146. border-radius: 100upx;
  147. font-size: 36upx;
  148. }
  149. .zai-btn:after{
  150. border: 0;
  151. }
  152. /*按钮点击效果*/
  153. .zai-btn.button-hover{
  154. transform: translate(1upx, 1upx);
  155. }
  156. .cu-form-group .title {
  157. min-width: calc(4em + 15px);
  158. }
  159. </style>