123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <template>
- <div class="background-image" v-loading="loadingView">
- <div class="border">
- <div class="leftLogin">
- <h1>风机数据管理平台</h1>
- <el-divider></el-divider>
- <div class="loginText">
- <el-form
- :model="loginForm"
- ref="ruleForm"
- label-width="0px"
- :rules="rules"
- class="demo-ruleForm"
- >
- <el-form-item prop="userName">
- <el-input
- placeholder="请输入用户名或账号"
- v-model="loginForm.userName"
- ></el-input>
- </el-form-item>
- <!-- TODO:删除placeholder -->
- <el-form-item prop="password">
- <el-input
- type="password"
- placeholder="请输入密码"
- v-model="loginForm.password"
- ></el-input>
- </el-form-item>
- <el-form-item>
- <el-button
- type="primary"
- class="custom-button"
- @click="login('ruleForm')"
- >登录</el-button
- >
- </el-form-item>
- </el-form>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- import { resetRouter } from "@/router/index.js";
- export default {
- data() {
- var validatePass = (rule, value, callback) => {
- if (value === "") {
- callback(new Error("请输入密码"));
- } else {
- callback();
- }
- };
- return {
- loginForm: {
- userName: "",
- password: "",
- },
- loadingView: false,
- rules: {
- userName: [
- { required: true, message: "请输入用户名或账号", trigger: "blur" },
- {
- type: "",
- message: "请输入用户名或账号",
- trigger: ["blur"],
- },
- ],
- password: [{ validator: validatePass, trigger: "blur" }],
- },
- };
- },
- created() {},
- methods: {
- // 登录
- login(formName) {
- this.loadingView = true;
- this.$refs[formName].validate((valid) => {
- if (valid) {
- try {
- this.$store.dispatch("auth/goLogin", {
- loginForm: this.loginForm,
- router: this.$router,
- });
- this.loadingView = false;
- } catch (error) {
- // Handle error if needed
- this.loadingView = false;
- }
- } else {
- this.loginForm.username = "";
- this.loginForm.password = "";
- this.loadingView = false;
- }
- });
- },
- // 忘记密码
- forgot() {
- this.$router.push("/forgot");
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .background-image {
- width: 100vw;
- height: 100vh;
- background-image: url("@/assets/login-img.png");
- background-size: cover;
- background-position: center;
- background-repeat: no-repeat;
- }
- .border {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- padding: 0 50px;
- width: 400px;
- background: #fff;
- border: 1px solid rgb(231, 231, 231);
- border-radius: 5px;
- box-shadow: 0px 1px 5px 0px rgba(0, 0, 0, 0.4);
- margin: auto;
- .leftLogin {
- align-items: center;
- h1 {
- width: 100%;
- text-align: center;
- line-height: 50px;
- font-size: 26px;
- font-weight: 600;
- color: #00baad;
- margin-top: 20px;
- }
- .el-divider--horizontal {
- margin: 10px 0;
- height: 4px;
- background: #00baad;
- }
- .loginText {
- .custom-button {
- width: 300px;
- margin-bottom: 10px;
- background-color: #00baad;
- color: white;
- border: 2px solid #00baad;
- }
- .custom-button:hover {
- background-color: #00baad;
- color: white;
- border: 2px solid #00baad;
- }
- }
- .forgot {
- font-size: 12px;
- color: rgb(143, 143, 143);
- margin-top: 20px;
- }
- .forgot:hover {
- font-size: 12px;
- color: rgb(0, 0, 0);
- margin-top: 20px;
- }
- .loginImg {
- width: 200px;
- height: 200px;
- margin: 50px auto;
- img {
- object-fit: cover;
- width: 100%;
- height: 100%;
- }
- }
- // TODO:新增
- .demo-ruleForm {
- display: flex;
- align-items: center;
- flex-direction: column;
- justify-content: center;
- .el-button {
- margin-top: 20px;
- }
- .el-form-item {
- margin-bottom: 10px;
- }
- }
- }
- .rightImg {
- width: 50%;
- height: 100%;
- img {
- object-fit: cover;
- width: 100%;
- height: 100%;
- border-radius: 0 5px 5px 0;
- /* 可以根据需要调整圆角的大小 */
- }
- }
- }
- .el-input {
- width: 300px;
- margin-top: 20px;
- }
- // ::v-deep .el-form-item__error {
- // left: 150;
- // }
- </style>
|