Commit 254019ff authored by Sixiang_Zzb's avatar Sixiang_Zzb

权限校验以及测试问题处理

parent f0bf87b9
...@@ -375,6 +375,9 @@ export default defineConfig({ ...@@ -375,6 +375,9 @@ export default defineConfig({
{ {
component: './404', component: './404',
}, },
{
component: './403',
},
], ],
// Theme for antd: https://ant.design/docs/react/customize-theme-cn // Theme for antd: https://ant.design/docs/react/customize-theme-cn
......
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { Row, Col, Table, Space, Tabs, Button } from 'antd'; import { Row, Col, Table, Space, Tabs, Button, message } from 'antd';
const { TabPane } = Tabs; const { TabPane } = Tabs;
import { objectColumns } from '@/utils/string'; import { objectColumns } from '@/utils/string';
...@@ -9,6 +9,11 @@ const TableShow = (props: any) => { ...@@ -9,6 +9,11 @@ const TableShow = (props: any) => {
const dataRow = data.rows; const dataRow = data.rows;
const goTo = (values: any, e: any) => { const goTo = (values: any, e: any) => {
const permissionArr = JSON.parse(localStorage.getItem('permission') || '[]');
if (permissionArr.indexOf('6') < 0) {
message.error('No Permissions!!!', 3);
return;
}
console.log(values); console.log(values);
props.onSubmit(values); props.onSubmit(values);
}; };
......
import React from 'react'; import React from 'react';
import { PageLoading } from '@ant-design/pro-layout'; import { PageLoading } from '@ant-design/pro-layout';
import { Redirect, connect, ConnectProps, StateType, history } from 'umi'; import { Redirect, connect, ConnectProps, StateType, history, Link } from 'umi';
import { stringify } from 'querystring'; import { stringify } from 'querystring';
import { ConnectState } from '@/models/connect'; import { ConnectState } from '@/models/connect';
import { CurrentUser } from '@/models/user'; import { CurrentUser } from '@/models/user';
import { getCookie } from '@/utils/method'; import { getCookie } from '@/utils/method';
import { Result, Button } from 'antd';
interface SecurityLayoutProps extends ConnectProps { interface SecurityLayoutProps extends ConnectProps {
loading?: boolean; loading?: boolean;
...@@ -24,7 +25,7 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout ...@@ -24,7 +25,7 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout
}; };
// componentDidMount() { // componentDidMount() {
// console.log('componentDidMount触发了23333333'); // console.log('componentDidMount触发了23333333');
// this.setState({ // this.setState({
// isReady: true, // isReady: true,
...@@ -46,12 +47,73 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout ...@@ -46,12 +47,73 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout
// } // }
render() { render() {
const { isReady, token } = this.state; const { children, loading } = this.props;
const { children, loading, currentUser, login } = this.props;
// You can replace it to your authentication rule (such as check token exists) // You can replace it to your authentication rule (such as check token exists)
// 你可以把它替换成你自己的登录认证规则(比如判断 token 是否存在) // 你可以把它替换成你自己的登录认证规则(比如判断 token 是否存在)
// console.log("是否已登录" + getCookie("token")) const perList = [
{
path: '/UserManagement/LIFEUserManagement',
key: '1',
},
{
path: '/UserManagement/ServiceProviderManagement',
key: '8',
},
{
path: '/PropertyManagement',
key: '15',
},
{
path: '/CommercialService/CommunityMaintenance',
key: '17',
},
{
path: '/CommercialService/OwnerComplaints',
key: '20',
},
{
path: '/CommercialService/ProblemFeedback',
key: '23',
},
{
path: '/CommercialService/RenovationApplication',
key: '26',
},
{
path: '/CommercialService/AccessCardApplication',
key: '29',
},
{
path: '/CommercialService/ReportOnline',
key: '33',
},
{
path: '/CommercialService/ShelfLifeService',
key: '36',
},
];
const permission = JSON.parse(localStorage.getItem('permission') || '[]');
console.log('验证权限' + location.pathname);
console.log('拿取所有权限' + permission);
// 判断是否有权限
// if (perList.indexOf("")) {
// }
let perObj = perList.filter((obj) => {
return obj.path === location.pathname;
});
console.log(perObj);
if (perObj.length !== 0) {
if (permission.indexOf(perObj[0].key) < 0) {
console.log('无权限');
history.push('/403');
}
}
// const isLogin = currentUser && currentUser.name;//isLogin为关键点 // const isLogin = currentUser && currentUser.name;//isLogin为关键点
var isLogin = false; var isLogin = false;
......
import { Button, Result } from 'antd';
import React from 'react';
import { history } from 'umi';
const NoFoundPage: React.FC<{}> = () => (
<Result
status="403"
title="403"
subTitle="Sorry, you are not authorized to access this page."
extra={
<Button type="primary" onClick={() => history.push('/')}>
Back Home
</Button>
}
/>
);
export default NoFoundPage;
...@@ -10,8 +10,7 @@ import TitleSearch from '../../../components/TitleSearch/TitleSearch'; ...@@ -10,8 +10,7 @@ import TitleSearch from '../../../components/TitleSearch/TitleSearch';
import { timestampToTime } from '../../../utils/time'; import { timestampToTime } from '../../../utils/time';
import { RA, getCookie, URL, filterObjbyTg, urlEncode, filterObj } from '@/utils/method'; import { RA, getCookie, URL, filterObjbyTg, urlEncode, filterObj } from '@/utils/method';
import { remove } from 'lodash';
console.log('检查是否有权限');
const module = 'User'; const module = 'User';
const module2 = 'History'; const module2 = 'History';
......
...@@ -32,7 +32,7 @@ const UsersDetail = (props: any) => { ...@@ -32,7 +32,7 @@ const UsersDetail = (props: any) => {
const MemberResultClear = () => { const MemberResultClear = () => {
dispatch({ type: 'User/MemberResultClear' }); dispatch({ type: 'User/MemberResultClear' });
}; };
const permissionArr = JSON.parse(localStorage.getItem('permission') || '[]');
const [memberDetail, setMemberDetail] = useState(false); const [memberDetail, setMemberDetail] = useState(false);
const [memberData, setMemberData] = useState(null as any); const [memberData, setMemberData] = useState(null as any);
const [editFlag, setEditFlag] = useState(false); const [editFlag, setEditFlag] = useState(false);
...@@ -140,7 +140,6 @@ const UsersDetail = (props: any) => { ...@@ -140,7 +140,6 @@ const UsersDetail = (props: any) => {
}; };
const deleteUnit = (values: any) => { const deleteUnit = (values: any) => {
const permissionArr = JSON.parse(localStorage.getItem('permission') || '[]');
if (permissionArr.indexOf('5') < 0) { if (permissionArr.indexOf('5') < 0) {
message.error('No Permissions!!!', 3); message.error('No Permissions!!!', 3);
return; return;
...@@ -169,6 +168,10 @@ const UsersDetail = (props: any) => { ...@@ -169,6 +168,10 @@ const UsersDetail = (props: any) => {
const DeleteMember = (values: any, e: any) => { const DeleteMember = (values: any, e: any) => {
console.log(values); console.log(values);
if (permissionArr.indexOf('7') < 0) {
message.error('No Permissions!!!', 3);
return;
}
RA(39, { id: values.id, ownerId: values.owner_id }); RA(39, { id: values.id, ownerId: values.owner_id });
}; };
......
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