Commit 528265d9 authored by XieZhiXiong's avatar XieZhiXiong

feat: 添加 onBack 自定义返回事件

parent 13aa9fff
......@@ -40,6 +40,10 @@ interface IProps {
* 自定义样式
*/
customStyle?: React.CSSProperties,
/**
* 自定义返回事件
*/
onBack?: () => void,
children?: React.ReactNode,
}
......@@ -50,6 +54,7 @@ const AnchorPage: React.FC<IProps> = (props: IProps) => {
extra,
anchors,
customStyle,
onBack,
children,
} = props;
const firstKey = anchors.length ? `#${anchors[0].key}` : '';
......@@ -57,6 +62,10 @@ const AnchorPage: React.FC<IProps> = (props: IProps) => {
const [rect, measuredRef] = useClientRect();
const handleBack = () => {
if (onBack) {
onBack();
return;
}
history.goBack();
};
......@@ -81,7 +90,6 @@ const AnchorPage: React.FC<IProps> = (props: IProps) => {
>
<div
className={styles['anchor-page-header']}
style={customStyle}
ref={measuredRef}
>
<Anchor
......@@ -132,6 +140,7 @@ const AnchorPage: React.FC<IProps> = (props: IProps) => {
AnchorPage.defaultProps = {
extra: null,
customStyle: {},
onBack: undefined,
children: null,
};
......
......@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2021-01-06 11:36:35
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-05-20 13:54:45
* @LastEditTime: 2021-05-24 10:12:09
* @Description:
*/
import React, { useState, useEffect } from 'react';
......@@ -74,7 +74,7 @@ const MemberMaintainDetailed: React.FC<QueryProps> = props => {
getBasicInfo();
}, []);
const handleTabChange = (val: string) => {
const handleBookmarkChange = (val: string) => {
const { match } = props;
const url = match.url === '/' ? '' : match.url;
switch (val) {
......@@ -95,20 +95,20 @@ const MemberMaintainDetailed: React.FC<QueryProps> = props => {
}
};
const getTabKey = () => {
const getBookmarkKey = () => {
const { match, location } = props;
const url = match.path === '/' ? '' : match.path;
const tabKey = location.pathname.replace(`${url}/`, '');
if (tabKey && tabKey !== '/') {
return tabKey;
const markKey = location.pathname.replace(`${url}/`, '');
if (markKey && markKey !== '/') {
return markKey;
}
return 'basicInfo';
};
const getAnchorsArr = () => {
const tabKey = getTabKey();
const markKey = getBookmarkKey();
let ret = [];
switch (tabKey) {
switch (markKey) {
case 'basicInfo':
ret = [
{
......@@ -209,9 +209,10 @@ const MemberMaintainDetailed: React.FC<QueryProps> = props => {
)}
/>
)}
onBack={() => history.push(`/memberCenter/memberAbility/manage/maintain`)}
anchors={getAnchorsArr()}
extra={(
<Bookmark value={getTabKey()} onChange={handleTabChange}>
<Bookmark value={getBookmarkKey()} onChange={handleBookmarkChange}>
<Bookmark.Item value="basicInfo" title="基本信息" icon={<UnorderedListOutlined />} />
<Bookmark.Item value="2" title="档案信息" icon={<FolderOutlined />} />
<Bookmark.Item value="levelInfo" title="等级信息" icon={<BarChartOutlined />} />
......
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