Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
chenqs
2024-07-29 14:32:21 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3e9eeffa53558a46e8d2b1e5f97388b0973a5824
3e9eeffa
1 parent
fa120d22
ref |> 添加长按复制到剪切板功能
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
1 deletions
sight_harmony/products/phone/src/main/ets/pages/web/H5TipsPage.ets
sight_harmony/products/phone/src/main/ets/pages/web/H5TipsPage.ets
View file @
3e9eeff
import router from '@ohos.router';
import { Params } from '../../../../../../../commons/wdRouter/oh_modules/wdBean/src/main/ets/bean/content/Params';
import { Logger } from 'wdKit';
import { Logger
, ToastUtils
} from 'wdKit';
import { CustomTitleUI } from 'wdComponent/src/main/ets/components/reusable/CustomTitleUI';
import {BusinessError, pasteboard} from '@kit.BasicServicesKit';
const TAG = 'H5TipsPage'
...
...
@@ -42,10 +43,35 @@ struct H5TipsPage {
.textAlign(TextAlign.Center)
.margin({left: 40, right: 40})
.height(40)
.gesture(
LongPressGesture()
.onAction((event: GestureEvent|undefined)=>{
if (event) {
this.longPressToCopy()
}
})
)
}
.backgroundColor(Color.White)
.width("100%")
.height("100%")
}
private longPressToCopy() {
// 获取系统剪贴板对象
let systemPasteboard = pasteboard.getSystemPasteboard();
// 创建一条纯文本类型的剪贴板内容对象createPlainTextData
let pasteData = pasteboard.createPlainTextData(this.webUrl);
pasteData.addTextRecord(this.webUrl);
// 将数据写入系统剪贴板
systemPasteboard.setData(pasteData).then(()=>{
// 存入成功,处理正常场景
ToastUtils.shortToast('复制成功')
}).catch((error: BusinessError) => {
// 处理异常场景
Logger.info(TAG, '长按文字存储失败:' + error);
});
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment