|
@@ -115,6 +115,7 @@ class ComPDFKitViewer {
|
|
const verified = this._decrypt(resp.data)
|
|
const verified = this._decrypt(resp.data)
|
|
return verified
|
|
return verified
|
|
} else {
|
|
} else {
|
|
|
|
+ alert(resp.message)
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -166,8 +167,20 @@ class ComPDFKitViewer {
|
|
this.eventBus.dispatch("toolChanged", { tool, color });
|
|
this.eventBus.dispatch("toolChanged", { tool, color });
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ addEventListener (eventName, listener) {
|
|
|
|
+ if (this.eventBus) {
|
|
|
|
+ this.eventBus.on(eventName, listener)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ removeEventListener (eventName, listener) {
|
|
|
|
+ if (this.eventBus) {
|
|
|
|
+ this.eventBus.of(eventName, listener)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
initAnnotations (annotations) {
|
|
initAnnotations (annotations) {
|
|
- console.log(annotations)
|
|
|
|
|
|
+ // console.log(annotations)
|
|
for (const type in annotations) {
|
|
for (const type in annotations) {
|
|
const annotation = annotations[type]
|
|
const annotation = annotations[type]
|
|
if (Array.isArray(annotation)) {
|
|
if (Array.isArray(annotation)) {
|
|
@@ -181,7 +194,7 @@ class ComPDFKitViewer {
|
|
this.handleAnnotations(annotation, true)
|
|
this.handleAnnotations(annotation, true)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- console.log(this.annotations)
|
|
|
|
|
|
+ // console.log(this.annotations)
|
|
this.eventBus.dispatch('annotationChanged', { annotations: this.annotations })
|
|
this.eventBus.dispatch('annotationChanged', { annotations: this.annotations })
|
|
}
|
|
}
|
|
|
|
|
|
@@ -306,24 +319,27 @@ class ComPDFKitViewer {
|
|
},
|
|
},
|
|
body: formData
|
|
body: formData
|
|
}
|
|
}
|
|
- await fetch(this.optionUrl.webviewBaseUrl + this.optionUrl.uploadUrl, data)
|
|
|
|
- .then((res) => {
|
|
|
|
- return res.json()
|
|
|
|
- })
|
|
|
|
- .then((resp) => {
|
|
|
|
- if (resp.code === "200") {
|
|
|
|
- const data = resp.data
|
|
|
|
- this._pdfId = data.pdfId
|
|
|
|
- const annotations = data.annotateJson && JSON.parse(data.annotateJson)
|
|
|
|
- this.initAnnotations(annotations)
|
|
|
|
- } else if (resp.code === "319") {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- .catch((error) => {
|
|
|
|
- console.log(error)
|
|
|
|
- return { error: true, message: error.message }
|
|
|
|
- });
|
|
|
|
|
|
+ const uploadFile = async () => {
|
|
|
|
+ await fetch(this.optionUrl.webviewBaseUrl + this.optionUrl.uploadUrl, data)
|
|
|
|
+ .then((res) => {
|
|
|
|
+ return res.json()
|
|
|
|
+ })
|
|
|
|
+ .then((resp) => {
|
|
|
|
+ if (resp.code === "200") {
|
|
|
|
+ const data = resp.data
|
|
|
|
+ this._pdfId = data.pdfId
|
|
|
|
+ const annotations = data.annotateJson && JSON.parse(data.annotateJson)
|
|
|
|
+ this.initAnnotations(annotations)
|
|
|
|
+ } else {
|
|
|
|
+ this.handleExpiredToken(resp.code, uploadFile)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => {
|
|
|
|
+ console.log(error)
|
|
|
|
+ return { error: true, message: error.message }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ await uploadFile()
|
|
})
|
|
})
|
|
this.load(pdfDocument);
|
|
this.load(pdfDocument);
|
|
},
|
|
},
|
|
@@ -715,18 +731,53 @@ class ComPDFKitViewer {
|
|
annotateHandles
|
|
annotateHandles
|
|
}),
|
|
}),
|
|
}
|
|
}
|
|
- fetch(this.optionUrl.webviewBaseUrl + this.optionUrl.editUrl, options)
|
|
|
|
- .then((res) => {
|
|
|
|
- return res.json()
|
|
|
|
- })
|
|
|
|
- .then((data) => {
|
|
|
|
- if (data.code === "200") {
|
|
|
|
- return true
|
|
|
|
- } else {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- .catch((error) => (console.log(error)));
|
|
|
|
|
|
+ const editPDF = () => {
|
|
|
|
+ fetch(this.optionUrl.webviewBaseUrl + this.optionUrl.editUrl, options)
|
|
|
|
+ .then((res) => {
|
|
|
|
+ return res.json()
|
|
|
|
+ })
|
|
|
|
+ .then((data) => {
|
|
|
|
+ if (data.code === "200") {
|
|
|
|
+ return true
|
|
|
|
+ } else {
|
|
|
|
+ this.handleExpiredToken(data.code, editPDF)
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => (console.log(error)));
|
|
|
|
+ }
|
|
|
|
+ editPDF()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ handleExpiredToken (code, callback) {
|
|
|
|
+ if (code === '319') {
|
|
|
|
+ const data = {
|
|
|
|
+ method: 'POST',
|
|
|
|
+ headers: {
|
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
|
+ },
|
|
|
|
+ body: JSON.stringify({
|
|
|
|
+ license: this._license
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ fetch(this.optionUrl.baseUrl + this.optionUrl.verifyUrl, data)
|
|
|
|
+ .then((res) => {
|
|
|
|
+ return res.json()
|
|
|
|
+ })
|
|
|
|
+ .then((resp) => {
|
|
|
|
+ if (resp.code === 200) {
|
|
|
|
+ const verified = this._decrypt(resp.data)
|
|
|
|
+ callback()
|
|
|
|
+ return verified
|
|
|
|
+ } else {
|
|
|
|
+ alert(resp.message)
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => ({ error: true, message: error.message }));
|
|
|
|
+ } else {
|
|
|
|
+ alert('Invalid license')
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
webViewerSearch (value) {
|
|
webViewerSearch (value) {
|