Commit 88d9c550 authored by chenshouchao's avatar chenshouchao

feat: tabs切换记住activetab 刷新也保持

parent 287ce476
...@@ -15,6 +15,7 @@ import { ThemeProvider, createTheme } from "@mui/material/styles"; ...@@ -15,6 +15,7 @@ import { ThemeProvider, createTheme } from "@mui/material/styles";
import { TabContext, TabList, TabPanel } from "@mui/lab"; import { TabContext, TabList, TabPanel } from "@mui/lab";
import { Typography } from "@mui/material"; import { Typography } from "@mui/material";
import classNames from "classnames"; import classNames from "classnames";
import { useNavigate } from "react-router-dom";
import styles from "./index.module.css"; import styles from "./index.module.css";
...@@ -46,6 +47,8 @@ interface IProps { ...@@ -46,6 +47,8 @@ interface IProps {
tabPanelSx?: any; tabPanelSx?: any;
/** 是否允许空值 */ /** 是否允许空值 */
allowNullValue?: boolean; allowNullValue?: boolean;
/** 路由地址 配合navigate和MyTabs组件的defaultValue组合使用、F5刷新也可以保存激活的tab */
navigateUrl?: string;
} }
const theme = createTheme({ const theme = createTheme({
...@@ -101,8 +104,11 @@ const Tabs = (props: IProps) => { ...@@ -101,8 +104,11 @@ const Tabs = (props: IProps) => {
tabPanelSx = { padding: "20px 0 0 0" }, tabPanelSx = { padding: "20px 0 0 0" },
title, title,
titleClass, titleClass,
navigateUrl,
} = props; } = props;
const navigate = useNavigate();
const [tabValue, setTabValue] = useState( const [tabValue, setTabValue] = useState(
defaultValue defaultValue
? defaultValue ? defaultValue
...@@ -116,6 +122,10 @@ const Tabs = (props: IProps) => { ...@@ -116,6 +122,10 @@ const Tabs = (props: IProps) => {
const onTabChange = (val: string) => { const onTabChange = (val: string) => {
setTabValue(val); setTabValue(val);
onChange && onChange(val); onChange && onChange(val);
navigateUrl &&
navigate(navigateUrl, {
state: { defaultTab: val },
});
}; };
const getImgSrc = useCallback( const getImgSrc = useCallback(
......
...@@ -499,7 +499,7 @@ const AddOperator = observer((props: IAddOperator) => { ...@@ -499,7 +499,7 @@ const AddOperator = observer((props: IAddOperator) => {
style={{ style={{
position: "absolute", position: "absolute",
fontSize: "14px", fontSize: "14px",
bottom: "7px", top: "96px",
right: "12px", right: "12px",
color: color:
Number(formData?.description?.length) >= 300 Number(formData?.description?.length) >= 300
......
...@@ -40,6 +40,7 @@ const UserResources = () => { ...@@ -40,6 +40,7 @@ const UserResources = () => {
tabList={tabList} tabList={tabList}
defaultValue={location?.state?.defaultTab || "USERRESOURCES_TEMPLATE"} defaultValue={location?.state?.defaultTab || "USERRESOURCES_TEMPLATE"}
tabPanelSx={{ padding: "0" }} tabPanelSx={{ padding: "0" }}
navigateUrl="/utility/resourceCenter/userResources"
/> />
{/* <OperatorDetails /> */} {/* <OperatorDetails /> */}
</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