import { IControl, IDataSource, SourceCode, ITableDefinition, ComponentControl, ControlType } from '@datahu/core' import {I18n} from '../i18n' import {BaseDataSource, BaseDataSourceOption} from '../base' import {InfluxHelper} from './InfluxHelper' export class InfluxDataSourceOption extends BaseDataSourceOption { static controls: Array = [] @ComponentControl({ type: ControlType.text, title: '服务器' }) host: string = 'localhost' @ComponentControl({ type: ControlType.number, title: '端口' }) port: number = 8086 @ComponentControl({ type: ControlType.select, title: '协议', options: [ {label: 'http', value: 'http'}, {label: 'https', value: 'https'} ] }) protocol: string = 'http' @ComponentControl({ type: ControlType.text, title: '用户名' }) username: string = '' @ComponentControl({ type: ControlType.password, title: '密码' }) password: string = '' @ComponentControl({ type: ControlType.text, title: '默认数据库' }) database: string = '' @ComponentControl({ type: ControlType.text, title: '路径' }) path: string = '' } export class InfluxDataSource extends BaseDataSource { helper?: InfluxHelper constructor(language: string, config?: InfluxDataSourceOption) { super(language, config) this.title = 'Influx DB' this.description = '时序数据库' if (config) { this.helper = new InfluxHelper(config) } } // 数据源默认配置值 config: InfluxDataSourceOption = new InfluxDataSourceOption() icon: string = '' sourceCode: SourceCode = SourceCode.Javascript getTables(): Promise> { return this.helper!.getTables() } getData(tables: Array): Promise> { return this.helper!.getData(tables) } }