修复pageTitle

This commit is contained in:
hanhh 2021-09-18 23:27:50 +08:00
parent 41ef87d9f8
commit ea44e5f209
4 changed files with 12 additions and 32 deletions

View File

@ -1,22 +0,0 @@
import { history } from 'umi';
import { request } from '@/utils/http';
import config from '@/utils/config';
const titleMap: any = {
'/': '控制面板',
'/login': '登录',
'/crontab': '定时任务',
'/env': '环境变量',
'/config': '配置文件',
'/script': '脚本管理',
'/diff': '对比工具',
'/log': '任务日志',
'/setting': '系统设置',
};
export function onRouteChange({ matchedRoutes }: any) {
if (matchedRoutes.length) {
const path: string = matchedRoutes[matchedRoutes.length - 1].route.path;
document.title = `${titleMap[path]} - 控制面板`;
}
}

View File

@ -62,9 +62,6 @@ export default {
},
],
},
location: {
pathname: '/',
},
navTheme: 'light',
fixSiderbar: true,
contentWidth: 'Fixed',

View File

@ -56,9 +56,6 @@ export default function (props: any) {
history.push('/login');
}
vhCheck();
// patch custome layout title as react node [object, object]
document.title = '控制面板';
}, []);
useEffect(() => {
@ -135,7 +132,12 @@ export default function (props: any) {
},
];
}}
pageTitleRender={() => '控制面板'}
pageTitleRender={(props, pageName, info) => {
if (info) {
return `${info.pageName} - 控制面板`;
}
return '控制面板';
}}
{...defaultProps}
>
{React.Children.map(props.children, (child) => {

View File

@ -42,7 +42,7 @@ const LangMap: any = {
const Script = ({ headerStyle, isPhone, theme }: any) => {
const [title, setTitle] = useState('请选择脚本文件');
const [value, setValue] = useState('请选择脚本文件');
const [select, setSelect] = useState<string>();
const [select, setSelect] = useState<any>();
const [data, setData] = useState<any[]>([]);
const [filterData, setFilterData] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
@ -73,8 +73,11 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
};
const onSelect = (value: any, node: any) => {
if (node.key === select || !value) {
return;
}
setValue('加载中...');
const newMode = LangMap[value.slice(-3)] || '';
const newMode = value ? LangMap[value.slice(-3)] : '';
setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode);
setSelect(value);
setTitle(node.parent || node.value);
@ -286,9 +289,9 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
treeData={filterData}
showIcon={true}
height={height}
selectedKeys={[select]}
showLine={{ showLeafIcon: true }}
onSelect={onTreeSelect}
defaultSelectedKeys={[data[0] && data[0].key]}
></Tree>
</div>
</div>