mirror of
https://github.com/YMFE/yapi.git
synced 2025-03-01 14:05:44 +08:00
feat: 面包屑异步逻辑
This commit is contained in:
parent
0077b731d3
commit
b4dbf651d8
@ -1,36 +1,65 @@
|
||||
import './Breadcrumb.scss';
|
||||
import { withRouter, Link } from 'react-router-dom';
|
||||
import { Breadcrumb } from 'antd';
|
||||
// import { withRouter } from 'react-router';
|
||||
import axios from 'axios';
|
||||
import React, { Component } from 'react';
|
||||
// const breadcrumbNameMap = {
|
||||
// '/group': '分组',
|
||||
// '/apps/1': 'Application1',
|
||||
// '/apps/2': 'Application2',
|
||||
// '/apps/1/detail': 'Detail',
|
||||
// '/apps/2/detail': 'Detail'
|
||||
// };
|
||||
|
||||
@withRouter
|
||||
export default class BreadcrumbNavigation extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
// breadcrumb: [{name:'首页', path: '/'}],
|
||||
hash: '',
|
||||
breadcrumb: []
|
||||
}
|
||||
}
|
||||
getBreadcrumb = (pathSnippets) => {
|
||||
console.log(pathSnippets);
|
||||
|
||||
if (/['project'|'group'|'add-interface']/.test(pathSnippets)) {
|
||||
const type = pathSnippets[0],
|
||||
id = pathSnippets[1];
|
||||
const params = {
|
||||
type,
|
||||
id
|
||||
}
|
||||
axios.get('/user/nav', {params: params}).then( res => {
|
||||
console.log(res);
|
||||
});
|
||||
}
|
||||
}
|
||||
componentDidMount() {
|
||||
this.setState({
|
||||
hash: location.hash
|
||||
})
|
||||
}
|
||||
shouldComponentUpdate = (nextProps, nextState) => {
|
||||
// hash改变的时候才render
|
||||
if (nextState.hash !== this.state.hash) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
render () {
|
||||
// 获取接口路径并分割
|
||||
const pathSnippets = location.hash.split('#')[1].split('/').filter(i => i);
|
||||
const extraBreadcrumbItems = pathSnippets.map((_, index) => {
|
||||
const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
|
||||
this.getBreadcrumb(pathSnippets);
|
||||
const extraBreadcrumbItems = this.state.breadcrumb.map((item, index) => {
|
||||
// const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
|
||||
console.log(index);
|
||||
return (
|
||||
<Breadcrumb.Item key={url}>
|
||||
<Link to={url}>
|
||||
{url}
|
||||
<Breadcrumb.Item key={item.path}>
|
||||
<Link to={item.path}>
|
||||
{item.name}
|
||||
</Link>
|
||||
</Breadcrumb.Item>
|
||||
);
|
||||
});
|
||||
const breadcrumbItems = [(
|
||||
<Breadcrumb.Item key="home">
|
||||
<Link to="/">Home</Link>
|
||||
<Link to="/">首页</Link>
|
||||
</Breadcrumb.Item>
|
||||
)].concat(extraBreadcrumbItems);
|
||||
if (pathSnippets.length) {
|
||||
|
Loading…
Reference in New Issue
Block a user