提交 243c069f 编写于 作者: D DCloud_LXH

feat: setClipboardData 支持配置是否弹出提示

上级 5e2caae8
...@@ -204,7 +204,7 @@ function createApiCallback (apiName, params = {}, extras = {}) { ...@@ -204,7 +204,7 @@ function createApiCallback (apiName, params = {}, extras = {}) {
const errMsg = res.errMsg const errMsg = res.errMsg
if (errMsg.indexOf(apiName + ':ok') === 0) { if (errMsg.indexOf(apiName + ':ok') === 0) {
isFn(beforeSuccess) && beforeSuccess(res) isFn(beforeSuccess) && beforeSuccess(res, params)
hasSuccess && success(res) hasSuccess && success(res)
......
...@@ -3,11 +3,20 @@ import { ...@@ -3,11 +3,20 @@ import {
} from 'uni-core/helpers/i18n' } from 'uni-core/helpers/i18n'
export const setClipboardData = { export const setClipboardData = {
beforeSuccess () { data: {
type: String,
required: true
},
showToast: {
type: Boolean,
default: true
},
beforeSuccess (res, params) {
if (!params.showToast) return
const title = t('uni.setClipboardData.success') const title = t('uni.setClipboardData.success')
if (title) { if (title) {
uni.showToast({ uni.showToast({
title: t('uni.setClipboardData.success'), title,
icon: 'success', icon: 'success',
mask: false, mask: false,
style: { style: {
......
...@@ -22,7 +22,7 @@ export function setClipboardData ({ ...@@ -22,7 +22,7 @@ export function setClipboardData ({
const textarea = document.createElement('textarea') const textarea = document.createElement('textarea')
textarea.id = '#clipboard' textarea.id = '#clipboard'
textarea.style.position = 'absolute' textarea.style.position = 'absolute'
textarea.style.top = '0' textarea.style.top = '-9999px'
textarea.style.zIndex = '-9999' textarea.style.zIndex = '-9999'
document.body.appendChild(textarea) document.body.appendChild(textarea)
textarea.value = data textarea.value = data
...@@ -30,10 +30,6 @@ export function setClipboardData ({ ...@@ -30,10 +30,6 @@ export function setClipboardData ({
textarea.select() textarea.select()
const result = document.execCommand('Copy', false, null) const result = document.execCommand('Copy', false, null)
if (result) { if (result) {
uni.showToast({
title: '复制成功',
icon: 'none'
})
return { return {
errMsg: 'setClipboardData:ok' errMsg: 'setClipboardData:ok'
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册