剧场模式
首页前后端分离ReactUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程

UmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #5 关于 footer 和 layout

海外散仙厉飞雨 · 真仙发布于
0

https://pro.ant.design/docs/environment-variables-cn

https://umijs.org/zh/guide/env-variables.html#mock

https://umijs.org/zh/guide/app-structure.html#src

/**
 * Ant Design Pro v4 use `@ant-design/pro-layout` to handle Layout.
 * You can view component api by:
 * https://github.com/ant-design/ant-design-pro-layout
 */

import ProLayout, {
  MenuDataItem,
  BasicLayoutProps as ProLayoutProps,
  Settings,
  DefaultFooter,
} from '@ant-design/pro-layout';
import React, { useEffect } from 'react';
import Link from 'umi/link';
import { connect } from 'dva';
import { formatMessage } from 'umi-plugin-react/locale';

import Authorized from '@/utils/Authorized';
import RightContent from '@/components/GlobalHeader/RightContent';
import { ConnectState, Dispatch } from '@/models/connect';
import { isAntDesignPro } from '@/utils/utils';
import logo from '@/assets/logo.png';

export interface BasicLayoutProps extends ProLayoutProps {
  breadcrumbNameMap: {
    [path: string]: MenuDataItem;
  };
  settings: Settings;
  dispatch: Dispatch;
}
export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & {
  breadcrumbNameMap: {
    [path: string]: MenuDataItem;
  };
};

/**
 * use Authorized check all menu item
 */
const menuDataRender = (menuList: MenuDataItem[]): MenuDataItem[] =>
  menuList.map(item => {
    const localItem = {
      ...item,
      children: item.children ? menuDataRender(item.children) : [],
    };
    return Authorized.check(item.authority, localItem, null) as MenuDataItem;
  });

const links = [
  {
    key: 'qiuzhi99',
    title: 'qiuzhi99',
    href: 'https://pro.ant.design',
    blankTarget: true,
  },
  {
    key: 'Ant Design',
    title: 'Ant Design',
    href: 'https://ant.design',
    blankTarget: true,
  },
];

const copyright = '汕尾求知科技有限公司';

const footerRender: BasicLayoutProps['footerRender'] = (_, defaultDom) => {
  if (!isAntDesignPro()) {
    return (
      <>
        <DefaultFooter links={links} copyright={copyright} />
      </>
    );
  }
  return (
    <>
      {defaultDom}
      <div
        style={{
          padding: '0px 24px 24px',
          textAlign: 'center',
        }}
      >
        <a href="https://www.netlify.com" target="_blank" rel="noopener noreferrer">
          <img
            src="https://www.netlify.com/img/global/badges/netlify-color-bg.svg"
            width="82px"
            alt="netlify logo"
          />
        </a>
      </div>
    </>
  );
};

const BasicLayout: React.FC<BasicLayoutProps> = props => {
  const { dispatch, children, settings } = props;
  /**
   * constructor
   */

  useEffect(() => {
    if (dispatch) {
      dispatch({
        type: 'user/fetchCurrent',
      });
      dispatch({
        type: 'settings/getSetting',
      });
    }
  }, []);

  /**
   * init variables
   */
  const handleMenuCollapse = (payload: boolean): void =>
    dispatch &&
    dispatch({
      type: 'global/changeLayoutCollapsed',
      payload,
    });

  return (
    <ProLayout
      logo={logo}
      onCollapse={handleMenuCollapse}
      menuItemRender={(menuItemProps, defaultDom) => {
        if (menuItemProps.isUrl) {
          return defaultDom;
        }
        return <Link to={menuItemProps.path}>{defaultDom}</Link>;
      }}
      breadcrumbRender={(routers = []) => [
        {
          path: '/',
          breadcrumbName: formatMessage({
            id: 'menu.home',
            defaultMessage: 'Home',
          }),
        },
        ...routers,
      ]}
      itemRender={(route, params, routes, paths) => {
        const first = routes.indexOf(route) === 0;
        return first ? (
          <Link to={paths.join('/')}>{route.breadcrumbName}</Link>
        ) : (
          <span>{route.breadcrumbName}</span>
        );
      }}
      footerRender={footerRender}
      menuDataRender={menuDataRender}
      formatMessage={formatMessage}
      rightContentRender={rightProps => <RightContent {...rightProps} />}
      {...props}
      {...settings}
    >
      {children}
    </ProLayout>
  );
};

