login.vue 8.7 KB

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