|
@@ -1,14 +1,17 @@
|
|
|
-import React from 'react';
|
|
|
+import React,{useEffect,useState} from 'react';
|
|
|
import { Settings as LayoutSettings, PageLoading } from '@ant-design/pro-layout';
|
|
|
import {message, notification} from 'antd';
|
|
|
import qs from 'qs';
|
|
|
-import { history, RequestConfig, RunTimeLayoutConfig } from 'umi';
|
|
|
+import { history, RequestConfig, RunTimeLayoutConfig, ErrorShowType } from 'umi';
|
|
|
import RightContent from '@/components/RightContent';
|
|
|
import Footer from '@/components/Footer';
|
|
|
import { ResponseError } from 'umi-request';
|
|
|
-import { queryCurrent } from './services/user';
|
|
|
+import {
|
|
|
+ queryCurrent,
|
|
|
+ selectNavList
|
|
|
+} from './services/user';
|
|
|
import defaultSettings from '../config/defaultSettings';
|
|
|
-import cookies from 'js-cookie';
|
|
|
+import DataTable from "@/components/common/DataTable";
|
|
|
|
|
|
/**
|
|
|
* 获取用户信息比较慢的时候会展示一个 loading
|
|
@@ -21,6 +24,7 @@ export async function getInitialState(): Promise<{
|
|
|
settings?: LayoutSettings;
|
|
|
currentUser?: API.CurrentUser;
|
|
|
fetchUserInfo?: () => Promise<API.CurrentUser | undefined>;
|
|
|
+ fetchNavList?: () => Promise<API.CurrentUser | undefined>;
|
|
|
}> {
|
|
|
const fetchUserInfo = async () => {
|
|
|
try {
|
|
@@ -32,17 +36,30 @@ export async function getInitialState(): Promise<{
|
|
|
}
|
|
|
return undefined;
|
|
|
};
|
|
|
+ const fetchNavList = async () => {
|
|
|
+ try {
|
|
|
+ const currentNavList = await selectNavList();
|
|
|
+ return currentNavList.data;
|
|
|
+ } catch (error) {
|
|
|
+ history.push('/user/login');
|
|
|
+ }
|
|
|
+ return undefined;
|
|
|
+ };
|
|
|
// 如果是登录页面,不执行
|
|
|
if (history.location.pathname !== '/user/login') {
|
|
|
const currentUser = await fetchUserInfo();
|
|
|
+ const currentNavList = await fetchNavList();
|
|
|
return {
|
|
|
fetchUserInfo,
|
|
|
+ fetchNavList,
|
|
|
currentUser,
|
|
|
+ currentNavList,
|
|
|
settings: defaultSettings,
|
|
|
};
|
|
|
}
|
|
|
return {
|
|
|
fetchUserInfo,
|
|
|
+ fetchNavList,
|
|
|
settings: defaultSettings,
|
|
|
};
|
|
|
}
|
|
@@ -59,6 +76,24 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
|
|
|
history.push('/user/login');
|
|
|
}
|
|
|
},
|
|
|
+ menuDataRender: (menuData)=>{
|
|
|
+ console.debug(initialState)
|
|
|
+ if(initialState.currentNavList && initialState.currentNavList.length>0){
|
|
|
+ return [{
|
|
|
+ name: 'list.table-list',
|
|
|
+ icon: 'table',
|
|
|
+ path: '/order',
|
|
|
+ component: './Order/Billing',
|
|
|
+ },{
|
|
|
+ path: '/welcome',
|
|
|
+ name: 'welcome',
|
|
|
+ icon: 'smile',
|
|
|
+ hideInMenu: true,
|
|
|
+ component: './Welcome',
|
|
|
+ }]
|
|
|
+ }
|
|
|
+ return [];
|
|
|
+ },
|
|
|
menuHeaderRender: undefined,
|
|
|
// 自定义 403 页面
|
|
|
// unAccessible: <div>unAccessible</div>,
|
|
@@ -66,25 +101,6 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
-const codeMessage = {
|
|
|
- 200: '服务器成功返回请求的数据。',
|
|
|
- 201: '新建或修改数据成功。',
|
|
|
- 202: '一个请求已经进入后台排队(异步任务)。',
|
|
|
- 204: '删除数据成功。',
|
|
|
- 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
|
|
|
- 401: '用户没有权限(令牌、用户名、密码错误)。',
|
|
|
- 403: '用户得到授权,但是访问是被禁止的。',
|
|
|
- 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
|
|
|
- 405: '请求方法不被允许。',
|
|
|
- 406: '请求的格式不可得。',
|
|
|
- 410: '请求的资源被永久删除,且不会再得到的。',
|
|
|
- 422: '当创建一个对象时,发生一个验证错误。',
|
|
|
- 500: '服务器发生错误,请检查服务器。',
|
|
|
- 502: '网关错误。',
|
|
|
- 503: '服务不可用,服务器暂时过载或维护。',
|
|
|
- 504: '网关超时。',
|
|
|
-};
|
|
|
-
|
|
|
/**
|
|
|
* 异常处理程序
|
|
|
* {
|
|
@@ -107,12 +123,6 @@ const codeMessage = {
|
|
|
const errorHandler = (error: ResponseError) => {
|
|
|
const { info } = error;
|
|
|
if (error.name === 'BizError') {
|
|
|
- // const { errorCode } = info;
|
|
|
- // notification.warning({
|
|
|
- // message: `请求错误`,
|
|
|
- // description: '111111',
|
|
|
- // });
|
|
|
- console.log(info)
|
|
|
if(info.errorCode === '403'){
|
|
|
message.warning('登录超时请重新登录');
|
|
|
history.push('/user/login');
|
|
@@ -132,19 +142,18 @@ const errorHandler = (error: ResponseError) => {
|
|
|
export const request: RequestConfig = {
|
|
|
errorHandler,
|
|
|
errorConfig: {
|
|
|
- adaptor: (resData)=>{
|
|
|
- console.log(resData,'resData')
|
|
|
+ adaptor: (resData,ctx)=>{
|
|
|
return {
|
|
|
success: resData.error && resData.error.length === 0,
|
|
|
- data: resData.data || null,
|
|
|
+ data: resData.error || null,
|
|
|
errorCode: (resData.error && resData.error.length > 0) ? resData.error[0].field : 0,
|
|
|
errorMessage: (resData.error && resData.error.length > 0) ? resData.error[0].message : '',
|
|
|
- showType: (resData.error && resData.error.length > 0) ? (resData.error[0].field === '403' ? 9 : 2) : 0,
|
|
|
- traceId: '-1',
|
|
|
- host: '-1',
|
|
|
+ showType: (resData.error && resData.error.length > 0) ? (resData.error[0].field === '403' ? ErrorShowType.REDIRECT : ErrorShowType.ERROR_MESSAGE) : 0,
|
|
|
+ traceId: ctx.res ? ctx.res.token : '',
|
|
|
+ host: ctx.req ? ctx.req.originUrl : '-1',
|
|
|
};
|
|
|
},
|
|
|
- errorPage: '/user/login', //showType为9是跳这个地址
|
|
|
+ errorPage: '/user/login', // showType为9是跳这个地址
|
|
|
},
|
|
|
requestInterceptors: [
|
|
|
(url, config) => {
|
|
@@ -171,7 +180,6 @@ export const request: RequestConfig = {
|
|
|
responseInterceptors: [
|
|
|
async (config) => {
|
|
|
return config;
|
|
|
-
|
|
|
}
|
|
|
]
|
|
|
};
|