Commit 528265d9 authored by XieZhiXiong's avatar XieZhiXiong

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

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