login.vue 3.8 KB

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