|
|
|
@ -19,7 +19,7 @@ import url from '@/utils/url';
|
|
|
|
|
import { ColumnsType } from 'antd/lib/table';
|
|
|
|
|
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
|
|
|
|
import { uniqWith, isEqual } from 'lodash';
|
|
|
|
|
|
|
|
|
|
import * as XLSX from 'xlsx';
|
|
|
|
|
const { Dragger } = Upload;
|
|
|
|
|
|
|
|
|
|
interface PageProps {}
|
|
|
|
@ -210,7 +210,7 @@ const Page: FC<PageProps> = () => {
|
|
|
|
|
info?.name?.length,
|
|
|
|
|
);
|
|
|
|
|
fileText = fileText?.toLowerCase();
|
|
|
|
|
if (fileText !== '.xml' && fileText !== '.XML') {
|
|
|
|
|
if (fileText !== '.xlsx' && fileText !== '.XLSX') {
|
|
|
|
|
message.error('只能上传.xml,.XML格式的文档');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -228,7 +228,7 @@ const Page: FC<PageProps> = () => {
|
|
|
|
|
fileList,
|
|
|
|
|
disabled: fileList.length > 10,
|
|
|
|
|
maxCount: 10,
|
|
|
|
|
accept: '.xml, .XML',
|
|
|
|
|
accept: '.xlsx, .XLSX',
|
|
|
|
|
// action: `${ENV.API_SERVER}/api/attachments.json`,
|
|
|
|
|
// onChange: handleChangeFile,
|
|
|
|
|
onRemove: handleRemoveFile,
|
|
|
|
@ -244,14 +244,12 @@ const Page: FC<PageProps> = () => {
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const loadXML = function (file: any) {
|
|
|
|
|
const loadXML = function (file: any, fileType?: string, fuc?: any) {
|
|
|
|
|
const item: any = [];
|
|
|
|
|
const cb = () => {
|
|
|
|
|
console.log(item, 22222);
|
|
|
|
|
const dealItem = uniqWith(item, isEqual);
|
|
|
|
|
console.log(dealItem, 3333);
|
|
|
|
|
const dealItem = uniqWith(item.flat(Infinity), isEqual);
|
|
|
|
|
fuc(dealItem);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 将 xml 报文转化为dom对象,注意去掉xml的协议头
|
|
|
|
|
const parseXML = (xml: any) => {
|
|
|
|
|
return new DOMParser().parseFromString(xml, 'text/xml');
|
|
|
|
@ -297,37 +295,78 @@ const Page: FC<PageProps> = () => {
|
|
|
|
|
}
|
|
|
|
|
return buffer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const xmlText = (xmlFile: any, cb: any) => {
|
|
|
|
|
const excel2Json = (file: any) => {
|
|
|
|
|
let dataItem: any = []; // 存储获取到的数据
|
|
|
|
|
try {
|
|
|
|
|
// 以二进制流方式读取得到整份excel表格对象
|
|
|
|
|
const workbook = XLSX.read(file, { type: 'binary' });
|
|
|
|
|
// 遍历每张工作表进行读取(这里默认只读取第一张表)
|
|
|
|
|
for (const sheet in workbook.Sheets) {
|
|
|
|
|
if (workbook.Sheets.hasOwnProperty(sheet)) {
|
|
|
|
|
// 利用 sheet_to_json 方法将 excel 转成 json 数据
|
|
|
|
|
dataItem = dataItem.concat(
|
|
|
|
|
XLSX.utils.sheet_to_json(workbook.Sheets[sheet]),
|
|
|
|
|
);
|
|
|
|
|
// break; // 如果只取第一张表,就取消注释这行
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log(dataItem);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// 这里可以抛出文件类型错误不正确的相关提示
|
|
|
|
|
console.log('文件类型不正确', e);
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
return dataItem;
|
|
|
|
|
};
|
|
|
|
|
const convertText = (dataFile: any, cb: any) => {
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
reader.readAsText(xmlFile.file, 'utf8');
|
|
|
|
|
if (fileType === 'excel') {
|
|
|
|
|
reader.readAsBinaryString(dataFile.file); //二进制
|
|
|
|
|
} else {
|
|
|
|
|
reader.readAsText(dataFile.file, 'utf8');
|
|
|
|
|
}
|
|
|
|
|
reader.onload = () => {
|
|
|
|
|
item.push(xml2Json(reader.result));
|
|
|
|
|
if (fileType === 'excel') {
|
|
|
|
|
item.push(excel2Json(reader.result));
|
|
|
|
|
} else {
|
|
|
|
|
item.push(xml2Json(reader.result));
|
|
|
|
|
}
|
|
|
|
|
if (item.length === file.length) {
|
|
|
|
|
cb();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < file.length; i++) {
|
|
|
|
|
xmlText(file[i], cb);
|
|
|
|
|
convertText(file[i], cb);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleLoad = () => {
|
|
|
|
|
const k = [
|
|
|
|
|
{
|
|
|
|
|
name: 'U盘',
|
|
|
|
|
typeNumber: '8782',
|
|
|
|
|
pattern: '国家保密机',
|
|
|
|
|
secretLevel: '3级',
|
|
|
|
|
managementLevel: '公司 ',
|
|
|
|
|
// const k = [
|
|
|
|
|
// {
|
|
|
|
|
// name: 'U盘',
|
|
|
|
|
// typeNumber: '8782',
|
|
|
|
|
// pattern: '国家保密机',
|
|
|
|
|
// secretLevel: '3级',
|
|
|
|
|
// managementLevel: '公司 ',
|
|
|
|
|
// producerIdList: [''],
|
|
|
|
|
// },
|
|
|
|
|
// ];
|
|
|
|
|
const fnc = (k: any) => {
|
|
|
|
|
const sights = k?.map((e: any) => ({
|
|
|
|
|
name: e?.['装备名称'] || '',
|
|
|
|
|
typeNumber: e?.['装备代号'] || '',
|
|
|
|
|
pattern: e?.['工作模式'] || '',
|
|
|
|
|
secretLevel: e?.['装备密级'] || '',
|
|
|
|
|
managementLevel: e?.['管理层级'] || '',
|
|
|
|
|
producerIdList: [''],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
formAdd.setFieldsValue({
|
|
|
|
|
sights: k,
|
|
|
|
|
});
|
|
|
|
|
loadXML(fileList);
|
|
|
|
|
}));
|
|
|
|
|
formAdd.setFieldsValue({
|
|
|
|
|
sights,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
loadXML(fileList, 'excel', fnc);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
@ -359,6 +398,9 @@ const Page: FC<PageProps> = () => {
|
|
|
|
|
>
|
|
|
|
|
新增装备型号
|
|
|
|
|
</Button>
|
|
|
|
|
<Button href={'/装备型号模板.xlsx'} className="ml10">
|
|
|
|
|
下载模版
|
|
|
|
|
</Button>
|
|
|
|
|
</Row>
|
|
|
|
|
<Table
|
|
|
|
|
dataSource={data}
|
|
|
|
|