1、更换 Ant Design Pro 的 logo 和名称

image.png
需要修改文件所在位置:/config/defaultSetting.js

  1. const proSettings: DefaultSettings = {
  2. navTheme: 'dark',
  3. // 拂晓蓝
  4. primaryColor: '#1890ff',
  5. layout: 'side',
  6. contentWidth: 'Fluid',
  7. fixedHeader: false,
  8. fixSiderbar: true,
  9. colorWeak: false,
  10. title: '青锋后台系统',
  11. pwa: false,
  12. iconfontUrl: '',
  13. menu: {
  14. locale: false,
  15. },
  16. };

将其中的 title 改成公司的项目名称即可。

2、清除头部不必要的小组件

image.png
文件所在位置:src/components/GlobalHeader/RightContent.js

  1. return (
  2. <div className={className}>
  3. {/* <HeaderSearch
  4. className={`${styles.action} ${styles.search}`}
  5. placeholder="站内搜索"
  6. defaultValue="umi ui"
  7. options={[
  8. { label: <a href="https://umijs.org/zh/guide/umi-ui.html">umi ui</a>, value: 'umi ui' },
  9. {
  10. label: <a href="next.ant.design">Ant Design</a>,
  11. value: 'Ant Design',
  12. },
  13. {
  14. label: <a href="https://protable.ant.design/">Pro Table</a>,
  15. value: 'Pro Table',
  16. },
  17. {
  18. label: <a href="https://prolayout.ant.design/">Pro Layout</a>,
  19. value: 'Pro Layout',
  20. },
  21. ]}
  22. // onSearch={value => {
  23. // //console.log('input', value);
  24. // }}
  25. /> */}
  26. <Tooltip title="使用文档">
  27. <a
  28. style={{
  29. color: 'inherit',
  30. }}
  31. target="_blank"
  32. href="https://pro.ant.design/docs/getting-started"
  33. rel="noopener noreferrer"
  34. className={styles.action}
  35. >
  36. <QuestionCircleOutlined />
  37. </a>
  38. </Tooltip>
  39. <Avatar />
  40. {REACT_APP_ENV && (
  41. <span>
  42. <Tag color={ENVTagColor[REACT_APP_ENV]}>{REACT_APP_ENV}</Tag>
  43. </span>
  44. )}
  45. <SelectLang className={styles.action} />
  46. </div>
  47. );

HeaderSearchTooltipNoticeIconHeaderDropdownSelectLang 它们分别代表 “全局搜索”、”使用文档”、”消息通知框”、”用户信息”、”国际化切换”,将不需要的内容注释掉即可。

3、更换地址栏图标

image.png
文件所在位置:/public/favicon.ico
制作自己的地址图标进行替换即可。
在线制作ico图标地址:https://www.bitbug.net/
大家可以根据自己的实际情况制作自己的地址图标即可。
替换后依然没有起作用。这是有缓存的问题,解决办法:重启浏览器,或者重启一下本地服务器(npm start)即可。

4、配置代理服务

如果我们不再使用mock 中的预设数据,就须通过 API 向后端获取相关数据。这时会碰到一个棘手的问题—同源策略。跨域用通俗的讲,浏览器不能跨域名访问别的网站获取数据。目前有两种解决方案:
第一种方案:
跨域是存在浏览器与浏览器之间的。所以知道这层概念之后,我可以走这种流程:浏览器->本地服务器->远程服务器。Ant Design Pro 也暖心的帮我们提供了跨域的配置项,那我们在那里设置呢?
位置:/config/proxy.ts

  1. /**
  2. * 在生产环境 代理是无法生效的,所以这里没有生产环境的配置
  3. * The agent cannot take effect in the production environment
  4. * so there is no configuration of the production environment
  5. * For details, please see
  6. * https://pro.ant.design/docs/deploy
  7. */
  8. export default {
  9. dev: {
  10. '/api/': {
  11. target: 'http://localhost:8301',
  12. changeOrigin: true,
  13. pathRewrite: { '^/api': '' },
  14. },
  15. },
  16. test: {
  17. '/api/': {
  18. target: 'http://localhost:8301',
  19. changeOrigin: true,
  20. pathRewrite: { '^/api': '' },
  21. },
  22. },
  23. pre: {
  24. '/api/': {
  25. target: 'http://localhost:8301',
  26. changeOrigin: true,
  27. pathRewrite: { '^/api': '' },
  28. },
  29. },
  30. };

