forked from Gitlink/forgeplus-react
修复切换路由时的bug
This commit is contained in:
parent
bf6e95d182
commit
dfcecc1f2d
|
@ -8,10 +8,12 @@ const { SubMenu } = Menu;
|
|||
const titleObj = {};
|
||||
const locationObj = {};
|
||||
const parentKeyObj = {};
|
||||
const allRouter = [];
|
||||
function titleFun(menus) {
|
||||
menus.forEach(i => {
|
||||
titleObj[i.key] = i.title;
|
||||
locationObj[i.location] = i;
|
||||
i.location && allRouter.push(i.location);
|
||||
if (Array.isArray(i.children) && i.children.length > 0) {
|
||||
titleFun(i.children);
|
||||
i.parentKey && (parentKeyObj[i.key] = i.parentKey);
|
||||
|
@ -21,15 +23,18 @@ function titleFun(menus) {
|
|||
titleFun(urlConfig);
|
||||
|
||||
export default (props) => {
|
||||
const { current_user, children,location:{pathname} } = props;
|
||||
const { current_user, children,history, location: { pathname } } = props;
|
||||
const setting = (localStorage.chromesetting && JSON.parse(localStorage.chromesetting)) || {};
|
||||
useEffect(() => {
|
||||
sessionStorage.setItem("current_user", JSON.stringify(current_user));
|
||||
}, [current_user.login]);
|
||||
|
||||
const [current, setCurrent] = useState([locationObj[pathname].key]);
|
||||
const [keyPath, setKeyPath] = useState([locationObj[pathname].parentKey,locationObj[pathname].key]);
|
||||
const [acitve, setActive] = useState(locationObj[pathname]);
|
||||
let initCurrent = locationObj[pathname] ? [locationObj[pathname].key] : [];
|
||||
let initKeyPath = locationObj[pathname] ? [locationObj[pathname].parentKey, locationObj[pathname].key] : [];
|
||||
|
||||
const [current, setCurrent] = useState(initCurrent);
|
||||
const [keyPath, setKeyPath] = useState(initKeyPath);
|
||||
const [acitve, setActive] = useState(locationObj[pathname] || {});
|
||||
|
||||
function handleClick(e) {
|
||||
console.log(e.item);
|
||||
|
@ -71,17 +76,28 @@ export default (props) => {
|
|||
})
|
||||
}
|
||||
|
||||
function iframeLoad(){
|
||||
try{
|
||||
document.getElementById("iframe").height=document.getElementById("iframe").contentWindow.top.document.documentElement.scrollHeight;
|
||||
}catch(err){
|
||||
function iframeLoad() {
|
||||
try {
|
||||
document.getElementById("iframe").height = document.getElementById("iframe").contentWindow.top.document.documentElement.scrollHeight;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
// 添加路由监听函数
|
||||
history.listen(historyLocation => {
|
||||
// 每次路由变化都会执行这个方法
|
||||
if (allRouter.includes(historyLocation.pathname)) {
|
||||
setCurrent([locationObj[historyLocation.pathname].key]);
|
||||
setKeyPath([locationObj[pathname].parentKey, locationObj[pathname].key])
|
||||
}
|
||||
})
|
||||
}, [history]);
|
||||
|
||||
const defaultOpenKeys = [];
|
||||
const myKey = locationObj && pathname && locationObj[pathname].parentKey;
|
||||
defaultOpenKeys.push(myKey ? myKey: "task") ;
|
||||
const myKey = pathname && locationObj[pathname] && locationObj[pathname].parentKey;
|
||||
defaultOpenKeys.push(myKey ? myKey : "task");
|
||||
defaultOpenKeys.push(parentKeyObj[myKey]);
|
||||
|
||||
return (
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useCallback, useEffect, useState, useMemo } from 'react';
|
||||
import { Input, Select, Button, Form, DatePicker, Modal, message, Popover } from 'antd';
|
||||
import { Input, Select, Button, Form, DatePicker, Modal, message, Popover,Switch } from 'antd';
|
||||
import PaginationTable from '../../../components/pagination-table';
|
||||
|
||||
export default Form.create()(({ form, showNotification, match, history, state }) => {
|
||||
|
|
|
@ -27,3 +27,16 @@
|
|||
.encrypt-item .ant-form-item-label{
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.ant-radio-checked .ant-radio-inner{
|
||||
border-color: #4154f1;
|
||||
}
|
||||
.ant-radio-inner::after{
|
||||
background-color: #4154f1;
|
||||
}
|
||||
.ant-radio-wrapper:hover .ant-radio, .ant-radio:hover .ant-radio-inner, .ant-radio-input:focus + .ant-radio-inner{
|
||||
border-color: #4154f1;
|
||||
}
|
||||
.ant-radio-checked::after{
|
||||
border: 1px solid #4154f1;
|
||||
}
|
|
@ -42,7 +42,7 @@ const IndexPage = ({ match, history, current_user: { admin } }) => {
|
|||
}
|
||||
|
||||
function download(url) {
|
||||
if (location.href.indexOf('localhost') > -1) {
|
||||
if (window.location.href.indexOf('localhost') > -1) {
|
||||
url = 'http://106.75.31.211:58088' + url;
|
||||
}
|
||||
window.open(url);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React, { forwardRef, useEffect, useState, useCallback } from 'react';
|
||||
import { Table, Pagination, Button, Form, Modal, Input, Select, Radio, } from 'antd';
|
||||
import { Button, Form, Modal, Input, Select, Radio, } from 'antd';
|
||||
import PaginationTable from "../../../components/pagination-table";
|
||||
import { noticeType } from '../../common/static';
|
||||
import DelModal from '../../components/DelModal';
|
||||
|
@ -27,6 +27,7 @@ const NoticeList = Form.create()(forwardRef(({ form, match, history, current_use
|
|||
|
||||
const [type, setType] = useState(undefined);
|
||||
const [title, setTitle] = useState(undefined);
|
||||
const [pageSize, setPageSize] = useState(10);
|
||||
const [curPage, setCurPage] = useState(1);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [orderBy, setOrderBy] = useState('');
|
||||
|
@ -64,7 +65,7 @@ const NoticeList = Form.create()(forwardRef(({ form, match, history, current_use
|
|||
orderBy,
|
||||
curPage,
|
||||
isChecked,
|
||||
pageSize: 10,
|
||||
pageSize,
|
||||
status,
|
||||
type,
|
||||
title,
|
||||
|
@ -79,7 +80,7 @@ const NoticeList = Form.create()(forwardRef(({ form, match, history, current_use
|
|||
setDataList([]);
|
||||
}
|
||||
});
|
||||
}, [curPage, type, title, isChecked, reload]);
|
||||
}, [curPage, type, title, isChecked, reload,pageSize]);
|
||||
|
||||
|
||||
const columns = [
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { Button, Descriptions,Pagination, Icon, Table } from 'antd';
|
||||
import { Button, Descriptions, Pagination, Icon, Table } from 'antd';
|
||||
import PaginationTable from "../../../components/pagination-table";
|
||||
import { noticeType, noticeChecked } from '../../common/static';
|
||||
import { getNoticeDetail, getNoticeReader } from '../api';
|
||||
import '../index.css';
|
||||
|
@ -7,11 +8,11 @@ import './index.scss';
|
|||
|
||||
const noticeTypeArr = [];
|
||||
for (const item of noticeType) {
|
||||
noticeTypeArr[item.code]=(item.name);
|
||||
noticeTypeArr[item.code] = (item.name);
|
||||
}
|
||||
const noticeCheckedArr = [];
|
||||
for (const item of noticeChecked) {
|
||||
noticeCheckedArr[item.code]=(item.name);
|
||||
noticeCheckedArr[item.code] = (item.name);
|
||||
}
|
||||
|
||||
const NoticeReader = ({ match, history }) => {
|
||||
|
@ -19,6 +20,7 @@ const NoticeReader = ({ match, history }) => {
|
|||
const [noticeData, setNoticeData] = useState({});
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [dataList, setDataList] = useState([]);
|
||||
const [pageSize, setPageSize] = useState(10);
|
||||
const [curPage, setCurPage] = useState(1);
|
||||
const [total, setTotal] = useState(0);
|
||||
|
||||
|
@ -31,9 +33,9 @@ const NoticeReader = ({ match, history }) => {
|
|||
useEffect(() => {
|
||||
setLoading(true);
|
||||
id && getNoticeReader({
|
||||
currentPage:curPage,
|
||||
annId:id,
|
||||
pageSize:10
|
||||
currentPage: curPage,
|
||||
annId: id,
|
||||
pageSize,
|
||||
}).then(data => {
|
||||
setLoading(false);
|
||||
if (data) {
|
||||
|
@ -44,63 +46,56 @@ const NoticeReader = ({ match, history }) => {
|
|||
setDataList([]);
|
||||
}
|
||||
})
|
||||
}, [id,curPage]);
|
||||
|
||||
function download(url) {
|
||||
if (location.href.indexOf('localhost') > -1) {
|
||||
url = 'http://106.75.31.211:58088' + url;
|
||||
}
|
||||
window.open(url);
|
||||
}
|
||||
}, [id, curPage, pageSize]);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: '用户姓名',
|
||||
key: 'readerName',
|
||||
dataIndex: 'readerName',
|
||||
width:'20%',
|
||||
width: '20%',
|
||||
},
|
||||
{
|
||||
title: '公司名称',
|
||||
key: 'companyName',
|
||||
dataIndex: 'companyName',
|
||||
width:'40%',
|
||||
width: '40%',
|
||||
},
|
||||
{
|
||||
title: '联系方式',
|
||||
key: 'contactInfo',
|
||||
dataIndex: 'contactInfo',
|
||||
width:'40%',
|
||||
width: '40%',
|
||||
},
|
||||
];
|
||||
|
||||
function onShowSizeChange(current, pageSize) {
|
||||
setCurPage(current);
|
||||
setPageSize(pageSize);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="notice-content">
|
||||
<h4 className="notice-title"><span className='backList' onClick={() => { history.go(-1) }}><Icon type="left" />返回</span>浏览过该公告加密内容的用户详情</h4>
|
||||
|
||||
<Descriptions className='itemContent' column={1}>
|
||||
<Descriptions.Item label="公告标题">{noticeData.title}</Descriptions.Item>
|
||||
<Descriptions.Item label="加密信息被浏览数">{total}</Descriptions.Item>
|
||||
<Descriptions.Item label="浏览过该公告加密内容的用户信息"></Descriptions.Item>
|
||||
<Descriptions.Item label="公告标题">{noticeData.title}</Descriptions.Item>
|
||||
<Descriptions.Item label="加密信息被浏览数">{total}</Descriptions.Item>
|
||||
<Descriptions.Item label="浏览过该公告加密内容的用户信息"></Descriptions.Item>
|
||||
</Descriptions>
|
||||
|
||||
<div className="table-detail">
|
||||
<Table
|
||||
<PaginationTable
|
||||
loading={loading}
|
||||
rowKey={(row) => row.id}
|
||||
dataSource={dataList}
|
||||
columns={columns}
|
||||
pagination={false}
|
||||
total={total}
|
||||
setCurPage={setCurPage}
|
||||
current={curPage}
|
||||
onShowSizeChange={onShowSizeChange}
|
||||
showSizeChanger
|
||||
/>
|
||||
|
||||
{dataList.length > 0 &&
|
||||
<Pagination
|
||||
onChange={(page) => { setCurPage(page) }}
|
||||
current={curPage}
|
||||
total={total}
|
||||
/>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue