diff --git a/console/src/main/resources/static/console-fe/src/pages/ConfigurationManagement/ConfigEditor/NewConfigEditor.js b/console/src/main/resources/static/console-fe/src/pages/ConfigurationManagement/ConfigEditor/NewConfigEditor.js new file mode 100644 index 000000000..2af714adc --- /dev/null +++ b/console/src/main/resources/static/console-fe/src/pages/ConfigurationManagement/ConfigEditor/NewConfigEditor.js @@ -0,0 +1,301 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import PropTypes from 'prop-types'; +import './index.scss'; +import { + Balloon, + Button, + Dialog, + Field, + Form, + Checkbox, + Icon, + Input, + Loading, + Radio, + Switch, + Select, + Tab, + Message, + Grid, + ConfigProvider, +} from '@alifd/next'; + +const { Row, Col } = Grid; + +const LANGUAGE_LIST = [ + { value: 'text', label: 'TEXT' }, + { value: 'json', label: 'JSON' }, + { value: 'xml', label: 'XML' }, + { value: 'yaml', label: 'YAML' }, + { value: 'html', label: 'HTML' }, + { value: 'properties', label: 'Properties' }, +]; + +const TAB_LIST = [{ key: 'production', label: '正式' }, { key: 'beta', label: 'BETA' }]; + +@ConfigProvider.config +class ConfigEditor extends React.Component { + static displayName = 'ConfigEditor'; + + static propTypes = { + locale: PropTypes.object, + // history: PropTypes.object, + }; + + constructor(props) { + super(props); + this.state = { + loading: false, + isBeta: false, + betaPublishSuccess: false, + betaIps: '', + tabActiveKey: '', + form: { + dataId: '', // 配置 ID + group: '', // 分组 + tenant: '', // 租户 ID + content: '', // 配置内容 + appName: '', // 应用名 + desc: '', // 描述 + tags: [], + type: 'text', // 配置格式 + }, + tagDataSource: [], + openAdvancedSettings: false, + }; + this.field = new Field(this); + } + + componentDidMount() { + this.initMoacoEditor('json', '{"a":100}'); + } + + initMoacoEditor(language, value) { + const container = document.getElementById('container'); + const options = { + value, + language: this.state.configType, + codeLens: true, + selectOnLineNumbers: true, + roundedSelection: false, + readOnly: false, + lineNumbersMinChars: true, + theme: 'vs-dark', + wordWrapColumn: 120, + folding: false, + showFoldingControls: 'always', + wordWrap: 'wordWrapColumn', + cursorStyle: 'line', + automaticLayout: true, + }; + if (!window.monaco) { + window.importEditor(() => { + this.monacoEditor = window.monaco.editor.create(container, options); + }); + } else { + this.monacoEditor = window.monaco.editor.create(container, options); + } + } + + clickTab(tabActiveKey) { + this.setState({ tabActiveKey }); + } + + publish() { + console.log('publish...', this.state.form); + } + + publishBeta() { + this.setState({ betaPublishSuccess: true, tabActiveKey: 'beta' }); + } + + stopBeta() { + this.setState({ isBeta: false, betaPublishSuccess: false, tabActiveKey: '' }); + } + + changeForm(item) { + const { form } = this.state; + this.setState({ form: { ...form, ...item } }); + } + + setConfigTags(tags) { + const { tagDataSource } = this.state; + const lastTag = tags[tags.length - 1]; + if (tagDataSource.indexOf(lastTag) < 0) { + this.setState({ tagDataSource: [...tagDataSource, lastTag] }); + } + if (tags.length > 5) { + tags.pop(); + } + tags.forEach((v, i) => { + if (v.indexOf(',') !== -1 || v.indexOf('=') !== -1) { + tags.splice(i, 1); + } + }); + this.changeForm({ tags }); + } + + goBack() { + console.log('goBack'); + } + + render() { + const { + loading, + openAdvancedSettings, + isBeta, + betaPublishSuccess, + form, + tagDataSource, + tabActiveKey, + } = this.state; + const { locale = {} } = this.props; + + return ( +