Commit c15bced2 authored by krysent's avatar krysent

bug

parent f8200974
...@@ -23,8 +23,6 @@ const Mtable = (props) => { ...@@ -23,8 +23,6 @@ const Mtable = (props) => {
getDefaultSelected, //存在默认选中向上返回选中值 getDefaultSelected, //存在默认选中向上返回选中值
} = props; } = props;
const actionRefs = actionRef ?? useRef(), const actionRefs = actionRef ?? useRef(),
formRefs = formRef ?? useRef(), formRefs = formRef ?? useRef(),
ifspagination = pagination == "false" || pagination === false, ifspagination = pagination == "false" || pagination === false,
...@@ -66,7 +64,6 @@ const Mtable = (props) => { ...@@ -66,7 +64,6 @@ const Mtable = (props) => {
}; };
}; };
//更新 columns //更新 columns
useEffect(() => { useEffect(() => {
setcolumnes((s) => { setcolumnes((s) => {
...@@ -136,7 +133,15 @@ const Mtable = (props) => { ...@@ -136,7 +133,15 @@ const Mtable = (props) => {
//初始化操作数据 //初始化操作数据
const initDrage = async () => { const initDrage = async () => {
console.log(valueColumns);
if (!path) return; if (!path) return;
if (Object.keys(valueColumns).length !== 0) {
console.log(valueColumns);
return;
}
actionRefs?.current?.reset();
let res = await doFetch({ let res = await doFetch({
url: "/ngic-base-business/paFieldScene/queryContro", url: "/ngic-base-business/paFieldScene/queryContro",
params: { params: {
...@@ -148,6 +153,9 @@ const Mtable = (props) => { ...@@ -148,6 +153,9 @@ const Mtable = (props) => {
}, },
}); });
if (res.code == "0000") { if (res.code == "0000") {
// if (res?.data?.dataList?.length == 0) {
// setvalueColumns({});
// }
//datalist:接口返回状态 //datalist:接口返回状态
let datalist = {}; let datalist = {};
res?.data?.dataList && res?.data?.dataList &&
...@@ -184,16 +192,20 @@ const Mtable = (props) => { ...@@ -184,16 +192,20 @@ const Mtable = (props) => {
}); });
setvalueColumns(allcol); setvalueColumns(allcol);
} }
actionRefs?.current?.reset(); // actionRefs?.current?.clearSelected();
// actionRefs?.current?.reload(); // actionRefs?.current?.reload();
// actionRefs?.current?.clearSelected()
}; };
//调用重新渲染表格 //调用重新渲染表格
useEffect(async () => { useEffect(async () => {
// console.log(history?.location?.pathname); // console.log(history?.location?.pathname);
await initDrage(); await initDrage();
}, [columns, extraparams, path, activeTabKey, refreshDep]); setvalueColumns({});
}, [extraparams, path, activeTabKey, refreshDep]);
// useEffect(() => {
// actionRefs?.current?.reload();
// }, [columns]);
// //
//缩放表格 //缩放表格
const handleResize = const handleResize =
......
...@@ -17,14 +17,14 @@ import moment from "moment"; ...@@ -17,14 +17,14 @@ import moment from "moment";
* 退出登录,并且将当前的 url 保存 * 退出登录,并且将当前的 url 保存
*/ */
const loginOut = async () => { const loginOut = async () => {
await fakeAccountLoginOut(); // await fakeAccountLoginOut();
const { query = {} } = history.location; // const { query = {} } = history.location;
const { redirect } = query; // Note: There may be security issues, please note // const { redirect } = query; // Note: There may be security issues, please note
if (window.location.pathname !== "/user/login" && !redirect) { // if (window.location.pathname !== "/user/login" && !redirect) {
localStorage.clear(); // localStorage.clear();
// }
history.replace("/user/login"); history.replace("/user/login");
}
}; };
const AvatarDropdown = ({ menu }) => { const AvatarDropdown = ({ menu }) => {
......
import React, { useState, useRef, useEffect } from "react"; import React, { useState, useRef, useEffect } from 'react';
import { history } from "umi"; import { history } from 'umi';
import { Scrollbars } from "react-custom-scrollbars"; import { Scrollbars } from 'react-custom-scrollbars';
import { CloseOutlined } from "@ant-design/icons"; import { CloseOutlined } from '@ant-design/icons';
import styles from "./index.less"; import styles from './index.less';
const Tags = ({ const Tags = ({ tagList, closeTag, closeAllTag, closeOtherTag, refreshTag, home }) => {
tagList,
closeTag,
closeAllTag,
closeOtherTag,
refreshTag,
home,
}) => {
const [left, setLeft] = useState(0); const [left, setLeft] = useState(0);
const [top, setTop] = useState(0); const [top, setTop] = useState(0);
const [menuVisible, setMenuVisible] = useState(false); const [menuVisible, setMenuVisible] = useState(false);
...@@ -22,20 +15,18 @@ const Tags = ({ ...@@ -22,20 +15,18 @@ const Tags = ({
useEffect(() => { useEffect(() => {
return () => { return () => {
document.body.removeEventListener("click", handleClickOutside); document.body.removeEventListener('click', handleClickOutside);
}; };
}, []); }, []);
// 由于react的state不能及时穿透到 document.body.addEventListener去,需要在每次值发送改变时进行解绑和再次监听 // 由于react的state不能及时穿透到 document.body.addEventListener去,需要在每次值发送改变时进行解绑和再次监听
useEffect(() => { useEffect(() => {
document.body.removeEventListener("click", handleClickOutside); document.body.removeEventListener('click', handleClickOutside);
document.body.addEventListener("click", handleClickOutside); document.body.addEventListener('click', handleClickOutside);
}, [menuVisible]); }, [menuVisible]);
const handleClickOutside = (event) => { const handleClickOutside = (event) => {
const isOutside = !( const isOutside = !(contextMenuRef.current && contextMenuRef.current.contains(event.target));
contextMenuRef.current && contextMenuRef.current.contains(event.target)
);
if (isOutside && menuVisible) { if (isOutside && menuVisible) {
setMenuVisible(false); setMenuVisible(false);
} }
...@@ -63,12 +54,8 @@ const Tags = ({ ...@@ -63,12 +54,8 @@ const Tags = ({
{tagList?.map?.((item, i) => ( {tagList?.map?.((item, i) => (
<div <div
key={item.path} key={item.path}
className={ className={item.active ? `${styles.item} ${styles.active}` : styles.item}
item.active ? `${styles.item} ${styles.active}` : styles.item onClick={() => history.push({ pathname: item.path, query: item.query })}
}
onClick={() =>
history.push({ pathname: item.path, query: item.query })
}
onContextMenu={(e) => openContextMenu(e, item)} onContextMenu={(e) => openContextMenu(e, item)}
> >
<span>{item.title}</span> <span>{item.title}</span>
......
import React, { useState, useEffect, useRef } from "react"; /* eslint-disable react/jsx-key */
import { RouteContext } from "@ant-design/pro-layout"; import React, { useState, useEffect, useRef, memo } from 'react';
import { history, FormattedMessage } from "umi"; import { RouteContext } from '@ant-design/pro-layout';
import Tags from "./Tags"; import { history } from 'umi';
import styles from "./index.less"; import Tags from './Tags';
import styles from './index.less';
import { Scrollbars } from 'react-custom-scrollbars';
// tree遍历
function treeForeach(tree, func) {
tree.forEach((data) => {
func(data);
data.children && treeForeach(data.children, func); // 遍历子树
});
}
/**
* @component TagView 标签页组件
*/
const TagView = ({ children, home }) => { const TagView = ({ children, home }) => {
const [tagList, setTagList] = useState([]); const [tagList, setTagList] = useState([]);
...@@ -21,24 +27,23 @@ const TagView = ({ children, home }) => { ...@@ -21,24 +27,23 @@ const TagView = ({ children, home }) => {
// 初始化 visitedViews,设置首页 // 初始化 visitedViews,设置首页
const initTags = (routeContext) => { const initTags = (routeContext) => {
// console.log(routeContext);
const { menuData } = routeContext; const { menuData } = routeContext;
if (tagList.length === 0 && menuData) { if (tagList.length === 0 && menuData) {
const firstTag = menuData.filter((el) => el.path === home)[0]; const allarr = [];
treeForeach(menuData, (node) => {
allarr.push(node);
});
const firstTag = allarr.filter((el) => el.path === location?.hash?.replace('#', ''))[0];
if (firstTag) { if (firstTag) {
const title = ( const title = firstTag.name;
<FormattedMessage
key={firstTag.name}
id={`menu.${firstTag.name}`}
defaultMessage="首页"
/>
);
const path = firstTag.path; const path = firstTag.path;
history.push({ pathname: firstTag.path, query: firstTag.query }); history.push({ pathname: firstTag.path, query: firstTag.query });
setTagList([ setTagList([
{ {
title, title,
path, path,
children: firstTag.children, children: firstTag.element,
refresh: 0, refresh: 0,
active: true, active: true,
key: firstTag.key, key: firstTag.key,
...@@ -51,6 +56,7 @@ const TagView = ({ children, home }) => { ...@@ -51,6 +56,7 @@ const TagView = ({ children, home }) => {
// 监听路由改变 // 监听路由改变
const handleOnChange = (routeContext) => { const handleOnChange = (routeContext) => {
const { currentMenu } = routeContext; const { currentMenu } = routeContext;
// console.log(tagList);
// tags初始化 // tags初始化
if (tagList.length === 0) { if (tagList.length === 0) {
return initTags(routeContext); return initTags(routeContext);
...@@ -60,9 +66,11 @@ const TagView = ({ children, home }) => { ...@@ -60,9 +66,11 @@ const TagView = ({ children, home }) => {
if (currentMenu.path) { if (currentMenu.path) {
const tagsCopy = tagList.map((item) => { const tagsCopy = tagList.map((item) => {
if (currentMenu?.path === item.path) { if (currentMenu?.path === item.path) {
//console.log(item);
hasOpen = true; hasOpen = true;
// 刷新浏览器时,重新覆盖当前 path 的 children // 刷新浏览器时,重新覆盖当前 path 的 children
return { ...item, active: true, children }; // console.log(item);
return { ...item, active: true, children: item.children };
} else { } else {
return { ...item, active: false }; return { ...item, active: false };
} }
...@@ -70,7 +78,7 @@ const TagView = ({ children, home }) => { ...@@ -70,7 +78,7 @@ const TagView = ({ children, home }) => {
// 没有该tag时追加一个,并打开这个tag页面 // 没有该tag时追加一个,并打开这个tag页面
if (!hasOpen) { if (!hasOpen) {
const title = routeContext.title || ""; const title = routeContext.title || '';
const path = currentMenu?.path; const path = currentMenu?.path;
tagsCopy.push({ tagsCopy.push({
title, title,
...@@ -80,6 +88,7 @@ const TagView = ({ children, home }) => { ...@@ -80,6 +88,7 @@ const TagView = ({ children, home }) => {
active: true, active: true,
}); });
} }
return setTagList(tagsCopy); return setTagList(tagsCopy);
} }
}; };
...@@ -89,7 +98,7 @@ const TagView = ({ children, home }) => { ...@@ -89,7 +98,7 @@ const TagView = ({ children, home }) => {
const tagsCopy = tagList.map((el, i) => ({ ...el })); const tagsCopy = tagList.map((el, i) => ({ ...el }));
// 判断关闭标签是否处于打开状态 // 判断关闭标签是否处于打开状态
tagList.forEach((el, i) => { tagList.forEach?.((el, i) => {
if (el.path === tag.path && tag.active) { if (el.path === tag.path && tag.active) {
const next = tagList[i - 1]; const next = tagList[i - 1];
next.active = true; next.active = true;
...@@ -109,23 +118,24 @@ const TagView = ({ children, home }) => { ...@@ -109,23 +118,24 @@ const TagView = ({ children, home }) => {
// 关闭其他标签 // 关闭其他标签
const handleCloseOther = (tag) => { const handleCloseOther = (tag) => {
const tagsCopy = tagList.filter( const tagsCopy = tagList.filter((el) => el.path === home || el.path === tag.path);
(el) => el.path === home || el.path === tag.path
);
history.push({ pathname: tag?.path, query: tag?.query }); history.push({ pathname: tag?.path, query: tag?.query });
setTagList(tagsCopy); setTagList(tagsCopy);
}; };
const [refresh, setrefresh] = useState(true);
// 刷新选择的标签 // 刷新选择的标签
const handleRefreshTag = (tag) => { const handleRefreshTag = async (tag) => {
const tagsCopy = tagList.map((item) => { // const tagsCopy = tagList.map((item) => {
if (item.path === tag.path) { // if (item.path === tag.path) {
history.push({ pathname: tag?.path, query: tag?.query }); // history.push({ pathname: tag?.path, query: tag?.query });
return { ...item, refresh: item.refresh + 1, active: true }; // return { ...item, refresh: item.refresh + 1, active: true };
} // }
return { ...item, active: false }; // return { ...item, active: false };
}); // });
setTagList(tagsCopy); // setTagList(tagsCopy);
await setrefresh(false);
setrefresh(true);
}; };
return ( return (
...@@ -153,16 +163,14 @@ const TagView = ({ children, home }) => { ...@@ -153,16 +163,14 @@ const TagView = ({ children, home }) => {
</div> </div>
<div className={styles.child}> <div className={styles.child}>
<div className={styles.contianbox}> <div className={styles.contianbox}>
{tagList.map((item) => { <Scrollbars
return ( thumbMinSize={10}
<div autoHide
key={item.path} style={{ width: '100%', height: '100%' }}
style={{ display: item.active ? "block" : "none" }} hideTracksWhenNotNeeded={true}
> >
<div key={item.refresh}>{item.children}</div> {refresh && children}
</div> </Scrollbars>
);
})}
</div> </div>
</div> </div>
</> </>
......
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