login.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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: '/pages/index/index',
  92. // });
  93. this.$router.push('/pages/index/index');
  94. }).catch(e => {
  95. this.getCaptcha()
  96. console.error(e)
  97. })
  98. })
  99. },
  100. // 获取验证码
  101. getCaptcha () {
  102. loginService.getCode().then((data) => {
  103. this.captchaImg = 'data:image/gif;base64,' + data.codeImg
  104. this.inputForm.uuid = data.uuid
  105. })
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. #box {
  112. position: relative;
  113. // color: $u-content-color;
  114. }
  115. .title {
  116. position: absolute;
  117. top: 15vh;
  118. width: 100vw;
  119. text-align: center;
  120. font-size: 28rpx;
  121. color: #198bfa;
  122. }
  123. .title view:nth-child(1) {
  124. height: 54px;
  125. font-size: 56rpx;
  126. font-family: PingFang SC;
  127. font-weight: bold;
  128. text-shadow: 0px 2px 24px rgba(58, 199, 118, 0.4);
  129. }
  130. .title view:nth-child(2) {
  131. font-size: 32rpx;
  132. font-family: PingFang SC;
  133. font-weight: 500;
  134. color: #198BFA;
  135. margin-top: 5vw;
  136. }
  137. #top {
  138. width: 100vw;
  139. height: 40vh;
  140. position: relative;
  141. }
  142. .top_ri {
  143. width: 100vw;
  144. height: 100vw;
  145. background: linear-gradient(141deg, #19C0FA 0%, #198BFA 100%);
  146. opacity: 0.1;
  147. border-radius: 50%;
  148. position: absolute;
  149. right: -47vw;
  150. top: -37vw;
  151. }
  152. .top_le {
  153. width: 100vw;
  154. height: 100vw;
  155. background: linear-gradient(141deg, #19C0FA 0%, #198BFA 100%);
  156. opacity: 0.1;
  157. border-radius: 50%;
  158. position: absolute;
  159. left: -34vw;
  160. top: -54vw;
  161. }
  162. .inp {
  163. padding-left: 5vw;
  164. position: relative;
  165. top: -4vh;
  166. }
  167. .inp text {
  168. font-size: 36rpx;
  169. font-family: PingFang SC;
  170. font-weight: 500;
  171. color: #333333;
  172. margin-left: 5px;
  173. }
  174. .but {
  175. padding-left: 50rpx;
  176. padding-right: 50rpx;
  177. margin-top: 60rpx;
  178. }
  179. .fot {
  180. width: 100vw;
  181. height: 26px;
  182. text-align: center;
  183. font-size: 28rpx;
  184. font-family: PingFang SC;
  185. font-weight: 500;
  186. color: #8E8E8E;
  187. margin-top: 20px;
  188. }
  189. .login-form {
  190. padding-left: 100rpx;
  191. padding-right: 30rpx;
  192. }
  193. </style>