Kaynağa Gözat

中间计量,草图调整

MaiXinRong 1 ay önce
ebeveyn
işleme
cc43570458
2 değiştirilmiş dosya ile 38 ekleme ve 2 silme
  1. 37 1
      app/public/js/stage.js
  2. 1 1
      app/view/stage/modal.ejs

+ 37 - 1
app/public/js/stage.js

@@ -4140,7 +4140,43 @@ $(document).ready(() => {
                     updateData.pos_name = data.pos_name;
                     updateData.im_type = data.im_type;
                 }
-                if (items.length > 0) {
+                if (items.length === 1) {
+                    const itemInfo = [];
+                    for (const item of items) {
+                        const itemData = {
+                            src: $('img', item).attr('src'),
+                            left: item.style.left,
+                            top: item.style.top,
+                            width: item.style.width,
+                            height: item.style.height,
+                        };
+                        itemInfo.push(itemData);
+                    }
+                    // 获取合并好的图片数据
+                    const canvas = document.createElement('canvas');
+                    const view = $('.img-view')[0];
+                    const b = items[0];
+                    const pos = $(b).position();
+                    const img = $('img', b)[0];
+                    canvas.height = Math.max(view.clientHeight, Math.ceil(pos.top + img.naturalHeight));
+                    canvas.width = Math.max(view.clientWidth, Math.ceil(pos.left + img.naturalWidth));
+                    const ctx = canvas.getContext('2d');
+                    ctx.fillStyle = '#ffffff';
+                    ctx.fillRect(0, 0, canvas.width, canvas.height);
+                    ctx.drawImage(img, pos.left, pos.top);
+
+                    updateData.img = canvas.toDataURL('image/png');
+                    updateData.imgInfo = itemInfo;
+                    self.updateImageData = updateData;
+                    $('#calc-img').attr('src', updateData.img);
+                    $('#calc-remark').html(img_remark);
+                    $('#view-calc-img').attr('src', updateData.img);
+                    $('#show-calc-img').attr('src', updateData.img);
+                    $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
+                    $('#view-calc-remark').text(img_remark);
+
+                    $('#edit-img').modal('hide');
+                } else if (items.length > 0) {
                     const itemInfo = [];
                     for (const item of items) {
                         const itemData = {

+ 1 - 1
app/view/stage/modal.ejs

@@ -396,7 +396,7 @@
                 <h5 class="modal-title">查看草图</h5>
             </div>
             <div class="modal-body">
-                <img src="" id="view-calc-img">
+                <img src="" id="view-calc-img" style="width:100%">
                 <div class="mt-2">
                     <textarea id="view-calc-remark" class="form-control form-control-sm" placeholder="草图备注" rows="3">
                     </textarea>