import React from 'react';
import { connect } from 'dva';
import { FolderOpen, File, DeleteFilled } from '@ant-design/icons';
import { Button, Popconfirm } from 'antd';
import './ui.css';
import model from './model';
const Routes = connect(state => ({
routes: state.routes,
}))(props => {
function renderRoutes(routes) {
return (
{routes.map((route, i) => {
if (!route.path) return null;
const keys = Object.keys(route).filter(key => {
if (['exact', 'routes', 'component'].includes(key)) return false;
if (key.charAt(0) === '_') return false;
return true;
});
function getValue(key) {
if (key === 'path') {
return {route[key]};
}
return route[key];
}
return (
-
{route.routes ? (
) : (
)}
{keys.map((key, i) => (
{key}:
{getValue(key)}
{i === keys.length - 1 ? '' : , }
))}
{/*
*/}
{
window.send('rm', ['page', route.component]);
}).bind(null, route)}
>
{route.routes ? renderRoutes(route.routes) : null}
);
})}
);
}
return (
{renderRoutes(props.routes.data)}
);
});
export default api => {
api.addPanel({
title: 'Routes Manager',
path: '/routes',
component: Routes,
models: [model],
});
};