yuansh преди 5 дни
родител
ревизия
a19633a429

+ 167 - 2
src/components/Form/src/jeecg/components/JUpload/JUpload.vue

@@ -6,6 +6,7 @@
       :action="uploadUrl"
       :fileList="fileList"
       :disabled="disabled"
+      :item-render="previewItemRender"
       v-bind="bindProps"
       @remove="onRemove"
       @change="onFileChange"
@@ -26,7 +27,7 @@
 </template>
 
 <script lang="ts" setup>
-  import { ref, reactive, computed, watch, nextTick, createApp,unref } from 'vue';
+  import { ref, reactive, computed, watch, nextTick, createApp, unref, h, isVNode } from 'vue';
   import { Icon } from '/@/components/Icon';
   import { getToken } from '/@/utils/auth';
   import { uploadUrl } from '/@/api/common/api';
@@ -69,6 +70,8 @@
     disabled: propTypes.bool.def(false),
     // 替换前一个文件,用于超出最大数量依然允许上传
     replaceLastOne: propTypes.bool.def(false),
+    // 是否开启附件预览(pdf、图片,仅对非图片模式生效)
+    filePreview: propTypes.bool.def(true),
   });
 
   const headers = getHeaders();
@@ -80,6 +83,8 @@
   const isMaxCount = computed(() => props.maxCount > 0 && fileList.value.length >= props.maxCount);
   // 当前是否是上传图片模式
   const isImageMode = computed(() => props.fileType === UploadTypeEnum.image);
