Commit 8bfd9fb8 by qinjianhui

fix: 问题修改

parent 1e825855
...@@ -1992,13 +1992,15 @@ const printOrder = async ( ...@@ -1992,13 +1992,15 @@ const printOrder = async (
return return
} }
if (data.filePath) { if (data.filePath) {
const strURL = /^https?:/i.test(data.filePath) const strURL = filePath + data.filePath
? data.filePath console.log('strURL', strURL, data)
: filePath + data.filePath lodop.ADD_PRINT_PDF(
const pdfData = /^https?:/i.test(strURL) 0,
? await downloadPDF(strURL) 0,
: strURL '100%',
lodop.ADD_PRINT_PDF(0, 0, '100%', '100%', pdfData) '100%',
/(https):\/\/([^/]+)/i.test(strURL) ? downloadPDF(strURL) : strURL,
)
} else { } else {
lodop.SEND_PRINT_RAWDATA(data.fileData || '') lodop.SEND_PRINT_RAWDATA(data.fileData || '')
} }
...@@ -2079,28 +2081,57 @@ const lodopCall = (fn: (lodop: LODOPObject) => string) => { ...@@ -2079,28 +2081,57 @@ const lodopCall = (fn: (lodop: LODOPObject) => string) => {
_lodopCallback[id] = resolve _lodopCallback[id] = resolve
}) })
} }
const downloadPDF = async (url: string): Promise<string> => { const downloadPDF = (url: string) => {
if (!/^https?:/i.test(url)) return url if (!/^https?:/i.test(url)) return url
let xhr,
const headers: Record<string, string> = {} arrybuffer = false,
const token = localStorage.getItem('token') dataArray = null
if (token) headers['jwt-token'] = token if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest()
const response = await fetch(url, { headers }) } else {
if (!response.ok) { xhr = new window.ActiveXObject('MSXML2.XMLHTTP')
console.error(
`PDF download failed: ${response.status} ${response.statusText}`,
)
return ''
} }
xhr.open('GET', url, false) //同步方式
const arrayBuffer = await response.arrayBuffer() if (xhr.overrideMimeType)
const bytes = new Uint8Array(arrayBuffer) try {
let binary = '' xhr.responseType = 'arraybuffer'
for (let i = 0; i < bytes.byteLength; i++) { arrybuffer = true
binary += String.fromCharCode(bytes[i]) } catch (err) {
xhr.overrideMimeType('text/plain; charset=x-user-defined')
}
xhr.send(null)
const data = xhr.response || xhr.responseBody
if (typeof Uint8Array !== 'undefined') {
if (arrybuffer) {
dataArray = new Uint8Array(data)
} else {
dataArray = new Uint8Array(data.length)
for (let i = 0; i < dataArray.length; i++) {
dataArray[i] = data.charCodeAt(i)
}
}
} else {
dataArray = window.VBS_BinaryToArray(data).toArray() //兼容IE低版本
}
const digits =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
let strData = ''
for (let i = 0, ii = dataArray.length; i < ii; i += 3) {
if (isNaN(dataArray[i])) break
const b1 = dataArray[i] & 0xff,
b2 = dataArray[i + 1] & 0xff,
b3 = dataArray[i + 2] & 0xff
const d1 = b1 >> 2,
d2 = ((b1 & 3) << 4) | (b2 >> 4)
const d3 = i + 1 < ii ? ((b2 & 0xf) << 2) | (b3 >> 6) : 64
const d4 = i + 2 < ii ? b3 & 0x3f : 64
strData +=
digits.substring(d1, d1 + 1) +
digits.substring(d2, d2 + 1) +
digits.substring(d3, d3 + 1) +
digits.substring(d4, d4 + 1)
} }
return 'data:application/pdf;base64,' + btoa(binary) return strData
} }
const handleDownloadMaterial = async () => { const handleDownloadMaterial = async () => {
if (!ensureSelection()) return if (!ensureSelection()) return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment