PreviewPrintTaskTemplate.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="preview-print-task-template">
  3. <!-- view template-->
  4. <el-dialog
  5. :visible.sync="templateDialogIsShow"
  6. title="查看印品"
  7. width="500px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @open="initData"
  12. >
  13. <el-table :data="templates">
  14. <el-table-column
  15. type="index"
  16. label="序号"
  17. width="70"
  18. :index="indexMethod"
  19. ></el-table-column>
  20. <el-table-column prop="type" label="印品名称">
  21. <span slot-scope="scope">
  22. {{ scope.row.type | templateClassifyFilter }}
  23. </span>
  24. </el-table-column>
  25. <el-table-column class-name="action-column" label="操作">
  26. <div slot-scope="scope">
  27. <el-button
  28. class="btn-primary"
  29. type="text"
  30. icon="icon icon-circle-right"
  31. @click="toViewTemplate(scope.row)"
  32. title="查看详情"
  33. ></el-button>
  34. </div>
  35. </el-table-column>
  36. </el-table>
  37. <div slot="footer"></div>
  38. </el-dialog>
  39. <!-- template-detail -->
  40. <el-dialog
  41. :visible.sync="templateDetailDialogIsShow"
  42. title="印品模板"
  43. width="1200px"
  44. top="0px"
  45. :close-on-click-modal="false"
  46. :close-on-press-escape="false"
  47. append-to-body
  48. >
  49. <div id="template-frame"></div>
  50. <div slot="footer"></div>
  51. </el-dialog>
  52. </div>
  53. </template>
  54. <script>
  55. import { printTaskTemplateView } from "../api";
  56. export default {
  57. name: "preview-print-task-template",
  58. props: {
  59. instance: {
  60. type: Object,
  61. default() {
  62. return {};
  63. }
  64. }
  65. },
  66. data() {
  67. return {
  68. templateDialogIsShow: false,
  69. templateDetailDialogIsShow: false,
  70. templates: []
  71. };
  72. },
  73. methods: {
  74. async initData() {
  75. this.templates = [];
  76. const data = await printTaskTemplateView(this.instance.printPlanId);
  77. this.templates = data || [];
  78. },
  79. toViewTemplate(row) {
  80. if (row.url) {
  81. window.open(row.url);
  82. } else {
  83. this.templateDetailDialogIsShow = true;
  84. this.$nextTick(() => {
  85. this.initFrame(row.content);
  86. });
  87. }
  88. },
  89. initFrame(htmlContent) {
  90. htmlContent = htmlContent
  91. .replace(/\$\{.+?\}/g, "")
  92. .replace(/<#.+?>/g, "")
  93. .replace(/<\/#.+?>/g, "");
  94. const frameContainerDom = document.getElementById("template-frame");
  95. frameContainerDom.innerHTML = "";
  96. const iframeDom = document.createElement("iframe");
  97. frameContainerDom.appendChild(iframeDom);
  98. console.dir(frameContainerDom);
  99. const wwidth = frameContainerDom.parentNode.clientWidth - 50;
  100. const wheight = window.innerHeight - 130;
  101. iframeDom.style.cssText = `width: ${wwidth}px;height: ${wheight}px;border:none;outline:none;background-color: #fff;`;
  102. const iframeDoc = iframeDom.contentDocument;
  103. iframeDoc.open();
  104. iframeDoc.write(htmlContent);
  105. iframeDoc.close();
  106. },
  107. open() {
  108. this.templateDialogIsShow = true;
  109. }
  110. }
  111. };
  112. </script>