index.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import { Card } from 'antd';
  3. import styles from './index.less';
  4. import CollectorTree from './components/Tree';
  5. import { observer } from '@formily/reactive-react';
  6. import { model } from '@formily/reactive';
  7. import Point from './components/Point';
  8. import { useEffect } from 'react';
  9. import useLocations from '@/hooks/route/useLocation';
  10. export const DataCollectModel = model<{
  11. provider: 'OPC_UA' | 'MODBUS_TCP';
  12. data: any;
  13. reload: boolean;
  14. refresh: boolean;
  15. channelId: string;
  16. }>({
  17. provider: 'MODBUS_TCP',
  18. data: {},
  19. reload: false,
  20. refresh: false,
  21. channelId: '',
  22. });
  23. export default observer(() => {
  24. const location = useLocations();
  25. useEffect(() => {
  26. if (location.state?.channelId) {
  27. DataCollectModel.channelId = location.state.channelId;
  28. } else {
  29. DataCollectModel.channelId = '';
  30. }
  31. }, [location.state]);
  32. return (
  33. <PageContainer>
  34. <Card bordered={false} bodyStyle={{ paddingTop: 0 }}>
  35. <div className={styles.container}>
  36. <div className={styles.left}>
  37. <CollectorTree
  38. channelId={DataCollectModel.channelId}
  39. change={(data) => {
  40. DataCollectModel.provider = data?.provider;
  41. DataCollectModel.data = data || {};
  42. }}
  43. />
  44. </div>
  45. <div className={styles.right}>
  46. <Point provider={DataCollectModel.provider} data={DataCollectModel.data} />
  47. </div>
  48. </div>
  49. </Card>
  50. </PageContainer>
  51. );
  52. });