Просмотр исходного кода

feat: 添加签章使用记录功能

yusheng 2 месяцев назад
Родитель
Сommit
57f355f388

+ 7 - 0
src/api/bpm/components/sealManagement/index.js

@@ -160,3 +160,10 @@ export async function getSealUsageRecordList(id, params) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+export async function usageRecordAdd(data) {
+  const res = await request.post('/seal/management/usageRecord/add', data);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}

+ 43 - 36
src/components/addDoc/seal.vue

@@ -69,34 +69,34 @@
   // 引入 html2canvas 和 jsPDF
   import html2canvas from 'html2canvas';
   import jsPDF from 'jspdf';
-//   const imageUrl = [
-//     require('@/assets/0.jpg'),
-//     require('@/assets/1.jpg'),
-//     require('@/assets/2.jpg'),
-//     require('@/assets/3.jpg'),
-//     require('@/assets/4.jpg'),
-//     require('@/assets/5.jpg')
-//   ]; // 使用相对路径或别名路径
-//   // 默认精美的示例HTML + CSS (内联样式丰富,展示能力)
-//   const DEFAULT_HTML = `
-//  <div class="container">
-//         <div class="img-area">
-//             <img class="my-photo" alt="loading" src="${imageUrl[0]}">
-//         </div>
-//         <div class="img-area">
-//             <img class="my-photo" alt="loading"  src="${imageUrl[1]}">
-//         </div>
-//              <div class="img-area">
-//             <img class="my-photo" alt="loading"  src="${imageUrl[2]}">
-//         </div>      <div class="img-area">
-//             <img class="my-photo" alt="loading"  src="${imageUrl[3]}">
-//         </div>      <div class="img-area">
-//             <img class="my-photo" alt="loading"  src="${imageUrl[4]}">
-//         </div>      <div class="img-area">
-//             <img class="my-photo" alt="loading"  src="${imageUrl[5]}">
-//         </div>
-// </div>
-// `;
+  //   const imageUrl = [
+  //     require('@/assets/0.jpg'),
+  //     require('@/assets/1.jpg'),
+  //     require('@/assets/2.jpg'),
+  //     require('@/assets/3.jpg'),
+  //     require('@/assets/4.jpg'),
+  //     require('@/assets/5.jpg')
+  //   ]; // 使用相对路径或别名路径
+  //   // 默认精美的示例HTML + CSS (内联样式丰富,展示能力)
+  //   const DEFAULT_HTML = `
+  //  <div class="container">
+  //         <div class="img-area">
+  //             <img class="my-photo" alt="loading" src="${imageUrl[0]}">
+  //         </div>
+  //         <div class="img-area">
+  //             <img class="my-photo" alt="loading"  src="${imageUrl[1]}">
+  //         </div>
+  //              <div class="img-area">
+  //             <img class="my-photo" alt="loading"  src="${imageUrl[2]}">
+  //         </div>      <div class="img-area">
+  //             <img class="my-photo" alt="loading"  src="${imageUrl[3]}">
+  //         </div>      <div class="img-area">
+  //             <img class="my-photo" alt="loading"  src="${imageUrl[4]}">
+  //         </div>      <div class="img-area">
+  //             <img class="my-photo" alt="loading"  src="${imageUrl[5]}">
+  //         </div>
+  // </div>
+  // `;
 
   export default {
     name: 'HtmlToCanvas',
@@ -119,7 +119,7 @@
         limit: 1,
         status: 1,
         approvalStatus: 2,
-        sealHolderId:this.$store.state.user.info.userId
+        sealHolderId: this.$store.state.user.info.userId
       }).then((res) => {
         this.publicImages = res.list;
       });
@@ -250,7 +250,7 @@
           if (imageData) {
             const data = JSON.parse(imageData);
             console.log('解析后的数据:', data);
-            this.addImageToCanvas(data.url, e.offsetX, e.offsetY);
+            this.addImageToCanvas(data, e.offsetX, e.offsetY);
           }
         });
 
@@ -262,10 +262,12 @@
       },
 
       // 处理拖拽开始
