@nstc-business/imes 1.1.11 → 1.1.13

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nstc-business/imes",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "private": false,
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1194,9 +1194,27 @@ export default {
1194
1194
  return
1195
1195
  }
1196
1196
  if (action === 'print') {
1197
- // PDF blob 直接 printJS 时,Edge「将打印输出另存为」文件名常为空;
1198
- // 改为带 <title> 的 HTML 壳嵌入 PDF 再打印,便于另存为预填文件名
1199
- this.printPdfWithFileName(res.data, this.resolvePrintFileBaseName())
1197
+ // 打印必须走 printJS(PDF blob):HTML+embed 方案在 Edge/Chrome 常打不出 PDF
1198
+ // 另存为文件名尽力用 document.title;稳定带名请用「下载」
1199
+ const printTitle = this.resolvePrintFileBaseName()
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
+ }, 1500)
1216
+ }
1217
+ }
1200
1218
  } else {
1201
1219
  this.downloadPdfBase64(res.data)
1202
1220
  }
@@ -1209,81 +1227,18 @@ export default {
1209
1227
  },
1210
1228
  /**
1211
1229
  * 解析打印/下载文件名(不含 .pdf)
1212
- * 时间:2026-10-29 17:27:04
1230
+ * 时间:2026-10-29 18:30:29
1213
1231
  * 人员:AI && 徐红飞
1214
1232
  * 入参:无
1215
- * 出参:文件名基名
1216
- * 方法内容:优先 downloadFileName,否则 model.code,再否则「测算结果」
1233
+ * 出参:文件名基名(已清洗非法字符)
1234
+ * 方法内容:优先 downloadFileName,否则 model.code;统一清洗 \/:*?"<>| 供下载与打印共用
1217
1235
  */
1218
1236
  resolvePrintFileBaseName() {
1219
1237
  const raw = this.downloadFileName || (this.model && this.model.code) || '测算结果'
1220
- return String(raw).replace(/\.pdf$/i, '')
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, '&amp;')
1251
- .replace(/</g, '&lt;')
1252
- .replace(/>/g, '&gt;')
1253
- .replace(/"/g, '&quot;')
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)
1238
+ return String(raw)
1239
+ .replace(/\.pdf$/i, '')
1240
+ .replace(/[\\/:*?"<>|]/g, '_')
1241
+ .trim() || '测算结果'
1287
1242
  },
1288
1243
  downloadPdfBase64(base64) {
1289
1244
  const pure = String(base64 || '').replace(/^data:application\/pdf;base64,/, '')