Commit d9329b8f authored by liwenhong's avatar liwenhong

update:login permission

parent 949f0a56
...@@ -10,36 +10,16 @@ ...@@ -10,36 +10,16 @@
</template> </template>
<script> <script>
import { fetchCurrentUser } from "./service/user";
import { getCookie, redirectToLogin } from "@/utils/util"; import { getCookie, redirectToLogin } from "@/utils/util";
export default { export default {
async mounted() { async mounted() {
if (this.$store.state.permissions && this.$store.state.userInfo) return; if (this.$store.state.permissions && this.$store.state.userInfo) return;
if(!getCookie('username')) { if(!getCookie('username') && window.location.pathname != '/op/login') {
this.$message('请先登录'); this.$message('请先登录');
return redirectToLogin(); 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();
}
}, },
computed: {
}
}; };
</script> </script>
......
...@@ -155,6 +155,7 @@ export default { ...@@ -155,6 +155,7 @@ export default {
let appId = this.appId || ""; let appId = this.appId || "";
const modulePermissions = const modulePermissions =
this.$store.getters.moduleSubPermissions(rolePermissionId, appId) || []; this.$store.getters.moduleSubPermissions(rolePermissionId, appId) || [];
console.log('modulePermissions', modulePermissions)
return new Map(modulePermissions.map((ele) => [ele.name, true])); return new Map(modulePermissions.map((ele) => [ele.name, true]));
}, },
}, },
......
...@@ -19,26 +19,26 @@ router.beforeResolve(async (to, from, next) => { ...@@ -19,26 +19,26 @@ router.beforeResolve(async (to, from, next) => {
next(); next();
return true; return true;
} }
let isDefault = window.localStorage.getItem("isDefault"); if (!store.state.permissions) {
if (!store.state.permissions && isDefault == 1) {
const { status, user } = await fetchCurrentUser(); const { status, user } = await fetchCurrentUser();
if (status === "success") { if (status === "success") {
store.commit("updateUserInfo", user); store.commit("updateUserInfo", user);
console.log("updateUserInfo=====", user);
await store.dispatch("updateUserPermission", { email: user.email }); await store.dispatch("updateUserPermission", { email: user.email });
store.dispatch("fetchPermission", {
appId: "merchant-op-auditing",
});
} else { } else {
redirectToLogin(); redirectToLogin();
return ElMessage("您没有权限"); return ElMessage("您没有权限");
} }
} }
// ....... // if (isDefault === "2") {
if (isDefault === "2") { // await store.dispatch("updateUserPermission", {
await store.dispatch("updateUserPermission", { // email: localStorage.getItem("_user_email")
email: localStorage.getItem("_user_email") // });
}); // }
}
if (!checkPathAuth(to.path)) { if (!checkPathAuth(to.path)) {
redirectToLogin(); redirectToLogin();
......
...@@ -32,6 +32,7 @@ export default { ...@@ -32,6 +32,7 @@ export default {
async fetchPermission({ commit }, { email, appId }) { async fetchPermission({ commit }, { email, appId }) {
if (appId === "merchant-op-auditing") { if (appId === "merchant-op-auditing") {
const permissions = await getRolesForUser(email); const permissions = await getRolesForUser(email);
console.log('permissions', permissions)
if (!permissions) { if (!permissions) {
return; return;
} }
...@@ -62,7 +63,7 @@ export default { ...@@ -62,7 +63,7 @@ export default {
* @returns * @returns
*/ */
moduleSubPermissions: state => (module, appId = "") => { moduleSubPermissions: state => (module, appId = "") => {
if (appId !== "") { if (appId !== "") {
if (!state.permissionsForApp[appId]) { if (!state.permissionsForApp[appId]) {
return []; 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