mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-27 21:37:54 +08:00
77 lines
1.9 KiB
JavaScript
77 lines
1.9 KiB
JavaScript
/**
|
|
* @Author: 王林
|
|
* @Date: 2021-07-11 21:38:09
|
|
* @Desc: 全屏事件检测
|
|
*/
|
|
const getOnfullscreEnevt = () => {
|
|
if (document.documentElement.requestFullScreen) {
|
|
return 'onfullscreenchange'
|
|
} else if (document.documentElement.webkitRequestFullScreen) {
|
|
return 'onwebkitfullscreenchange'
|
|
} else if (document.documentElement.mozRequestFullScreen) {
|
|
return 'onmozfullscreenchange'
|
|
} else if (document.documentElement.msRequestFullscreen) {
|
|
return 'onmsfullscreenchange'
|
|
}
|
|
}
|
|
|
|
export const fullscrrenEvent = getOnfullscreEnevt()
|
|
|
|
/**
|
|
* @Author: 王林
|
|
* @Date: 2021-07-11 21:45:06
|
|
* @Desc: 全屏
|
|
*/
|
|
export const fullScreen = element => {
|
|
if (element.requestFullScreen) {
|
|
element.requestFullScreen()
|
|
} else if (element.webkitRequestFullScreen) {
|
|
element.webkitRequestFullScreen()
|
|
} else if (element.mozRequestFullScreen) {
|
|
element.mozRequestFullScreen()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* javascript comment
|
|
* @Author: 王林25
|
|
* @Date: 2022-10-24 14:16:18
|
|
* @Desc: 文件转buffer
|
|
*/
|
|
export const fileToBuffer = file => {
|
|
return new Promise(r => {
|
|
const reader = new FileReader()
|
|
reader.onload = () => {
|
|
r(reader.result)
|
|
}
|
|
reader.readAsArrayBuffer(file)
|
|
})
|
|
}
|
|
|
|
// 复制文本到剪贴板
|
|
export const copy = text => {
|
|
// 使用textarea可以保留换行
|
|
const input = document.createElement('textarea')
|
|
// input.setAttribute('value', text)
|
|
input.innerHTML = text
|
|
document.body.appendChild(input)
|
|
input.select()
|
|
document.execCommand('copy')
|
|
document.body.removeChild(input)
|
|
}
|
|
|
|
// 复制文本到剪贴板
|
|
export const setDataToClipboard = data => {
|
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
navigator.clipboard.writeText(data)
|
|
}
|
|
}
|
|
|
|
// 复制图片到剪贴板
|
|
export const setImgToClipboard = img => {
|
|
if (navigator.clipboard && navigator.clipboard.write) {
|
|
const data = [new ClipboardItem({ ['image/png']: img })]
|
|
navigator.clipboard.write(data)
|
|
}
|
|
}
|