You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
2.6 KiB
105 lines
2.6 KiB
/* eslint-disable import/no-dynamic-require */
|
|
/* eslint-disable global-require */
|
|
/* eslint-disable no-param-reassign */
|
|
import { getMenu, getMenuForList, leaveCheckNewsDraft } from '@/service/common';
|
|
import { localStorage } from 'js-storage';
|
|
import RightContent from './components/RightContent';
|
|
import { history } from 'umi';
|
|
import dayjs from 'dayjs';
|
|
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
import localeData from 'dayjs/plugin/localeData';
|
|
import weekday from 'dayjs/plugin/weekday';
|
|
import weekOfYear from 'dayjs/plugin/weekOfYear';
|
|
import weekYear from 'dayjs/plugin/weekYear';
|
|
|
|
dayjs.extend(customParseFormat);
|
|
dayjs.extend(advancedFormat);
|
|
dayjs.extend(weekday);
|
|
dayjs.extend(localeData);
|
|
dayjs.extend(weekOfYear);
|
|
dayjs.extend(weekYear);
|
|
|
|
// import * as icons from '@ant-design/icons';
|
|
|
|
// 刷新时判断是否离开新闻详情页 用于解锁新闻详情的编辑
|
|
|
|
async function leaveCheckNews(params) {
|
|
const checkNewsId = localStorage.get('checkNewsId');
|
|
if (checkNewsId) {
|
|
await leaveCheckNewsDraft({ id: checkNewsId });
|
|
localStorage.remove('checkNewsId');
|
|
}
|
|
}
|
|
|
|
leaveCheckNews();
|
|
|
|
function covertRoutes(list) {
|
|
list.forEach((element) => {
|
|
const {
|
|
path,
|
|
hidden,
|
|
meta: { title },
|
|
children,
|
|
} = element;
|
|
Object.assign(element, {
|
|
path,
|
|
name: title,
|
|
hideInMenu: hidden,
|
|
// icon: (() => {
|
|
// const Icon = icons[icon];
|
|
// if (Icon) {
|
|
// return <Icon />;
|
|
// }
|
|
// return null;
|
|
// })(),
|
|
routes: children,
|
|
exact: !children?.length,
|
|
});
|
|
if (element.routes) {
|
|
covertRoutes(element.routes);
|
|
}
|
|
});
|
|
}
|
|
|
|
export async function getInitialState() {
|
|
const store = localStorage.get('user');
|
|
const resp = await getMenuForList();
|
|
if (resp) {
|
|
const { menus, apis } = resp;
|
|
return {
|
|
menus,
|
|
...store,
|
|
apis: apis?.map((item) => `${item.path}|${item.method}`),
|
|
};
|
|
}
|
|
return {};
|
|
}
|
|
|
|
export const layout = ({ initialState }) => {
|
|
const { token } = initialState;
|
|
return {
|
|
rightContentRender: () => <RightContent />,
|
|
onPageChange: () => {
|
|
const { location } = history;
|
|
if (!token && location.pathname !== '/login') {
|
|
history.push('/login');
|
|
}
|
|
},
|
|
menu: {
|
|
params: {
|
|
token,
|
|
},
|
|
request: async () => {
|
|
// initialState.currentUser 中包含了所有用户信息
|
|
let menuData = [];
|
|
const resp = await getMenu();
|
|
if (resp) {
|
|
menuData = resp.menus;
|
|
}
|
|
covertRoutes(menuData);
|
|
return menuData;
|
|
},
|
|
},
|
|
};
|
|
};
|
|
|