export default connect(({ global, settings }: ConnectState) => ({
  collapsed: global.collapsed,
  settings,
}))(BasicLayout);
3 条回复
  • netNowork · 金仙巅峰

    哦哦哦,来了来了, 学学学!

  • netNowork · 金仙巅峰
    /**
     * Ant Design Pro v4 use `@ant-design/pro-layout` to handle Layout.
     * You can view component api by:
     * https://github.com/ant-design/ant-design-pro-layout
     */
    import ProLayout, { DefaultFooter } from '@ant-design/pro-layout';
    // 用js的朋友需要注意一下这里可能跟用ts 的导入方式不同 在外部导入 , { DefaultFooter }
    
    import React, { useEffect, useState } from 'react';
    import Link from 'umi/link';
    import { connect } from 'dva';
    import { formatMessage } from 'umi-plugin-react/locale';
    import Authorized from '@/utils/Authorized';
    import RightContent from '@/components/GlobalHeader/RightContent';
    import { isAntDesignPro } from '@/utils/utils';
    import logo from '../assets/logo.png';
    
    // import { Icon, Layout } from 'antd';
    // import GlobalFooter from '@ant-design/pro-layout/lib/GlobalFooter';
    
    // const { Footer } = Layout;
    /**
     * use Authorized check all menu item
     */
    const menuDataRender = menuList =>
      menuList.map(item => {
        const localItem = { ...item, children: item.children ? menuDataRender(item.children) : [] };
        return Authorized.check(item.authority, localItem, null);
      });
    
    const defaultLinks = [
      {
        key: 'tile',
        title: 'tile',
        href: 'url',
        blankTarget: true,
      },
      {
        key: 'title',
        title: 'title',
        href: 'url',
        blankTarget: true,
      },
    ];
    const defaultCopyright = '写上你的footer';
    
    const footerRender = (_, defaultDom) => {
      if (!isAntDesignPro()) {
        return (
          <>
            <DefaultFooter
              links={defaultLinks} //进行绑定``` javascript
    
    
          copyright={defaultCopyright} //进行绑定
        />
      </>
    );
    

    }

    return (
    <>
    {defaultDom}





    </>
    );
    };

    const BasicLayout = props => {
    const { dispatch, children, settings } = props;
    /**

    • constructor */

    useEffect(() => {
    if (dispatch) {
    dispatch({
    type: 'user/fetchCurrent',
    });
    dispatch({
    type: 'settings/getSetting',
    });
    }
    }, []);
    /**

    • init variables */

    const handleMenuCollapse = payload =>
    dispatch &&
    dispatch({
    type: 'global/changeLayoutCollapsed',
    payload,
    });

    const [menuData, setMenuData] = useState([]);
    useEffect(() => {
    fetch('https://api.1km.im/jychannel/sel')
    .then(response => response.json())
    .then(data => {
    setMenuData(data.list || []);
    });
    }, []);

    return (
    {
    if (menuItemProps.isUrl) {
    return defaultDom;
    }

        return <Link to={menuItemProps.path}>{defaultDom}</Link>;
      }}
      breadcrumbRender={(routers = []) => [
        {
          path: '/',
          breadcrumbName: formatMessage({
            id: 'menu.home',
            defaultMessage: 'Home',
          }),
        },
        ...routers,
      ]}
      itemRender={(route, params, routes, paths) => {
        const first = routes.indexOf(route) === 0;
        return first ? (
          <Link to={paths.join('/')}>{route.breadcrumbName}</Link>
        ) : (
          <span>{route.breadcrumbName}</span>
        );
      }}
      footerRender={footerRender}
      menuDataRender={() => menuData}
      formatMessage={formatMessage}
      rightContentRender={rightProps => <RightContent {...rightProps} />}
      {...props}
      {...settings}
    >
      {children}
    </ProLayout>
    

    );
    };

    export default connect(({ global, settings }) => ({
    collapsed: global.collapsed,
    settings,
    }))(BasicLayout);

  • netNowork · 金仙巅峰

    上面是错误的 ❌,不用模仿了 导入的时候注意一下就好了,

