安装md5包:
npm install js-md5 -s
快速配置
import md5 from 'js-md5'
Vue.prototype.$md5 = md5
使用
this.$md5('需要加密的内容')
实例
data() {
return {
user_account: "",
userpwd: "",
radio: "user",
};
},
methods: {
// 登录
submit() {
if (this.user_account === "" || this.userpwd === "") {
this.$message({
message: "请填写用户名或密码",
type: "error",
});
return false;
} else {
let day = new Date();
let token = this.$md5(day.getTime + this.user_account);
login({
user_id: this.user_account,
password: this.$md5(this.userpwd),
table_name: this.radio,
token: token,
}).then((res) => {
if (res.data.state == 1) {
sessionStorage.setItem("token", token);
sessionStorage.setItem("userid", this.user_account);
sessionStorage.setItem("table", this.radio);
sessionStorage.setItem("username", res.data.name);
sessionStorage.setItem("authorityId", res.data.authority_id); //权级ID
sessionStorage.setItem("userdep", res.data.user_dep);
sessionStorage.setItem("nav", JSON.stringify(res.data.nav));
this.$router.push("/Home");
} else {
this.$message.error(res.data.msg);
}
});
}
},
},