diff --git a/console-ui/src/components/Copy/index.jsx b/console-ui/src/components/Copy/index.jsx index a29ffc7f835..576cd0d4b19 100644 --- a/console-ui/src/components/Copy/index.jsx +++ b/console-ui/src/components/Copy/index.jsx @@ -18,37 +18,10 @@ import React from 'react'; import { withRouter } from 'react-router-dom'; import { Icon, Message } from '@alifd/next'; import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; -// 创建假元素 -function createFakeElement(value) { - const fakeElement = document.createElement('textarea'); - - fakeElement.style.border = '0'; - fakeElement.style.padding = '0'; - fakeElement.style.margin = '0'; - - fakeElement.style.position = 'absolute'; - fakeElement.style.left = '-999px'; - fakeElement.style.top = `${window.pageYOffset || document.documentElement.scrollTop}px`; - fakeElement.setAttribute('readonly', ''); - fakeElement.value = value; - return fakeElement; -} - -function copyText(value) { - const element = createFakeElement(value); - document.body.appendChild(element); - - // 选中元素 - element.focus(); - element.select(); - element.setSelectionRange(0, element.value.length); - - document.execCommand('copy'); - document.body.removeChild(element); - Message.success('Success copied!'); -} +@connect(state => ({ ...state.locale })) @withRouter class Copy extends React.Component { static displayName = 'Copy'; @@ -59,20 +32,27 @@ class Copy extends React.Component { textNode: PropTypes.string, className: PropTypes.string, showIcon: PropTypes.bool, + title: PropTypes.string, + locale: PropTypes.object, }; +copyText(locale, value) { + navigator.clipboard.writeText(value); + Message.success(locale.Components.copySuccessfully); +} + render() { - const { style = {}, value, textNode, className, showIcon = true } = this.props; + const { style = {}, value, textNode, className, showIcon = true, title, locale } = this.props; return ( -
(showIcon ? '' : copyText(value))} style={style}> +
(showIcon ? '' : this.copyText(locale, value))} style={style}> {textNode || value} {showIcon && ( copyText(value)} + onClick={() => this.copyText(locale, value)} /> )}
diff --git a/console-ui/src/components/PageTitle/index.js b/console-ui/src/components/PageTitle/index.js index 816faf9578b..b8933e086e8 100644 --- a/console-ui/src/components/PageTitle/index.js +++ b/console-ui/src/components/PageTitle/index.js @@ -15,7 +15,7 @@ */ import React from 'react'; -import { Provider, connect } from 'react-redux'; +import { connect } from 'react-redux'; import { withRouter } from 'react-router-dom'; import PropTypes from 'prop-types'; import Copy from '../Copy'; @@ -25,18 +25,20 @@ import Copy from '../Copy'; class PageTitle extends React.Component { static propTypes = { title: PropTypes.string, + namespaceId: PropTypes.string, + namespaceName: PropTypes.string, desc: PropTypes.string, nameSpace: PropTypes.bool, locale: PropTypes.object, }; - getNameSpace(locale, desc, nameSpace) { + getNameSpace(locale, namespaceId, namespaceName, desc, nameSpace) { if (!nameSpace) { - return desc; + return namespaceId; } return ( - {locale.NameSpace.namespaceID} + {locale.NameSpace.namespace} ); } render() { - const { title, desc, nameSpace, locale } = this.props; + const { title, namespaceId, namespaceName, desc, nameSpace, locale } = this.props; return (
{title} - {desc && desc !== 'undefined' ? this.getNameSpace(locale, desc, nameSpace) : ''} + {namespaceId && namespaceId !== 'undefined' + ? this.getNameSpace(locale, namespaceId, namespaceName, desc, nameSpace) + : ''}
); diff --git a/console-ui/src/pages/NameSpace/NameSpace.js b/console-ui/src/pages/NameSpace/NameSpace.js index 75f144497ec..e5e119138e5 100644 --- a/console-ui/src/pages/NameSpace/NameSpace.js +++ b/console-ui/src/pages/NameSpace/NameSpace.js @@ -16,13 +16,14 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Button, ConfigProvider, Dialog, Loading, Table } from '@alifd/next'; +import { Button, ConfigProvider, Dialog, Loading, Table, Form } from '@alifd/next'; import RegionGroup from '../../components/RegionGroup'; import NewNameSpace from '../../components/NewNameSpace'; import EditorNameSpace from '../../components/EditorNameSpace'; import { getParams, setParams, request } from '../../globalLib'; import './index.scss'; +import PageTitle from '../../components/PageTitle'; @ConfigProvider.config class NameSpace extends React.Component { @@ -297,7 +298,7 @@ class NameSpace extends React.Component { } = locale; return ( <> - +
+
+
+ + + + + + +
+
+
-
- - -