Skip to content

Commit

Permalink
Merge pull request #18 from lsxuan12138/main
Browse files Browse the repository at this point in the history
feat:点击token时,将其复制到剪切板
  • Loading branch information
SolidFaker authored Nov 1, 2024
2 parents deecafc + 3b59044 commit e2d2fa8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion entry/src/main/ets/components/TokenItem.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 });
}

0 comments on commit e2d2fa8

Please sign in to comment.