login.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="login shoue">
  3. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  4. <img src="../assets/images/pic_htgl_dl_logo.png" alt="" style="margin-left: 50%; transform: translateX(-50%);">
  5. <h3 class="title">登录</h3>
  6. <el-form-item prop="username">
  7. <el-input
  8. v-model="loginForm.username"
  9. type="text"
  10. auto-complete="off"
  11. placeholder="账号"
  12. >
  13. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  14. </el-input>
  15. </el-form-item>
  16. <el-form-item prop="password">
  17. <el-input
  18. v-model="loginForm.password"
  19. type="password"
  20. auto-complete="off"
  21. placeholder="密码"
  22. @keyup.enter.native="handleLogin"
  23. >
  24. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  25. </el-input>
  26. </el-form-item>
  27. <el-form-item prop="code" v-if="captchaEnabled">
  28. <el-input
  29. v-model="loginForm.code"
  30. auto-complete="off"
  31. placeholder="验证码"
  32. style="width: 63%"
  33. @keyup.enter.native="handleLogin"
  34. >
  35. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  36. </el-input>
  37. <div class="login-code">
  38. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  39. </div>
  40. </el-form-item>
  41. <div class="ingwe">
  42. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 0px 0px;color: #333;">记住密码</el-checkbox>
  43. <div style="float: right;" v-if="register">
  44. <router-link class="link-type" :to="'/register'" style="color: #03BF8A; font-size: 16px;">还没有账号?去注册</router-link>
  45. </div>
  46. </div>
  47. <el-form-item style="width:100%;">
  48. <el-button
  49. :loading="loading"
  50. size="medium"
  51. type="primary"
  52. style="width:100%;background-color: #03BF8A; border-color: #03BF8A;"
  53. @click.native.prevent="handleLogin"
  54. >
  55. <span v-if="!loading">登 录</span>
  56. <span v-else>登 录 中...</span>
  57. </el-button>
  58. </el-form-item>
  59. </el-form>
  60. <!-- 底部 -->
  61. <!-- <div class="el-login-footer">
  62. <span>Copyright © 2018-2025 ruoyi.vip All Rights Reserved.</span>
  63. </div> -->
  64. </div>
  65. </template>
  66. <script>
  67. import { getCodeImg } from "@/api/login"
  68. import Cookies from "js-cookie"
  69. import { encrypt, decrypt } from '@/utils/jsencrypt'
  70. export default {
  71. name: "Login",
  72. data() {
  73. return {
  74. title: process.env.VUE_APP_TITLE,
  75. codeUrl: "",
  76. loginForm: {
  77. username: "admin",
  78. password: "admin123",
  79. rememberMe: false,
  80. code: "",
  81. uuid: ""
  82. },
  83. loginRules: {
  84. username: [
  85. { required: true, trigger: "blur", message: "请输入您的账号" }
  86. ],
  87. password: [
  88. { required: true, trigger: "blur", message: "请输入您的密码" }
  89. ],
  90. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  91. },
  92. loading: false,
  93. // 验证码开关
  94. captchaEnabled: false,
  95. // 注册开关
  96. register: true,
  97. redirect: undefined
  98. }
  99. },
  100. watch: {
  101. $route: {
  102. handler: function(route) {
  103. this.redirect = route.query && route.query.redirect
  104. },
  105. immediate: true
  106. }
  107. },
  108. created() {
  109. this.getCode()
  110. this.getCookie()
  111. },
  112. methods: {
  113. getCode() {
  114. getCodeImg().then(res => {
  115. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  116. if (this.captchaEnabled) {
  117. this.codeUrl = "data:image/gif;base64," + res.img
  118. this.loginForm.uuid = res.uuid
  119. }
  120. })
  121. },
  122. getCookie() {
  123. const username = Cookies.get("username")
  124. const password = Cookies.get("password")
  125. const rememberMe = Cookies.get('rememberMe')
  126. this.loginForm = {
  127. username: username === undefined ? this.loginForm.username : username,
  128. password: password === undefined ? this.loginForm.password : decrypt(password),
  129. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  130. }
  131. },
  132. handleLogin() {
  133. this.$refs.loginForm.validate(valid => {
  134. if (valid) {
  135. this.loading = true
  136. if (this.loginForm.rememberMe) {
  137. Cookies.set("username", this.loginForm.username, { expires: 30 })
  138. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 })
  139. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 })
  140. } else {
  141. Cookies.remove("username")
  142. Cookies.remove("password")
  143. Cookies.remove('rememberMe')
  144. }
  145. this.$store.dispatch("Login", this.loginForm).then(() => {
  146. this.$router.push({ path: this.redirect || "/" }).catch(()=>{})
  147. }).catch(() => {
  148. this.loading = false
  149. if (this.captchaEnabled) {
  150. this.getCode()
  151. }
  152. })
  153. }
  154. })
  155. }
  156. }
  157. }
  158. </script>
  159. <style rel="stylesheet/scss" lang="scss">
  160. .shoue .el-input input{
  161. background:#fff;
  162. border: 0;
  163. color: #A7A7A7;
  164. }
  165. .ingwe{
  166. display: flex;
  167. justify-content: space-between;
  168. align-items: center;
  169. margin-bottom: 20px;
  170. .el-checkbox__input.is-checked .el-checkbox__inner{
  171. background-color:#03BF8A;
  172. border-color:#03BF8A;
  173. }
  174. .el-checkbox__input.is-checked + .el-checkbox__label{
  175. color:#03BF8A ;
  176. }
  177. }
  178. .login {
  179. display: flex;
  180. justify-content: center;
  181. align-items: center;
  182. height: 100%;
  183. background-image: url("../assets/images/pic_htgl_bg.png");
  184. background-size: cover;
  185. position: relative;
  186. }
  187. .title {
  188. margin: 20px auto 20px auto;
  189. text-align: center;
  190. color: #707070;
  191. font-family: PingFang SC;
  192. font-weight: bold;
  193. font-size: 24px;
  194. color: #333333;
  195. }
  196. .login-form {
  197. background-image: url("../assets/images/pic_htgl_srbg.png");
  198. background-size: cover;
  199. width: 400px;
  200. padding: 40px 25px 5px 25px;
  201. z-index: 1;
  202. position: absolute;
  203. top:25.5%;
  204. left: 17.5%;
  205. .el-input {
  206. height: 38px;
  207. input {
  208. height: 38px;
  209. }
  210. }
  211. .input-icon {
  212. height: 39px;
  213. width: 14px;
  214. margin-left: 2px;
  215. }
  216. .el-form-item{
  217. margin-bottom: 32px;
  218. }
  219. }
  220. .login-tip {
  221. font-size: 13px;
  222. text-align: center;
  223. color: #bfbfbf;
  224. }
  225. .login-code {
  226. width: 33%;
  227. height: 38px;
  228. float: right;
  229. img {
  230. cursor: pointer;
  231. vertical-align: middle;
  232. }
  233. }
  234. .el-login-footer {
  235. height: 40px;
  236. line-height: 40px;
  237. position: fixed;
  238. bottom: 0;
  239. width: 100%;
  240. text-align: center;
  241. color: #fff;
  242. font-family: Arial;
  243. font-size: 12px;
  244. letter-spacing: 1px;
  245. }
  246. .login-code-img {
  247. height: 38px;
  248. }
  249. </style>