44 updateShorten ,
55 deleteShorten ,
66} from '@/services/shortener/shorten' ;
7- import { PlusOutlined } from '@ant-design/icons' ;
7+ import { CopyOutlined , PlusOutlined } from '@ant-design/icons' ;
88import type { ActionType , ProColumns , ProFormInstance } from '@ant-design/pro-components' ;
99import {
1010 FooterToolbar ,
@@ -15,18 +15,28 @@ import {
1515 ProTable ,
1616} from '@ant-design/pro-components' ;
1717import '@umijs/max' ;
18- import { Button , message } from 'antd' ;
18+ import { Button , message , Tooltip } from 'antd' ;
1919import React , { useRef , useState } from 'react' ;
2020import type { FormValueType } from './components/UpdateForm' ;
2121import UpdateForm from './components/UpdateForm' ;
2222import { createStyles } from 'antd-style' ;
2323import { history } from 'umi' ;
2424
25- const useStyles = createStyles ( ( ) => {
25+ const useStyles = createStyles ( ( { token } ) => {
2626 return {
2727 footerToolBar : {
2828 fontWeight : 600 ,
2929 } ,
30+ codeContainer : {
31+ display : 'flex' ,
32+ justifyContent : 'flex-end' ,
33+ alignItems : 'center' ,
34+ gap : 8 ,
35+ } ,
36+ copyIcon : {
37+ cursor : 'pointer' ,
38+ color : token . colorPrimary ,
39+ } ,
3040 } ;
3141} ) ;
3242
@@ -49,6 +59,12 @@ const TableList: React.FC = () => {
4959
5060 const { styles } = useStyles ( ) ;
5161
62+ const copyToClipboard = ( text : string , messageText : string ) => {
63+ navigator . clipboard . writeText ( text ) . then ( ( ) => {
64+ messageApi . success ( messageText ) ;
65+ } ) ;
66+ } ;
67+
5268 /**
5369 * @en -US Add node
5470 * @zh -CN 添加节点
@@ -129,21 +145,51 @@ const TableList: React.FC = () => {
129145 dataIndex : 'id' ,
130146 hideInSearch : true ,
131147 } ,
148+ // {
149+ // title: '短码',
150+ // dataIndex: 'code',
151+ // copyable: true,
152+ // renderText: (text, record) => record.short_url, // 指定复制的内容
153+ // render: (dom, entity) => {
154+ // return (
155+ // <a
156+ // onClick={() => {
157+ // window.open(entity.short_url, '_blank');
158+ // }}
159+ // >
160+ // {dom}
161+ // </a>
162+ // );
163+ // },
164+ // },
132165 {
133166 title : '短码' ,
134167 dataIndex : 'code' ,
135- copyable : true ,
136- render : ( dom , entity ) => {
137- return (
168+ width : 10 ,
169+ render : ( _ , entity ) => (
170+ < span className = { styles . codeContainer } >
138171 < a
139- onClick = { ( ) => {
140- window . open ( entity . short_url , '_blank' ) ;
141- } }
172+ href = { entity . short_url }
173+ target = "_blank"
174+ rel = "noopener noreferrer"
175+ onClick = { ( e ) => e . stopPropagation ( ) }
142176 >
143- { dom }
177+ { entity . code }
144178 </ a >
145- ) ;
146- } ,
179+ < Tooltip title = "复制短码" >
180+ < CopyOutlined
181+ className = { styles . copyIcon }
182+ onClick = { ( ) => copyToClipboard ( entity . code as string , '短码复制成功' ) }
183+ />
184+ </ Tooltip >
185+ < Tooltip title = "复制短链" >
186+ < CopyOutlined
187+ className = { styles . copyIcon }
188+ onClick = { ( ) => copyToClipboard ( entity . short_url as string , '短链复制成功' ) }
189+ />
190+ </ Tooltip >
191+ </ span >
192+ ) ,
147193 } ,
148194 {
149195 title : '源地址' ,
0 commit comments