From 3b5904448402f408e4c938a96fe1abb80fef9c44 Mon Sep 17 00:00:00 2001 From: lsxuan12138 <1146887979@qq.com> Date: Fri, 1 Nov 2024 13:51:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=82=B9=E5=87=BBtoken=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=B0=86=E5=85=B6=E5=A4=8D=E5=88=B6=E5=88=B0=E5=89=AA=E5=88=87?= =?UTF-8?q?=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/components/TokenItem.ets | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/components/TokenItem.ets b/entry/src/main/ets/components/TokenItem.ets index b7a3176..a2eaeed 100644 --- a/entry/src/main/ets/components/TokenItem.ets +++ b/entry/src/main/ets/components/TokenItem.ets @@ -2,7 +2,8 @@ import { systemDateTime } from '@kit.BasicServicesKit'; import { otpType, TokenConfig } from '../utils/TokenConfig'; import { generateOTP } from '../utils/TokenUtils'; import { TokenIcon } from './TokenIcon'; -import { router } from '@kit.ArkUI'; +import { pasteboard } from '@kit.BasicServicesKit'; +import { promptAction } from '@kit.ArkUI'; @Preview @ComponentV2 @@ -83,6 +84,7 @@ export struct TokenItem { .maxLines(1) .fontColor($r('app.color.token_number')) .fontSize(30) + .onClick(() => copyText(this.TokenNumber)) if (this.Config.TokenType == otpType.HOTP) { Text(this.TokenCounter) .textAlign(TextAlign.End) @@ -136,4 +138,10 @@ export struct TokenItem { //router.pushUrl({ url: 'pages/ShowCodePage' }); }) } +} +function copyText(text: string) { + const pasteboardData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, text); + const systemPasteboard = pasteboard.getSystemPasteboard(); + systemPasteboard.setData(pasteboardData); // 将数据放入剪切板 + promptAction.showToast({ message: 'Token copied:'+text }); } \ No newline at end of file