+  // 附件预览模式下自定义列表项渲染,为 pdf、图片文件增加「预览」入口
+  const previewItemRender = computed(() => (props.filePreview && !isImageMode.value ? renderPreviewItem : undefined));
   // 上传按钮是否禁用
   const buttonDisabled = computed(()=>{
     if(props.disabled === true){
@@ -360,7 +365,146 @@
     if (isImageMode.value) {
       createImgPreview({ imageList: [file.url], maskClosable: true });
     } else {
-      window.open(file.url);
+      previewAttachFile(file);
+    }
+  }
+
+  // 获取文件名称(用于判断文件类型)
+  function getFileTypeName(file) {
+    return (file && (file.name || file.url || (file.response && file.response.message))) || '';
+  }
+
+  // 是否为 pdf 文件
+  function isPdfFile(file) {
+    return /\.pdf(\?.*)?$/i.test(getFileTypeName(file));
+  }
+
+  // 是否为图片文件
+  function isImageFile(file) {
+    return /\.(png|jpe?g|gif|bmp|webp|svg)(\?.*)?$/i.test(getFileTypeName(file));
+  }
+
+  // 获取文件访问地址
+  function getFileUrl(file) {
+    if (file && file.url) {
+      return file.url;
+    }
+    const path = file && file.response && file.response.message;
+    return path ? getFileAccessHttpUrl(path) : '';
+  }
+
+  // 附件预览:图片使用图片预览框,pdf 使用新标签页预览,其它类型直接新窗口打开
+  function previewAttachFile(file) {
+    const url = getFileUrl(file);
+    if (!url) {
+      return;
+    }
+    if (isImageFile(file)) {
+      createImgPreview({ imageList: [url], maskClosable: true });
+    } else if (isPdfFile(file)) {
+      previewPdfFile(url);
+    } else {
+      window.open(url, '_blank');
+    }
+  }
+
+  // 自定义上传列表项:pdf、图片文件增加「预览」「下载」入口,其他类型文件增加「下载」入口
+  function renderPreviewItem(originNode: any, file: any) {
+    // 兼容 itemRender 参数为对象的形式
+    if (originNode && typeof originNode === 'object' && !isVNode(originNode) && originNode.originNode) {
+      file = originNode.file;
+      originNode = originNode.originNode;
+    }
+    // 上传中不显示预览/下载入口
+    if (file && file.status === 'uploading') {
+      return originNode;
+    }
+    const children = [originNode];
+    if (isPdfFile(file) || isImageFile(file)) {
+      children.push(
+        h(
+          'a',
+          {
+            class: 'attachment-preview-link',
+            title: '预览(preview)',
+            onClick: (e) => {
+              e.preventDefault();
+              e.stopPropagation();
+              previewAttachFile(file);
+            },
+          },
+          h(Icon, { icon: 'ant-design:eye-outlined' })
+        )
+      );
+    }
+    children.push(
+      h(
+        'a',
+        {
+          class: 'attachment-preview-link',
+          title: '下载(download)',
+          onClick: (e) => {
+            e.preventDefault();
+            e.stopPropagation();
+            downloadAttachFile(file);
+          },
+        },
+        h(Icon, { icon: 'ant-design:download-outlined' })
+      )
+    );
+    return h('div', { class: 'attachment-preview-item-wrapper' }, children);
+  }
+
+  // 下载附件:以 blob 方式触发浏览器下载,跨域失败时回退为新窗口打开
+  async function downloadAttachFile(file) {
+    const url = getFileUrl(file);
+    if (!url) {
+      return;
+    }
+    try {
+      const res = await fetch(url);
+      if (!res.ok) {
+        throw new Error(`status: ${res.status}`);
+      }
+      const blob = await res.blob();
+      const blobUrl = URL.createObjectURL(blob);
+      const a = document.createElement('a');
+      a.href = blobUrl;
+      a.download = decodeURIComponent(getFileName(url));
+      document.body.appendChild(a);
+      a.click();
+      a.remove();
+      setTimeout(() => URL.revokeObjectURL(blobUrl), 60000);
+    } catch (e) {
+      // 跨域等场景下直接新窗口打开(由浏览器处理下载)
+      window.open(url, '_blank');
+    }
+  }
+
+  // pdf 在新标签页中预览(浏览器自带预览能力)
+  async function previewPdfFile(url) {
+    if (!url) {
+      return;
+    }
+    const win = window.open('', '_blank');
+    if (!win) {
+      createMessage.warning('预览窗口被浏览器拦截,请允许本站弹出窗口');
+      return;
+    }
+    win.document.title = 'PDF 预览';
+    try {
+      // 以 blob 方式加载,避免服务端返回 attachment 时变成下载
+      const res = await fetch(url);
+      if (!res.ok) {
+        throw new Error(`status: ${res.status}`);
+      }
+      const blob = await res.blob();
+      const blobUrl = URL.createObjectURL(new Blob([blob], { type: 'application/pdf' }));
+      win.location.href = blobUrl;
+      setTimeout(() => URL.revokeObjectURL(blobUrl), 60000);
+    } catch (e) {
+      // 跨域等场景下直接新窗口打开
+      win.location.href = url;
     }
   }
 
@@ -414,6 +558,27 @@
       .ant-upload-text-icon {
         color: @primary-color;
       }
+      /* 附件预览入口(pdf、图片) */
+      .attachment-preview-item-wrapper {
+        display: flex;
+        align-items: center;
+
+        > .ant-upload-list-item {
+          flex: 1 1 auto;
+          min-width: 0;
+        }
+
+        .attachment-preview-link {
+          flex: none;
+          display: inline-flex;
+          align-items: center;
+          margin-left: 8px;
+          font-size: 14px;
+          cursor: pointer;
+          /* 详情(禁用)状态外层 fieldset 为 pointer-events:none,这里恢复可点击 */
+          pointer-events: auto;
+        }
+      }
       .ant-upload-list-item {
         .upload-actions-container {
           position: absolute;

+ 60 - 19
src/components/Preview/src/Functional.vue

@@ -23,6 +23,9 @@
     moveX: number;
     moveY: number;
     show: boolean;
+    /* 图片缩放范围(相对图片原始尺寸),限定显示大小为页面的 20% ~ 80% */
+    minScale: number;
+    maxScale: number;
   }
   const props = {
     show: {
@@ -75,6 +78,8 @@
         moveX: 0,
         moveY: 0,
         show: props.show,
+        minScale: 0.5,
+        maxScale: 0.9,
       });
 
       const wrapElRef = ref<HTMLDivElement | null>(null);
@@ -94,12 +99,29 @@
 
       // 重置
       function initState() {
-        imgState.imgScale = 1;
+        imgState.imgScale = clampScale(1);
         imgState.imgRotate = 0;
         imgState.imgTop = 0;
         imgState.imgLeft = 0;
       }
 
+      // 将缩放比例限制在 [minScale, maxScale] 区间内
+      function clampScale(scale: number) {
+        return Math.min(Math.max(scale, imgState.minScale), imgState.maxScale);
+      }
+
+      // 根据图片原始尺寸与当前页面大小,计算显示范围(页面的 20% ~ 80%)
+      function initScaleRange(naturalWidth: number, naturalHeight: number) {
+        const vw = window.innerWidth || document.documentElement.clientWidth;
+        const vh = window.innerHeight || document.documentElement.clientHeight;
+        if (!naturalWidth || !naturalHeight) {
+          return;
+        }
+        const baseScale = Math.min(vw / naturalWidth, vh / naturalHeight);
+        imgState.minScale = 0.5 * baseScale;
+        imgState.maxScale = 0.9 * baseScale;
+      }
+
       // 初始化鼠标滚轮事件
       function initMouseWheel() {
         const wrapEl = unref(wrapElRef);
@@ -115,14 +137,20 @@
         };
       }
 
-      const getScaleStep = computed(() => {
-        const scaleStep = props?.scaleStep ?? 0;
-        if (scaleStep ?? (0 > 0 && scaleStep < 100)) {
-          return scaleStep / 100;
-        } else {
-          return imgState.imgScale / 10;
-        }
-      });
+      // 缩放档位:每 20% 一档,最小 20%,最大 200%(100% 为适配页面的尺寸)
+      const ZOOM_STEP_PERCENT = 20;
+      const ZOOM_MIN_PERCENT = 20;
+      const ZOOM_MAX_PERCENT = 500;
+
+      // 当前缩放百分比(相对适配页面的尺寸)
+      function getZoomPercent() {
+        return Math.round((imgState.imgScale / (imgState.maxScale || 1)) * 100);
+      }
+
+      // 按档位对齐的缩放百分比
+      function getAlignedZoomPercent() {
+        return Math.round(getZoomPercent() / ZOOM_STEP_PERCENT) * ZOOM_STEP_PERCENT;
+      }
 
       // 监听鼠标滚轮
       function scrollFunc(e: any) {
@@ -132,17 +160,21 @@
         e.preventDefault();
         if (e.delta > 0) {
           // 滑轮向上滚动
-          scaleFunc(getScaleStep.value);
+          scaleFunc(ZOOM_STEP_PERCENT);
         }
         if (e.delta < 0) {
           // 滑轮向下滚动
-          scaleFunc(-getScaleStep.value);
+          scaleFunc(-ZOOM_STEP_PERCENT);
         }
       }
-      // 缩放函数
-      function scaleFunc(num: number) {
-        if (imgState.imgScale <= 0.2 && num < 0) return;
-        imgState.imgScale += num;
+
+      // 缩放函数:按百分比缩放,每 20% 一档,范围 20% ~ 200%
+      function scaleFunc(stepPercent: number) {
+        const targetPercent = getAlignedZoomPercent() + stepPercent;
+        if (targetPercent < ZOOM_MIN_PERCENT || targetPercent > ZOOM_MAX_PERCENT) {
+          return;
+        }
+        imgState.imgScale = (targetPercent / 100) * imgState.maxScale;
       }
 
       // 旋转图片
@@ -165,6 +197,8 @@
         img.onload = (e: Event) => {
           if (imgState.currentUrl !== url) {
             const ele: any[] = e.composedPath();
+            // 根据图片原始尺寸初始化显示范围(页面的 20% ~ 80%)
+            initScaleRange(ele[0].naturalWidth, ele[0].naturalHeight);
             if (props.rememberState) {
               // 保存当前图片的缩放信息
               stateMap.set(imgState.currentUrl, {
@@ -191,6 +225,8 @@
                 imgState.imgScale = props.defaultWidth / ele[0].naturalWidth;
               }
             }
+            // 恢复/初始缩放后同样限制在显示范围内
+            imgState.imgScale = clampScale(imgState.imgScale);
 
             ele &&
               emit('img-load', {
@@ -239,7 +275,11 @@
         prev: handleChange.bind(null, 'left'),
         next: handleChange.bind(null, 'right'),
         setScale: (scale: number) => {
-          if (scale > 0 && scale <= 10) imgState.imgScale = scale;
+          // 外部传入的比例按百分比处理,并限制在 20% ~ 200%
+          if (scale > 0) {
+            const percent = Math.min(Math.max(scale * 100, ZOOM_MIN_PERCENT), ZOOM_MAX_PERCENT);
+            imgState.imgScale = (percent / 100) * imgState.maxScale;
+          }
         },
         setRotate: (rotate: number) => {
           imgState.imgRotate = rotate;
@@ -293,7 +333,8 @@
           transform: `scale(${imgScale}) rotate(${imgRotate}deg)`,
           marginTop: `${imgTop}px`,
           marginLeft: `${imgLeft}px`,
-          maxWidth: props.defaultWidth ? 'unset' : '100%',
+          // 不限制宽度,保证按百分比缩放时尺寸计算准确(初始显示范围已在 initScaleRange 中限制)
+          maxWidth: 'unset',
         };
       });
 
@@ -341,10 +382,10 @@
       const renderController = () => {
         return (
           <div class={`${prefixCls}__controller`}>
-            <div class={`${prefixCls}__controller-item`} onClick={() => scaleFunc(-getScaleStep.value)}>
+            <div class={`${prefixCls}__controller-item`} onClick={() => scaleFunc(-ZOOM_STEP_PERCENT)}>
               <img src={unScaleSvg} />
             </div>
-            <div class={`${prefixCls}__controller-item`} onClick={() => scaleFunc(getScaleStep.value)}>
+            <div class={`${prefixCls}__controller-item`} onClick={() => scaleFunc(ZOOM_STEP_PERCENT)}>
               <img src={scaleSvg} />
             </div>
             <div class={`${prefixCls}__controller-item`} onClick={resume}>

+ 19 - 0
src/main.ts

@@ -62,6 +62,25 @@ async function bootstrap() {
 
   // 挂载应用
   app.mount('#app', true);
+  
+  // 重写 toFixed,解决精度丢失和四舍五入问题
+  Number.prototype.toFixed = function (n) {
+    if (n > 20 || n < 0) {
+      throw new RangeError('toFixed() digits argument must be between 0 and 20')
+    }
+    const number = this
+    if (isNaN(number) || number >= Math.pow(10, 21)) {
+      return number.toString()
+    }
+    if (typeof n === 'undefined' || n === 0) {
+      return Math.round(number).toString()
+    }
+    const factor = Math.pow(10, n);
+        // 使用 Number.EPSILON 处理浮点数精度问题 (如 1.005 * 100 变成 100.4999... 的情况)
+        // 注意:对于负数,EPSILON 的处理逻辑可能需要调整,通常业务场景多为正数金额
+        // 更稳健的做法是判断正负,但简单场景下直接加 EPSILON 能解决大部分正数边界问题
+    return Math.round((number + Number.EPSILON) * factor) / factor;
+  }
 
   console.log(" vue3 app 加载完成!")
 }

+ 1 - 1
src/views/purchase/freightPurchaseOrder/components/FreightPurOrderForm.vue

@@ -90,7 +90,7 @@
 			
 			<a-col :span="12">
 			  <a-form-item label="附件(attachs)" id="SaleOrderForm-attachs" name="attachs">
-			    <JUpload v-model:value="formData.attachs" bizPath="freightPurOrder" />
+			    <JUpload v-model:value="formData.attachs" bizPath="freightPurOrder" file-preview />
 			  </a-form-item>
 			</a-col>
           </a-row>

+ 14 - 1
src/views/purchase/purchaseInquiryForm/purchaseInquiryFormList.vue

@@ -273,7 +273,7 @@
 
 
   
-  const {onExportXls: onExportXls2} = useListPage({
+  const {onExportXls: onExportXls2Origin} = useListPage({
     tableProps: {
       title: '采购询价单',
       api: list,
@@ -300,6 +300,19 @@
     },
   });
 
+  /**
+   * 导出(把选中行id传给后台,未选中时提示)
+   */
+  async function onExportXls2() {
+    if (!selectedRowKeys.value || selectedRowKeys.value.length === 0) {
+      message.warning('请选择要导出的数据');
+      return;
+    }
+    queryParam['selections'] = selectedRowKeys.value.join(',');
+    await onExportXls2Origin();
+    delete queryParam['selections'];
+  }
+
   /**
    * 新增事件
    */

+ 14 - 1
src/views/purchase/purchaseOrder/PurchaseOrderFormList.vue

@@ -364,7 +364,7 @@
   
   
   //注册table数据
-  const { onExportXls: onExportXls2 } = useListPage({
+  const { onExportXls: onExportXls2Origin } = useListPage({
     tableProps: {
       title: '采购订单列表',
       api: list,
@@ -390,6 +390,19 @@
       params: queryParam,
     }
   });
+
+  /**
+   * 导出(把选中行id传给后台,未选中时提示)
+   */
+  async function onExportXls2() {
+    if (!selectedRowKeys.value || selectedRowKeys.value.length === 0) {
+      message.warning('请选择要导出的数据');
+      return;
+    }
+    queryParam['selections'] = selectedRowKeys.value.join(',');
+    await onExportXls2Origin();
+    delete queryParam['selections'];
+  }
   
   /**
    * 新增事件(售后)

+ 14 - 1
src/views/purchase/purchaseQuotationFrm/purchaseQuotationFormList.vue

@@ -228,7 +228,7 @@
   const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
 
   //注册table数据
-  const { onExportXls: onExportXls2 } = useListPage({
+  const { onExportXls: onExportXls2Origin } = useListPage({
     tableProps: {
       title: '采购报价单列表',
       api: list,
@@ -254,6 +254,19 @@
       params: queryParam,
     }
   });
+
+  /**
+   * 导出(把选中行id传给后台,未选中时提示)
+   */
+  async function onExportXls2() {
+    if (!selectedRowKeys.value || selectedRowKeys.value.length === 0) {
+      message.warning('请选择要导出的数据');
+      return;
+    }
+    queryParam['selections'] = selectedRowKeys.value.join(',');
+    await onExportXls2Origin();
+    delete queryParam['selections'];
+  }
   
   /**
    * 新增事件

+ 14 - 1
src/views/report/deliveryNotice/deliveryNoticeList.vue

@@ -240,7 +240,7 @@
 
 
   //注册table数据
-  const { onExportXls: onExportXls2 } = useListPage({
+  const { onExportXls: onExportXls2Origin } = useListPage({
     tableProps: {
       title: '运费包装统计',
       api: list,
@@ -264,6 +264,19 @@
     }
   });
 
+  /**
+   * 导出(把选中行id传给后台,未选中时提示)
+   */
+  async function onExportXls2() {
+    if (!selectedRowKeys.value || selectedRowKeys.value.length === 0) {
+      message.warning('请选择要导出的数据');
+      return;
+    }
+    queryParam['selections'] = selectedRowKeys.value.join(',');
+    await onExportXls2Origin();
+    delete queryParam['selections'];
+  }
+
 
   const [registerTable, { reload, getSelectRows }, { rowSelection, selectedRowKeys }] = tableContext;
 

+ 14 - 1
src/views/saleCode/deliveryNotice/deliveryNoticeList.vue

@@ -284,7 +284,7 @@
 
 
   //注册table数据
-  const { onExportXls: onExportXls2 } = useListPage({
+  const { onExportXls: onExportXls2Origin } = useListPage({
     tableProps: {
       title: '发货通知单明细',
       api: list,
@@ -311,6 +311,19 @@
     }
   });
 
+  /**
+   * 导出明细(把选中行id传给后台,未选中时提示)
+   */
+  async function onExportXls2() {
+    if (!selectedRowKeys.value || selectedRowKeys.value.length === 0) {
+      message.warning('请选择要导出的数据');
+      return;
+    }
+    queryParam['selections'] = selectedRowKeys.value.join(',');
+    await onExportXls2Origin();
+    delete queryParam['selections'];
+  }
+
 
   const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
 

+ 14 - 1
src/views/saleCode/quotation/quotation.vue

@@ -347,7 +347,7 @@
 
   
   //注册table数据
-  const { onExportXls: onExportXls2 } = useListPage({
+  const { onExportXls: onExportXls2Origin } = useListPage({
     tableProps: {
       title: '销售报价单明细',
       api: list,
@@ -374,6 +374,19 @@
     }
   });
 
+  /**
+   * 导出明细(把选中行id传给后台,未选中时提示)
+   */
+  async function onExportXls2() {
+    if (!selectedRowKeys.value || selectedRowKeys.value.length === 0) {
+      message.warning('请选择要导出的数据');
+      return;
+    }
+    queryParam['selections'] = selectedRowKeys.value.join(',');
+    await onExportXls2Origin();
+    delete queryParam['selections'];
+  }
+
   const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
 
   // 高级查询配置

+ 14 - 1
src/views/saleCode/saleInquiryForm/SaleInquiryFormList.vue

@@ -347,7 +347,7 @@
   });
 
   //注册table数据
-  const { onExportXls: onExportXls2 } = useListPage({
+  const { onExportXls: onExportXls2Origin } = useListPage({
     tableProps: {
       title: '销售询价单明细',
       api: list,
@@ -374,6 +374,19 @@
     }
   });
 
+  /**
+   * 导出明细(把选中行id传给后台,未选中时提示)
+   */
+  async function onExportXls2() {
+    if (!selectedRowKeys.value || selectedRowKeys.value.length === 0) {
+      message.warning('请选择要导出的数据');
+      return;
+    }
+    queryParam['selections'] = selectedRowKeys.value.join(',');
+    await onExportXls2Origin();
+    delete queryParam['selections'];
+  }
+
   const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
 
   // 高级查询配置

+ 14 - 1
src/views/saleCode/salesOrder/SaleOrderFormList.vue

@@ -392,7 +392,7 @@
   
   
   //注册table数据
-  const { onExportXls: onExportXls2 } = useListPage({
+  const { onExportXls: onExportXls2Origin } = useListPage({
     tableProps: {
       title: '销售订单明细',
       api: list,
@@ -419,6 +419,19 @@
     }
   });
 
+  /**
+   * 导出明细(把选中行id传给后台,未选中时提示)
+   */
+  async function onExportXls2() {
+    if (!selectedRowKeys.value || selectedRowKeys.value.length === 0) {
+      message.warning('请选择要导出的数据');
+      return;
+    }
+    queryParam['selections'] = selectedRowKeys.value.join(',');
+    await onExportXls2Origin();
+    delete queryParam['selections'];
+  }
+
   const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
 
   // 高级查询配置