Index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import React, { useEffect, useMemo } from 'react';
  2. import { Badge, Layout, Menu } from 'antd';
  3. import { connect } from 'dva';
  4. import RightContent from './RightContent';
  5. import Link from 'umi/link';
  6. import styles from './Index.less';
  7. const { Header, Content, Footer } = Layout;
  8. const { SubMenu } = Menu;
  9. let timer;
  10. const isMobile = isMobileDevice();
  11. // 布局
  12. function LayoutDetail(props) {
  13. const { currentUser, permission, dispatch, authList } = props;
  14. const isAdmin = currentUser.UserName == 'admin';
  15. var logoStyle = {
  16. color: 'white',
  17. fontWeight: 600,
  18. fontSize: 20,
  19. verticalAlign: 'middle',
  20. marginRight: 60,
  21. width: 120,
  22. };
  23. const authCount = useMemo(() => {
  24. let count = 0;
  25. Object.values(authList).forEach(list => (count += list.length));
  26. return count;
  27. }, [authList]);
  28. useEffect(() => {
  29. if (isMobile) return;
  30. // 查询用户信息
  31. dispatch({
  32. type: 'user/fetchCurrent',
  33. });
  34. }, []);
  35. useEffect(() => {
  36. if (isMobile) return;
  37. if (!currentUser.ID) return;
  38. dispatch({
  39. type: 'authList/queryAuthList',
  40. payload: { user_id: currentUser.ID },
  41. });
  42. clearInterval(timer);
  43. timer = setInterval(() => {
  44. if (location.href.indexOf('/bom/home/audit') != -1) return;
  45. dispatch({
  46. type: 'authList/queryAuthList',
  47. payload: { user_id: currentUser.ID },
  48. });
  49. }, 60000);
  50. return () => clearInterval(timer);
  51. }, [currentUser.ID]);
  52. // 不支持移动端使用,做判断
  53. if (isMobile) {
  54. return (
  55. <Layout>
  56. <Header>
  57. <div style={{ display: 'flex', height: '100%', justifyContent: 'space-between' }}>
  58. <div style={{ display: 'flex', width: '70%' }}>
  59. <div style={logoStyle}>金科环境</div>
  60. </div>
  61. </div>
  62. </Header>
  63. <Content
  64. style={{
  65. padding: '50px 0',
  66. minHeight: 'calc(100vh - 64px)',
  67. textAlign: 'center',
  68. fontSize: 24,
  69. }}
  70. >
  71. 请使用PC端进行审批
  72. </Content>
  73. </Layout>
  74. );
  75. }
  76. return (
  77. <Layout>
  78. <Header>
  79. <div style={{ display: 'flex', height: '100%', justifyContent: 'space-between' }}>
  80. <div style={{ display: 'flex', width: '70%' }}>
  81. <div style={logoStyle}>金科环境</div>
  82. <Menu
  83. theme="dark"
  84. mode="horizontal"
  85. defaultSelectedKeys={[props.location.pathname]}
  86. style={{ lineHeight: '64px', width: '100%' }}
  87. >
  88. <Menu.Item key="/home">
  89. <Link to="/home">采购清单</Link>
  90. </Menu.Item>
  91. <Menu.Item key="/home/flow-list">
  92. <Link to="/home/flow-list">流程管理</Link>
  93. </Menu.Item>
  94. <Menu.Item key="/home/auth">
  95. <Link to="/home/auth">
  96. <Badge count={authCount} className={styles.badge}>
  97. 审核列表
  98. </Badge>
  99. </Link>
  100. </Menu.Item>
  101. <Menu.Item key="/home/submit">
  102. <Link to="/home/submit">已提交审批</Link>
  103. </Menu.Item>
  104. </Menu>
  105. </div>
  106. <RightContent />
  107. </div>
  108. </Header>
  109. <Content style={{ padding: '0 50px', minHeight: 'calc(100vh - 64px)' }}>
  110. <div style={{ background: '#fff', padding: 24, minHeight: 280 }}>{props.children}</div>
  111. </Content>
  112. {/* <Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer> */}
  113. </Layout>
  114. );
  115. }
  116. function isMobileDevice() {
  117. return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
  118. }
  119. export default connect(({ user, authList }) => ({
  120. currentUser: user.currentUser,
  121. permission: user.currentUser.Permission,
  122. authList: authList.authList,
  123. }))(LayoutDetail);