Commit d9329b8f authored by liwenhong's avatar liwenhong

update:login permission

parent 949f0a56
......@@ -10,36 +10,16 @@
</template>
<script>
import { fetchCurrentUser } from "./service/user";
import { getCookie, redirectToLogin } from "@/utils/util";
export default {
async mounted() {
if (this.$store.state.permissions && this.$store.state.userInfo) return;
if(!getCookie('username')) {
this.$message('请先登录');
return redirectToLogin();
}
const { status, user } = await fetchCurrentUser();
// let isDefault = window.localStorage.getItem('isDefault');
// if (isDefault == 2) return;
console.log('status',status)
console.log('user',user)
if (status === "success") {
this.$store.commit("updateUserInfo", user);
this.$store.dispatch("updateUserPermission", { email: user.email });
// 无奈之举,后期需要重构到提现管理中
this.$store.dispatch("fetchPermission", {
appId: "merchant-op-auditing",
});
} else {
return redirectToLogin();
}
if(!getCookie('username') && window.location.pathname != '/op/login') {
this.$message('请先登录');
return redirectToLogin();
}
},
computed: {
}
};
</script>
......
......@@ -155,6 +155,7 @@ export default {
let appId = this.appId || "";
const modulePermissions =
this.$store.getters.moduleSubPermissions(rolePermissionId, appId) || [];
console.log('modulePermissions', modulePermissions)
return new Map(modulePermissions.map((ele) => [ele.name, true]));
},
},
......
......@@ -19,26 +19,26 @@ router.beforeResolve(async (to, from, next) => {
next();
return true;
}
let isDefault = window.localStorage.getItem("isDefault");
if (!store.state.permissions && isDefault == 1) {
if (!store.state.permissions) {
const { status, user } = await fetchCurrentUser();
if (status === "success") {
store.commit("updateUserInfo", user);
console.log("updateUserInfo=====", user);
await store.dispatch("updateUserPermission", { email: user.email });
store.dispatch("fetchPermission", {
appId: "merchant-op-auditing",
});
} else {
redirectToLogin();
return ElMessage("您没有权限");
}
}
// .......
if (isDefault === "2") {
await store.dispatch("updateUserPermission", {
email: localStorage.getItem("_user_email")
});
}
// if (isDefault === "2") {
// await store.dispatch("updateUserPermission", {
// email: localStorage.getItem("_user_email")
// });
// }
if (!checkPathAuth(to.path)) {
redirectToLogin();
......
......@@ -32,6 +32,7 @@ export default {
async fetchPermission({ commit }, { email, appId }) {
if (appId === "merchant-op-auditing") {
const permissions = await getRolesForUser(email);
console.log('permissions', permissions)
if (!permissions) {
return;
}
......@@ -62,7 +63,7 @@ export default {
* @returns
*/
moduleSubPermissions: state => (module, appId = "") => {
if (appId !== "") {
if (appId !== "") {
if (!state.permissionsForApp[appId]) {
return [];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment