From 17eee73f3765a7cab183d5919e3ba6621bde89b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E5=BC=BA?= <2997723368@qq.com> Date: Wed, 3 Jan 2024 14:23:15 +0800 Subject: [PATCH] =?UTF-8?q?json=E6=96=87=E4=BB=B6=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E9=A1=B5=E9=9D=A2=E8=B7=B3=E8=BD=AC=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.tsx | 1 - .../pdManer/components/groupicon/index.js | 63 ++- src/pages/pdManer/lang/zh.js | 2 + src/pages/pdManer/pages/Main/HeaderTool.js | 150 +----- src/pages/pdManer/pages/Main/index.js | 123 ++++- src/pages/pdManer/pages/Main/mock.json | 507 ++++++++++++++++++ src/pages/pdManer/pages/home/home1.js | 20 +- src/pages/pdManer/pages/home/index.less | 4 + 8 files changed, 693 insertions(+), 177 deletions(-) create mode 100644 src/pages/pdManer/pages/Main/mock.json diff --git a/src/app.tsx b/src/app.tsx index 2c8b9b5..5fdc1a1 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -126,7 +126,6 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) = } // initialState.currentUser 中包含了所有用户信息 const menus = await getRoutersInfo(); - const urlParams = new URLSearchParams(window.location.search); // const hideInMenu = urlParams.get('hideInMenu'); // 替换 'hideInMenu' 为你要获取的参数名 // if (hideInMenu) { // menus = menus.map((item) => { diff --git a/src/pages/pdManer/components/groupicon/index.js b/src/pages/pdManer/components/groupicon/index.js index bf7e82b..618902e 100644 --- a/src/pages/pdManer/components/groupicon/index.js +++ b/src/pages/pdManer/components/groupicon/index.js @@ -1,15 +1,24 @@ -import React, {useRef, useState, useEffect, useMemo } from 'react'; +/* + * @version: V1.0.0 + * @Date: 2023-12-28 11:28:35 + * @LastEditors: lzq + * @LastEditTime: 2024-01-03 11:32:11 + * @company: 睿展数据 + * @FilePath: \salpa-web\src\pages\pdManer\components\groupicon\index.js + * @Descripttion: + */ +import React, { useRef, useState, useEffect, useMemo } from 'react'; import { v4 as uuidv4 } from "uuid" import GroupIconGroup from './GroupIconGroup'; import DropDown from '../dropdown'; import Icon from '../icon'; import './style/index.less'; -import {getPrefix} from '../../lib/prefixUtil'; -import {addBodyClick, removeBodyClick} from '../../lib/listener'; +import { getPrefix } from '../../lib/prefixUtil'; +import { addBodyClick, removeBodyClick } from '../../lib/listener'; -const GroupIcon = React.memo(({prefix, title, onClick, icon, dropMenu, dropType = 'all', - disable, hoverTitle, style, draggable, onMouseDown, groupKey, - topStyle = {}, dropMenuStyle, className = ''}) => { +const GroupIcon = React.memo(({ prefix, title, onClick, icon, dropMenu, dropType = 'all', + disable, hoverTitle, style, draggable, onMouseDown, groupKey, + topStyle = {}, dropMenuStyle, className = '' }) => { const id = useMemo(() => uuidv4(), []); const menuContainerRef = useRef(null); const [status, setStatus] = useState(false); @@ -22,7 +31,7 @@ const GroupIcon = React.memo(({prefix, title, onClick, icon, dropMenu, dropType } }; const dropClick = (m, e) => { - onClick && onClick(e, m.key); + onClick && onClick(e, m.key, m?.dataSource); e.stopPropagation(); }; const onIconClick = (e) => { @@ -40,7 +49,7 @@ const GroupIcon = React.memo(({prefix, title, onClick, icon, dropMenu, dropType removeBodyClick(id); }; } - return () => {}; + return () => { }; }, []); return ( + >
{} : _onClick} + onClick={disable ? () => { } : _onClick} ref={menuContainerRef} style={style} - > + > { - typeof icon === 'string' ? - - {(dropMenu && dropType === 'icon') ? - - - : ''} - + typeof icon === 'string' ? + + {(dropMenu && dropType === 'icon') ? + + + : ''} + : icon - } + } {title} { - status &&
+ status &&
{dropType === 'all' && !disable && !Array.isArray(dropMenu) && dropMenu}
} diff --git a/src/pages/pdManer/lang/zh.js b/src/pages/pdManer/lang/zh.js index 6de29ec..87a1fc7 100644 --- a/src/pages/pdManer/lang/zh.js +++ b/src/pages/pdManer/lang/zh.js @@ -37,6 +37,8 @@ export default { exportConfig: '导出系统设置', importConfig: '导入系统设置', importDDL: '导入DDL', + standardDataImport:'标准数据导入', + standardDataExport:'标准数据导出', exportImg: '导出当前画布为图片', exportImgLoading: '正在导出当前画布为图片...', exportSql: '导出DDL', diff --git a/src/pages/pdManer/pages/Main/HeaderTool.js b/src/pages/pdManer/pages/Main/HeaderTool.js index ca700d7..e6f9c62 100644 --- a/src/pages/pdManer/pages/Main/HeaderTool.js +++ b/src/pages/pdManer/pages/Main/HeaderTool.js @@ -1,5 +1,5 @@ import { executeSql } from '@/services/api.ts'; -import { Divider, Upload,message } from 'antd'; +import { Divider, Upload, message } from 'antd'; import numeral from 'numeral'; import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react'; @@ -186,63 +186,7 @@ export default React.memo( setIssee(!issee); }; - const props = { - maxCount: 1, - beforeUpload: (file) => { - 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) - }) - const currentDataSource = getDataSource(); - console.log(entities, currentDataSource, restProps); - // 字典映射 - restProps.updateDataSource({ - ...currentDataSource, - entities - }) - - }; - reader.readAsArrayBuffer(file); // 读取文件为ArrayBuffer - return false; - }, - fileList, - }; return (
@@ -530,63 +474,27 @@ export default React.memo( } /> - {/* } - dropMenu={[ - { key: 'chiner', name: FormatMessage.string({ id: 'toolbar.importCHNR' }) }, - { - key: 'powerdesigner', - name: FormatMessage.string({ id: 'toolbar.importPowerDesigner' }), - }, - { key: 'db', name: FormatMessage.string({ id: 'toolbar.importDb' }) }, - { key: 'importDDL', name: FormatMessage.string({ id: 'toolbar.importDDL' }) }, - { - style: { borderTop: '1px solid #DFE3EB' }, - key: 'domains', - name: FormatMessage.string({ id: 'toolbar.importDomains' }), - }, - { - key: 'appCodes', - name: FormatMessage.string({ id: 'toolbar.importAppCodes' }), - }, - { - key: 'importConfig', - name: FormatMessage.string({ id: 'toolbar.importConfig' }), - }, - ]} - /> - } - dropMenu={[ - { key: 'word', name: FormatMessage.string({ id: 'toolbar.exportWord' }) }, - { key: 'sql', name: FormatMessage.string({ id: 'toolbar.exportSql' }) }, - { key: 'dict', name: FormatMessage.string({ id: 'toolbar.exportDict' }) }, - { - key: 'img', - name: FormatMessage.string({ id: 'toolbar.exportImg' }), - disable: activeTab?.type !== 'diagram', - }, - { - style: { borderTop: '1px solid #DFE3EB' }, - key: 'exportDomains', - name: FormatMessage.string({ id: 'toolbar.exportDomains' }), - }, - { - key: 'exportAppCodes', - name: FormatMessage.string({ id: 'toolbar.exportAppCodes' }), - }, - { - key: 'exportConfig', - name: FormatMessage.string({ id: 'toolbar.exportConfig' }), - }, - ]} - /> */} + } + dropMenu={[ + { key: 'importDDL', name: FormatMessage.string({ id: 'toolbar.importDDL' }) }, + { key: 'standardDataImport', name: FormatMessage.string({ id: 'toolbar.standardDataImport' }), dataSource }, + ]} + /> + } + dropMenu={[ + { key: 'sql', name: FormatMessage.string({ id: 'toolbar.exportSql' }) }, + { key: 'standardDataExport', name: FormatMessage.string({ id: 'toolbar.standardDataExport' }), dataSource }, + ]} + /> + {/* - - handleExportDataBase()} - hoverTitle={FormatMessage.string({ id: 'toolbar.export' })} - icon={} - /> - - } - /> -
diff --git a/src/pages/pdManer/pages/Main/index.js b/src/pages/pdManer/pages/Main/index.js index f7aeebb..1cfd7c9 100644 --- a/src/pages/pdManer/pages/Main/index.js +++ b/src/pages/pdManer/pages/Main/index.js @@ -16,6 +16,7 @@ import { Upload, } from '../../components'; import { moveArrayPosition } from '../../lib/array_util'; +import mockData from './mock.json' import { clearAllTabData, getAllTabData, @@ -419,9 +420,8 @@ const Index = React.memo( const mapping = mappings.filter((m) => m.id === domain.applyFor)[0]; return { id: domain.id, - type: `${mapping?.[currentDb]?.toLocaleLowerCase()}${domain.len || ''}${ - domain.scale || '' - }`, + type: `${mapping?.[currentDb]?.toLocaleLowerCase()}${domain.len || ''}${domain.scale || '' + }`, }; }) .filter( @@ -541,13 +541,12 @@ const Index = React.memo( ], // eslint-disable-next-line no-nested-ternary title: FormatMessage.string({ - id: `toolbar.${ - type === 'chiner' - ? 'importCHNR' - : type === 'PDManer' + id: `toolbar.${type === 'chiner' + ? 'importCHNR' + : type === 'PDManer' ? 'importPDManer' : 'importPDMan' - }`, + }`, }), }, ); @@ -577,8 +576,8 @@ const Index = React.memo( type === 'chiner' ? 'invalidCHNRFile' : type === 'PDManer' - ? 'invalidPDManerFile' - : 'invalidPDManFile', + ? 'invalidPDManerFile' + : 'invalidPDManFile', }), }); } @@ -766,11 +765,11 @@ const Index = React.memo( codeTemplates: 'dictSQLTemplate' in data ? codeTemplates.map((t) => { - if (t.applyFor === 'dictSQLTemplate' && t.type === 'dbDDL') { - return data.dictSQLTemplate; - } - return t; - }) + if (t.applyFor === 'dictSQLTemplate' && t.type === 'dbDDL') { + return data.dictSQLTemplate; + } + return t; + }) : codeTemplates, }, }); @@ -1421,12 +1420,91 @@ const Index = React.memo( } return m.defName; }; + const handleExportDataBase = (e, dataSource) => { + e.stopPropagation() + const { entities, domains } = dataSource + const workBook = window.XLSX.utils.book_new(); + for (let index = 0; index < entities.length; index++) { + const data = entities[index]; + const headers = data.headers + .filter((item) => item.refKey !== 'isStandard') + .map((item) => FormatMessage.string({ id: `tableExportHeaders.${item.refKey}` })); + const keyList = data.headers + .filter((item) => item.refKey !== 'isStandard') + .map((item) => item.refKey); + const tableColumnData = data.fields + .map((item) => { + // 判断为哪个数据域字典 + const { + len, + defName: domain, + scale, + uiHint, + } = domains.find((domain) => domain.id === item.domain); + + // 数据字典处理 + const obj = { ...item, len, domain, scale, uiHint }; + if (item.defKey.indexOf('time') === -1) { + obj.type = 'VARCHAR'; + } else { + obj.type = 'DATETIME'; + } + return obj; + }) + .map((item) => { + return keyList.map((key) => + typeof item[key] === 'boolean' ? (item[key] ? '是' : '否') : item[key], + ); + }); + tableColumnData.unshift(headers); + const workSheet = window.XLSX.utils.aoa_to_sheet(tableColumnData); + + if (!workSheet['!cols']) workSheet['!cols'] = []; + for (let i = 0; i <= 21; i += 1) { + if (i === 0 || i === 1) { + workSheet['!cols'][i] = { wpx: 260 }; + } else { + workSheet['!cols'][i] = { wpx: 150 }; + } + } + window.XLSX.utils.book_append_sheet(workBook, workSheet, data.defName); + } + + window.XLSX.writeFile(workBook, '数据表.xlsx'); + }; + const handleImportDataBase = (e, dataSource) => { + e.stopPropagation() + + const fileInput = document.createElement('input'); // 创建文件选择输入框 + fileInput.setAttribute('type', 'file'); // 设置类型为'file' + fileInput.onchange = function (event) { + restProps.openLoading(FormatMessage.string({ id: 'toolbar.standardDataImport' })); + var file = event.target.files; + const { entities, domains } = JSON.parse(JSON.stringify(dataSource)); + const currentDataSource = getDataSource(); + console.log(entities, currentDataSource, restProps, file, mockData); + // 字典映射 + restProps.update({ + ...currentDataSource, + entities: [...entities, ...mockData] + }) + setTimeout(()=>{ + restProps.closeLoading(); + },2000) + // 进行相关操作... + }; + + fileInput.click(); // 模拟点击事件,弹出文件选择对话框 + + + + } const _colorChange = (key, value) => { // 颜色发生变化 const cavRef = getCurrentCav(); cavRef.updateColor(key, value); }; - const iconClick = (e, key) => { + const iconClick = (e, key, dataSource) => { switch (key) { case 'save': saveProject(); @@ -1510,10 +1588,19 @@ const Index = React.memo( case 'group': createGroupNode(e); break; + case 'standardDataExport': + handleExportDataBase(e, dataSource); + case 'standardDataImport': + handleImportDataBase(e, dataSource); default: + + break; } }; + + + // 在过滤为空的数据 const tempMenu = menus[groupType]; const currentPrefix = getPrefix(prefix); @@ -1724,7 +1811,7 @@ const Index = React.memo( const setCurrentVersion = (v, i) => { currentVersionRef.current?.setVersion(v, restProps.versionsData[i + 1]); }; - const getanniu = () => {}; + const getanniu = () => { }; return ( - {} + { }
{ const [eidtLoading, setEidtLoading] = useState(false) const [searchLoading, setSearchLoading] = useState(false) React.useEffect(() => { - goin(current, pagesize) + const params = new URLSearchParams(window.location.search); + const projectId = params.get('projectId'); + if (projectId) { + setSpinCard(true) + getModelId(projectId).then((res) => { + if (res.code == 200) { + setSpinCard(false) + const manerDataKey = JSON.parse(res.data.jsonFile) + openTemplate(manerDataKey, res.data.projectName) + } + }) + } else { + goin(current, pagesize) + } user() }, []) // 用户列表 @@ -259,7 +272,7 @@ export default ({ openTemplate }) => { okText: '确定', okType: 'danger', cancelText: '取消', - async onOk () { + async onOk() { await deleteProject(projectId) setTimeout(() => { message.success('删除成功') @@ -286,6 +299,7 @@ export default ({ openTemplate }) => {
-
{item.projectDescription}
+
{item.projectDescription}