导入处理
This commit is contained in:
parent
c403dadb93
commit
80fb10fa46
@ -72,12 +72,6 @@ export const updateProject = (data) => {
|
||||
data,
|
||||
};
|
||||
};
|
||||
export const updateDataSource = (data) => {
|
||||
return {
|
||||
type: UPDATE_DATASOURCE,
|
||||
data,
|
||||
};
|
||||
};
|
||||
const saveAllVersionSuccess = (data) => {
|
||||
return {
|
||||
type: SAVE_ALL_VERSION_SUCCESS,
|
||||
@ -415,6 +409,13 @@ export const openDemoProject = (h, t, title, type) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const updateDataSource = (data) => {
|
||||
return (dispatch, getState) => {
|
||||
let isDemoProject = getState().core.isDemoProject;
|
||||
dispatch(readProjectSuccess(data, [], '', isDemoProject));
|
||||
}
|
||||
}
|
||||
|
||||
export const close = () => {
|
||||
return {
|
||||
type: CLOSE_PROJECT,
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { executeSql } from '@/services/api.ts';
|
||||
import { Divider, Upload } from 'antd';
|
||||
import { Divider, Upload,message } from 'antd';
|
||||
import numeral from 'numeral';
|
||||
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
||||
|
||||
import { SketchPicker } from 'react-color';
|
||||
import _ from 'lodash/object'
|
||||
import {
|
||||
@ -32,6 +33,7 @@ export default React.memo(
|
||||
resize,
|
||||
sliderChange,
|
||||
dataSource,
|
||||
getDataSource,
|
||||
restProps,
|
||||
jumpPosition,
|
||||
jumpDetail,
|
||||
@ -186,32 +188,57 @@ export default React.memo(
|
||||
|
||||
const props = {
|
||||
maxCount: 1,
|
||||
accept: 'application/vnd.ms-excel',
|
||||
beforeUpload: (file) => {
|
||||
new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
resolve(e.target.result);
|
||||
};
|
||||
reader.onerror = reject;
|
||||
reader.readAsBinaryString(file);
|
||||
})
|
||||
.then((fileData) => {
|
||||
// 解析XLSX
|
||||
return XLSX.read(fileData, { type: 'binary' });
|
||||
if(file.name.indexOf('xls') === -1){
|
||||
message.error('请上传xlsx格式文件')
|
||||
return
|
||||
}
|
||||
const { entities, domains } = JSON.parse(JSON.stringify(dataSource));
|
||||
const reader = new FileReader();
|
||||
reader.onload = function (e) {
|
||||
const data = new Uint8Array(e.target.result); // 获取文件数据
|
||||
const workbook = XLSX.read(data, { type: 'array' }); // 解析为工作簿对象
|
||||
const keyList = entities[0].headers
|
||||
.filter((item) => item.refKey !== 'isStandard')
|
||||
.map((item) => item.refKey);
|
||||
workbook.SheetNames.map((defName, index) => {
|
||||
const worksheet = workbook.Sheets[workbook.SheetNames[index]]; // 获取工作表
|
||||
let fields = XLSX.utils.sheet_to_json(worksheet, { header: keyList }); // 将工作表转换为JSON数组
|
||||
fields = fields.slice(1).map(item => {
|
||||
// 判断为哪个数据域字典
|
||||
const {
|
||||
len,
|
||||
id,
|
||||
defName,
|
||||
scale,
|
||||
uiHint,
|
||||
} = domains.find((domain) => domain.defName === item.domain);
|
||||
const obj = { ...item, domain: id }
|
||||
const booleanList = ['notNull', 'primaryKey', 'autoIncrement', 'hideInGraph']
|
||||
booleanList.forEach((key) => {
|
||||
obj[key] = item[key] === '是'
|
||||
})
|
||||
return obj
|
||||
})
|
||||
const entitie = {
|
||||
...entities[0],
|
||||
fields,
|
||||
defName,
|
||||
id: entities[0].id + Math.random()
|
||||
}
|
||||
entities.push(entitie)
|
||||
})
|
||||
.then((workBook) => {
|
||||
const { entities, domains } = dataSource;
|
||||
const keyList = entities[0].headers
|
||||
.filter((item) => item.refKey !== 'isStandard')
|
||||
.map((item) => item.refKey);
|
||||
const currentDataSource = getDataSource();
|
||||
console.log(entities, currentDataSource, restProps);
|
||||
// 字典映射
|
||||
|
||||
let data = workBook.Sheets.forEach((sheet) => {
|
||||
window.XLSX.utils.sheet_to_json(workBook.Sheets[sheet], {
|
||||
headers: keyList,
|
||||
});
|
||||
});
|
||||
});
|
||||
restProps.updateDataSource({
|
||||
...currentDataSource,
|
||||
entities
|
||||
})
|
||||
|
||||
};
|
||||
reader.readAsArrayBuffer(file); // 读取文件为ArrayBuffer
|
||||
return false;
|
||||
},
|
||||
fileList,
|
||||
@ -271,7 +298,7 @@ export default React.memo(
|
||||
//style={{cursor: 'move'}}
|
||||
onClick={iconClick}
|
||||
groupKey="empty"
|
||||
//onMouseDown={e => iconClick(e, 'empty')}
|
||||
//onMouseDown={e => iconClick(e, 'empty')}
|
||||
/>
|
||||
<GroupIcon
|
||||
className={`${currentPrefix}-icongroup`}
|
||||
@ -281,7 +308,7 @@ export default React.memo(
|
||||
onClick={iconClick}
|
||||
groupKey="group"
|
||||
disable={activeTab?.type !== 'diagram'}
|
||||
//onMouseDown={e => iconClick(e, 'group')}
|
||||
//onMouseDown={e => iconClick(e, 'group')}
|
||||
/>
|
||||
<GroupIcon
|
||||
className={`${currentPrefix}-icongroup`}
|
||||
@ -303,13 +330,13 @@ export default React.memo(
|
||||
//style={{cursor: 'move'}}
|
||||
icon={
|
||||
<div className={`${currentPrefix}-head-rect`}>
|
||||
<span>{}</span>
|
||||
<span>{ }</span>
|
||||
</div>
|
||||
}
|
||||
groupKey="polygon"
|
||||
onClick={iconClick}
|
||||
disable={activeTab?.type !== 'diagram'}
|
||||
//onMouseDown={e => iconClick(e, 'polygon')}
|
||||
//onMouseDown={e => iconClick(e, 'polygon')}
|
||||
/>
|
||||
|
||||
<div className="fontColor1">
|
||||
|
@ -1729,6 +1729,7 @@ const Index = React.memo(
|
||||
<Loading visible={common.loading} title={common.title}>
|
||||
<HeaderTool
|
||||
dataSource={restProps.dataSource}
|
||||
getDataSource={getDataSource}
|
||||
ref={headerToolRef}
|
||||
currentPrefix={currentPrefix}
|
||||
close={restProps.close}
|
||||
|
Loading…
x
Reference in New Issue
Block a user