index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div :style="{ backgroundImage: `url(${backgroundImage})` }" class="login-bg">
  3. <div class="login-top">
  4. <div class="login-top__header">
  5. <div class="logo"><img :alt="$CONFIG.APP_NAME" :src="require('/public/img/logo.png')"></div>
  6. <label>{{ $CONFIG.APP_NAME }}</label>
  7. </div>
  8. <div class="login-config">
  9. <el-button type="info" :icon="config.dark ? 'el-icon-sunny' : 'el-icon-moon'" circle @click="config.dark = !config.dark"></el-button>
  10. </div>
  11. </div>
  12. <div class="login-form">
  13. <el-form ref="loginForm" :model="form" :rules="rules" label-width="0" @keyup.enter="login">
  14. <div class="login-form__title">{{ $t("login.formTitle") }}</div>
  15. <el-form-item prop="user">
  16. <el-input v-model="form.user" prefix-icon="el-icon-user" :placeholder="$t('login.userPlaceholder')"></el-input>
  17. </el-form-item>
  18. <el-form-item prop="password">
  19. <el-input v-model="form.password" prefix-icon="el-icon-lock" show-password :placeholder="$t('login.PWPlaceholder')"></el-input>
  20. </el-form-item>
  21. <el-form-item class="login-form__code-item" prop="code">
  22. <el-input v-model="form.code" prefix-icon="sc-icon-valid-code" :placeholder="$t('login.codePlaceholder')"></el-input>
  23. <div class="code-image" @click="getCode">
  24. <el-image :src="codeUrl">
  25. <template #placeholder>
  26. <div class="sc-upload__img-slot">Loading...</div>
  27. </template>
  28. </el-image>
  29. </div>
  30. </el-form-item>
  31. <el-form-item>
  32. <el-checkbox v-model="form.rememberMe" :label="$t('login.rememberMe')"></el-checkbox>
  33. </el-form-item>
  34. <el-form-item>
  35. <el-button style="width: 100%;" :loading="islogin" type="primary" size="large" round auto-insert-space @click="login">{{ $t('login.signIn') }}</el-button>
  36. </el-form-item>
  37. </el-form>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import XEUtils from "xe-utils";
  43. import { VxeUI } from "vxe-table";
  44. export default {
  45. data() {
  46. return {
  47. backgroundImage: require("/public/img/background.png"),
  48. config: {
  49. dark: this.$TOOL.data.get("APP_DARK") || false
  50. },
  51. islogin: false,
  52. codeUrl: "",
  53. form: {
  54. user: "easydoadm",
  55. password: "_adm202404Easy$",
  56. rememberMe: false,
  57. code: null,
  58. uuid: null
  59. },
  60. rules: {
  61. user: [{ required: true, message: this.$t("login.userError") }],
  62. password: [{ required: true, message: this.$t("login.PWError") }],
  63. code: [{ required: true, message: this.$t("login.codeError") }]
  64. }
  65. }
  66. },
  67. watch: {
  68. "config.dark"(val) {
  69. if (val) {
  70. document.documentElement.classList.add("dark");
  71. this.$TOOL.data.set("APP_DARK", val);
  72. VxeUI.setTheme("dark");
  73. } else {
  74. document.documentElement.classList.remove("dark");
  75. this.$TOOL.data.remove("APP_DARK");
  76. VxeUI.setTheme("light");
  77. }
  78. }
  79. },
  80. created() {
  81. this.$TOOL.cookie.remove("MES_TOKEN");
  82. this.$TOOL.data.remove("USER_INFO");
  83. this.$TOOL.data.remove("MENU");
  84. this.$store.commit("clearViewTags");
  85. this.$store.commit("clearKeepLive");
  86. this.$store.commit("clearIframeList");
  87. this.getCode();
  88. },
  89. methods: {
  90. getCode() {
  91. this.$API.auth.codeImg().then(res => {
  92. this.codeUrl = res.img;
  93. this.form.uuid = res.uuid;
  94. }).catch(() => {
  95. this.codeUrl = "";
  96. this.form.code = null;
  97. this.form.uuid = null;
  98. });
  99. },
  100. login() {
  101. this.$refs.loginForm.validate(valid => {
  102. if (valid) {
  103. this.islogin = true;
  104. this.$API.auth.token(this.form).then(res => {
  105. this.islogin = false;
  106. this.$TOOL.cookie.set("MES_TOKEN", res.token, { expires: this.form.rememberMe ? 24 * 60 * 60 : 2 * 60 * 60 });
  107. this.$TOOL.data.set("USER_INFO", res.user.user);
  108. this.$router.replace({ path: XEUtils.get(this.$route, "redirectedFrom.fullPath", "/") });
  109. }).catch(() => {
  110. this.islogin = false;
  111. this.getCode();
  112. });
  113. } else {
  114. return false;
  115. }
  116. });
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .login-bg {width: 100%;height: 100%;background-size: 100% 100%;}
  123. .login-top {height: 60px;padding: 10px 5px 0;background: var(--el-bg-color);}
  124. .login-top__header {display: flex;align-items: center;width: 1200px;margin: auto;}
  125. .login-top__header .logo {display: flex;justify-content: center;align-items: center;width: 64px;height: 50px;margin-left: 90px;}
  126. .login-top__header .logo img {width: 35px;margin-right: 2px;}
  127. .login-top__header label {line-height: 50px;font-size: 24px;font-weight: bold;}
  128. .login-config {position: absolute;top: 15px;right: 20px;}
  129. .login-form {position: relative;height: calc(100% - 60px);}
  130. .login-form .el-form {position: absolute;left: calc(56% - 220px);top: calc(25% - 45px);width: 400px;background: var(--el-bg-color);padding: 25px 25px 5px;border-radius: 6px;}
  131. .login-form__title {position: relative;margin-bottom: 3px;padding-left: 14px;line-height: 30px;font-size: 16px;font-weight: bold;color: #636db7;}
  132. .login-form__title::before {content: "";position: absolute;left: 0;top: 6px;width: 4px;height: 18px;background: #636db7;}
  133. .login-form .el-form .el-input {height: 38px;}
  134. .login-form .el-form .el-input :deep(.el-input__wrapper) {font-size: 13px;}
  135. .login-form__code-item :deep(.el-form-item__content) {justify-content: space-between;}
  136. .login-form__code-item .el-input {width: 63%;}
  137. .login-form__code-item .code-image {width: 33%;height: 42px;}
  138. .login-form__code-item .el-image {cursor: pointer;width: 100%;height: 100%;}
  139. .sc-upload__img-slot {background: #e8f0fe;border-radius: var(--el-border-radius-base);text-align: center;line-height: 38px;font-size: 12px;color: var(--el-text-color-placeholder);}
  140. </style>