Sfoglia il codice sorgente

修改上传文件

bill 2 anni fa
parent
commit
d539aa6db3
2 ha cambiato i file con 14 aggiunte e 11 eliminazioni
  1. 11 9
      src/views/draw-file/modal.tsx
  2. 3 2
      src/views/draw-file/style.module.scss

+ 11 - 9
src/views/draw-file/modal.tsx

@@ -15,6 +15,8 @@ import { BoardType, BoardTypeDesc } from 'api'
 import type { Tagging } from 'api'
 import type { UploadProps } from 'antd'
 
+const width = 500
+
 const domScreenshot = async (dom: HTMLElement) => {
   const canvas = (dom.tagName.toUpperCase() === 'CANVAS' ? dom : dom.querySelector('canvas')) as HTMLCanvasElement
   return new Promise<Blob | null>(resolve => {
@@ -164,14 +166,14 @@ const getFuseImage = async (iframe: HTMLIFrameElement) => {
   if (isLaser) {
     const sdk = await targetWindow.__sdk
     return new Promise<FuseImageRet>(resolve => {
-      sdk.scene.screenshot(540, 390).done((data: string) => {
+      sdk.scene.screenshot(width, width).done((data: string) => {
         resolve({ type: ImageType.FUSE, blob: base64ToBlob(data) })
       })
     })
   } else {
     const sdk = targetWindow.__sdk
     return new Promise<FuseImageRet>(resolve => {
-      sdk.Camera.screenshot([ {width: 540, height: 390, name: '2k' }],false).then((result: any)=>{
+      sdk.Camera.screenshot([ {width: width, height: width, name: '2k' }],false).then((result: any)=>{
         resolve({ type: ImageType.KANKAN, blob: base64ToBlob(result[0].data) })
       })
     })
@@ -231,7 +233,7 @@ export const SelectFuse = (props: SelectImageProps & { caseId: number }) => {
         const index = addTags.findIndex(tag => tag.tagTitle.trim() === hotTitle.trim())
         if (index !== -1) {
           const bound = hot.getBoundingClientRect()
-          const size = (img.width / 540) * 32
+          const size = (img.width / width) * 32
 
           const left = bound.left + size / 2
           const top = bound.top + size / 2
@@ -254,8 +256,8 @@ export const SelectFuse = (props: SelectImageProps & { caseId: number }) => {
       })
       
       const $ccanvas = document.createElement('canvas')
-      $ccanvas.width = 540 
-      $ccanvas.height = 390
+      $ccanvas.width = width
+      $ccanvas.height = width
       const cctx = $ccanvas.getContext('2d')!
       drawImage(
         cctx, 
@@ -333,10 +335,10 @@ export const DfUploadCrop = ({ type, caseId, onClose, onSave }: DfUploadCropProp
       img.onload = resolve
     })
     const $canvas = document.createElement("canvas");
-    $canvas.width = 540;
-    $canvas.height = 390;
+    $canvas.width = width;
+    $canvas.height = width;
     const ctx = $canvas.getContext("2d")
-    ctx?.drawImage(img, 0, 0, 540, 390);
+    ctx?.drawImage(img, 0, 0, width, width);
     const blob = await domScreenshot($canvas);
     onSave && onSave(blob, [])
     return Upload.LIST_IGNORE
@@ -360,7 +362,7 @@ export const DfUploadCrop = ({ type, caseId, onClose, onSave }: DfUploadCropProp
   }
 
   return (
-    <ImgCrop beforeCrop={beforeCrop} rotationSlider modalTitle={"裁剪" + BoardTypeDesc[type]} aspect={540 / 390} minZoom={1} maxZoom={5}>
+    <ImgCrop beforeCrop={beforeCrop} rotationSlider modalTitle={"裁剪" + BoardTypeDesc[type]} aspect={width / width} minZoom={1} maxZoom={5}>
       <Upload beforeUpload={onUpload}  multiple={false} accept="png">
           <Button type="primary" ghost block>上传{ BoardTypeDesc[type] }</Button>
       </Upload>

+ 3 - 2
src/views/draw-file/style.module.scss

@@ -292,7 +292,7 @@ body {
 }
 .house-image {
   border: 1px solid #D9D9D9;
-  padding-top: 72.2222%;
+  padding-top: 68%;
   position: relative;
 
   > div {
@@ -305,7 +305,8 @@ body {
   }
   img {
     width: 100%;
-    object-fit: cover;
+    height: 100%;
+    object-fit: contain;
   }
 }