login.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="zai-box">
  3. <view class="zai-title2">
  4. <image mode="aspectFit" src="/static/img/logo.png" class="zai-title"></image>
  5. <form class="zai-form">
  6. <view class="title1">登录</view>
  7. <view class="formg">
  8. <image class="formimg" src="@/static/img/zhanghao-.png"></image>
  9. <input class="formgin" placeholder="请输入账号" v-model="account" name="input"></input>
  10. </view>
  11. <view class="formg">
  12. <image class="formimg" src="@/static/img/mima.png"></image>
  13. <input class="formgin" placeholder="请输入密码" type="password" displayable v-model="password" name="input"></input>
  14. </view>
  15. <view class="formg">
  16. <image class="formimg" src="@/static/img/yanzhengma.png"></image>
  17. <input class="formgin" placeholder="请输入验证码" v-model="code" name="input"></input>
  18. <image @click="getCaptcha" style="height: 50rpx;width: 160rpx;" :src="captchaImg" mode="aspectFill"></image>
  19. </view>
  20. </form>
  21. <!-- <view class="zai-label" @click="gotoNewPass">忘记密码?</view> -->
  22. <button style="margin-left: 69upx;margin-top: 100upx;margin-right: 69upx;" @click="bindLogin" class="bg-gradual-blue shadow-blur round cu-btn block lg " >立即登录</button>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import * as $auth from "@/common/auth.js"
  28. import loginService from "@/api/auth/loginService"
  29. import {mapActions} from 'vuex'
  30. export default {
  31. data() {
  32. return {
  33. captchaImg: '',
  34. account: '',
  35. password: '',
  36. code: '',
  37. uuid: ''
  38. }
  39. },
  40. created() {
  41. this.getCaptcha()
  42. },
  43. methods: {
  44. ...mapActions(['refreshUserInfo']),
  45. gotoNewPass() {
  46. uni.navigateTo({
  47. url: '/pages/newPass/newPass'
  48. })
  49. },
  50. // 登录
  51. bindLogin() {
  52. /**
  53. * 客户端对账号信息进行一些必要的校验。
  54. * 实际开发中,根据业务需要进行处理,这里仅做示例。
  55. */
  56. if (this.account.length < 1) {
  57. uni.showToast({
  58. icon: 'none',
  59. title: '账号不能为空'
  60. });
  61. return;
  62. }
  63. if (this.password.length < 1) {
  64. uni.showToast({
  65. icon: 'none',
  66. title: '密码不能为空'
  67. });
  68. return;
  69. }
  70. const inputForm ={
  71. 'username': this.account,
  72. 'password': this.password,
  73. 'code': this.code,
  74. 'uuid': this.uuid
  75. }
  76. loginService.login(inputForm).then(({data}) => {
  77. this.$store.commit('SET_TOKEN',data.token);
  78. this.refreshUserInfo();
  79. setTimeout(function() {
  80. uni.reLaunch({
  81. url: '../index/index',
  82. });
  83. },1000)
  84. }).catch(e => {
  85. this.getCaptcha()
  86. console.error(e)
  87. })
  88. },
  89. // 获取验证码
  90. getCaptcha () {
  91. loginService.getCode().then(({data}) => {
  92. this.captchaImg = 'data:image/gif;base64,' + data.codeImg
  93. this.uuid = data.uuid
  94. })
  95. }
  96. }
  97. }
  98. </script>
  99. <style>
  100. .zai-box{
  101. background-size: cover;
  102. background-position: center;
  103. background-repeat: no-repeat;
  104. height: 100vh; /* 设置高度,确保背景图片显示完整 */
  105. display: flex;
  106. justify-content: center;
  107. background-image: url('~@/static/img/login1.jpg');
  108. background-size: cover; /* 调整图片大小以覆盖整个屏幕 */
  109. background-position: center; /* 图片居中 */
  110. background-repeat: no-repeat; /* 防止图片重复 */
  111. }
  112. .zai-title2{
  113. display: flex;
  114. flex-direction: column;
  115. align-items: center; /* 水平居中 */
  116. }
  117. .zai-title{
  118. margin-top: 260upx;
  119. color: #fff;
  120. width: 100%; /* 可选:确保图片适应容器宽度 */
  121. max-width: 610rpx;
  122. height: 100rpx;
  123. }
  124. .title1{
  125. font-size: 32upx;
  126. font-weight: 600;
  127. color: #000;
  128. }
  129. .zai-form{
  130. margin-top: 120upx;
  131. border-radius: 20upx;
  132. height: 400upx;
  133. background: #fff;
  134. padding: 45upx;
  135. margin-left: 80upx;
  136. margin-right: 80upx;
  137. }
  138. .formg{
  139. display: flex;
  140. padding-bottom: 43upx;
  141. padding-top: 43upx;
  142. border-bottom: 1px solid #dcdcdc;
  143. }
  144. .formimg{
  145. width: 42upx;
  146. height: 42upx;
  147. }
  148. .formgin{
  149. margin-left: 32upx;
  150. width: 250upx;
  151. }
  152. .zai-input{
  153. background: #e2f5fc;
  154. margin-top: 30upx;
  155. border-radius: 100upx;
  156. padding: 20upx 40upx;
  157. font-size: 36upx;
  158. }
  159. .input-placeholder, .zai-input{
  160. color: #94afce;
  161. }
  162. .zai-label{
  163. padding: 60upx 0;
  164. text-align: center;
  165. font-size: 30upx;
  166. color: #a7b6d0;
  167. }
  168. .zai-btn{
  169. background: #ff65a3;
  170. color: #fff;
  171. border: 0;
  172. border-radius: 100upx;
  173. font-size: 36upx;
  174. }
  175. .zai-btn:after{
  176. border: 0;
  177. }
  178. /*按钮点击效果*/
  179. .zai-btn.button-hover{
  180. transform: translate(1upx, 1upx);
  181. }
  182. .cu-form-group .title {
  183. min-width: calc(4em + 15px);
  184. }
  185. </style>