1.用户登录 url +用户id 或 其他的唯一标识 发送请求
2 后台返回一个 这个id 对应的字段 存储
userLogin() {
if (this.userInfo.username !== "" && this.userInfo.password !== "") {
this.$post(this.$url + "mgr/login", this.userInfo)
.then(data => {
if (data.code == 1) {
this.$store.commit("setTokenKey", data.data.sessionId);
this.$store.commit("userinfo", data.data);
// 保存用户的权限路由
localStorage.setItem("roles", data.data.roles); //这个localstorage需要考虑
this.$store.commit("updateMenulist");
this.$router.push({ name: "person" });
} else {
this.$message.error(data.info);
}
})
.catch(err => {});
}
}
3.解析对应字段
let roles = localStorage.getItem('roles') ? localStorage.getItem('roles') : "";
console.log(roles);
roles = roles.split(",");
this.agent = roles.indexOf('agent') != -1?true:false;
if(this.agent){
this.isChildUpdate1 = true;
this.isChildUpdate2 = false;
}else{
this.isChildUpdate1 = false;
this.isChildUpdate2 = true;
this.activeName = "second";
}
this.operator = roles.indexOf('operator') != -1?true:false;
之后 使用v-if 控制 显示到前端