提交 6b0586dc 编写于 作者: D DCloud_LXH

feat(H5): setClipboardData、getClipboardData

上级 02488769
......@@ -17,6 +17,8 @@
"uni.previewImage.save.success": "Saved successfully",
"uni.previewImage.save.fail": "Save failed",
"uni.setClipboardData.success": "Content copied",
"uni.setClipboardData.fail": "Copy failed, please copy manually",
"uni.getClipboardData.fail": "Reading failed, please paste manually",
"uni.scanCode.title": "Scan code",
"uni.scanCode.album": "Album",
"uni.scanCode.fail": "Recognition failure",
......
......@@ -17,6 +17,8 @@
"uni.previewImage.save.success": "Guardado exitosamente",
"uni.previewImage.save.fail": "Error al guardar",
"uni.setClipboardData.success": "Contenido copiado",
"uni.setClipboardData.fail": "Error al copiar, copie manualmente",
"uni.getClipboardData.fail": "Error de lectura, pegue manualmente",
"uni.scanCode.title": "Código de escaneo",
"uni.scanCode.album": "Álbum",
"uni.scanCode.fail": "Échec de la reconnaissance",
......
......@@ -17,6 +17,8 @@
"uni.previewImage.save.success": "Enregistré avec succès",
"uni.previewImage.save.fail": "Échec de la sauvegarde",
"uni.setClipboardData.success": "Contenu copié",
"uni.setClipboardData.fail": "Échec de la copie, copiez manuellement",
"uni.getClipboardData.fail": "Échec de la lecture, veuillez coller manuellement",
"uni.scanCode.title": "Code d’analyse",
"uni.scanCode.album": "Album",
"uni.scanCode.fail": "Fallo de reconocimiento",
......
......@@ -410,39 +410,89 @@ export const initI18nPreviewImageMsgsOnce = /*#__PURE__*/ once(() => {
})
export const initI18nSetClipboardDataMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.setClipboardData.'
const keys = ['success']
const keys = ['success', 'fail']
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(
LOCALE_EN,
normalizeMessages(name, keys, ['Content copied']),
normalizeMessages(name, keys, [
'Content copied',
'Copy failed, please copy manually',
]),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(
LOCALE_ES,
normalizeMessages(name, keys, ['Contenido copiado']),
normalizeMessages(name, keys, [
'Contenido copiado',
'Error al copiar, copie manualmente',
]),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(
LOCALE_FR,
normalizeMessages(name, keys, ['Contenu copié']),
normalizeMessages(name, keys, [
'Contenu copié',
'Échec de la copie, copiez manuellement',
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['内容已复制', '复制失败,请手动复制']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['內容已復制', '復制失敗,請手動復製']),
false
)
}
})
export const initI18nGetClipboardDataMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.getClipboardData.'
const keys = ['fail']
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(
LOCALE_EN,
normalizeMessages(name, keys, ['Reading failed, please paste manually']),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(
LOCALE_ES,
normalizeMessages(name, keys, ['Error de lectura, pegue manualmente']),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(
LOCALE_FR,
normalizeMessages(name, keys, [
'Échec de la lecture, veuillez coller manuellement',
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['内容已复制']),
normalizeMessages(name, keys, ['读取失败,请手动粘贴']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['內容已復制']),
normalizeMessages(name, keys, ['讀取失敗,請手動粘貼']),
false
)
}
......
......@@ -17,6 +17,8 @@
"uni.previewImage.save.success": "保存图像到相册成功",
"uni.previewImage.save.fail": "保存图像到相册失败",
"uni.setClipboardData.success": "内容已复制",
"uni.setClipboardData.fail": "复制失败,请手动复制",
"uni.getClipboardData.fail": "读取失败,请手动粘贴",
"uni.scanCode.title": "扫码",
"uni.scanCode.album": "相册",
"uni.scanCode.fail": "识别失败",
......
......@@ -17,6 +17,8 @@
"uni.previewImage.save.success": "保存圖像到相冊成功",
"uni.previewImage.save.fail": "保存圖像到相冊失敗",
"uni.setClipboardData.success": "內容已復制",
"uni.setClipboardData.fail": "復制失敗,請手動復製",
"uni.getClipboardData.fail": "讀取失敗,請手動粘貼",
"uni.scanCode.title": "掃碼",
"uni.scanCode.album": "相冊",
"uni.scanCode.fail": "識別失敗",
......
......@@ -30,6 +30,7 @@
"createSelectorQuery",
"createVideoContext",
"downloadFile",
"getClipboardData",
"getFileInfo",
"getImageInfo",
"getLeftWindowStyle",
......@@ -103,6 +104,7 @@
"saveVideoToPhotosAlbum",
"scanCode",
"sendSocketMessage",
"setClipboardData",
"setKeepScreenOn",
"setLeftWindowStyle",
"setLocale",
......
import {
API_GET_CLIPBOARD_DATA,
API_SET_CLIPBOARD_DATA,
API_TYPE_GET_CLIPBOARD_DATA,
API_TYPE_SET_CLIPBOARD_DATA,
SetClipboardDataOptions,
SetClipboardDataProtocol,
defineAsyncApi,
} from '@dcloudio/uni-api'
import { showModal } from '../../api/ui/popup/showModal'
import {
useI18n,
initI18nSetClipboardDataMsgsOnce,
initI18nGetClipboardDataMsgsOnce,
} from '@dcloudio/uni-core'
export const getClipboardData = defineAsyncApi<API_TYPE_GET_CLIPBOARD_DATA>(
API_GET_CLIPBOARD_DATA,
async (_, { resolve, reject }) => {
initI18nGetClipboardDataMsgsOnce()
const { t } = useI18n()
try {
const data = await navigator.clipboard.readText()
resolve({ data })
} catch (error: any) {
reject(`${error} ${t('uni.getClipboardData.fail')}`)
}
}
)
export const setClipboardData = defineAsyncApi<API_TYPE_SET_CLIPBOARD_DATA>(
API_SET_CLIPBOARD_DATA,
async ({ data }, { resolve, reject }) => {
initI18nSetClipboardDataMsgsOnce()
const { t } = useI18n()
try {
await navigator.clipboard.writeText(data)
resolve()
} catch (error) {
reject()
showModal({
title: t('uni.setClipboardData.fail'),
content: data,
editable: true,
})
}
},
SetClipboardDataProtocol,
SetClipboardDataOptions
)
......@@ -20,6 +20,7 @@ export * from './device/network'
export * from './device/accelerometer'
export * from './device/compass'
export * from './device/vibrate'
export * from './device/clipboard'
export * from './storage/storage'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册