小程序(beta)
课程目录

1FreeUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #1 开始玩起来

2FreeUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #2 了解项目源码并尝试修改

3FreeUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #3 继续了解项目源码并修改代码

4FreeUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #4 如何修改 footer 及其原理

FreeUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #5 关于 footer 和 layout

6ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #6 如何好好利用 ant-design-pro-layout

7ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #7 如何下载和使用区块

8ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #8 为什么下载区块后会添加菜单

9ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #9 umi-plugin-pro-block-ts

10ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #10 删除国际化 i18n part 1

11ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #11 删除国际化 i18n part 2

12ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #12 用户注册的 block

13ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #13 让用户注册工作起来

14ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #14 注册的流程理解

15ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #15 准备好 API

16ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #16 对接好后端的注册功能

17ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #17 表单的前端验证与后端验证

18ProUmiJS & TypeScript & Ant Design Pro v4 从零开始实战教程 #18 后端的数据验证与前端的结合

学员
这家伙真懒丶 · 太乙玉仙ShuWangSam · 金仙后期zhangxuanhtml5 · 真仙979164900 · 真仙guxiaobai · 道祖bluesky160 · 金仙后期swdcode · 真仙521707 · 真仙szy0syz · 金仙后期阿白 · 真仙pijunhuis · 金仙巅峰no_heart · 金仙后期华仔 · 真仙刘小帅 · 真仙从前明月光 · 真仙qianyaqun · 真仙Ming · 太乙玉仙KaierChou · 大罗李忠 · 金仙巅峰oldtimestj · 金仙后期yangy_11 · 金仙后期winds · 金仙后期deliphi · 真仙hanruiying · 道祖luz · 真仙李卓 · 真仙wlison123 · 真仙18361082737 · 太乙巅峰Jonathan · 真仙oldwolf · 真仙wlccgp3 · 真仙leeruigan · 金仙后期Fu.H · 真仙尹迪 · 金仙后期cc20140820 · 真仙huangqiangqiang · 真仙꧁Cheri꧂ · 真仙     · 金仙后期xawn10917 · 真仙itMyron · 道祖chaosJS · 真仙靓狼仔 · 太乙玉仙wjm0913 · 大罗yxxwym · 真仙漫长 · 金仙巅峰二木三水一州 · 真仙凉风ToT · 真仙范特西的范 · 真仙heiy · 大罗cometjun · 道祖liuhao0813 · 真仙MDZZh · 真仙zenkun · 大罗qwer630701 · 真仙zhichaoren · 大罗巅峰studytm · 太乙玉仙yeziahehe · 真仙suheme · 真仙wuhua · 大罗shaohuatsou · 金仙巅峰Hichank · 真仙OOM · 大罗气体销售 · 金仙巅峰frank · 太乙玉仙南国 · 真仙CRAZY · 真仙Sen0118 · 真仙lolotang · 真仙唐志龙 · 真仙netNowork · 金仙巅峰gangpu · 真仙
最新动态
这家伙真懒丶 · 太乙玉仙学习到了7:44
ShuWangSam · 金仙后期学习到了1:23
zhangxuanhtml5 · 真仙学习到了7:45
979164900 · 真仙学习到了7:42
guxiaobai · 道祖学习到了0:01

© 汕尾市求知科技有限公司 | 粤ICP备19038915号 | 在线学员:88

Top