-      handleDragStart(e, img, index) {
+      handleDragStart(e, img, index, type) {
         const data = {
           url: img.imgUrl,
-          name: img.name
+          name: img.name,
+          version: img.version,
+          imgId: type == 'public' ? img.id : ''
         };
         e.dataTransfer.setData('imageData', JSON.stringify(data));
         e.dataTransfer.effectAllowed = 'copy';
@@ -273,7 +275,7 @@
       },
 
       // 添加图片到 Canvas
-      addImageToCanvas(imgUrl, x, y) {
+      addImageToCanvas(data, x, y) {
         const canvas = document.getElementById('outputCanvas');
         if (!canvas || !this.canvasGenerated) {
           console.log('请先渲染 Canvas');
@@ -308,7 +310,9 @@
 
           this.droppedImages.push({
             id: imageId,
-            imgUrl: imgUrl,
+            imgId: data.imgId,
+            imgUrl: data.url,
+            version: data.version,
             x: posX,
             y: posY,
             width,
@@ -338,7 +342,7 @@
           // this.showMessage('⚠️ 图片加载失败', 'error');
         };
 
-        img.src = imgUrl;
+        img.src = data.url;
       },
 
       // 重新绘制整个 Canvas
@@ -815,7 +819,10 @@
           });
 
           // 触发 PDF 生成事件,父组件可以监听此事件
-          this.$emit('pdf-generated', pdfFile);
+          this.$emit('pdf-generated', {
+            pdfFile,
+            droppedImages: this.droppedImages
+          });
 
           // // 保存 PDF
           // const timestamp = new Date()

+ 21 - 12
src/components/addDoc/sealManagement.vue

@@ -62,16 +62,18 @@
       handleSave() {
         this.$refs.sealRef.exportToPDF();
       },
-      pdfGenerated(data) {
+      pdfGenerated({ pdfFile, droppedImages }) {
         uploadFileNew({
           module: 'fm',
-          multiPartFile: data
+          multiPartFile: pdfFile
         })
           .then((res) => {
             this.$emit('save', {
               stampStoragePath: res.data ? [res.data] : [],
-              id: this.restoreData.id
+              id: this.restoreData.id,
+              droppedImages
             });
+            this.showEditFlag = false;
           })
           .finally(() => {
             this.loading = false;
@@ -88,15 +90,22 @@
           fileNames[fileNames.length - 1];
         this.fileUrl = '/kkfile/onlinePreview?url=' + btoa(url);
         this.$nextTick(() => {
-          var iframe = document.getElementById('Iframe');
-          var iframeDocument = iframe.contentWindow.document;
-          var container = iframeDocument.querySelectorAll('.container');
-          this.$refs.sealRef.init(
-            container[0].innerHTML.replace(
-              /src="https?:\/\/[^\/]+(\/[^"]*)"/g,
-              `src="${window.location.origin}$1"`
-            )
-          );
+          setImmediate(() => {
+            var iframe = document.getElementById('Iframe');
+            console.log(iframe);
+            var iframeDocument = iframe.contentWindow.document;
+            console.log(iframeDocument);
+
+            var container = iframeDocument.querySelectorAll('.container');
+            console.log(container);
+
+            this.$refs.sealRef.init(
+              container[0].innerHTML.replace(
+                /src="https?:\/\/[^\/]+(\/[^"]*)"/g,
+                `src="${window.location.origin}$1"`
+              )
+            );
+          });
         });
       }
     }

+ 53 - 9
src/views/bpm/handleTask/components/doc/send/sendDialog.vue

@@ -76,10 +76,22 @@
                 type="primary"
                 :underline="false"
                 icon="el-icon-edit"
-                @click="browseOpen(row)"
+                @click="browseOpen(row, 1)"
+                v-if="['docx', 'pdf', 'doc'].includes(row.storagePath[0]?.type)"
               >
                 签章
               </el-link>
+              <el-link
+                type="primary"
+                :underline="false"
+                icon="el-icon-edit"
+                @click="browseOpen(row, 2)"
+                v-if="
+                  !['docx', 'pdf', 'doc'].includes(row.storagePath[0]?.type)
+                "
+              >
+                预览
+              </el-link>
             </template>
           </ele-pro-table>
         </el-form-item>
@@ -95,14 +107,22 @@
         </el-form-item>
       </el-col>
     </el-row>
-    <browse ref="browseRef" @save="save"></browse>
+    <sealManagement ref="sealManagementRef" @save="save"></sealManagement>
+    <browse ref="browseRef"></browse>
   </el-form>
 </template>
 
 <script>
   import power from './power.vue';
-  import { sendGetById, fileUpdateAPI } from '@/api/bpm/components/doc';
-  import browse from '@/components/addDoc/sealManagement.vue';
+  import {
+    sendGetById,
+    fileUpdateAPI,
+    getById
+  } from '@/api/bpm/components/doc';
+  import sealManagement from '@/components/addDoc/sealManagement.vue';
+  import browse from '@/components/addDoc/browse.vue';
+  import { usageRecordAdd } from '@/api/bpm/components/sealManagement';
+
   const defaultForm = {
     name: '', //名称
     fileList: [], //文档集合json
@@ -113,7 +133,7 @@
     remark: ''
   };
   export default {
-    components: { power, browse },
+    components: { power, browse, sealManagement },
     props: {
       businessId: {
         default: ''
@@ -238,8 +258,28 @@
       this.init();
     },
     methods: {
-      save(data) {
-        fileUpdateAPI(data);
+      save({ stampStoragePath, id, droppedImages }) {
+        fileUpdateAPI({ stampStoragePath, id }).then((res) => {
+          let fileData = this.form.fileList.find((item) => item.id == id);
+          droppedImages.forEach((item) => {
+            if (item.imgId) {
+              usageRecordAdd({
+                sealId: item.imgId,
+                name: item.name,
+                version: item.version,
+                documentCode: fileData.code,
+                documentName: fileData.name,
+                usageObjectId: fileData.id,
+                usageObjectName: fileData.name,
+                usageDeptName: this.$store.state.user.info.groupName,
+                usageDeptId: this.$store.state.user.info.groupId,
+                userName: this.$store.state.user.info.name,
+                userId: this.$store.state.user.info.userId,
+                useTime: new Date()
+              });
+            }
+          });
+        });
       },
       async init() {
         const data = await sendGetById(this.businessId);
@@ -250,8 +290,12 @@
             this.$refs.powerRef.setTableList(data.userAuthority);
         });
       },
-      browseOpen(row) {
-        this.$refs.browseRef.open(row);
+      async browseOpen(row, type) {
+        if (type == 1) {
+          this.$refs.sealManagementRef.open(await getById(row.id));
+        } else {
+          this.$refs.browseRef.open(await getById(row.id));
+        }
       }
     }
   };