Przeglądaj źródła

feat: pdf阅览调整

zhangjie 6 miesięcy temu
rodzic
commit
365da38f35

+ 34 - 2
src/components/PreviewFile.vue

@@ -25,6 +25,9 @@
 </template>
 
 <script>
+import { attachmentWatermarkPreview } from "@/modules/login/api";
+import { objTypeOf, blobToText } from "@/plugins/utils";
+
 export default {
   name: "preview-file",
   props: {
@@ -32,6 +35,7 @@ export default {
       type: Object,
       default() {
         return {
+          id: "",
           url: "",
           type: "",
         };
@@ -46,7 +50,11 @@ export default {
   },
   methods: {
     visibleChange() {
-      this.getFile();
+      if (this.data.id) {
+        this.getIdFile();
+      } else {
+        this.getUrlFile();
+      }
       this.registResizeEvent();
     },
     cancel() {
@@ -55,7 +63,31 @@ export default {
     open() {
       this.modalIsShow = true;
     },
-    getFile() {
+    async getIdFile() {
+      let errorInfo = null;
+      const res = await attachmentWatermarkPreview(this.data.id).catch((e) => {
+        errorInfo = e;
+      });
+
+      // 展示后台错误信息
+      if (errorInfo && objTypeOf(errorInfo) === "blob") {
+        const res = await blobToText(errorInfo).catch(() => {});
+        if (!res) return Promise.reject("下载失败!");
+        const resJson = JSON.parse(res);
+        this.$message.error(resJson);
+        return;
+      }
+
+      this.url = URL.createObjectURL(
+        new Blob([res.data], { type: this.data.type })
+      );
+
+      this.$nextTick(() => {
+        document.getElementById("frame-content").height =
+          window.innerHeight - 51;
+      });
+    },
+    getUrlFile() {
       fetch(this.data.url)
         .then((response) => response.blob())
         .then((blob) => {

+ 8 - 28
src/modules/exam/components/PreviewTaskPaper.vue

@@ -72,11 +72,6 @@
       </div>
     </el-dialog>
 
-    <!-- PreviewAttachment -->
-    <preview-attachment
-      ref="PreviewAttachment"
-      :attachment-ids="attachmentIds"
-    ></preview-attachment>
     <!-- PreviewFile -->
     <preview-file ref="PreviewFile" :data="curFile"></preview-file>
   </div>
@@ -84,11 +79,9 @@
 
 <script>
 import { mapState, mapMutations } from "vuex";
-import PreviewAttachment from "@/components/PreviewAttachment.vue";
 import PreviewFile from "@/components/PreviewFile.vue";
 import TaskPaper from "./taskApply/TaskPaper.vue";
 import { taskApplyDetail } from "../api";
-import { attachmentPreview } from "../../login/api";
 
 const initExamTask = {
   id: null,
@@ -164,7 +157,6 @@ const initTaskApply = {
 export default {
   name: "preview-task-paper",
   components: {
-    PreviewAttachment,
     TaskPaper,
     PreviewFile,
   },
@@ -184,10 +176,9 @@ export default {
       isSubmit: false,
       modalIsShow: false,
       dataReady: false,
-      attachmentIds: [],
       // preview file
       curFile: {
-        url: "",
+        id: "",
         type: "",
       },
     };
@@ -246,27 +237,16 @@ export default {
       this.modalIsShow = true;
     },
     async toViewAttachment(attachment) {
-      if (!attachment.jpgAttachmentId) {
-        if (!attachment.attachmentId) {
-          this.$message.error("附件丢失!");
-          return;
-        }
-        const data = await attachmentPreview(attachment.attachmentId);
-        if (!data[0].url) {
-          this.$message.error("附件丢失!");
-          return;
-        }
-        this.curFile = {
-          url: data[0].url,
-          type: "application/pdf",
-        };
-        this.$refs.PreviewFile.open();
+      if (!attachment.attachmentId) {
+        this.$message.error("附件丢失!");
         return;
       }
 
-      const datas = JSON.parse(attachment.jpgAttachmentId);
-      this.attachmentIds = datas.map((item) => item.attachmentId);
-      this.$refs.PreviewAttachment.open();
+      this.curFile = {
+        id: attachment.attachmentId,
+        type: "application/pdf",
+      };
+      this.$refs.PreviewFile.open();
     },
     toViewCard(attachment) {
       this.curAttachment = { ...attachment };

+ 8 - 29
src/modules/exam/components/taskApply/ModifyTaskApply.vue

@@ -44,11 +44,6 @@
       </div>
     </el-dialog>
 
-    <!-- PreviewAttachment -->
-    <preview-attachment
-      ref="PreviewAttachment"
-      :attachment-ids="attachmentIds"
-    ></preview-attachment>
     <!-- PreviewFile -->
     <preview-file ref="PreviewFile" :data="curFile"></preview-file>
   </div>
@@ -68,9 +63,7 @@ import TaskInfo from "./TaskInfo.vue";
 import TaskPaper from "./TaskPaper.vue";
 import TaskPrint from "./TaskPrint.vue";
 import TaskFlow from "./TaskFlow.vue";
-import PreviewAttachment from "@/components/PreviewAttachment.vue";
 import PreviewFile from "@/components/PreviewFile.vue";
-import { attachmentPreview } from "@/modules/login/api";
 
 const initExamTask = {
   id: null,
@@ -150,7 +143,6 @@ export default {
     TaskPaper,
     TaskFlow,
     TaskPrint,
-    PreviewAttachment,
     PreviewFile,
   },
   props: {
@@ -201,10 +193,9 @@ export default {
       loading: false,
       examRule: {},
       dataReady: false,
-      attachmentIds: [],
       // preview file
       curFile: {
-        url: "",
+        id: "",
         type: "",
       },
     };
@@ -306,27 +297,15 @@ export default {
       this.$emit("modified");
     },
     async toViewAttachment(attachment) {
-      if (!attachment.jpgAttachmentId) {
-        if (!attachment.attachmentId) {
-          this.$message.error("附件丢失!");
-          return;
-        }
-        const data = await attachmentPreview(attachment.attachmentId);
-        if (!data[0].url) {
-          this.$message.error("附件丢失!");
-          return;
-        }
-        this.curFile = {
-          url: data[0].url,
-          type: "application/pdf",
-        };
-        this.$refs.PreviewFile.open();
+      if (!attachment.attachmentId) {
+        this.$message.error("附件丢失!");
         return;
       }
-
-      const datas = JSON.parse(attachment.jpgAttachmentId);
-      this.attachmentIds = datas.map((item) => item.attachmentId);
-      this.$refs.PreviewAttachment.open();
+      this.curFile = {
+        id: attachment.attachmentId,
+        type: "application/pdf",
+      };
+      this.$refs.PreviewFile.open();
     },
     async submit() {
       if (!this.$refs.TaskPaper.checkData()) return;

+ 1 - 1
src/modules/exam/components/taskApply/TaskPaper.vue

@@ -597,7 +597,7 @@ export default {
       if (pAttachment) {
         this.curTab = "tiku";
         this.uuid =
-          this.paperAttachments[0]?.paperAttachments[0]?.uuid ||
+          this.paperAttachments[0]?.paperAttachmentIds[0]?.uuid ||
           this.$randomCode(32);
       } else {
         this.curTab = "upload";

+ 7 - 0
src/modules/login/api.js

@@ -24,6 +24,13 @@ export const attachmentPreview = (ids) => {
 export const attachmentDetail = (id) => {
   return $postParam("/api/admin/common/file/get_one", { id });
 };
+export const attachmentWatermarkPreview = (id) => {
+  return $postParam(
+    "/api/admin/common/pdf/watermark/preview",
+    { id },
+    { responseType: "blob" }
+  );
+};
 export const attachmentDownload = ({ id, type }) => {
   return $postParam("/api/admin/common/file/download", { id, type });
 };

+ 9 - 29
src/modules/print/components/ModifyPlanPaper.vue

@@ -176,11 +176,6 @@
       show-watermark
     ></card-preview-dialog>
 
-    <!-- PreviewAttachment -->
-    <preview-attachment
-      ref="PreviewAttachment"
-      :attachment-ids="attachmentIds"
-    ></preview-attachment>
     <!-- PreviewFile -->
     <preview-file ref="PreviewFile" :data="curFile"></preview-file>
   </div>
@@ -189,8 +184,6 @@
 <script>
 import { updatePlanLinkPaper, linkPaperNumberList } from "../api";
 import { taskApplyDetail } from "../../exam/api";
-import { attachmentPreview } from "../../login/api";
-import PreviewAttachment from "@/components/PreviewAttachment.vue";
 import PreviewFile from "@/components/PreviewFile.vue";
 import CardPreviewDialog from "../../card/components/CardPreviewDialog.vue";
 
@@ -203,7 +196,7 @@ const initModalForm = {
 
 export default {
   name: "modify-plan-paper",
-  components: { PreviewAttachment, PreviewFile, CardPreviewDialog },
+  components: { PreviewFile, CardPreviewDialog },
   props: {
     instance: {
       type: Object,
@@ -238,11 +231,9 @@ export default {
         ],
       },
       curAttachment: {},
-      // attachmentId preview
-      attachmentIds: [],
       // preview file
       curFile: {
-        url: "",
+        id: "",
         type: "",
       },
     };
@@ -310,27 +301,16 @@ export default {
       if (paper) this.paperTypes = paper.paperTypes.map((item) => `${item}`);
     },
     async toViewAttachment(attachment) {
-      if (!attachment.jpgAttachmentId) {
-        if (!attachment.attachmentId) {
-          this.$message.error("附件丢失!");
-          return;
-        }
-        const data = await attachmentPreview(attachment.attachmentId);
-        if (!data[0].url) {
-          this.$message.error("附件丢失!");
-          return;
-        }
-        this.curFile = {
-          url: data[0].url,
-          type: "application/pdf",
-        };
-        this.$refs.PreviewFile.open();
+      if (!attachment.attachmentId) {
+        this.$message.error("附件丢失!");
         return;
       }
 
-      const datas = JSON.parse(attachment.jpgAttachmentId);
-      this.attachmentIds = datas.map((item) => item.attachmentId);
-      this.$refs.PreviewAttachment.open();
+      this.curFile = {
+        id: attachment.attachmentId,
+        type: "application/pdf",
+      };
+      this.$refs.PreviewFile.open();
     },
     toViewCard(attachment) {
       this.curAttachment = { ...attachment };

+ 2 - 15
src/modules/print/views/PrintTaskManage.vue

@@ -474,12 +474,6 @@
       task-type="PRINT_PDF_DOWNLOAD"
     ></data-task-dialog>
 
-    <!-- PreviewAttachment -->
-    <preview-attachment
-      ref="PreviewAttachment"
-      :attachment-id="curAttachmentId"
-    ></preview-attachment>
-
     <!-- PreviewFile -->
     <preview-file ref="PreviewFile" :data="curFile"></preview-file>
   </div>
@@ -504,7 +498,6 @@ import { PRINT_TASK_STATUS } from "@/constants/enumerate";
 import pickerOptions from "@/constants/datePickerOptions";
 import { parseTimeRangeDateAndTime } from "@/plugins/utils";
 import PreviewPrintTaskTemplate from "../components/PreviewPrintTaskTemplate";
-import PreviewAttachment from "@/components/PreviewAttachment.vue";
 import PreviewFile from "@/components/PreviewFile.vue";
 
 const defaultTotalInfo = {
@@ -521,7 +514,7 @@ const defaultTotalInfo = {
 
 export default {
   name: "print-task-manage",
-  components: { PreviewPrintTaskTemplate, PreviewAttachment, PreviewFile },
+  components: { PreviewPrintTaskTemplate, PreviewFile },
   data() {
     return {
       filter: {
@@ -569,7 +562,7 @@ export default {
       pickerOptions,
       // preview file
       curFile: {
-        url: "",
+        id: "",
         type: "",
       },
     };
@@ -790,10 +783,6 @@ export default {
         this.rebuildPdf(item);
       }
     },
-    toViewAttachment(curAttachmentId) {
-      this.curAttachmentId = curAttachmentId;
-      this.$refs.PreviewAttachment.open();
-    },
     async rebuildPdf(item) {
       const action = await this.$confirm(
         `确定要重新生成该印刷任务PDF吗?`,
@@ -819,8 +808,6 @@ export default {
         type: "application/pdf",
       };
       this.$refs.PreviewFile.open();
-      // window.open(item.url);
-      // this.padViewDialogVisible = false;
     },
     async toExport() {
       if (this.loading) return;