[update] pdf预览页面、标准解读查看页面 增加复制字符长度限制1000,超出后复制自动截取前1000个字符

This commit is contained in:
fengchenchen
2024-10-12 11:38:42 +08:00
parent b58f1e89c1
commit d35dbdcbc3
5 changed files with 98 additions and 6 deletions
+43 -4
View File
@@ -623,11 +623,50 @@ See https://github.com/adobe-type-tools/cmap-resources
const handleSelectionChange = (event) => { const handleSelectionChange = (event) => {
const windowSelection = window.getSelection() const windowSelection = window.getSelection()
const selectionText = windowSelection ? window.getSelection().toString() : document.selection.createRange().text const selectionText = windowSelection ? window.getSelection().toString() : document.selection.createRange().text
if (selectionText.length > 500) { // if (selectionText.length > 50) {
alert('超出可复制长度') // alert('超出可复制长度')
windowSelection ? window.getSelection().removeAllRanges() : document.selection.empty() // windowSelection ? window.getSelection().removeAllRanges() : document.selection.empty()
// }
}
document.addEventListener('selectionchange', handleSelectionChange);
const handleCopy = (e) => {
const COPY_MAX_LENGTH = 1000
const windowSelection = window.getSelection()
let selectionText = windowSelection ? window.getSelection().toString() : document.selection.createRange().text
if (selectionText.length > COPY_MAX_LENGTH) {
// 单次复制超过x个字,提示并截取前x字
alert('超出可复制长度' + COPY_MAX_LENGTH)
selectionText = selectionText.substring(0, COPY_MAX_LENGTH)
// 清楚页面选中的效果
const wSelections = window.getSelection()
if (wSelections) {
wSelections.removeAllRanges()
} else {
document.selection.empty()
}
const tempTextarea = document.createElement('textarea')
tempTextarea.value = selectionText
tempTextarea.style.height = '0px'
tempTextarea.style.width = '0px'
document.body.appendChild(tempTextarea)
tempTextarea.select()// Safari兼容
tempTextarea.setSelectionRange(0, 99999999)
let timer = setTimeout(() => {
document.execCommand('copy')
document.body.removeChild(tempTextarea)
// 清除 textarea 选中的效果
if (window.getSelection()) {
window.getSelection()?.removeAllRanges && window.getSelection()?.removeAllRanges()
} else {
document.selection.empty()
}
clearTimeout(timer)
timer = null
}, 100)
} }
} }
document.addEventListener('selectionchange', handleSelectionChange) // 监听复制
document.addEventListener('copy', handleCopy);
</script> </script>
</html> </html>
+1 -1
View File
@@ -1,5 +1,5 @@
<template> <template>
<a-spin :spinning="loading"> <a-spin :spinning="loading" v-copy-limit>
<!-- 搜索条件 --> <!-- 搜索条件 -->
<div class="table-page-search-wrapper"> <div class="table-page-search-wrapper">
<a-form layout="inline" @keyup.enter.native="searchQuery"> <a-form layout="inline" @keyup.enter.native="searchQuery">
+2
View File
@@ -43,6 +43,7 @@ import {
import config from '@/defaultSettings' import config from '@/defaultSettings'
import hasPermission from '@/utils/hasPermission' import hasPermission from '@/utils/hasPermission'
import copyLimit from '@/utils/copyLimit'
import JeroComponents from '@/components/jero/index' import JeroComponents from '@/components/jero/index'
@@ -59,6 +60,7 @@ Vue.use(Antd)
Vue.use(VueAxios, router) Vue.use(VueAxios, router)
Vue.use(hasPermission) Vue.use(hasPermission)
Vue.use(copyLimit)
Vue.use(Viewer) Vue.use(Viewer)
Vue.use(JeroComponents) Vue.use(JeroComponents)
Vue.use(JDictComponenets) Vue.use(JDictComponenets)
+51
View File
@@ -0,0 +1,51 @@
export function handleCopyLimit () {
const COPY_MAX_LENGTH = 1000
const windowSelection = window.getSelection()
let selectionText = windowSelection ? window.getSelection().toString() : document.selection.createRange().text
if (selectionText.length > COPY_MAX_LENGTH) {
// 单次复制超过x个字,提示并截取前x字
alert('超出可复制长度' + COPY_MAX_LENGTH)
selectionText = selectionText.substring(0, COPY_MAX_LENGTH)
// 清楚页面选中的效果
const wSelections = window.getSelection()
if (wSelections) {
wSelections.removeAllRanges()
} else {
document.selection.empty()
}
const tempTextarea = document.createElement('textarea')
tempTextarea.value = selectionText
tempTextarea.style.height = '0px'
tempTextarea.style.width = '0px'
document.body.appendChild(tempTextarea)
tempTextarea.select()// Safari兼容
tempTextarea.setSelectionRange(0, 99999999)
let timer = setTimeout(() => {
document.execCommand('copy')
document.body.removeChild(tempTextarea)
// 清除 textarea 选中的效果
if (window.getSelection()) {
window.getSelection().removeAllRanges && window.getSelection().removeAllRanges()
} else {
document.selection.empty()
}
clearTimeout(timer)
timer = null
}, 100)
}
}
const copyLimit = {
install (Vue) {
Vue.directive('copy-limit', {
inserted: function (el) {
el.addEventListener('copy', handleCopyLimit)
},
unbind: function (el) {
el.removeEventListener('copy', handleCopyLimit)
}
})
}
}
export default copyLimit
@@ -1,5 +1,5 @@
<template> <template>
<div class="detail-page"> <div class="detail-page" v-copy-limit>
<a-spin :spinning="loading"> <a-spin :spinning="loading">
<!-- 展示已有新版本或者废止废止状态并且被代替标准编号存在则显示已有新版本不存在被代替标准显示废止 --> <!-- 展示已有新版本或者废止废止状态并且被代替标准编号存在则显示已有新版本不存在被代替标准显示废止 -->
<div class="detail-page-title">{{ pageTitle }}{{ $t('details') }}<span class="title-red-span">{{ haveNewVersion }}</span></div> <div class="detail-page-title">{{ pageTitle }}{{ $t('details') }}<span class="title-red-span">{{ haveNewVersion }}</span></div>