Index.vue 4.8 KB

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