home.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { connect } from 'umi';
  2. import React from 'react';
  3. import './global.less';
  4. import Router from '@/Frameworks/SysRouter';
  5. import Os from '../Os';
  6. window.GT_APP = new Os();
  7. window.GT_APP.funcMain.setActive(true);
  8. // window.GT_APP.funcLimitedSpace.setActive(true);
  9. const Home: React.FC = (props: any) => {
  10. const {
  11. page: { active, zoomOutList },
  12. dispatch,
  13. } = props;
  14. const zoomOut = (index: number, options: GT.IPageOptions) => {
  15. dispatch({
  16. type: 'page/zoomOut',
  17. payload: { index, options },
  18. });
  19. };
  20. const zoomIn = (index: number) => {
  21. dispatch({
  22. type: 'page/zoomIn',
  23. payload: { index },
  24. });
  25. };
  26. const onClickPage = (index: number) => {
  27. dispatch({
  28. type: 'page/setActive',
  29. payload: { index },
  30. });
  31. };
  32. return (
  33. <div
  34. style={{
  35. position: 'fixed',
  36. height: '100vh',
  37. width: '100vw',
  38. top: 0,
  39. left: 0,
  40. }}
  41. >
  42. <div>
  43. {active.map((aItem: GT.IActive, index: number) => {
  44. const { key, params = {}, id, options } = aItem;
  45. const Component = Router[key];
  46. if (!Component) {
  47. console.error(`key=${key} 不存在`);
  48. return <div>`key=${key} 不存在`</div>;
  49. }
  50. return (
  51. <Component
  52. options={options}
  53. key={id}
  54. id={id}
  55. params={params}
  56. zoomOut={(options: GT.IPageOptions) => zoomOut(index, options)}
  57. onActive={() => {
  58. onClickPage(index);
  59. }}
  60. />
  61. );
  62. })}
  63. </div>
  64. <ZoomOutList
  65. list={zoomOutList}
  66. zoomIn={(index: number) => zoomIn(index)}
  67. />
  68. </div>
  69. );
  70. };
  71. function ZoomOutList(props: { list: GT.IActive[]; zoomIn: Function }) {
  72. const { list, zoomIn } = props;
  73. return (
  74. <div
  75. style={{
  76. backgroundColor: '#66ccff',
  77. position: 'fixed',
  78. right: 20,
  79. bottom: 20,
  80. zIndex: 9999,
  81. }}
  82. >
  83. {list.map((item) => (
  84. <div
  85. style={{ padding: 10, borderBottom: '1px solid #fff' }}
  86. onClick={() => zoomIn(item)}
  87. >
  88. {item.options?.name}
  89. </div>
  90. ))}
  91. </div>
  92. );
  93. }
  94. export default connect(({ page }: { page: any }) => ({ page }))(Home);