login.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <div class="login">
  3. <h1>ByteSailing</h1>
  4. <div class="content">
  5. <div class="warp-bg">
  6. <div class="left-bg">
  7. <img src="../assets/images/login-img.png" alt="" />
  8. <div class="swiper-text">
  9. <el-carousel
  10. height="100px"
  11. direction="vertical"
  12. indicator-position="none"
  13. :autoplay="true"
  14. >
  15. <el-carousel-item>
  16. <h3>{{$t('login.li1H3')}}</h3>
  17. <p>{{$t('login.li1P')}}</p>
  18. </el-carousel-item>
  19. <el-carousel-item>
  20. <h3>{{$t('login.li2H3')}}</h3>
  21. <p>{{$t('login.li2P')}}</p>
  22. </el-carousel-item>
  23. <el-carousel-item>
  24. <h3>{{$t('login.li3H3')}}</h3>
  25. <p>{{$t('login.li3P')}}</p>
  26. </el-carousel-item>
  27. </el-carousel>
  28. </div>
  29. </div>
  30. <div class="right-bg">
  31. <el-form
  32. ref="loginRef"
  33. :model="loginForm"
  34. :rules="loginRules"
  35. class="login-form"
  36. >
  37. <div class="form" style="margin-top: 300px">
  38. <div class="">{{$t('login.welcomeToLogin')}}~</div>
  39. <h2>ByteSailing {{$t('login.managementSystem')}}</h2>
  40. <el-form-item prop="tenantId" style="margin-top: 30px">
  41. <el-input
  42. :placeholder="$t('login.pleaseEnterTheTenantId')"
  43. prefix-icon="user"
  44. @keyup.enter="handleLogin"
  45. autocomplete="email"
  46. v-model="loginForm.tenantId"
  47. >
  48. </el-input>
  49. </el-form-item>
  50. <el-form-item prop="username" style="margin-top: 30px">
  51. <el-input
  52. :placeholder="$t('login.pleaseEnterYourAccountNumber')"
  53. prefix-icon="UserFilled"
  54. @keyup.enter="handleLogin"
  55. autocomplete="username"
  56. v-model="loginForm.username"
  57. >
  58. </el-input>
  59. </el-form-item>
  60. <el-form-item prop="password" style="margin-top: 30px">
  61. <el-input
  62. :placeholder="$t('login.pleaseEnterYourPassword')"
  63. prefix-icon="View"
  64. type="password"
  65. v-model="loginForm.password"
  66. autocomplete="current-password"
  67. @keyup.enter="handleLogin"
  68. >
  69. </el-input>
  70. </el-form-item>
  71. <!-- <el-form-item prop="code" class="code" style="margin-top:30px">
  72. <el-input
  73. placeholder="请输入验证码"
  74. prefix-icon="ChatSquare"
  75. v-model="loginForm.code"
  76. @keyup.enter="handleLogin">
  77. </el-input>
  78. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  79. </el-form-item> -->
  80. <div style="margin-top: 30px">
  81. <el-checkbox
  82. v-model="loginForm.rememberMe"
  83. style="margin: 0px 0px 25px 0px"
  84. >{{$t('login.rememberPassword')}}</el-checkbox
  85. >
  86. </div>
  87. <el-button
  88. type="primary"
  89. @click="handleLogin"
  90. style="width: 100%; margin-top: 30px"
  91. >{{$t('login.login')}}</el-button
  92. >
  93. </div>
  94. </el-form>
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. </template>
  100. <script setup>
  101. import { getCodeImg } from "@/api/login";
  102. import Cookies from "js-cookie";
  103. import { encrypt, decrypt } from "@/utils/jsencrypt";
  104. import useUserStore from "@/store/modules/user";
  105. const userStore = useUserStore();
  106. const router = useRouter();
  107. const { proxy } = getCurrentInstance();
  108. const loginForm = ref({
  109. username: "",
  110. password: "",
  111. rememberMe: false,
  112. tenantId: "",
  113. code: "",
  114. uuid: "",
  115. });
  116. const loginRules = {
  117. username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
  118. password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
  119. code: [{ required: true, trigger: "change", message: "请输入验证码" }],
  120. };
  121. const codeUrl = ref("");
  122. const loading = ref(false);
  123. // 验证码开关
  124. const captchaEnabled = ref(true);
  125. // 注册开关
  126. const register = ref(false);
  127. const redirect = ref(undefined);
  128. function handleLogin() {
  129. proxy.$refs.loginRef.validate((valid) => {
  130. if (valid) {
  131. loading.value = true;
  132. Cookies.set("tenantId", loginForm.value.tenantId, {
  133. expires: 30,
  134. });
  135. // 勾选了需要记住密码设置在 cookie 中设置记住用户名和密码
  136. if (loginForm.value.rememberMe) {
  137. Cookies.set("username", loginForm.value.username, {
  138. expires: 30,
  139. });
  140. Cookies.set("password", encrypt(loginForm.value.password), {
  141. expires: 30,
  142. });
  143. Cookies.set("rememberMe", loginForm.value.rememberMe, {
  144. expires: 30,
  145. });
  146. } else {
  147. // 否则移除
  148. Cookies.remove("username");
  149. Cookies.remove("password");
  150. Cookies.remove("rememberMe");
  151. }
  152. // 调用action的登录方法
  153. userStore
  154. .login(loginForm.value)
  155. .then(() => {
  156. router.push({ path: redirect.value || "/" });
  157. // 登录刷新
  158. setTimeout(() => {
  159. location.reload();
  160. }, 100);
  161. })
  162. .catch(() => {
  163. loading.value = false;
  164. // 重新获取验证码
  165. if (captchaEnabled.value) {
  166. getCode();
  167. }
  168. });
  169. }
  170. });
  171. }
  172. function getCode() {
  173. getCodeImg().then((res) => {
  174. captchaEnabled.value =
  175. res.captchaEnabled === undefined ? true : res.captchaEnabled;
  176. if (captchaEnabled.value) {
  177. codeUrl.value = "data:image/gif;base64," + res.img;
  178. loginForm.value.uuid = res.uuid;
  179. }
  180. });
  181. }
  182. function getCookie() {
  183. const username = Cookies.get("username");
  184. const password = Cookies.get("password");
  185. const rememberMe = Cookies.get("rememberMe");
  186. const tenantId = Cookies.get("tenantId");
  187. loginForm.value = {
  188. username: username === undefined ? loginForm.value.username : username,
  189. password:
  190. password === undefined ? loginForm.value.password : decrypt(password),
  191. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  192. tenantId: tenantId === undefined ? loginForm.value.tenantId : tenantId,
  193. };
  194. }
  195. getCode();
  196. getCookie();
  197. </script>
  198. <style lang="scss">
  199. .login {
  200. .warp-bg {
  201. background: #fff;
  202. height: 100vh;
  203. width: 100vw;
  204. overflow: hidden;
  205. .left-bg {
  206. width: calc(50vw + 200px);
  207. background: #0084ff;
  208. height: 100vh;
  209. float: left;
  210. overflow: hidden;
  211. position: relative;
  212. img {
  213. float: right;
  214. margin-right: 75px;
  215. margin-top: 120px;
  216. }
  217. .swiper-text {
  218. position: absolute;
  219. right: 164px;
  220. top: 120px;
  221. color: #fff;
  222. overflow: hidden;
  223. height: 200px;
  224. width: 500px;
  225. .el-carousel {
  226. width: 100%;
  227. height: 100%;
  228. }
  229. h3 {
  230. font-size: 40px;
  231. font-weight: 400;
  232. margin-bottom: 20px;
  233. margin-top: 0;
  234. }
  235. p {
  236. font-size: 26px;
  237. margin: 0;
  238. }
  239. p::before {
  240. content: " ";
  241. border-bottom: 4px solid #fff;
  242. display: inline-block;
  243. width: 60px;
  244. margin-right: 20px;
  245. position: relative;
  246. top: -5px;
  247. }
  248. }
  249. }
  250. .right-bg {
  251. width: calc(50vw - 200px);
  252. background: url(../assets/images/login-right-bg.png) no-repeat;
  253. background-size: cover;
  254. height: 100vh;
  255. float: right;
  256. overflow: hidden;
  257. .form {
  258. width: 500px;
  259. padding: 0 75px;
  260. box-sizing: border-box;
  261. .el-input {
  262. input {
  263. border: none;
  264. border-bottom: 1px solid #dddddd;
  265. }
  266. }
  267. .el-input__wrapper {
  268. box-shadow: 0 0 0 0 !important;
  269. }
  270. .code {
  271. position: relative;
  272. img {
  273. position: absolute;
  274. right: 0;
  275. bottom: 0;
  276. }
  277. }
  278. }
  279. }
  280. }
  281. h1 {
  282. position: fixed;
  283. left: 40px;
  284. top: 0;
  285. height: 96px;
  286. line-height: 96px;
  287. font-size: 26px;
  288. color: #fff;
  289. }
  290. }
  291. </style>