提交 82acc025 编写于 作者: D DCloud_LXH

feat(App): setClipboardData 支持配置 showToast

上级 7a5c0f88
......@@ -132,7 +132,7 @@ export function createAsyncApiCallback(
res.errMsg = normalizeErrMsg(res.errMsg, name)
isFunction(beforeAll) && beforeAll(res)
if (res.errMsg === name + ':ok') {
isFunction(beforeSuccess) && beforeSuccess(res)
isFunction(beforeSuccess) && beforeSuccess(res, args)
hasSuccess && success!(res)
} else {
hasFail && fail!(res)
......
import { initI18nSetClipboardDataMsgsOnce, useI18n } from '@dcloudio/uni-core'
export const API_GET_CLIPBOARD_DATA = 'getClipboardData'
export const API_SET_CLIPBOARD_DATA = 'setClipboardData'
export type API_TYPE_GET_CLIPBOARD_DATA = typeof uni.getClipboardData
export type API_TYPE_SET_CLIPBOARD_DATA = typeof uni.setClipboardData
export const SetClipboardDataOptions: ApiOptions<API_TYPE_SET_CLIPBOARD_DATA> =
{
beforeSuccess() {
uni.showToast({
title: '内容已复制',
icon: 'success',
mask: false,
})
formatArgs: {
showToast: true,
},
beforeInvoke() {
initI18nSetClipboardDataMsgsOnce()
},
beforeSuccess(res, params) {
if (params.showToast) return
const { t } = useI18n()
const title = t('uni.setClipboardData.success')
if (title) {
uni.showToast({
title: title,
icon: 'success',
mask: false,
})
}
},
}
export const SetClipboardDataProtocol: ApiProtocol<API_TYPE_SET_CLIPBOARD_DATA> =
{
data: {
type: String,
required: true,
},
showToast: {
type: Boolean,
},
}
......@@ -20,7 +20,7 @@ type ApiProtocols<T extends ApiLike> = ApiProtocol<T> | ProtocolOptions[]
interface ApiOptions<T extends ApiLike, P = AsyncApiOptions<T>> {
beforeInvoke?: (args: unknown) => boolean | void | string
beforeAll?: (res: unknown) => void
beforeSuccess?: (res: unknown) => void
beforeSuccess?: (res: unknown, args: P) => void
formatArgs?: {
[K in keyof P]?: ApiArgsValidator<P[K], P> | P[K]
}
......
......@@ -3,6 +3,8 @@ import {
API_SET_CLIPBOARD_DATA,
API_TYPE_GET_CLIPBOARD_DATA,
API_TYPE_SET_CLIPBOARD_DATA,
SetClipboardDataOptions,
SetClipboardDataProtocol,
defineAsyncApi,
} from '@dcloudio/uni-api'
import { requireNativePlugin } from '../plugin/requireNativePlugin'
......@@ -29,5 +31,7 @@ export const setClipboardData = defineAsyncApi<API_TYPE_SET_CLIPBOARD_DATA>(
const clipboard = requireNativePlugin('clipboard')
clipboard.setString(options.data)
resolve()
}
},
SetClipboardDataProtocol,
SetClipboardDataOptions
)
......@@ -922,10 +922,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@dcloudio/types@2.5.11":
version "2.5.11"
resolved "https://registry.yarnpkg.com/@dcloudio/types/-/types-2.5.11.tgz#12bacd800807965e3d0002022efebba38c243b71"
integrity sha512-dgAI1fNAhOhQumxO3P901VOYlfnXGJCDljFsZ3EqGGKitf5FB0HSZEutnam2O1zrHwqmHkSSJ+5jiYOED0B8kA==
"@dcloudio/types@2.5.12":
version "2.5.12"
resolved "https://registry.yarnpkg.com/@dcloudio/types/-/types-2.5.12.tgz#e731f45f92ded64f9823fef8699ffddf2b7998de"
integrity sha512-BIO2fZTW+L2MybVDsIIYuk3Z7EHB5bi7V4AQw8WzjkdDBzHZuiCCTrwPpVDhDWEKDvaWYMZNCJx9w7Z357x//w==
"@eslint/eslintrc@^0.4.3":
version "0.4.3"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册