| | |
| | | data() { |
| | | return { |
| | | ruleForm: { |
| | | username: "admin", |
| | | password: "admin", |
| | | username: "", |
| | | password: "", |
| | | remumberme: false, |
| | | autoenter: false |
| | | }, |
| | |
| | | var user = JSON.parse(localStorage.getItem('user')) |
| | | if (user != null && user != undefined) { |
| | | if (this.ruleForm.remumberme==true) { |
| | | this.ruleForm.username = user.username |
| | | this.ruleForm.password = user.password |
| | | this.ruleForm.username = user.username; |
| | | this.ruleForm.password = user.password; |
| | | } |
| | | if (this.ruleForm.autoenter==true) { |
| | | this.submitForm('ruleForm') |
| | | this.submitForm('ruleForm'); |
| | | } |
| | | } |
| | | }, |
| | |
| | | this.btnload = true |
| | | this.$refs[formName].validate((valid) => { |
| | | if (valid) { |
| | | this.$store.dispatch('user/login', this.ruleForm).then(async () => { |
| | | this.$store.dispatch('user/login', this.ruleForm).then(async (res) => { |
| | | let name = ""; |
| | | await get(this.$url.info).then(res => { |
| | | this.user = res.data; |
| | | sessionStorage.setItem("user", JSON.stringify(res.data)); |
| | | sessionStorage.setItem("flushPage",0); |
| | | }) |
| | | this.user = res.data; |
| | | name = res.data.name; |
| | | sessionStorage.setItem("user", JSON.stringify(res.data)); |
| | | sessionStorage.setItem("flushPage",0); |
| | | }) |
| | | localStorage.setItem('rememberme', this.ruleForm.remumberme); |
| | | localStorage.setItem('autoenter', this.ruleForm.autoenter); |
| | | if (this.ruleForm.remumberme==true||this.ruleForm.autoenter==true) { |
| | | localStorage.setItem("user", JSON.stringify({ |
| | | username: this.ruleForm.username, |
| | | password: this.ruleForm.password, |
| | | name: name, |
| | | })); |
| | | } |
| | | this.$message.success("登录成功") |
| | | this.btnload = false |
| | | this.$router.push({ path: this.redirect || '/' }) |
| | | this.loading = false |
| | | }).catch(() => { |
| | | this.loading = false |
| | | }).catch((error) => { |
| | | this.$message.error(error.message) |
| | | this.btnload = false |
| | | }) |
| | | } else { |
| | | this.btnload = false |
| | | this.$message.error('登录失败!') |
| | | this.$message.error('账号或密码未输入!') |
| | | return false; |
| | | } |
| | | }) |