From a1fe2b94ba4d37ffc6bd200c63f89567c3ad5c50 Mon Sep 17 00:00:00 2001 From: tianjiaxing Date: Fri, 25 Jun 2021 15:01:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(App):=20setClipboardData=E3=80=81getClipbo?= =?UTF-8?q?ardData?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/protocols/device/setClipboardData.ts | 2 ++ .../src/service/api/device/clipboard.ts | 33 +++++++++++++++++++ .../uni-app-plus/src/service/api/index.ts | 1 + 3 files changed, 36 insertions(+) create mode 100644 packages/uni-app-plus/src/service/api/device/clipboard.ts diff --git a/packages/uni-api/src/protocols/device/setClipboardData.ts b/packages/uni-api/src/protocols/device/setClipboardData.ts index c630129b44..01d3088aee 100644 --- a/packages/uni-api/src/protocols/device/setClipboardData.ts +++ b/packages/uni-api/src/protocols/device/setClipboardData.ts @@ -1,4 +1,6 @@ +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 = { diff --git a/packages/uni-app-plus/src/service/api/device/clipboard.ts b/packages/uni-app-plus/src/service/api/device/clipboard.ts new file mode 100644 index 0000000000..9f0a971719 --- /dev/null +++ b/packages/uni-app-plus/src/service/api/device/clipboard.ts @@ -0,0 +1,33 @@ +import { + API_GET_CLIPBOARD_DATA, + API_SET_CLIPBOARD_DATA, + API_TYPE_GET_CLIPBOARD_DATA, + API_TYPE_SET_CLIPBOARD_DATA, + defineAsyncApi, +} from '@dcloudio/uni-api' +import { requireNativePlugin } from '../base' + +export const getClipboardData = defineAsyncApi( + API_GET_CLIPBOARD_DATA, + (_, { resolve, reject }) => { + const clipboard = requireNativePlugin('clipboard') + clipboard.getString((ret: any) => { + if (ret.result === 'success') { + resolve({ + data: ret.data, + }) + } else { + reject('getClipboardData:fail') + } + }) + } +) + +export const setClipboardData = defineAsyncApi( + API_SET_CLIPBOARD_DATA, + (options, { resolve }) => { + const clipboard = requireNativePlugin('clipboard') + clipboard.setString(options.data) + resolve() + } +) diff --git a/packages/uni-app-plus/src/service/api/index.ts b/packages/uni-app-plus/src/service/api/index.ts index adcf00c366..91edd3200f 100644 --- a/packages/uni-app-plus/src/service/api/index.ts +++ b/packages/uni-app-plus/src/service/api/index.ts @@ -8,6 +8,7 @@ export * from './device/accelerometer' export * from './device/bluetooth' export * from './device/ibeacon' export * from './device/makePhoneCall' +export * from './device/clipboard' export * from './media/getImageInfo' export * from './media/getVideoInfo' -- GitLab