login.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <div class="login">
  3. <el-form
  4. ref="loginForm"
  5. :model="loginForm"
  6. :rules="loginRules"
  7. class="login-form"
  8. >
  9. <img src="../assets/logo/GQY_logo1.png" class="title_img" alt="">
  10. <!-- <h3 class="title">GQY</h3> -->
  11. <el-form-item prop="username">
  12. <el-input
  13. v-model="loginForm.username"
  14. type="text"
  15. auto-complete="off"
  16. placeholder="账号"
  17. >
  18. <!-- <svg-icon
  19. slot="prefix"
  20. icon-class="user"
  21. class="el-input__icon input-icon"
  22. /> -->
  23. </el-input>
  24. </el-form-item>
  25. <el-form-item prop="password">
  26. <el-input
  27. v-model="loginForm.password"
  28. type="password"
  29. auto-complete="off"
  30. placeholder="密码"
  31. style="border-radius: 50px;"
  32. @keyup.enter.native="handleLogin"
  33. >
  34. <!-- <svg-icon
  35. slot="prefix"
  36. icon-class="password"
  37. class="el-input__icon input-icon"
  38. /> -->
  39. </el-input>
  40. </el-form-item>
  41. <el-form-item prop="code" v-if="captchaEnabled">
  42. <el-input
  43. v-model="loginForm.code"
  44. auto-complete="off"
  45. placeholder="验证码"
  46. style="width: 63%"
  47. @keyup.enter.native="handleLogin"
  48. >
  49. <!-- <svg-icon
  50. slot="prefix"
  51. icon-class="validCode"
  52. class="el-input__icon input-icon"
  53. /> -->
  54. </el-input>
  55. <div class="login-code">
  56. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  57. </div>
  58. </el-form-item>
  59. <el-checkbox
  60. v-model="loginForm.rememberMe"
  61. style="margin: 0px 0px 25px 0px"
  62. >记住密码</el-checkbox
  63. >
  64. <el-form-item style="width: 100%">
  65. <el-button
  66. :loading="loading"
  67. size="medium"
  68. type="primary"
  69. style="width: 100%"
  70. class="login-button"
  71. @click.native.prevent="handleLogin"
  72. >
  73. <span v-if="!loading">登 录</span>
  74. <span v-else>登 录 中...</span>
  75. </el-button>
  76. <div style="float: right" v-if="register">
  77. <router-link class="link-type" :to="'/register'"
  78. >立即注册</router-link
  79. >
  80. </div>
  81. </el-form-item>
  82. </el-form>
  83. <!-- 底部 -->
  84. <div class="el-login-footer">
  85. <span>Copyright © 2018-2024 ruoyi.vip All Rights Reserved.</span>
  86. </div>
  87. </div>
  88. </template>
  89. <script>
  90. import { getCodeImg } from "@/api/login";
  91. import Cookies from "js-cookie";
  92. import { encrypt, decrypt } from "@/utils/jsencrypt";
  93. export default {
  94. name: "Login",
  95. data() {
  96. return {
  97. codeUrl: "",
  98. loginForm: {
  99. username: "admin",
  100. password: "admin123",
  101. rememberMe: false,
  102. code: "",
  103. uuid: "",
  104. },
  105. loginRules: {
  106. username: [
  107. { required: true, trigger: "blur", message: "请输入您的账号" },
  108. ],
  109. password: [
  110. { required: true, trigger: "blur", message: "请输入您的密码" },
  111. ],
  112. code: [{ required: true, trigger: "change", message: "请输入验证码" }],
  113. },
  114. loading: false,
  115. // 验证码开关
  116. captchaEnabled: true,
  117. // 注册开关
  118. register: false,
  119. redirect: undefined,
  120. };
  121. },
  122. watch: {
  123. $route: {
  124. handler: function (route) {
  125. this.redirect = route.query && route.query.redirect;
  126. },
  127. immediate: true,
  128. },
  129. },
  130. created() {
  131. this.getCode();
  132. this.getCookie();
  133. },
  134. methods: {
  135. getCode() {
  136. getCodeImg().then((res) => {
  137. this.captchaEnabled =
  138. res.captchaEnabled === undefined ? true : res.captchaEnabled;
  139. if (this.captchaEnabled) {
  140. this.codeUrl = "data:image/gif;base64," + res.img;
  141. this.loginForm.uuid = res.uuid;
  142. }
  143. });
  144. },
  145. getCookie() {
  146. const username = Cookies.get("username");
  147. const password = Cookies.get("password");
  148. const rememberMe = Cookies.get("rememberMe");
  149. this.loginForm = {
  150. username: username === undefined ? this.loginForm.username : username,
  151. password:
  152. password === undefined ? this.loginForm.password : decrypt(password),
  153. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  154. };
  155. },
  156. handleLogin() {
  157. this.$refs.loginForm.validate((valid) => {
  158. if (valid) {
  159. this.loading = true;
  160. if (this.loginForm.rememberMe) {
  161. Cookies.set("username", this.loginForm.username, { expires: 30 });
  162. Cookies.set("password", encrypt(this.loginForm.password), {
  163. expires: 30,
  164. });
  165. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  166. expires: 30,
  167. });
  168. } else {
  169. Cookies.remove("username");
  170. Cookies.remove("password");
  171. Cookies.remove("rememberMe");
  172. }
  173. this.$store
  174. .dispatch("Login", this.loginForm)
  175. .then(() => {
  176. this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  177. })
  178. .catch(() => {
  179. this.loading = false;
  180. if (this.captchaEnabled) {
  181. this.getCode();
  182. }
  183. });
  184. }
  185. });
  186. },
  187. },
  188. };
  189. </script>
  190. <style rel="stylesheet/scss" lang="scss">
  191. .login {
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. height: 100%;
  196. background-image: url("../assets/images/login_background.jpg");
  197. background-size: cover;
  198. .login-form {
  199. width: 400px;
  200. padding: 30px;
  201. background: #ffffff;
  202. border-radius: 12px;
  203. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  204. .el-form-item {
  205. margin-bottom: 20px;
  206. }
  207. }
  208. // 自定义输入框样式
  209. .el-input {
  210. .el-input__inner {
  211. height: 45px;
  212. background: #f0f2f5; // 浅灰色背景
  213. border: none;
  214. border-radius: 25px; // 大圆角
  215. padding: 0 20px;
  216. font-size: 14px;
  217. color: #333;
  218. &::placeholder {
  219. color: #999;
  220. }
  221. &:focus {
  222. background: #e8eaed; // 聚焦时稍微深一点的背景色
  223. box-shadow: none;
  224. }
  225. }
  226. }
  227. // 验证码输入框特殊处理
  228. .captcha-container {
  229. display: flex;
  230. gap: 10px;
  231. align-items: center;
  232. .el-input {
  233. flex: 1;
  234. }
  235. .captcha-img {
  236. height: 45px; // 与输入框等高
  237. border-radius: 25px; // 同样的圆角
  238. overflow: hidden;
  239. }
  240. }
  241. // 验证码输入框
  242. .captcha-input {
  243. .el-input__inner {
  244. border-radius: 25px;
  245. }
  246. }
  247. // 登录按钮样式
  248. .login-button {
  249. width: 100%;
  250. height: 45px;
  251. background: #ff0000;
  252. border: none;
  253. border-radius: 25px; // 与输入框相同的圆角
  254. font-size: 16px;
  255. margin-top: 20px;
  256. &:hover {
  257. background: #ff1a1a;
  258. }
  259. }
  260. }
  261. // 移除输入框的默认边框和阴影
  262. .el-input__inner:focus {
  263. border-color: transparent !important;
  264. box-shadow: none !important;
  265. }
  266. // 如果需要在输入框右侧显示验证码文字
  267. .captcha-text {
  268. position: absolute;
  269. right: 20px;
  270. top: 50%;
  271. transform: translateY(-50%);
  272. color: #666;
  273. font-size: 14px;
  274. }
  275. .title {
  276. margin: 0px auto 30px auto;
  277. text-align: center;
  278. color: #707070;
  279. }
  280. .title_img{
  281. width: 100px;
  282. height: 50px;
  283. margin-left: 10px;
  284. margin-bottom: 20px;
  285. }
  286. .login-form {
  287. border-radius: 6px;
  288. background: #ffffff;
  289. width: 400px;
  290. padding: 25px 25px 5px 25px;
  291. .el-input {
  292. height: 38px;
  293. input {
  294. height: 38px;
  295. }
  296. }
  297. .input-icon {
  298. height: 39px;
  299. width: 14px;
  300. margin-left: 2px;
  301. }
  302. }
  303. .title {
  304. font-size: 28px;
  305. color: #ff0000;
  306. text-align: center;
  307. margin-bottom: 30px;
  308. font-weight: bold;
  309. }
  310. .login-tip {
  311. font-size: 13px;
  312. text-align: center;
  313. color: #bfbfbf;
  314. }
  315. .login-code {
  316. width: 33%;
  317. height: 38px;
  318. float: right;
  319. img {
  320. cursor: pointer;
  321. vertical-align: middle;
  322. }
  323. }
  324. .el-login-footer {
  325. height: 40px;
  326. line-height: 40px;
  327. position: fixed;
  328. bottom: 0;
  329. width: 100%;
  330. text-align: center;
  331. color: #fff;
  332. font-family: Arial;
  333. font-size: 12px;
  334. letter-spacing: 1px;
  335. }
  336. .login-code-img {
  337. height: 38px;
  338. }
  339. </style>