index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { queryRecordSheet } from '@/services/boom';
  2. import LuckySheet from '../Detail/LuckySheet';
  3. import react, { useRef } from 'react';
  4. import LuckyExcel from 'luckyexcel';
  5. import { Button, message } from 'antd';
  6. import { getToken } from '@/utils/utils';
  7. import moment from 'moment';
  8. import uploadExcelByUrl from '@/utils/uploadExcelByUrl';
  9. const TEMPLATE_URL =
  10. 'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/doc/contract/2023-06-29/ed0d5dcd-6ce0-40df-9d17-a1f69245dbb9.xlsx';
  11. const TEMPLATE_URL2 =
  12. 'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/public/bom/ContractTemplate.xlsx';
  13. function Index(props) {
  14. const { versionId = 2554 } = props;
  15. const sheetRef = useRef();
  16. const luckysheetRef = useRef();
  17. const onClick = async type => {
  18. let data = await uploadExcelByUrl(type, versionId, {
  19. project_name: 'test水厂',
  20. project_full_code: 'TESTCODE',
  21. });
  22. luckysheetRef.current.destroy();
  23. luckysheetRef.current.create({
  24. data,
  25. lang: 'zh',
  26. showinfobar: false,
  27. showstatisticBar: false,
  28. hook: {
  29. cellMousedown: (cell, position, sheet) => {
  30. console.log(cell, position, sheet);
  31. },
  32. cellUpdated: () => {
  33. luckysheetRef.current.refreshFormula();
  34. },
  35. },
  36. });
  37. };
  38. const handleLoad = () => {
  39. let contentWindow = sheetRef.current.contentWindow;
  40. luckysheetRef.current = contentWindow.luckysheet;
  41. };
  42. return (
  43. <div>
  44. <Button type="primary" style={{ marginRight: 20 }} onClick={() => onClick(3)}>
  45. 导入投标投标
  46. </Button>
  47. <Button type="primary" onClick={() => onClick(4)}>
  48. 导入合同模板
  49. </Button>
  50. <iframe
  51. style={{
  52. width: '100%',
  53. height: '80vh',
  54. }}
  55. ref={sheetRef}
  56. onLoad={handleLoad}
  57. src="/luckysheet.html"
  58. ></iframe>
  59. </div>
  60. );
  61. }
  62. export default Index;