|
@@ -84,39 +84,49 @@ const Component = (props: any) => {
|
|
|
};
|
|
|
|
|
|
const beforeUpload = (file: any) => {
|
|
|
- LuckyExcel.transformExcelToLucky(file, (exportJson, luckysheetfile) => {
|
|
|
- if (exportJson.sheets == null || exportJson.sheets.length == 0) {
|
|
|
- message.error('读取xlsx文件失败!');
|
|
|
- return;
|
|
|
- }
|
|
|
- console.log(exportJson);
|
|
|
- const sheet = exportJson.sheets[0];
|
|
|
- let titleCell = [];
|
|
|
- sheet.celldata.forEach(item => {
|
|
|
- if (item.r == 0) {
|
|
|
- // 标题头
|
|
|
- titleCell.push(item);
|
|
|
+ try {
|
|
|
+ LuckyExcel.transformExcelToLucky(file, (exportJson, luckysheetfile) => {
|
|
|
+ if (exportJson.sheets == null || exportJson.sheets.length == 0) {
|
|
|
+ message.error('读取xlsx文件失败!');
|
|
|
+ return;
|
|
|
}
|
|
|
- // 生成cid
|
|
|
- item.v.cid = `${item.r}-${item.c}`;
|
|
|
- });
|
|
|
- let cell = titleCell.map(item => {
|
|
|
- let value = '';
|
|
|
- if (item.v?.v) {
|
|
|
- value = item.v?.v;
|
|
|
- } else if (item.v.ct?.s && item.v.ct?.s instanceof Array) {
|
|
|
- value = item.v.ct.s.map(item => item?.v).join?.('');
|
|
|
- }
|
|
|
- return { sheet_name: sheet.name, col_idx: item.r, col_axis: item.c, col_value: value };
|
|
|
- });
|
|
|
- onNodeConfigChange(null, {
|
|
|
- data: [sheet],
|
|
|
- excel_info: {
|
|
|
- file_name: file.name,
|
|
|
- excel_cols: cell,
|
|
|
- },
|
|
|
+ console.log(exportJson);
|
|
|
+ // const sheet = exportJson.sheets[0];
|
|
|
+ let cell = [];
|
|
|
+ exportJson.sheets.forEach(sheet => {
|
|
|
+ let titleCell = [];
|
|
|
+ sheet.celldata.forEach(item => {
|
|
|
+ if (item.r == 0) {
|
|
|
+ // 标题头
|
|
|
+ titleCell.push(item);
|
|
|
+ }
|
|
|
+ // 生成cid
|
|
|
+ item.v.cid = `${item.r}-${item.c}`;
|
|
|
+ });
|
|
|
+ let tempCell = titleCell.map(item => {
|
|
|
+ let value = '';
|
|
|
+ if (item.v?.v) {
|
|
|
+ value = item.v?.v;
|
|
|
+ } else if (item.v.ct?.s && item.v.ct?.s instanceof Array) {
|
|
|
+ value = item.v.ct.s.map(item => item?.v).join?.('');
|
|
|
+ }
|
|
|
+ return { sheet_name: sheet.name, col_idx: item.r, col_axis: item.c, col_value: value };
|
|
|
+ });
|
|
|
+ cell = [...cell, ...tempCell];
|
|
|
+ });
|
|
|
+ console.log(cell);
|
|
|
+ onNodeConfigChange(null, {
|
|
|
+ data: exportJson.sheets,
|
|
|
+ excel_info: {
|
|
|
+ file_name: file.name,
|
|
|
+ excel_cols: cell,
|
|
|
+ },
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
+ } catch (error) {
|
|
|
+ message.error("excel文件导入失败!请联系管理员。")
|
|
|
+ return false;
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
useEffect(() => {
|
|
@@ -211,11 +221,13 @@ const Component = (props: any) => {
|
|
|
}}
|
|
|
/>
|
|
|
|
|
|
- {meta?.editMode == 1 && <UploadFiled
|
|
|
- label="模板"
|
|
|
- onChange={url => onNodeConfigChange('bom_template', url)}
|
|
|
- beforeUpload={beforeUpload}
|
|
|
- />}
|
|
|
+ {meta?.editMode == 1 && (
|
|
|
+ <UploadFiled
|
|
|
+ label="模板"
|
|
|
+ onChange={url => onNodeConfigChange('bom_template', url)}
|
|
|
+ beforeUpload={beforeUpload}
|
|
|
+ />
|
|
|
+ )}
|
|
|
|
|
|
{/* <div onClick={handleFileNameClick}>{fileName}</div> */}
|
|
|
<a href={nodeConfig.bom_template}>{fileName}</a>
|
|
@@ -299,9 +311,9 @@ const Component = (props: any) => {
|
|
|
|
|
|
<Button type="primary" onClick={onSave}>
|
|
|
保存
|
|
|
- </Button></>
|
|
|
+ </Button>
|
|
|
+ </>
|
|
|
)}
|
|
|
-
|
|
|
</div>
|
|
|
);
|
|
|
};
|