@nstc-business/imes 1.1.9 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1194,27 +1194,9 @@ export default {
|
|
|
1194
1194
|
return
|
|
1195
1195
|
}
|
|
1196
1196
|
if (action === 'print') {
|
|
1197
|
-
// PDF blob
|
|
1198
|
-
//
|
|
1199
|
-
|
|
1200
|
-
const prevTitle = document.title
|
|
1201
|
-
if (printTitle) {
|
|
1202
|
-
document.title = printTitle
|
|
1203
|
-
}
|
|
1204
|
-
try {
|
|
1205
|
-
printJS({
|
|
1206
|
-
printable: res.data,
|
|
1207
|
-
type: 'pdf',
|
|
1208
|
-
base64: true,
|
|
1209
|
-
documentTitle: printTitle
|
|
1210
|
-
})
|
|
1211
|
-
} finally {
|
|
1212
|
-
if (printTitle) {
|
|
1213
|
-
setTimeout(() => {
|
|
1214
|
-
document.title = prevTitle
|
|
1215
|
-
}, 1000)
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1197
|
+
// PDF blob 直接 printJS 时,Edge「将打印输出另存为」文件名常为空;
|
|
1198
|
+
// 改为带 <title> 的 HTML 壳嵌入 PDF 再打印,便于另存为预填文件名
|
|
1199
|
+
this.printPdfWithFileName(res.data, this.resolvePrintFileBaseName())
|
|
1218
1200
|
} else {
|
|
1219
1201
|
this.downloadPdfBase64(res.data)
|
|
1220
1202
|
}
|
|
@@ -1237,6 +1219,72 @@ export default {
|
|
|
1237
1219
|
const raw = this.downloadFileName || (this.model && this.model.code) || '测算结果'
|
|
1238
1220
|
return String(raw).replace(/\.pdf$/i, '')
|
|
1239
1221
|
},
|
|
1222
|
+
/**
|
|
1223
|
+
* 带文件名打印 PDF(base64)
|
|
1224
|
+
* 时间:2026-10-29 18:16:00
|
|
1225
|
+
* 人员:AI && 徐红飞
|
|
1226
|
+
* 入参:base64 - PDF 内容;fileBaseName - 另存为预填名(不含 .pdf)
|
|
1227
|
+
* 出参:无
|
|
1228
|
+
* 方法内容:用 HTML iframe + title + embed 打印,规避 PDF blob 直接打印时另存为文件名为空
|
|
1229
|
+
*/
|
|
1230
|
+
printPdfWithFileName(base64, fileBaseName) {
|
|
1231
|
+
const title = String(fileBaseName || '测算结果').replace(/[\\/:*?"<>|]/g, '_')
|
|
1232
|
+
const pure = String(base64 || '').replace(/^data:application\/pdf;base64,/, '')
|
|
1233
|
+
const binary = atob(pure)
|
|
1234
|
+
const len = binary.length
|
|
1235
|
+
const bytes = new Uint8Array(len)
|
|
1236
|
+
for (let i = 0; i < len; i++) {
|
|
1237
|
+
bytes[i] = binary.charCodeAt(i)
|
|
1238
|
+
}
|
|
1239
|
+
const blob = new Blob([bytes], { type: 'application/pdf' })
|
|
1240
|
+
const pdfUrl = URL.createObjectURL(blob)
|
|
1241
|
+
const iframe = document.createElement('iframe')
|
|
1242
|
+
iframe.setAttribute(
|
|
1243
|
+
'style',
|
|
1244
|
+
'position:fixed;right:0;bottom:0;width:0;height:0;border:0;visibility:hidden'
|
|
1245
|
+
)
|
|
1246
|
+
document.body.appendChild(iframe)
|
|
1247
|
+
const frameWin = iframe.contentWindow
|
|
1248
|
+
const frameDoc = frameWin.document
|
|
1249
|
+
const safeTitle = title
|
|
1250
|
+
.replace(/&/g, '&')
|
|
1251
|
+
.replace(/</g, '<')
|
|
1252
|
+
.replace(/>/g, '>')
|
|
1253
|
+
.replace(/"/g, '"')
|
|
1254
|
+
frameDoc.open()
|
|
1255
|
+
frameDoc.write(
|
|
1256
|
+
`<!DOCTYPE html><html><head><meta charset="utf-8"><title>${safeTitle}</title></head>` +
|
|
1257
|
+
`<body style="margin:0"><embed src="${pdfUrl}" type="application/pdf" width="100%" height="100%" /></body></html>`
|
|
1258
|
+
)
|
|
1259
|
+
frameDoc.close()
|
|
1260
|
+
const cleanup = () => {
|
|
1261
|
+
try {
|
|
1262
|
+
if (iframe.parentNode) {
|
|
1263
|
+
iframe.parentNode.removeChild(iframe)
|
|
1264
|
+
}
|
|
1265
|
+
} catch (e) {
|
|
1266
|
+
/* ignore */
|
|
1267
|
+
}
|
|
1268
|
+
URL.revokeObjectURL(pdfUrl)
|
|
1269
|
+
}
|
|
1270
|
+
const doPrint = () => {
|
|
1271
|
+
try {
|
|
1272
|
+
frameWin.focus()
|
|
1273
|
+
frameWin.print()
|
|
1274
|
+
} catch (e) {
|
|
1275
|
+
// 回退 printJS(可能仍无文件名,但保证能打)
|
|
1276
|
+
printJS({
|
|
1277
|
+
printable: pure,
|
|
1278
|
+
type: 'pdf',
|
|
1279
|
+
base64: true,
|
|
1280
|
+
documentTitle: title
|
|
1281
|
+
})
|
|
1282
|
+
}
|
|
1283
|
+
setTimeout(cleanup, 2000)
|
|
1284
|
+
}
|
|
1285
|
+
// embed 加载需要一点时间;onload 在部分浏览器对 srcdoc/write 不可靠,用延时兜底
|
|
1286
|
+
setTimeout(doPrint, 400)
|
|
1287
|
+
},
|
|
1240
1288
|
downloadPdfBase64(base64) {
|
|
1241
1289
|
const pure = String(base64 || '').replace(/^data:application\/pdf;base64,/, '')
|
|
1242
1290
|
const binary = atob(pure)
|