Commit fb59c181 authored by liwenhong's avatar liwenhong

add:sub菜单校验

parent b0d1fe80
......@@ -10,33 +10,30 @@
</template>
<script>
// import { fetchCurrentUser } from "./service/user";
import { fetchCurrentUser } from "./service/user";
import { getCookie, redirectToLogin } from "@/utils/util";
export default {
async mounted() {
console.log(getCookie('username'));
if(!getCookie('username')) {
this.$message('请先登录');
redirectToLogin();
if (this.$store.state.permissions && this.$store.state.userInfo) return;
if(!getCookie('username')) {
this.$message('请先登录');
redirectToLogin();
}
const { status, user } = await fetchCurrentUser();
// let isDefault = window.localStorage.getItem('isDefault');
// if (isDefault == 2) return;
if (status === "success") {
this.$store.commit("updateUserInfo", user);
this.$store.dispatch("updateUserPermission", { email: user.email });
// 无奈之举,后期需要重构到提现管理中
this.$store.dispatch("fetchPermission", {
appId: "merchant-op-auditing",
});
} else {
redirectToLogin();
}
// if (this.$store.state.permissions && this.$store.state.userInfo) return;
// let isDefault = window.localStorage.getItem('isDefault');
// if(isDefault == 2) {
// user.email = getCookie('username');
// }
// const { status, user } = await fetchCurrentUser();
// if (status === "success") {
// this.$store.commit("updateUserInfo", user);
// console.log('user',user)
// this.$store.dispatch("updateUserPermission", { email: user.email });
// // 无奈之举,后期需要重构到提现管理中
// this.$store.dispatch("fetchPermission", {
// appId: "merchant-op-auditing",
// });
// } else {
// redirectToLogin();
// }
},
computed: {
......
......@@ -10,7 +10,7 @@ import locale from "element-plus/lib/locale/lang/zh-cn";
import { fetchCurrentUser } from "./service/user";
import { checkPathAuth } from "./utils/authUtil";
import { redirectToLogin, getCookie } from "./utils/util";
import { redirectToLogin } from "./utils/util";
import { ElMessage } from "element-plus";
// 处理路由权限
......@@ -20,19 +20,17 @@ router.beforeResolve(async (to, from, next) => {
next();
return true;
}
if (!store.state.permissions) {
let isDefault = window.localStorage.getItem('isDefault');
if (!store.state.permissions && isDefault == 1) {
const { status, user } = await fetchCurrentUser();
let isDefault = window.localStorage.getItem('isDefault');
if(isDefault == 2) {
user.email = getCookie('username');
}
if (status === 'success') {
store.commit('updateUserInfo', user);
console.log('updateUserInfo=====', user)
await store.dispatch('updateUserPermission', { email: user.email })
} else {
redirectToLogin();
return false;
return ElMessage("您没有权限");
}
}
......
......@@ -131,7 +131,6 @@ export default {
this.$router.push({ name: "Forbidden" });
return;
}
console.log("withdrawlPermission", withdrawlPermission);
withdrawlPermission = withdrawlPermission[0];
// judge subpermission
let subpermissions = withdrawlPermission.sub_permissions.filter(
......
......@@ -289,7 +289,7 @@ import {
} from "@/service/Withdrawal/withdrawal";
import { ElMessage } from "element-plus";
import { fetchCurrentUser } from "../../../service/user";
import { getCookie, redirectToLogin } from "@/utils/util";
import { redirectToLogin } from "@/utils/util";
const TABS = {
pending: "0",
......@@ -353,7 +353,6 @@ export default {
},
async mounted() {
const res = await this.getPermissionsAll();
if (!res) {
redirectToLogin();
return ElMessage("您没有权限");
......@@ -368,7 +367,6 @@ export default {
redirectToLogin();
return ElMessage("您没有权限");
}
console.log("withdrawlPermission", withdrawlPermission);
withdrawlPermission = withdrawlPermission[0];
// judge subpermission
let subpermissions = withdrawlPermission.sub_permissions.filter(
......@@ -384,10 +382,6 @@ export default {
// 不能够信赖 store 中的 email,无法知道全局中的 fetchCurrentUser 处理完毕
// 是一个重构的点
const { user } = await fetchCurrentUser();
let isDefault = window.localStorage.getItem('isDefault');
if(isDefault == 2) {
user.email = getCookie('username');
}
const res = await getRolesForUser(user.email);
this.permissions = res;
......
const headerConfig = [
{
name: "提现审核",
path: "/op/withdrawal/examine"
path: "/op/withdrawal/examine",
requiredPermission: "withdrawal_audit"
},
{
path: "/op/withdrawal/roleManageRole",
name: "角色管理",
// requireAuthentication: true,
// requiredPermission: "role_management"
requireAuthentication: true,
requiredPermission: "role_management"
},
{
path: "/op/withdrawal/user",
name: "用户管理",
// requireAuthentication: true,
// requiredPermission: "user_management"
requireAuthentication: true,
requiredPermission: "user_management"
}
];
......
......@@ -54,7 +54,7 @@ export default {
if (this.hasPermission(item.requiredPermission)) {
return true;
}
return true;
return false;
});
return visibleMenuItems;
},
......@@ -62,14 +62,13 @@ export default {
beforeMount() {},
methods: {
...mapActions(['logout']),
hasPermission() {
// return (
// this.moduleSubPermissions(
// permissionId,
// "merchant-op-auditing"
// ).length !== 0
// );
return true
hasPermission(permissionId) {
return (
this.$store.getters.moduleSubPermissions(
permissionId,
"merchant-op-auditing"
).length !== 0
);
},
handleLogout() {
this.logout()
......
......@@ -26,10 +26,10 @@ const withdrawalRoutes = [
import(
/* webpackChunkName: "Withdrawal" */ "@/pages/Withdrawal/Role/manage-role"
),
// meta: {
// requireAuth: true,
// keepAlive: true
// }
meta: {
requireAuth: true,
keepAlive: true
}
},
//角色管理
{
......
......@@ -94,9 +94,9 @@ const routes = [
path: "/op/roleManageRole",
name: "/op/ManageRole",
component: ManageRole,
// meta: {
// requireAuth: true
// }
meta: {
requireAuth: true
}
},
{
path: "/op/roleRoleDetail",
......
import axios from '../utils/request';
import { getCookie } from "@/utils/util";
export async function yd_login (userInfo) {
const res = await axios.post("/api/v1/YD_login", userInfo);
......@@ -12,7 +13,8 @@ export async function j_login (userInfo) {
export async function fetchCurrentUser () {
let isDefault = window.localStorage.getItem('isDefault');
if(isDefault == 2) return true;
let username = getCookie('username')
if(isDefault == 2) return {user: {email:username, status: 'success'}};
return await axios.get("/api/v1/fetch_user");
}
......
......@@ -43,12 +43,7 @@ export default {
logout() {
return new Promise(async (resolve) => {
window.localStorage.clear();
await delCookie('username')
await delCookie('uid')
await delCookie('YD_PANDORA_JWT_TOKEN')
await delCookie('nickname')
await delCookie('userid')
await delCookie('YD_PANDORA_UID')
delCookie()
redirectToLogin()
resolve()
});
......
......@@ -30,7 +30,6 @@ export function redirectToLogin() {
export function redirectPage() {
let url = window.location.search.split('?callback=')[1] || window.location.pathname;
router.push(window.decodeURIComponent(url))
console.log('redirectUrl', url)
}
export function isYdUser(email) {
......@@ -58,9 +57,13 @@ export function getCookie(NameOfCookie) {
return null;
}
export function delCookie(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if(cval != null) document.cookie= name + "="+cval+";expires="+exp.toGMTString()+";path=/";
export function delCookie() {
var keys = document.cookie.match(/[^ =;]+(?==)/g)
if (keys) {
for (var i = keys.length; i--;) {
document.cookie = keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString()
document.cookie = keys[i] + '=0;path=/;domain=' + document.domain + ';expires=' + new Date(0).toUTCString()
document.cookie = keys[i] + '=0;path=/;domain=yidian-inc.com;expires=' + new Date(0).toUTCString()
}
}
}
\ No newline at end of file
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