import { IControl, IDataSource, SourceCode, ITableDefinition, ComponentControl, ControlType } from '@datahu/core' import {I18n} from '../i18n' import {BaseDataSource, BaseDataSourceOption} from '../base' import {ExcelHelper} from './ExcelHelper' export class ExcelDataSourceOption extends BaseDataSourceOption { static controls: Array = [] @ComponentControl({ type: ControlType.filePath, title: '上传Excel文件' }) source: string = '' @ComponentControl({ type: ControlType.boolean, title: '指定表头起始位置' }) customStart: boolean = false @ComponentControl({ type: ControlType.number, title: '起始行', show: (opt: any) => { return opt.customStart } }) startRow: number = 1 @ComponentControl({ type: ControlType.select, title: '起始列', show: (opt: any) => { return opt.customStart }, options: () => { let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' let opts = [] let i = 1 for (let c of chars) { opts.push({label: c, value: i}) i++ } for (let c of chars) { opts.push({label: 'A' + c, value: i}) i++ } return opts } }) startColumn: number = 1 } export class ExcelDataSource extends BaseDataSource { helper?: ExcelHelper constructor(language: string, config?: ExcelDataSourceOption) { super(language, config) this.title = 'Excel' this.description = 'Excel文件' if (config) { this.helper = new ExcelHelper(config) } } // 数据源默认配置值 config: ExcelDataSourceOption = new ExcelDataSourceOption() icon: string = '' sourceCode: SourceCode = SourceCode.None getTables(): Promise> { return this.helper!.getTables() } getData(tables: Array): Promise> { return this.helper!.getData(tables) } }