Commit c9851406185199d62a0d465137d70a99dd6770ed

Authored by zhangzzzz
1 parent 65c63161

公式页面新增导入模板功能;

package.json
@@ -44,7 +44,8 @@ @@ -44,7 +44,8 @@
44 "react-sortable-hoc": "^2.0.0", 44 "react-sortable-hoc": "^2.0.0",
45 "react-to-print": "^3.0.5", 45 "react-to-print": "^3.0.5",
46 "umi": "^4.4.11", 46 "umi": "^4.4.11",
47 - "weixin-js-sdk": "1.6.0" 47 + "weixin-js-sdk": "1.6.0",
  48 + "xlsx": "^0.18.5"
48 }, 49 },
49 "devDependencies": { 50 "devDependencies": {
50 "@types/react": "^18.0.33", 51 "@types/react": "^18.0.33",
src/components/Common/CommonElementEvent.js
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 /* eslint-disable array-callback-return,no-undef,prefer-destructuring */ 2 /* eslint-disable array-callback-return,no-undef,prefer-destructuring */
3 import React, { Component } from 'react'; 3 import React, { Component } from 'react';
4 import { Modal, message } from 'antd-v4'; 4 import { Modal, message } from 'antd-v4';
  5 +import * as XLSX from 'xlsx';
5 import commonConfig from '../../utils/config'; 6 import commonConfig from '../../utils/config';
6 import * as commonFunc from './commonFunc'; 7 import * as commonFunc from './commonFunc';
7 import * as commonBusiness from './commonBusiness'; /* 单据业务功能 */ 8 import * as commonBusiness from './commonBusiness'; /* 单据业务功能 */
@@ -4068,6 +4069,9 @@ export default (ChildComponent) => { @@ -4068,6 +4069,9 @@ export default (ChildComponent) => {
4068 } 4069 }
4069 this.props.onSaveState({ 4070 this.props.onSaveState({
4070 masterData, masterConfig, customerInfoData, ...addState, contactData, enabled: sModelsType === 'system/sisformulaInfo' ? this.props.enabled : true, bUserModel: masterData.bUserModel, 4071 masterData, masterConfig, customerInfoData, ...addState, contactData, enabled: sModelsType === 'system/sisformulaInfo' ? this.props.enabled : true, bUserModel: masterData.bUserModel,
  4072 + }, () => {
  4073 + this.masterChangeCb && this.masterChangeCb();
  4074 + this.masterChangeCb = null;
4071 }); 4075 });
4072 }; 4076 };
4073 handleChangeProductParteName = (sAllPartsName, sisproductclassifyProcessClassifyConfigNew) => { 4077 handleChangeProductParteName = (sAllPartsName, sisproductclassifyProcessClassifyConfigNew) => {
@@ -4640,6 +4644,78 @@ export default (ChildComponent) => { @@ -4640,6 +4644,78 @@ export default (ChildComponent) => {
4640 return newWin; 4644 return newWin;
4641 } 4645 }
4642 4646
  4647 + // 导入模版功能
  4648 + handleImportExcel = () => {
  4649 + const fileInput = document.createElement('input');
  4650 + fileInput.type = 'file';
  4651 + fileInput.accept = '.xlsx, .xls';
  4652 + fileInput.style.position = 'fixed';
  4653 + fileInput.style.left = '-9999px';
  4654 + document.body.appendChild(fileInput);
  4655 +
  4656 + fileInput.addEventListener('change', (e) => {
  4657 + const file = e.target.files[0];
  4658 + if (file) {
  4659 + if (!file) return;
  4660 +
  4661 + const reader = new FileReader();
  4662 + reader.readAsArrayBuffer(file);
  4663 + reader.onload = (evt) => {
  4664 + try {
  4665 + const data = evt.target.result;
  4666 + const workbook = XLSX.read(data, { type: 'binary' });
  4667 + const sColTitleName = [];
  4668 + workbook.SheetNames.forEach((sheetName, i) => {
  4669 + const sheet = workbook.Sheets[sheetName];
  4670 + const parsedData = XLSX.utils.sheet_to_json(sheet, { header: 1 });
  4671 + const [firstRow, ...restRows] = parsedData;
  4672 + sColTitleName.push(firstRow.reduce((pre, item, index) => {
  4673 + if (index === 0) {
  4674 + pre.sName = item.replace('sName', '');
  4675 + } else if (item.endsWith('sName')) {
  4676 + pre[`sName${index}`] = item.replace('sName', '');
  4677 + } else {
  4678 + pre[`sValue${index}`] = item;
  4679 + }
  4680 + return pre;
  4681 + }, { panelName: sheetName }));
  4682 + });
  4683 + this.masterChangeCb = () => {
  4684 + const addState = {};
  4685 + workbook.SheetNames.forEach((sheetName, i) => {
  4686 + const sheet = workbook.Sheets[sheetName];
  4687 + const parsedData = XLSX.utils.sheet_to_json(sheet, { header: 1 });
  4688 + const [firstRow, ...restRows] = parsedData;
  4689 + const tableName = `customizeParam${i || ''}`;
  4690 + let { [`${tableName}Data`]: tableData = [], [`${tableName}DelData`]: tableDelData = [] } = this.props;
  4691 + tableDelData = [...tableDelData, ...tableData.map(item => ({ ...item, handleType: 'del' }))];
  4692 + tableData = restRows.map(item => {
  4693 + const columnKeys = Object.keys(sColTitleName[i]);
  4694 + columnKeys.shift();
  4695 + return { ...this.handleTableAdd(tableName, true), ...item.reduce((pre, cur, index) => {
  4696 + pre[columnKeys[index]] = cur;
  4697 + return pre;
  4698 + }, { sType: tableName }) };
  4699 + });
  4700 + addState[`${tableName}Data`] = tableData;
  4701 + addState[`${tableName}DelData`] = tableDelData;
  4702 + });
  4703 + this.props.onSaveState(addState);
  4704 + };
  4705 + this.handleMasterChange('masterData', 'sColTitleName', { sColTitleName: JSON.stringify(sColTitleName) }, undefined, []);
  4706 + } catch (error) {
  4707 + console.log('=====err', error);
  4708 + message.error('文件格式错误');
  4709 + }
  4710 + };
  4711 + }
  4712 +
  4713 + document.body.removeChild(fileInput);
  4714 + });
  4715 +
  4716 + fileInput.click();
  4717 + }
  4718 +
4643 /* 按钮点击功能 */ 4719 /* 按钮点击功能 */
4644 handleBtnClick = (e, btnName) => { 4720 handleBtnClick = (e, btnName) => {
4645 if (btnName === 'BtnAccounts') { 4721 if (btnName === 'BtnAccounts') {
@@ -4648,8 +4724,10 @@ export default (ChildComponent) => { @@ -4648,8 +4724,10 @@ export default (ChildComponent) => {
4648 this.handleDesignFunction(); 4724 this.handleDesignFunction();
4649 } else if (e === 'BtnResetpwd') { /* 管理员重置密码 */ 4725 } else if (e === 'BtnResetpwd') { /* 管理员重置密码 */
4650 this.handleResetPwd(); 4726 this.handleResetPwd();
4651 - } if (e === 'BtnOut') { 4727 + } else if (e === 'BtnOut') {
4652 this.handleOut(); 4728 this.handleOut();
  4729 + } else if (e === 'BtnImportExcel') { // 导入Excel模版
  4730 + this.handleImportExcel();
4653 } 4731 }
4654 // else if (e === 'BtnConfigCustomizeParam') { /* 生成变量设置 */ 4732 // else if (e === 'BtnConfigCustomizeParam') { /* 生成变量设置 */
4655 // const { masterData, customizeParamConfig } = this.props; 4733 // const { masterData, customizeParamConfig } = this.props;