|
@@ -124,7 +124,19 @@ export default class HcPdfSign {
|
|
|
if (typeof this.signChange !== 'function') {
|
|
|
return false
|
|
|
} else {
|
|
|
- this.signChange(this.signList)
|
|
|
+ //移除没必要的数据
|
|
|
+ const newSignList = [], list = this.signList
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
+ newSignList.push({
|
|
|
+ lx: list[i].lx,
|
|
|
+ ly: list[i].ly,
|
|
|
+ id: list[i].id,
|
|
|
+ page: list[i].page,
|
|
|
+ url: list[i].url,
|
|
|
+ type: list[i].type,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.signChange(newSignList)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -222,7 +234,7 @@ export default class HcPdfSign {
|
|
|
//批量处理
|
|
|
if (this.batchSign) {
|
|
|
const curDom = this.curSignDom
|
|
|
- let curSign = this.getSignImgDom(curDom)
|
|
|
+ let { data: curSign } = this.getSignImgDom(curDom)
|
|
|
if (!curSign) return
|
|
|
const newArr = this.signList.filter(item => {
|
|
|
return item.type === curSign.type
|
|
@@ -240,7 +252,7 @@ export default class HcPdfSign {
|
|
|
this.curSignDom.style.cursor = 'default'
|
|
|
const curDom = this.curSignDom
|
|
|
//获取数据
|
|
|
- let curSign = this.getSignImgDom(curDom)
|
|
|
+ let { data: curSign } = this.getSignImgDom(curDom)
|
|
|
if (!curSign) return
|
|
|
//计算坐标
|
|
|
const left = curDom.style.left.replace('px', '')
|
|
@@ -265,6 +277,17 @@ export default class HcPdfSign {
|
|
|
}
|
|
|
this.signChangeFunc()
|
|
|
})
|
|
|
+ //监听按键
|
|
|
+ const container = this.iframeDom?.contentDocument?.getElementById('outerContainer')
|
|
|
+ container.addEventListener('keyup', (event) => {
|
|
|
+ //删除签章
|
|
|
+ if (event.keyCode === 8 && event.key === 'Backspace') {
|
|
|
+ const curDom = this.curSignDom
|
|
|
+ const { index } = this.getSignImgDom(curDom)
|
|
|
+ if (index <= -1) return
|
|
|
+ this.delSignImg(index).then()
|
|
|
+ }
|
|
|
+ })
|
|
|
this.pdfViewer = viewer
|
|
|
//处理pdf渲染
|
|
|
if (this.batchSign) {
|
|
@@ -279,18 +302,46 @@ export default class HcPdfSign {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //删除签章
|
|
|
+ static async delSignImg(index) {
|
|
|
+ if (index <= -1) return
|
|
|
+ if (this.batchSign) {
|
|
|
+ const list = this.signList, curDom = list[index]
|
|
|
+ //倒序删除签章
|
|
|
+ for (let i = list.length - 1; i >= 0; i--) {
|
|
|
+ if (list[i].type === curDom.type) {
|
|
|
+ list[i].dom.remove()
|
|
|
+ delete list[i].dom
|
|
|
+ list.splice(i, 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.signList = list
|
|
|
+ this.signChangeFunc()
|
|
|
+ } else {
|
|
|
+ this.signList[index].dom.remove()
|
|
|
+ this.signList.splice(index, 1)
|
|
|
+ this.signChangeFunc()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//获取签章图片的数据
|
|
|
static getSignImgDom(curDom) {
|
|
|
- const id = curDom.getAttribute('id')
|
|
|
- let curSign = null
|
|
|
+ if (isNullES(curDom)) {
|
|
|
+ return { data: null, index: -1 }
|
|
|
+ }
|
|
|
+ //获取数据
|
|
|
+ const id = curDom?.getAttribute('id')
|
|
|
+ let curSign = null, index = -1
|
|
|
for (let i = 0; i < this.signList.length; i++) {
|
|
|
const item = this.signList[i]
|
|
|
if (item.id === id) {
|
|
|
curSign = item
|
|
|
+ index = i
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
- return curSign
|
|
|
+ return { data: curSign, index }
|
|
|
}
|
|
|
|
|
|
//页面被点击
|