This commit is contained in:
changkyu choi 2025-01-06 10:25:44 +09:00
commit db7a055e22
2 changed files with 81 additions and 10 deletions

View File

@ -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,11 +42,45 @@ export default function Stuff() {
//
const copyNo = async (value) => {
try {
await navigator.clipboard.writeText(value)
alert(getMessage('stuff.detail.header.successCopy'))
} catch (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()
}
}
}

View File

@ -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()
}
}
}