login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view class="content">
  3. <view id="box">
  4. <view id="top" class="">
  5. <view class="top_le"></view>
  6. <view class="top_ri"></view>
  7. </view>
  8. <view class="title">
  9. <view>欢迎登录JeePlus</view>
  10. </view>
  11. <view class="login-form">
  12. <u--form :model="inputForm" labelWidth="100px" labelPosition="left" :rules="rules" ref="uForm">
  13. <u-form-item label="用户名" borderBottom prop="username">
  14. <u-input border="none" v-model="inputForm.username" />
  15. </u-form-item>
  16. <u-form-item label="密码" borderBottom prop="password">
  17. <u-input border="none" password v-model="inputForm.password" />
  18. </u-form-item>
  19. <u-form-item label="验证码" borderBottom prop="code">
  20. <u-input border="none" v-model="inputForm.code" />
  21. <u--image :showLoading="true" :src="captchaImg" width="140px" height="40px" @click="getCaptcha"></u--image>
  22. </u-form-item>
  23. </u--form>
  24. </view>
  25. <view class="but">
  26. <u-button type="primary" shape="circle" color="linear-gradient(90deg, #1989FA, #19C2FA)" @click="bindLogin" text="欢迎登录"></u-button>
  27. </view>
  28. <view class="fot">
  29. <text @tap="reg_ok">免费注册</text>
  30. <text style="display: inline-block;width: 10vw;"></text>
  31. <text @tap="forget_ok">忘记密码</text>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import * as $auth from "@/common/auth.js"
  38. import loginService from "@/api/auth/loginService"
  39. import {mapActions} from 'vuex'
  40. export default {
  41. data() {
  42. return {
  43. captchaImg: '',
  44. inputForm: {
  45. 'username': '',
  46. 'password': '',
  47. 'code': '',
  48. 'uuid': ''
  49. },
  50. rules: {
  51. username: [
  52. {
  53. required: true,
  54. message: '请输入用户名',
  55. trigger: ['blur', 'change']
  56. }
  57. ],
  58. password: [
  59. {
  60. required: true,
  61. message: '请输入密码',
  62. trigger: ['blur', 'change']
  63. }
  64. ],
  65. code: [
  66. {
  67. required: true,
  68. message: '请输入验证码',
  69. trigger: ['blur', 'change']
  70. }
  71. ]
  72. }
  73. }
  74. },
  75. created() {
  76. this.getCaptcha()
  77. },
  78. methods: {
  79. ...mapActions(['refreshUserInfo']),
  80. // 登录
  81. bindLogin() {
  82. /**
  83. * 客户端对账号信息进行一些必要的校验。
  84. * 实际开发中,根据业务需要进行处理,这里仅做示例。
  85. */
  86. this.$refs.uForm.validate().then(res => {
  87. loginService.login(this.inputForm).then((data) => {
  88. this.$store.commit('SET_TOKEN',data.token);
  89. this.refreshUserInfo();
  90. uni.reLaunch({
  91. url: '../index/index',
  92. });
  93. }).catch(e => {
  94. this.getCaptcha()
  95. console.error(e)
  96. })
  97. })
  98. },
  99. // 获取验证码
  100. getCaptcha () {
  101. loginService.getCode().then((data) => {
  102. this.captchaImg = 'data:image/gif;base64,' + data.codeImg
  103. this.inputForm.uuid = data.uuid
  104. })
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. #box {
  111. position: relative;
  112. // color: $u-content-color;
  113. }
  114. .title {
  115. position: absolute;
  116. top: 15vh;
  117. width: 100vw;
  118. text-align: center;
  119. font-size: 28rpx;
  120. color: #198bfa;
  121. }
  122. .title view:nth-child(1) {
  123. height: 54px;
  124. font-size: 56rpx;
  125. font-family: PingFang SC;
  126. font-weight: bold;
  127. text-shadow: 0px 2px 24px rgba(58, 199, 118, 0.4);
  128. }
  129. .title view:nth-child(2) {
  130. font-size: 32rpx;
  131. font-family: PingFang SC;
  132. font-weight: 500;
  133. color: #198BFA;
  134. margin-top: 5vw;
  135. }
  136. #top {
  137. width: 100vw;
  138. height: 40vh;
  139. position: relative;
  140. }
  141. .top_ri {
  142. width: 100vw;
  143. height: 100vw;
  144. background: linear-gradient(141deg, #19C0FA 0%, #198BFA 100%);
  145. opacity: 0.1;
  146. border-radius: 50%;
  147. position: absolute;
  148. right: -47vw;
  149. top: -37vw;
  150. }
  151. .top_le {
  152. width: 100vw;
  153. height: 100vw;
  154. background: linear-gradient(141deg, #19C0FA 0%, #198BFA 100%);
  155. opacity: 0.1;
  156. border-radius: 50%;
  157. position: absolute;
  158. left: -34vw;
  159. top: -54vw;
  160. }
  161. .inp {
  162. padding-left: 5vw;
  163. position: relative;
  164. top: -4vh;
  165. }
  166. .inp text {
  167. font-size: 36rpx;
  168. font-family: PingFang SC;
  169. font-weight: 500;
  170. color: #333333;
  171. margin-left: 5px;
  172. }
  173. .but {
  174. padding-left: 50rpx;
  175. padding-right: 50rpx;
  176. margin-top: 60rpx;
  177. }
  178. .fot {
  179. width: 100vw;
  180. height: 26px;
  181. text-align: center;
  182. font-size: 28rpx;
  183. font-family: PingFang SC;
  184. font-weight: 500;
  185. color: #8E8E8E;
  186. margin-top: 20px;
  187. }
  188. .login-form {
  189. padding-left: 100rpx;
  190. padding-right: 30rpx;
  191. }
  192. </style>