导入处理
This commit is contained in:
parent
c403dadb93
commit
80fb10fa46
@ -72,12 +72,6 @@ export const updateProject = (data) => {
|
|||||||
data,
|
data,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export const updateDataSource = (data) => {
|
|
||||||
return {
|
|
||||||
type: UPDATE_DATASOURCE,
|
|
||||||
data,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
const saveAllVersionSuccess = (data) => {
|
const saveAllVersionSuccess = (data) => {
|
||||||
return {
|
return {
|
||||||
type: SAVE_ALL_VERSION_SUCCESS,
|
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 = () => {
|
export const close = () => {
|
||||||
return {
|
return {
|
||||||
type: CLOSE_PROJECT,
|
type: CLOSE_PROJECT,
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { executeSql } from '@/services/api.ts';
|
import { executeSql } from '@/services/api.ts';
|
||||||
import { Divider, Upload } from 'antd';
|
import { Divider, Upload,message } from 'antd';
|
||||||
import numeral from 'numeral';
|
import numeral from 'numeral';
|
||||||
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
||||||
|
|
||||||
import { SketchPicker } from 'react-color';
|
import { SketchPicker } from 'react-color';
|
||||||
import _ from 'lodash/object'
|
import _ from 'lodash/object'
|
||||||
import {
|
import {
|
||||||
@ -32,6 +33,7 @@ export default React.memo(
|
|||||||
resize,
|
resize,
|
||||||
sliderChange,
|
sliderChange,
|
||||||
dataSource,
|
dataSource,
|
||||||
|
getDataSource,
|
||||||
restProps,
|
restProps,
|
||||||
jumpPosition,
|
jumpPosition,
|
||||||
jumpDetail,
|
jumpDetail,
|
||||||
@ -186,32 +188,57 @@ export default React.memo(
|
|||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
maxCount: 1,
|
maxCount: 1,
|
||||||
accept: 'application/vnd.ms-excel',
|
|
||||||
beforeUpload: (file) => {
|
beforeUpload: (file) => {
|
||||||
new Promise((resolve, reject) => {
|
if(file.name.indexOf('xls') === -1){
|
||||||
|
message.error('请上传xlsx格式文件')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const { entities, domains } = JSON.parse(JSON.stringify(dataSource));
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = (e) => {
|
reader.onload = function (e) {
|
||||||
resolve(e.target.result);
|
const data = new Uint8Array(e.target.result); // 获取文件数据
|
||||||
};
|
const workbook = XLSX.read(data, { type: 'array' }); // 解析为工作簿对象
|
||||||
reader.onerror = reject;
|
|
||||||
reader.readAsBinaryString(file);
|
|
||||||
})
|
|
||||||
.then((fileData) => {
|
|
||||||
// 解析XLSX
|
|
||||||
return XLSX.read(fileData, { type: 'binary' });
|
|
||||||
})
|
|
||||||
.then((workBook) => {
|
|
||||||
const { entities, domains } = dataSource;
|
|
||||||
const keyList = entities[0].headers
|
const keyList = entities[0].headers
|
||||||
.filter((item) => item.refKey !== 'isStandard')
|
.filter((item) => item.refKey !== 'isStandard')
|
||||||
.map((item) => item.refKey);
|
.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)
|
||||||
|
})
|
||||||
|
const currentDataSource = getDataSource();
|
||||||
|
console.log(entities, currentDataSource, restProps);
|
||||||
|
// 字典映射
|
||||||
|
|
||||||
let data = workBook.Sheets.forEach((sheet) => {
|
restProps.updateDataSource({
|
||||||
window.XLSX.utils.sheet_to_json(workBook.Sheets[sheet], {
|
...currentDataSource,
|
||||||
headers: keyList,
|
entities
|
||||||
});
|
})
|
||||||
});
|
|
||||||
});
|
};
|
||||||
|
reader.readAsArrayBuffer(file); // 读取文件为ArrayBuffer
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
fileList,
|
fileList,
|
||||||
|
@ -1729,6 +1729,7 @@ const Index = React.memo(
|
|||||||
<Loading visible={common.loading} title={common.title}>
|
<Loading visible={common.loading} title={common.title}>
|
||||||
<HeaderTool
|
<HeaderTool
|
||||||
dataSource={restProps.dataSource}
|
dataSource={restProps.dataSource}
|
||||||
|
getDataSource={getDataSource}
|
||||||
ref={headerToolRef}
|
ref={headerToolRef}
|
||||||
currentPrefix={currentPrefix}
|
currentPrefix={currentPrefix}
|
||||||
close={restProps.close}
|
close={restProps.close}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user