Browse Source

开发环境无法console.log的问题。图纸增加下载按钮。

jiaxiaoqiang 3 months ago
parent
commit
f87870ba79
4 changed files with 44 additions and 1 deletions
  1. 1 0
      src/App.vue
  2. 1 0
      src/common/configs/buttonPermission.ts
  3. 39 0
      src/views/base/information/index.vue
  4. 3 1
      vite.config.ts

+ 1 - 0
src/App.vue

@@ -34,4 +34,5 @@ const fontColor = computed(() => {
     ? "rgba(255, 255, 255, .15)"
     : "rgba(0, 0, 0, .15)";
 });
+settingsStore.changeTheme(ThemeEnum.LIGHT)
 </script>

+ 1 - 0
src/common/configs/buttonPermission.ts

@@ -73,6 +73,7 @@ const ButtonPermKeys = {
     BTNS: {
       picture_del: "base:picture:del",
       picture_edit: "base:picture:edit",
+      picture_download: "base:picture:download",
     },
   },
   //设备管理

+ 39 - 0
src/views/base/information/index.vue

@@ -24,6 +24,7 @@
           v-model:pdf-list="pdfUrlList"
           v-model:file-name-list="fileNameList"
           :limit="10"
+          :show-tip="false"
           :generate-pdf="true"
           @finished="testFiles"
         />
@@ -62,6 +63,14 @@
           v-hasPerm="[buttonPermission.BasicData.BTNS.picture_edit]"
           >编辑</el-button
         >
+        <el-button
+          @click="downloadFile(row, index)"
+          :loading="downloadBtnLoading"
+          text
+          type="primary"
+          v-hasPerm="[buttonPermission.BasicData.BTNS.picture_download]"
+        >下载</el-button
+        >
       </template>
       <template #menu-left="{ size }">
         <el-button
@@ -163,6 +172,8 @@ onMounted?.(() => {
   dataEditList();
 });
 
+
+
 const onSelectedFinish = (selectedValue) => {
   form.value.associationCode = selectedValue.materialCode;
   form.value.associationName = selectedValue.materialName;
@@ -413,4 +424,32 @@ const deleteRecord = (row, index, done) => {
   deleteRow(row, index, done);
   dataEditList();
 };
+
+const downloadBtnLoading = ref(false);
+const downloadFile = async (row, index, done) => {
+
+  downloadBtnLoading.value = true;
+  let url = import.meta.env.VITE_APP_UPLOAD_URL + row.drawingPath;
+
+  // 1. 获取资源并转为Blob
+  const response = await fetch(url);
+  const blob = await response.blob();
+
+  // 2. 创建临时对象URL
+  const tempUrl = URL.createObjectURL(blob);
+
+  // 3. 创建隐藏a标签触发下载
+  const link = document.createElement("a");
+  link.href = tempUrl;
+  link.download = row.filename;
+  link.style.display = "none";
+  document.body.appendChild(link);
+  link.click();
+
+  // 4. 清理内存
+  URL.revokeObjectURL(tempUrl);
+  document.body.removeChild(link)
+  downloadBtnLoading.value = false;
+}
+
 </script>

+ 3 - 1
vite.config.ts

@@ -257,7 +257,9 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
       "process.env": process.env, //尝试访问 Node.js 环境变量,但这些变量在浏览器环境中是不存在的。(process is not defined)
     },
     esbuild: {
-      drop: ["console", "debugger"], // 去除 console.log 和 debugger
+      // 仅在生产环境删除调试语句
+      drop: mode === 'production' ? ["console", "debugger"] : [],
+      // drop: ["console", "debugger"], // 去除 console.log 和 debugger , 这行导致所有调试语句被删除
     },
   };
 });