pnpm提交
This commit is contained in:
parent
43b490a6b2
commit
d9013c6169
@ -3,9 +3,31 @@ import { writeClipboard } from '@solid-primitives/clipboard'
|
|||||||
|
|
||||||
export const useClipboardCopy = (source: string, delay = 1000) => {
|
export const useClipboardCopy = (source: string, delay = 1000) => {
|
||||||
const [copied, setCopied] = createSignal(false)
|
const [copied, setCopied] = createSignal(false)
|
||||||
|
//判断平台
|
||||||
|
const isMobile = () => {
|
||||||
|
let flag = navigator.userAgent.match(
|
||||||
|
/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
|
||||||
|
);
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
//手机端复制功能
|
||||||
|
const h5CopyText = (text: string) => {
|
||||||
|
var tempInput = document.createElement("input");
|
||||||
|
tempInput.value = text;
|
||||||
|
document.body.appendChild(tempInput);
|
||||||
|
tempInput.select();
|
||||||
|
document.execCommand("copy");
|
||||||
|
document.body.removeChild(tempInput);
|
||||||
|
};
|
||||||
|
|
||||||
|
const copy = async () => {
|
||||||
|
if (isMobile()) {
|
||||||
|
//复制功能
|
||||||
|
writeClipboard(source)
|
||||||
|
} else {
|
||||||
|
h5CopyText(source)
|
||||||
|
}
|
||||||
|
|
||||||
const copy = async() => {
|
|
||||||
writeClipboard(source)
|
|
||||||
setCopied(true)
|
setCopied(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,4 +39,4 @@ export const useClipboardCopy = (source: string, delay = 1000) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return [copied, copy] as const
|
return [copied, copy] as const
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user