chenqs

ref |> 添加长按复制到剪切板功能

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
... ...