Files
yshop-pro-uniapp/hooks/useShearPlate.js
2023-11-14 17:21:03 +08:00

51 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @name: 剪切版封装
* @author: kahu4
* @date: 2023-10-30 14:06
* @descriptionuseShearPlate
* @update: 2023-10-30 14:06
* */
export const useShearPlate = () => {
/**
* 设置剪切版
* @param text{string} 设置的内容
* @param toast{string} 是否需要toast提示
* @returns {Promise<unknown>}
*/
function setData(text, toast = '') {
return new Promise((resolve, reject) => {
uni.setClipboardData({
data:text,
showToast:false,
success:()=>{
if(toast){
uni.showToast({title:toast})
}
return resolve(true)
},
fail:(error)=> {
reject(error)
}
})
})
}
/**
* 获取当前剪切板内容
* @returns {Promise<unknown>}
*/
function getData() {
return new Promise((resolve, reject) => {
uni.getClipboardData({
success: (res) => resolve(res),
fail: (error) => reject(error)
})
})
}
return {
setData,
getData,
}
}