image.png
跨域问题,也可以在服务器后端解决的。
使用注解@CrossOrigin(局部跨域)

  1. @Controller
  2. @RequestMapping("/shop")
  3. @CrossOrigin(originPatterns = "*", methods = {RequestMethod.GET, RequestMethod.POST})
  4. public class ShopController {
  5. @GetMapping("/")
  6. @ResponseBody
  7. public Map<String, Object> findAll() {
  8. //返回数据
  9. return DataSchool.getStudents();
  10. }
  11. }

5、关闭 Ant Design Pro 国际化

在我们配置菜单模块时,会时常遇到一个强大 Ant Design Pro 的功能—-国际化。但是如果不需要可以关闭掉。
文件所在位置:/src/defaultSetting.ts

  1. const proSettings: DefaultSettings = {
  2. navTheme: 'dark',
  3. // 拂晓蓝
  4. primaryColor: '#1890ff',
  5. layout: 'side',
  6. contentWidth: 'Fluid',
  7. fixedHeader: false,
  8. fixSiderbar: true,
  9. colorWeak: false,
  10. title: '青锋后台系统',
  11. pwa: false,
  12. iconfontUrl: '',
  13. menu: {
  14. locale: false,
  15. },
  16. };

menu.disableLocal 的值改为:true ,即可关闭国际化配置。

6、调整打包JS的输出路径

在我们开发项目完成后,都会将打包后的文件,上传到服务器。但是有些情况下,我们需要对打包的输出路径。
文件所在位置:tsconfig.json

  1. {
  2. "compilerOptions": {
  3. "outDir": "build/dist",
  4. "module": "esnext",
  5. "target": "esnext",
  6. "lib": ["esnext", "dom"],
  7. "sourceMap": true,
  8. "baseUrl": ".",
  9. "jsx": "react-jsx",
  10. "resolveJsonModule": true,
  11. "allowSyntheticDefaultImports": true,
  12. "moduleResolution": "node",
  13. "forceConsistentCasingInFileNames": true,
  14. "noImplicitReturns": true,
  15. "suppressImplicitAnyIndexErrors": true,
  16. "noUnusedLocals": true,
  17. "allowJs": true,
  18. "skipLibCheck": true,
  19. "experimentalDecorators": true,
  20. "strict": true,
  21. "paths": {
  22. "@/*": ["./src/*"],
  23. "@@/*": ["./src/.umi/*"]
  24. }
  25. },
  26. "include": [
  27. "mock/**/*",
  28. "src/**/*",
  29. "tests/**/*",
  30. "test/**/*",
  31. "__test__/**/*",
  32. "typings/**/*",
  33. "config/**/*",
  34. ".eslintrc.js",
  35. ".stylelintrc.js",
  36. ".prettierrc.js",
  37. "jest.config.js",
  38. "mock/*"
  39. ],
  40. "exclude": ["node_modules", "build", "dist", "scripts", "src/.umi/*", "webpack", "jest"]
  41. }

image.png

7、修改底部页脚内容

image.png
修改文件所在位置:/src/layouts/BasicLayout.tsx

  1. <DefaultFooter
  2. copyright={`${new Date().getFullYear()} 青锋后台管理系统`}
  3. links={[
  4. {
  5. key: '青锋官网',
  6. title: '青锋官网',
  7. href: 'https://xinlingge.cn:8181',
  8. blankTarget: true,
  9. },
  10. // {
  11. // key: 'github',
  12. // title: <GithubOutlined />,
  13. // href: 'https://github.com/ant-design/ant-design-pro',
  14. // blankTarget: true,
  15. // },
  16. {
  17. key: '在线预览',
  18. title: '在线预览',
  19. href: 'https://xinlingge.cn:8181/qingfeng',
  20. blankTarget: true,
  21. },
  22. ]}
  23. />