12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import { queryRecordSheet } from '@/services/boom';
- import LuckySheet from '../Detail/LuckySheet';
- import react, { useRef } from 'react';
- import LuckyExcel from 'luckyexcel';
- import { Button, message } from 'antd';
- const TEMPLATE_URL =
- 'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/bom/635/%E5%90%88%E5%90%8C%E6%96%87%E4%BB%B6/%E6%8A%95%E6%A0%87%E6%A8%A1%E6%9D%BF.xlsx';
- const TEMPLATE_URL2 = 'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/public/bom/psr.xlsx';
- function Index(props) {
- const { versionId = 2418 } = props;
- const sheetRef = useRef();
- const luckysheetRef = useRef();
- const uploadExcelByUrl = type => {
- LuckyExcel.transformExcelToLuckyByUrl(
- type == 1 ? TEMPLATE_URL : TEMPLATE_URL2,
- '模板.xlsx',
- async (exportJson, luckysheetfile) => {
- let record = await getExcel(versionId);
- console.log(record);
- luckysheetRef.current.destroy();
- luckysheetRef.current.create({
- lang: 'zh',
- showinfobar: false,
- showstatisticBar: false,
- data: [...exportJson.sheets, ...record],
- hook: {
- cellMousedown: (cell, position, sheet) => {
- console.log(cell, position, sheet);
- },
- cellUpdated: () => {
- luckysheetRef.current.refreshFormula();
- },
- },
- });
- }
- );
- };
- const handleLoad = () => {
- let contentWindow = sheetRef.current.contentWindow;
- luckysheetRef.current = contentWindow.luckysheet;
- };
- return (
- <div>
- <Button type="primary" onClick={() => uploadExcelByUrl(1)}>
- 导入投标投标
- </Button>
- <Button type="primary" onClick={() => uploadExcelByUrl(2)}>
- 导入合同模板
- </Button>
- <iframe
- style={{
- width: '100%',
- height: '80vh',
- }}
- ref={sheetRef}
- onLoad={handleLoad}
- src="/luckysheet.html"
- ></iframe>
- </div>
- );
- }
- async function getExcel(gridKey) {
- var formData = new FormData();
- formData.append('gridKey', gridKey);
- let res = await fetch(
- `/api/v1/purchase/record/sheet?gridKey=${gridKey}&JWT-TOKEN=${getToken()}`,
- {
- method: 'POST',
- body: formData,
- }
- ).then(response => response.text());
- return JSON.parse(JSON.parse(res));
- }
- export default Index;
|