navigator.clipboard 로컬이나 http에서만 사용가능..
This commit is contained in:
parent
4d5bbfe875
commit
dcb4c55a74
@ -17,6 +17,7 @@ import QPagination from '../common/pagination/QPagination'
|
||||
import { SessionContext } from '@/app/SessionProvider'
|
||||
|
||||
import { QcastContext } from '@/app/QcastProvider'
|
||||
import { e } from 'mathjs'
|
||||
|
||||
export default function Stuff() {
|
||||
const { setIsGlobalLoading } = useContext(QcastContext)
|
||||
@ -41,13 +42,45 @@ export default function Stuff() {
|
||||
|
||||
//그리드 내부 복사버튼
|
||||
const copyNo = async (value) => {
|
||||
try {
|
||||
console.log('value::::::::', value)
|
||||
await navigator.clipboard.writeText(value)
|
||||
alert(getMessage('stuff.detail.header.successCopy'))
|
||||
} catch (error) {
|
||||
console.log('error::::::::::', error)
|
||||
alert(getMessage('stuff.detail.header.failCopy'))
|
||||
// try {
|
||||
// await navigator.clipboard.writeText(value)
|
||||
// alert(getMessage('stuff.detail.header.successCopy'))
|
||||
// } catch (error) {
|
||||
// alert(getMessage('stuff.detail.header.failCopy'))
|
||||
// }
|
||||
// Navigator clipboard api needs a secure context (https)
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
console.log('확인11', value)
|
||||
await navigator.clipboard
|
||||
.writeText(value)
|
||||
.then(() => {
|
||||
alert(getMessage('stuff.detail.header.successCopy'))
|
||||
})
|
||||
.catch((err) => {
|
||||
alert(getMessage('stuff.detail.header.failCopy'))
|
||||
})
|
||||
} else {
|
||||
console.log('확인22', value)
|
||||
// Use the 'out of viewport hidden text area' trick
|
||||
const textArea = document.createElement('textArea')
|
||||
textArea.value = value
|
||||
|
||||
// Move textarea out of the viewport so it's not visible
|
||||
textArea.style.position = 'absolute'
|
||||
textArea.style.left = '-999999px'
|
||||
|
||||
document.body.prepend(textArea)
|
||||
textArea.select()
|
||||
|
||||
try {
|
||||
console.log('deprecated::document.execCommand(`copy`)', document.execCommand('copy'))
|
||||
document.execCommand('copy')
|
||||
alert(getMessage('stuff.detail.header.successCopy'))
|
||||
} catch (err) {
|
||||
alert(getMessage('stuff.detail.header.failCopy'))
|
||||
} finally {
|
||||
textArea.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,12 +11,48 @@ export default function StuffHeader() {
|
||||
const { managementState } = useContext(GlobalDataContext)
|
||||
|
||||
//물건번호 복사
|
||||
// const copyObjectNo = async (objectNo) => {
|
||||
// await navigator.clipboard.writeText(objectNo)
|
||||
// alert(getMessage('stuff.detail.header.successCopy'))
|
||||
// try {
|
||||
// } catch (error) {
|
||||
// alert(getMessage('stuff.detail.header.failCopy'))
|
||||
// }
|
||||
// }
|
||||
|
||||
const copyObjectNo = async (objectNo) => {
|
||||
await navigator.clipboard.writeText(objectNo)
|
||||
alert(getMessage('stuff.detail.header.successCopy'))
|
||||
try {
|
||||
} catch (error) {
|
||||
alert(getMessage('stuff.detail.header.failCopy'))
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
console.log('확인11', objectNo)
|
||||
await navigator.clipboard
|
||||
.writeText(objectNo)
|
||||
.then(() => {
|
||||
alert(getMessage('stuff.detail.header.successCopy'))
|
||||
})
|
||||
.catch((err) => {
|
||||
alert(getMessage('stuff.detail.header.failCopy'))
|
||||
})
|
||||
} else {
|
||||
console.log('확인22', objectNo)
|
||||
// Use the 'out of viewport hidden text area' trick
|
||||
const textArea = document.createElement('textArea')
|
||||
textArea.value = objectNo
|
||||
|
||||
// Move textarea out of the viewport so it's not visible
|
||||
textArea.style.position = 'absolute'
|
||||
textArea.style.left = '-999999px'
|
||||
|
||||
document.body.prepend(textArea)
|
||||
textArea.select()
|
||||
|
||||
try {
|
||||
console.log('deprecated::document.execCommand(`copy`)', document.execCommand('copy'))
|
||||
document.execCommand('copy')
|
||||
alert(getMessage('stuff.detail.header.successCopy'))
|
||||
} catch (err) {
|
||||
alert(getMessage('stuff.detail.header.failCopy'))
|
||||
} finally {
|
||||
textArea.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user