Browse Source

已将新增工作表时的exportSheetName默认值修改为空字符串。现在添加新工作表时,"导出工作表名称"输入框将保持空白,用户可以根据需要填写自定义名称,若不填写则默认使用工作表名称作为导出名称。

yourname 5 months ago
parent
commit
10ca86b799

+ 2 - 0
.gitignore

@@ -101,3 +101,5 @@ app/routes/member/components/TemplateSelector.tsx
 app/routes/member/home/index.tsx
 app/routes/member/template/edit.tsx
 app/routes/member/template/list.tsx
+test/package.json
+test/pnpm-lock.yaml

+ 10 - 2
src/client/member/components/ExcelToJson/components/SheetConfig/index.tsx

@@ -1,7 +1,7 @@
 import React from 'react';
 import { Form, Input, InputNumber, Space, Card, Select, Switch } from 'antd';
-import { SheetConfigProps } from '../../types.ts';
-import FieldMapping from './FieldMapping.tsx';
+import { SheetConfigProps } from '../../types';
+import FieldMapping from './FieldMapping';
 
 const SheetConfig: React.FC<SheetConfigProps> = ({
   config,
@@ -74,6 +74,14 @@ const SheetConfig: React.FC<SheetConfigProps> = ({
         >
           <Input />
         </Form.Item>
+        <Form.Item
+          label="导出工作表名称"
+          name="exportSheetName"
+          rules={[{ required: false, message: '请输入导出工作表名称' }]}
+          style={{ marginBottom: '8px' }}
+        >
+          <Input placeholder="默认与工作表名称相同" />
+        </Form.Item>
         <Form.Item
           label="表头行号"
           name="headerRowIndex"

+ 3 - 1
src/client/member/components/ExcelToJson/hooks/useExcelParser.ts

@@ -394,7 +394,9 @@ export const useExcelParser = () => {
       }
       
       // 根据当前配置处理数据
-      exportData[sheetConfig.sheetName] = processDataForExport(
+      // 使用exportSheetName作为导出的工作表名称,默认为sheetName
+      const exportSheetName = sheetConfig.exportSheetName || sheetConfig.sheetName;
+      exportData[exportSheetName] = processDataForExport(
         rawDataForSheet,
         sheetConfig,
         1

+ 2 - 1
src/client/member/components/ExcelToJson/hooks/useSheetConfig.ts

@@ -16,13 +16,14 @@ export const useSheetConfig = (initialConfig: ExcelConfig, useDefaultSheet: bool
       dataStartRow: 2,
       endMarker: '',
       sheetName: `工作表${config.sheets.length + 1}`,
+      exportSheetName: '',
       exportFields: [],
       fieldMappings: {},
       requiredFields: []
     };
 
     const newSheetConfig = useDefaultSheet 
-      ? { ...defaultSheetConfig, sheetName: `工作表${config.sheets.length + 1}` }
+      ? { ...defaultSheetConfig, sheetName: `工作表${config.sheets.length + 1}`, exportSheetName: '' }
       : emptySheetConfig;
 
     const newConfig = {

+ 2 - 0
src/client/member/components/ExcelToJson/types.ts

@@ -21,6 +21,8 @@ export interface SheetConfig {
   endMarker: string;
   /** 工作表名称 */
   sheetName: string;
+  /** 导出工作表名称 */
+  exportSheetName: string;
   /** 导出字段 */
   exportFields: string[];
   /** 字段映射 */

+ 3 - 1
src/server/utils/excelParser.ts

@@ -573,7 +573,9 @@ export class ExcelParser {
       }
       
       // 根据当前配置处理数据
-      exportData[sheetConfig.sheetName] = this.processDataForExport(
+      // 使用exportSheetName作为导出的工作表名称,默认为sheetName
+      const exportSheetName = sheetConfig.exportSheetName || sheetConfig.sheetName;
+      exportData[exportSheetName] = this.processDataForExport(
         rawDataForSheet,
         sheetConfig,
         1