Index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div class="background-image" v-loading="loadingView">
  3. <div class="border">
  4. <div class="leftLogin">
  5. <!-- 华电 -->
  6. <h1>{{ title }}</h1>
  7. <el-divider></el-divider>
  8. <div class="loginText">
  9. <el-form
  10. :model="loginForm"
  11. ref="ruleForm"
  12. label-width="0px"
  13. :rules="rules"
  14. class="demo-ruleForm"
  15. >
  16. <el-form-item prop="userName">
  17. <el-input
  18. placeholder="请输入用户名或账号"
  19. v-model="loginForm.userName"
  20. ></el-input>
  21. </el-form-item>
  22. <!-- TODO:删除placeholder -->
  23. <el-form-item prop="password">
  24. <el-input
  25. type="password"
  26. placeholder="请输入密码"
  27. v-model="loginForm.password"
  28. ></el-input>
  29. </el-form-item>
  30. <el-form-item>
  31. <el-button
  32. type="primary"
  33. class="custom-button"
  34. @click="login('ruleForm')"
  35. >登录</el-button
  36. >
  37. </el-form-item>
  38. </el-form>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. /** `runtime-config.js` 未加载或字段为空时的兜底文案 */
  46. const DEFAULT_LOGIN_TITLE = "机组功率曲线异常检测数据分析系统";
  47. function getRuntimeTitle() {
  48. const cfg =
  49. typeof window !== "undefined" ? window.__RUNTIME_CONFIG__ : undefined;
  50. const t = cfg && cfg.title;
  51. return typeof t === "string" && t.trim() ? t.trim() : DEFAULT_LOGIN_TITLE;
  52. }
  53. export default {
  54. data() {
  55. var validatePass = (rule, value, callback) => {
  56. if (value === "") {
  57. callback(new Error("请输入密码"));
  58. } else {
  59. callback();
  60. }
  61. };
  62. return {
  63. loginForm: {
  64. userName: "",
  65. password: "",
  66. },
  67. loadingView: false,
  68. rules: {
  69. userName: [
  70. { required: true, message: "请输入用户名或账号", trigger: "blur" },
  71. {
  72. type: "",
  73. message: "请输入用户名或账号",
  74. trigger: ["blur"],
  75. },
  76. ],
  77. password: [{ validator: validatePass, trigger: "blur" }],
  78. },
  79. };
  80. },
  81. computed: {
  82. /** 与 `public/runtime-config.js` 中 title 同步,部署后改文件即可 */
  83. title() {
  84. return getRuntimeTitle();
  85. },
  86. },
  87. created() {
  88. document.title = this.title;
  89. },
  90. methods: {
  91. // 登录
  92. login(formName) {
  93. this.loadingView = true;
  94. this.$refs[formName].validate((valid) => {
  95. if (valid) {
  96. try {
  97. this.$store.dispatch("auth/goLogin", {
  98. loginForm: this.loginForm,
  99. router: this.$router,
  100. });
  101. this.loadingView = false;
  102. } catch (error) {
  103. // Handle error if needed
  104. this.loadingView = false;
  105. }
  106. } else {
  107. this.loginForm.username = "";
  108. this.loginForm.password = "";
  109. this.loadingView = false;
  110. }
  111. });
  112. },
  113. // 忘记密码
  114. forgot() {
  115. this.$router.push("/forgot");
  116. },
  117. },
  118. };
  119. </script>
  120. <style lang="scss" scoped>
  121. .background-image {
  122. width: 100vw;
  123. height: 100vh;
  124. background-image: url("@/assets/login-img.png");
  125. background-size: cover;
  126. background-position: center;
  127. background-repeat: no-repeat;
  128. }
  129. .border {
  130. position: absolute;
  131. top: 50%;
  132. left: 50%;
  133. transform: translate(-50%, -50%);
  134. padding: 0 50px;
  135. width: 450px;
  136. background: #fff;
  137. border: 1px solid rgb(231, 231, 231);
  138. border-radius: 5px;
  139. box-shadow: 0px 1px 5px 0px rgba(0, 0, 0, 0.4);
  140. margin: auto;
  141. .leftLogin {
  142. align-items: center;
  143. h1 {
  144. width: 100%;
  145. text-align: center;
  146. line-height: 50px;
  147. font-size: 20px;
  148. font-weight: 600;
  149. color: #00baad;
  150. margin-top: 20px;
  151. }
  152. .el-divider--horizontal {
  153. margin: 10px 0;
  154. height: 4px;
  155. background: #ba2200;
  156. }
  157. .loginText {
  158. .custom-button {
  159. width: 300px;
  160. margin-bottom: 10px;
  161. background-color: #00baad;
  162. color: white;
  163. border: 2px solid #00baad;
  164. }
  165. .custom-button:hover {
  166. background-color: #00baad;
  167. color: white;
  168. border: 2px solid #00baad;
  169. }
  170. }
  171. .forgot {
  172. font-size: 12px;
  173. color: rgb(143, 143, 143);
  174. margin-top: 20px;
  175. }
  176. .forgot:hover {
  177. font-size: 12px;
  178. color: rgb(0, 0, 0);
  179. margin-top: 20px;
  180. }
  181. .loginImg {
  182. width: 200px;
  183. height: 200px;
  184. margin: 50px auto;
  185. img {
  186. object-fit: cover;
  187. width: 100%;
  188. height: 100%;
  189. }
  190. }
  191. // TODO:新增
  192. .demo-ruleForm {
  193. display: flex;
  194. align-items: center;
  195. flex-direction: column;
  196. justify-content: center;
  197. .el-button {
  198. margin-top: 20px;
  199. }
  200. .el-form-item {
  201. margin-bottom: 10px;
  202. }
  203. }
  204. }
  205. .rightImg {
  206. width: 50%;
  207. height: 100%;
  208. img {
  209. object-fit: cover;
  210. width: 100%;
  211. height: 100%;
  212. border-radius: 0 5px 5px 0;
  213. /* 可以根据需要调整圆角的大小 */
  214. }
  215. }
  216. }
  217. .el-input {
  218. width: 300px;
  219. margin-top: 20px;
  220. }
  221. // ::v-deep .el-form-item__error {
  222. // left: 150;
  223. // }
  224. </style>