Home2.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import * as React from 'react';
  2. import Box from "@mui/material/Box";
  3. import 'handsontable/dist/handsontable.full.min.css';
  4. //import 'handsontable/styles/ht-theme-main.min.css';
  5. import { HandsonTable } from 'handsontable/base';
  6. import {HotTable} from "@handsontable/react";
  7. //import { registerAllModules } from 'handsontable/registry';
  8. import {RichTreeView } from "@mui/x-tree-view/RichTreeView";
  9. import { Grid } from '@mui/material';
  10. import Tab from "@mui/material/Tab";
  11. import TabContext from "@mui/lab/TabContext";
  12. import TabList from "@mui/lab/TabList";
  13. import TabPanel from "@mui/lab/TabPanel";
  14. //import { registerPlugin, NestedRows } from 'handsontable/plugins';
  15. //registerPlugin(NestedRows);
  16. import { textRenderer, registerRenderer } from 'handsontable/renderers';
  17. import useWebSocket, { ReadyState } from 'react-use-websocket';
  18. import Qingdan from './Qingdan';
  19. import Zjcs from './Zjcs';
  20. import Djcs from './Djcs';
  21. import Service from './Service';
  22. import {useNavigate, useLocation} from "react-router";
  23. //registerAllModules();
  24. export default function Home2() {
  25. const { sendMessage, lastMessage, readyState } = useWebSocket('ws://127.0.0.1:8000/ws', {
  26. shouldReconnect: (closeEvent) => true
  27. });
  28. function coverRenderer(_instance, td, _row, _col, _prop, value, _cellProperties) {
  29. const button = document.createElement('button');
  30. button.innerText="打开";
  31. if (_col == 2) {
  32. button.innerText="解析";
  33. }
  34. //img.src = value;
  35. /*button.addEventListener('click', (event) => {
  36. console.log(hotRef.current?.hotInstance?.getData()[selectedRow.current]);
  37. hotRef.current?.hotInstance?.alter('remove_row', selectedRow.current, 1);
  38. //console.log(plugin);
  39. event.preventDefault();
  40. });*/
  41. button.addEventListener('mousedown', (event) => {
  42. //console.log(plugin);
  43. event.preventDefault();
  44. });
  45. td.innerText = '';
  46. td.appendChild(button);
  47. return td;
  48. }
  49. const hotRef = React.useRef(null);
  50. const navigate = useNavigate();
  51. let location = useLocation();
  52. const [detail, setDetail] = React.useState([["File Name"]]);
  53. React.useEffect(
  54. () => {
  55. Service.generateFiles2().then(x=>{
  56. setDetail(x);
  57. });
  58. }, []
  59. );
  60. React.useEffect(() => {
  61. console.log(lastMessage);
  62. }, [lastMessage]);
  63. registerRenderer('highlightRowRenderer', (hotInstance, TD, row, column, ...rest) => {
  64. coverRenderer(hotInstance, TD, row, column, ...rest);
  65. });
  66. return (
  67. <HotTable nestedRows={false}
  68. data={detail
  69. }
  70. ref={hotRef}
  71. afterSelection={(row, column)=>{
  72. console.log(row);
  73. let selected = hotRef.current?.hotInstance?.getData()[row];
  74. console.log(selected[0]);
  75. if (column == 1) {
  76. navigate("/qingdan/".concat(selected[0]));
  77. } else {
  78. //sendMessage(selected[0]);
  79. }
  80. }}
  81. rowHeaders={true}
  82. colHeaders={false}
  83. height="800"
  84. readOnly={true}
  85. autoWrapRow={false}
  86. autoWrapCol={false}
  87. /*cells={(row, col, prop) => {
  88. if (col >= 1) {
  89. return {
  90. // row options, which apply to each cell of the second row
  91. // and to each cell of the fifth row
  92. renderer: "highlightRowRenderer"
  93. };
  94. }
  95. }
  96. }*/
  97. licenseKey="non-commercial-and-evaluation" // for non-commercial use only
  98. />
  99. );
  100. }