login.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <div class="login">
  3. <div class="header">
  4. <div class="logo_inner">
  5. <img src="@/assets/logo/logo.svg" alt="">
  6. <span>LibraAI智能体运营平台</span>
  7. </div>
  8. <span class="line"></span>
  9. <span class="title">后台管理系统</span>
  10. </div>
  11. <main class="main">
  12. <div class="main-left_text">
  13. <p>人工智能运营体</p>
  14. <p>全国首家落地水务大模型</p>
  15. </div>
  16. <el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form">
  17. <h3 class="title">系统登录</h3>
  18. <el-form-item prop="username">
  19. <el-input v-model="loginForm.username" type="text" size="large" auto-complete="off" placeholder="账号">
  20. <template #prefix><svg-icon icon-class="user" class="el-input__icon input-icon" /></template>
  21. </el-input>
  22. </el-form-item>
  23. <el-form-item prop="password">
  24. <el-input v-model="loginForm.password" type="password" size="large" auto-complete="off" placeholder="密码"
  25. @keyup.enter="handleLogin">
  26. <template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
  27. </el-input>
  28. </el-form-item>
  29. <!-- <el-form-item prop="code" v-if="captchaEnabled">
  30. <el-input
  31. v-model="loginForm.code"
  32. size="large"
  33. auto-complete="off"
  34. placeholder="验证码"
  35. style="width: 63%"
  36. @keyup.enter="handleLogin"
  37. >
  38. <template #prefix><svg-icon icon-class="validCode" class="el-input__icon input-icon" /></template>
  39. </el-input>
  40. <div class="login-code">
  41. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  42. </div>
  43. </el-form-item> -->
  44. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  45. <el-form-item style="width:100%;">
  46. <el-button :loading="loading" size="large" type="primary" style="width:100%;" @click.prevent="handleLogin">
  47. <span v-if="!loading">登 录</span>
  48. <span v-else>登 录 中...</span>
  49. </el-button>
  50. <div style="float: right;" v-if="register">
  51. <router-link class="link-type" :to="'/register'">立即注册</router-link>
  52. </div>
  53. </el-form-item>
  54. </el-form>
  55. </main>
  56. <!-- 底部 -->
  57. <div class="el-login-footer">
  58. <span>Copyright © 2018-2024 ruoyi.vip All Rights Reserved.</span>
  59. </div>
  60. </div>
  61. </template>
  62. <script setup>
  63. import { getCodeImg } from "@/api/login";
  64. import Cookies from "js-cookie";
  65. import { encrypt, decrypt } from "@/utils/jsencrypt";
  66. import useUserStore from '@/store/modules/user'
  67. const userStore = useUserStore()
  68. const route = useRoute();
  69. const router = useRouter();
  70. const { proxy } = getCurrentInstance();
  71. const loginForm = ref({
  72. username: "admin",
  73. password: "admin123",
  74. rememberMe: false,
  75. code: "",
  76. uuid: ""
  77. });
  78. const loginRules = {
  79. username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
  80. password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
  81. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  82. };
  83. const codeUrl = ref("");
  84. const loading = ref(false);
  85. // 验证码开关
  86. const captchaEnabled = ref(true);
  87. // 注册开关
  88. const register = ref(false);
  89. const redirect = ref(undefined);
  90. watch(route, (newRoute) => {
  91. redirect.value = newRoute.query && newRoute.query.redirect;
  92. }, { immediate: true });
  93. function handleLogin() {
  94. proxy.$refs.loginRef.validate(valid => {
  95. if (valid) {
  96. loading.value = true;
  97. // 勾选了需要记住密码设置在 cookie 中设置记住用户名和密码
  98. if (loginForm.value.rememberMe) {
  99. Cookies.set("username", loginForm.value.username, { expires: 30 });
  100. Cookies.set("password", encrypt(loginForm.value.password), { expires: 30 });
  101. Cookies.set("rememberMe", loginForm.value.rememberMe, { expires: 30 });
  102. } else {
  103. // 否则移除
  104. Cookies.remove("username");
  105. Cookies.remove("password");
  106. Cookies.remove("rememberMe");
  107. }
  108. // 调用action的登录方法
  109. userStore.login(loginForm.value).then(() => {
  110. const query = route.query;
  111. const otherQueryParams = Object.keys(query).reduce((acc, cur) => {
  112. if (cur !== "redirect") {
  113. acc[cur] = query[cur];
  114. }
  115. return acc;
  116. }, {});
  117. router.push({ path: redirect.value || "/", query: otherQueryParams });
  118. }).catch(() => {
  119. loading.value = false;
  120. // 重新获取验证码
  121. if (captchaEnabled.value) {
  122. getCode();
  123. }
  124. });
  125. }
  126. });
  127. }
  128. function getCode() {
  129. getCodeImg().then(res => {
  130. captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;
  131. if (captchaEnabled.value) {
  132. codeUrl.value = "data:image/gif;base64," + res.img;
  133. loginForm.value.uuid = res.uuid;
  134. }
  135. });
  136. }
  137. function getCookie() {
  138. const username = Cookies.get("username");
  139. const password = Cookies.get("password");
  140. const rememberMe = Cookies.get("rememberMe");
  141. loginForm.value = {
  142. username: username === undefined ? loginForm.value.username : username,
  143. password: password === undefined ? loginForm.value.password : decrypt(password),
  144. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  145. };
  146. }
  147. getCode();
  148. getCookie();
  149. </script>
  150. <style lang='scss' scoped>
  151. @font-face {
  152. font-display: swap;
  153. font-family: 'AlimamaShuHeiTi';
  154. src: url('@/assets/fonts/AlimamaShuHeiTi-Bold.woff2') format('woff2'),
  155. url('@/assets/fonts/AlimamaShuHeiTi-Bold.woff') format('woff'),
  156. url('@/assets/fonts/AlimamaShuHeiTi-Bold.ttf') format('ttf');
  157. font-weight: normal;
  158. font-style: normal;
  159. }
  160. .login {
  161. position: relative;
  162. display: flex;
  163. align-items: center;
  164. justify-content: center;
  165. height: 100%;
  166. background-image: url("../assets/images/login-background.jpg");
  167. background-size: cover;
  168. }
  169. .header {
  170. position: absolute;
  171. left: 0;
  172. top: 0;
  173. display: flex;
  174. align-items: center;
  175. justify-content: start;
  176. padding: 14px 20px;
  177. font-size: 16px;
  178. font-weight: bold;
  179. color: #000;
  180. .logo_inner {
  181. display: flex;
  182. align-items: center;
  183. justify-content: center;
  184. font-family: AlimamaShuHeiTi;
  185. font-size: 12px;
  186. span {
  187. display: inline-block;
  188. width: 90px;
  189. line-height: 14px;
  190. padding-left: 6px;
  191. }
  192. }
  193. .logo {
  194. width: 106px;
  195. height: 28px;
  196. }
  197. .line {
  198. width: 1px;
  199. height: 20px;
  200. margin: 0 12px;
  201. background: #9E9E9E;
  202. }
  203. }
  204. .main {
  205. display: flex;
  206. align-items: center;
  207. justify-content: space-between;
  208. .main-left_text {
  209. margin-right: 242px;
  210. font-size: 36px;
  211. line-height: 50px;
  212. font-weight: bold;
  213. }
  214. }
  215. .login-form {
  216. border-radius: 16px;
  217. background: #ffffff;
  218. width: 442px;
  219. padding: 60px 60px 40px 60px;
  220. .title {
  221. margin-bottom: 30px;
  222. font-size: 28px;
  223. font-weight: bold;
  224. line-height: 40px;
  225. color: #1A2029;
  226. }
  227. .el-input {
  228. height: 40px;
  229. input {
  230. height: 40px;
  231. }
  232. }
  233. .input-icon {
  234. height: 39px;
  235. width: 14px;
  236. margin-left: 0px;
  237. }
  238. }
  239. .login-tip {
  240. font-size: 13px;
  241. text-align: center;
  242. color: #bfbfbf;
  243. }
  244. .login-code {
  245. width: 33%;
  246. height: 40px;
  247. float: right;
  248. img {
  249. cursor: pointer;
  250. vertical-align: middle;
  251. }
  252. }
  253. .el-login-footer {
  254. height: 40px;
  255. line-height: 40px;
  256. position: fixed;
  257. bottom: 0;
  258. width: 100%;
  259. text-align: center;
  260. color: #fff;
  261. font-family: Arial;
  262. font-size: 12px;
  263. letter-spacing: 1px;
  264. }
  265. .login-code-img {
  266. height: 40px;
  267. padding-left: 12px;
  268. }
  269. </style>