Преглед изворни кода

feat: 添加打印页脚,显示打印人和打印时间

xieyong пре 2 недеља
родитељ
комит
c976dc70d2
1 измењених фајлова са 41 додато и 1 уклоњено
  1. 41 1
      src/views/bpm/collaborative/detail.vue

+ 41 - 1
src/views/bpm/collaborative/detail.vue

@@ -888,10 +888,50 @@ export default {
         + '.pf-table{width:100%;border-collapse:collapse;margin-top:6px} '
         + '.pf-table{width:100%;border-collapse:collapse;margin-top:6px} '
         + '.pf-table th,.pf-table td{border:1px solid #e8e8e8;padding:6px;text-align:left} '
         + '.pf-table th,.pf-table td{border:1px solid #e8e8e8;padding:6px;text-align:left} '
         + '.pf-tasks-title{font-size:16px;font-weight:600;margin-top:24px;margin-bottom:8px} '
         + '.pf-tasks-title{font-size:16px;font-weight:600;margin-top:24px;margin-bottom:8px} '
+        + '.pf-footer{margin-top:40px;padding-top:10px;border-top:1px solid #ccc;font-size:13px;color:#333;display:flex;justify-content:flex-start;gap:32px;font-family:"SimSun","宋体",serif} '
+        + '.pf-footer .pf-footer-item{display:flex;align-items:center;gap:6px} '
+        + '.pf-footer .pf-footer-label{font-weight:600 !important;color:#000 !important;margin-right:4px;letter-spacing:0.5px} '
         + '@media print{.pf-table thead{display:table-row-group}.pf-table tr{page-break-inside:avoid}}';
         + '@media print{.pf-table thead{display:table-row-group}.pf-table tr{page-break-inside:avoid}}';
 
 
+      // 打印人 / 打印时间
+      const footer = this.buildPrintFooter();
+
       return '<!doctype html><html><head><meta charset="utf-8" /><title>' + title + '</title><style>' + style + '</style></head><body>'
       return '<!doctype html><html><head><meta charset="utf-8" /><title>' + title + '</title><style>' + style + '</style></head><body>'
-        + '<div class="pf-container"><div class="pf-title">' + title + '</div>' + rows.join('\n') + this.generateTasksPrintHtml() + '</div></body></html>';
+        + '<div class="pf-container"><div class="pf-title">' + title + '</div>' + rows.join('\n') + this.generateTasksPrintHtml() + footer + '</div></body></html>';
+    },
+
+    // 拼接打印页脚(左下角:打印人 + 打印时间)
+    buildPrintFooter() {
+      // 优先从 Vuex store 取登录用户信息,与页面其他位置保持同一数据源
+      let printer = '';
+      try {
+        const userInfo = (this.$store && this.$store.state && this.$store.state.user && this.$store.state.user.info) || {};
+        printer = userInfo.name || userInfo.nickname || userInfo.username || '';
+      } catch (e) {
+        printer = '';
+      }
+      const now = this.formatPrintTime(new Date());
+      const items = [];
+      items.push(
+        '<div class="pf-footer-item">'
+          + '<span class="pf-footer-label">打印人:</span>'
+          + '<span>' + this.escapeHtml(printer || '-') + '</span>'
+          + '</div>'
+      );
+      items.push(
+        '<div class="pf-footer-item">'
+          + '<span class="pf-footer-label">打印时间:</span>'
+          + '<span>' + this.escapeHtml(now) + '</span>'
+          + '</div>'
+      );
+      return '<div class="pf-footer">' + items.join('') + '</div>';
+    },
+
+    // 格式化打印时间为 YYYY-MM-DD HH:mm:ss
+    formatPrintTime(date) {
+      const pad = (n) => (n < 10 ? '0' + n : '' + n);
+      return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate())
+        + ' ' + pad(date.getHours()) + ':' + pad(date.getMinutes()) + ':' + pad(date.getSeconds());
     },
     },
 
 
     // 将流程审批记录(tasks)拼接为可打印的表格 HTML
     // 将流程审批记录(tasks)拼接为可打印的表格 HTML