HW 4 年之前
父节点
当前提交
8a048cc378

+ 0 - 33
config/routes.ts

@@ -21,39 +21,6 @@
     icon: 'smile',
     component: './Welcome',
   },
-  // {
-  //   path: '/admin',
-  //   name: 'admin',
-  //   icon: 'crown',
-  //   access: 'canAdmin',
-  //   component: './Admin',
-  //   routes: [
-  //     {
-  //       path: '/admin/sub-page',
-  //       name: 'sub-page',
-  //       icon: 'smile',
-  //       component: './Welcome',
-  //     },
-  //   ],
-  // },
-  // {
-  //   name: 'list.table-list',
-  //   icon: 'table',
-  //   path: '/',
-  //   routes: [
-  //     {
-  //       name: 'list.table-list',
-  //       path: '/',
-  //       routes: [
-  //         {
-  //           name: 'list.table-list',
-  //           path: '/order',
-  //           component: './Order/Billing',
-  //         }
-  //       ]
-  //     }
-  //   ],
-  // },
   {
     name: 'list.table-list',
     icon: 'table',

+ 0 - 1
package.json

@@ -53,7 +53,6 @@
     "@umijs/route-utils": "^1.0.33",
     "antd": "^4.8.6",
     "classnames": "^2.2.6",
-    "js-cookie": "^2.2.1",
     "lodash": "^4.17.11",
     "moment": "^2.25.3",
     "omit.js": "^2.0.2",

+ 1 - 1
src/access.ts

@@ -2,6 +2,6 @@
 export default function access(initialState: { currentUser?: API.CurrentUser | undefined }) {
   const { currentUser } = initialState || {};
   return {
-    canAdmin: currentUser && currentUser.access === 'admin',
+    canAdmin: false,
   };
 }

+ 45 - 37
src/app.tsx

@@ -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;
-
     }
   ]
 };

+ 10 - 12
src/components/common/DataTable/index.tsx

@@ -1,6 +1,6 @@
 import React, { useRef } from 'react';
 import ProTable, { ActionType } from '@ant-design/pro-table';
-import request from 'umi-request';
+import { request } from 'umi';
 
 export interface DataTable {
   toolBarRender?: object;           // 表格操作栏
@@ -36,22 +36,20 @@ const DataTable: React.FC<DataTable> =  React.forwardRef((props, ref) => {
       actionRef={ref}
       params={props.params || {}}
       request={async (params = {}) =>{
-          params.pageNo = params.current;
-          delete params.current;
-          const msg = await request(props.url, {
-            params: props.requestProcess?props.requestProcess(params):params,
-          });
-          console.log(msg,'msg')
-          if(msg.error.length > 0){
-            return {
-              success: false,
-            };
-          }else{
+          try {
+            params.pageNo = params.current;
+            delete params.current;
+            const msg = await request(props.url, {
+              params: props.requestProcess?props.requestProcess(params):params,
+            });
             return {
               data: msg.data.list,
               success: true,
               total: msg.data.totalCount,
             };
+          }catch (error){
+            console.debug(error)
+            return {success: false};
           }
         }
       }

+ 1 - 0
src/pages/Order/Billing/components/createOrder.jsx

@@ -64,6 +64,7 @@ class CreateOrder extends Component{
     const msg = await createOrder(this.state.uid,v.orderType);
     if(msg.error.length === 0){
       message.success('创建成功');
+      this.props.dataTableRef.current && this.props.dataTableRef.current.reload();// 刷新列表
       return true;
     }else{
       message.info(msg.error[0].message)

+ 4 - 4
src/pages/Order/Billing/index.jsx

@@ -302,12 +302,12 @@ class Billing extends Component{
 
   // 结项
   async delectRow(orderNo,action) {
-    const msg = await getFakeCaptcha(orderNo);
-    if(msg.error.length === 0){
+    try {
+      await getFakeCaptcha(orderNo);
       message.success("该项目已成功结项!");
       action.reload();
-    }else{
-      message.info(msg.error[0].message)
+    }catch (error){
+      console.debug(error)
     }
   }
 

+ 1 - 1
src/pages/user/login/index.tsx

@@ -69,7 +69,7 @@ const Login: React.FC<{}> = () => {
       await fetchUserInfo();
       goto();
     } catch (error) {
-      console.log(error)
+      console.log(error,'error')
       // 如果失败去设置用户错误信息
       setUserLoginState({
         status: 'error',

+ 7 - 0
src/services/user.ts

@@ -11,6 +11,13 @@ export async function queryCurrent() {
   });
 }
 
+// 获得当前用户能看到的页面
+export async function selectNavList() {
+  return request<API.CurrentUser>('/api/admin/selectNavList',{
+    method: 'get',
+  });
+}
+
 export async function queryNotices(): Promise<any> {
   return request<{ data: API.NoticeIconData[] }>('/api/notices');
 }