wenhongquan 1 年之前
父節點
當前提交
35e0e67319
共有 5 個文件被更改,包括 69 次插入20 次删除
  1. 24 12
      src/components/pdfview/index.vue
  2. 19 2
      src/views/file/list/index.vue
  3. 2 2
      src/views/h5/filelist/index.vue
  4. 22 2
      src/views/project/list/index.vue
  5. 2 2
      vite.config.ts

+ 24 - 12
src/components/pdfview/index.vue

@@ -1,15 +1,14 @@
 <template>
   <div style="width: 100%;height:100%;position:absolute">
-
     <el-watermark :font="font" :content="watertext" style="width: 100%;height:100%;position:absolute">
-    <iframe v-loading style="width:100%;height:100%;border:none" :src="`${currentPdf}`" v-if="usepdf" />
-      <div style="height: 100%;overflow-y: auto" v-if="!usepdf">
-        <!-- <div v-for="page in pages" :key="page" style="width: 100%;">
-          <VuePDF :pdf="pdf" fit-parent :watermark-text="watermarkText" :watermark-options="watermarkOptions" :page="page">
-            <div v-loading="true"></div>
-          </VuePDF>
-        </div> -->
-      </div>
+      <iframe v-loading style="width:100%;height:100%;border:none" :src="`${currentPdf}`" />
+      <!--      <div style="height: 100%;overflow-y: auto" v-if="!usepdf">-->
+      <!--        &lt;!&ndash; <div v-for="page in pages" :key="page" style="width: 100%;">-->
+      <!--          <VuePDF :pdf="pdf" fit-parent :watermark-text="watermarkText" :watermark-options="watermarkOptions" :page="page">-->
+      <!--            <div v-loading="true"></div>-->
+      <!--          </VuePDF>-->
+      <!--        </div> &ndash;&gt;-->
+      <!--      </div>-->
     </el-watermark>
   </div>
 </template>
@@ -18,18 +17,22 @@ import {ref, onMounted, watchEffect} from 'vue'
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 // import { VuePDF, usePDF } from '@tato30/vue-pdf'
 import { propTypes } from '@/utils/propTypes';
-import base64 from 'base-64';
 import moment from 'moment';
 import useUserStore from '@/store/modules/user';
 
 const userStore = useUserStore();
 
+document.oncontextmenu = function(){
+  return false;
+}
+
 const { watermark } = toRefs<any>();
 
 const usepdf=ref(true);
 
 const props = defineProps({
   src: propTypes.string.def(''),
+  size:propTypes.number.def(0),
 });
 const content = ref(["text"])
 
@@ -42,13 +45,22 @@ const watertext = ref();
 
 const currentPdf = ref(props.src)
 watchEffect(() => {
+  if(props.size>1024*1024*38){
+    usepdf.value = false;
+  }else{
+    usepdf.value = true;
+  }
   if (usepdf.value) {
+    // if(props.size>1024*1024*20){
+    // }else{
+      currentPdf.value = `https://filesystem.njdnyjs.com/preview?url=${encodeURIComponent(props.src)}`
+    // }
     // currentPdf.value = `/preview/onlinePreview?url=${encodeURIComponent(base64.encode(props.src))}&watermarkTxt=${encodeURIComponent(watertext.value)}`;
     // currentPdf.value = `/preview/web/viewer.html?file=${encodeURIComponent(props.src)}`
-    currentPdf.value = `https://filesystem.njdnyjs.com/preview?url=${encodeURIComponent(props.src)}`
+    // currentPdf.value = `https://filesystem.njdnyjs.com/preview?url=${encodeURIComponent(props.src)}`
     // http://localhost:8083/preview/?url=https%3A%2F%2Fraw.githubusercontent.com%2Fmozilla%2Fpdf.js%2Fba2edeae%2Fweb%2Fcompressed.tracemonkey-pldi-09.pdf
   } else {
-    currentPdf.value = props.src;
+    currentPdf.value = props.src+"#toolbar=1";
   }
   //http://127.0.0.1:8012/onlinePreview?url='+encodeURIComponent(base64Encode(url))
 

+ 19 - 2
src/views/file/list/index.vue

@@ -137,7 +137,7 @@
             ></el-button>
           </div>
         </el-affix>
-        <pdfview :src="currentfile.url"></pdfview>
+        <pdfview :src="currentfile.url" :size="currentfile.size"></pdfview>
       </div>
       <template #footer>
         <div class="dialog-footer">
@@ -215,6 +215,7 @@ import _ from "lodash";
 import { getArchives } from "@/api/archives/index";
 
 import { list } from "@/api/monitor/operlog/index";
+import {ElLoading} from "element-plus";
 
 // const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 // const { sys_area, sys_project_status } = toRefs<any>(
@@ -272,9 +273,25 @@ const filepreview = (file) => {
   });
 };
 const downloadfile = (file) => {
-  proxy?.$download.oss(file.ossId);
+  // proxy?.$download.oss(file.ossId);
+  // currentfile.value = file;
+
+  const loadingInstance1 = ElLoading.service({ fullscreen: true,text:"下载中..." })
+  listByIds(file.ossId).then((res) => {
+    fetch(res.data[0].url)
+      .then(response => response.blob())
+      .then(blob => {
+        loadingInstance1.close();
+        const link = document.createElement('a');
+        link.href = URL.createObjectURL(blob);
+        link.download = file.originalName;
+        link.target = "_blank"; // 可选,如果希望在新窗口中下载文件,请取消注释此行
+        link.click();
+      });
+  });
 };
 
+
 const currentproject = ref({
   area: "",
   ecode: "",

+ 2 - 2
src/views/h5/filelist/index.vue

@@ -23,7 +23,7 @@
 
     <el-dialog v-model="pdfviewshow" :title="`文件预览`" width="90vw">
       <div style="position: relative;min-height:50vh">
-        <pdfview :src="currentfile.url"></pdfview>
+        <pdfview :src="currentfile.url" :size="currentfile.size"></pdfview>
       </div>
       <!-- <div><el-affix :offset="120" position="bottom"><el-button type="text" icon="DArrowRight"></el-button></el-affix></div>
       </div> -->
@@ -69,7 +69,7 @@ const finished = ref(false);
 const router = useRouter();
 const route = useRoute();
 
-const currentfile = ref({ url: "" })
+const currentfile = ref({ url: "" ,size:0})
 const pdfviewshow = ref(false);
 
 const onClickLeft = () => {

+ 22 - 2
src/views/project/list/index.vue

@@ -232,7 +232,7 @@
                  <el-button type="primary" icon="DArrowRight" :disabled="ccindex+1>=filelist.length" @click="fileindexlook(ccindex+1)"></el-button>
               </div>
            </el-affix>
-            <pdfview :src="currentfile.url"></pdfview>
+            <pdfview :src="currentfile.url" :size="currentfile.size"></pdfview>
 
 
 
@@ -436,6 +436,7 @@ import _ from "lodash";
 import {useRoute} from "vue-router";
 import useUserStore from "@/store/modules/user";
 import moment from "moment";
+import {ElLoading} from "element-plus";
 
 
 const userroles = useUserStore().roles;
@@ -770,8 +771,27 @@ const filepreview = (file) => {
     pdfviewshow.value = true;
   });
 }
+
 const downloadfile = (file) => {
-   proxy?.$download.oss(file.ossId)
+   // proxy?.$download.oss(file.ossId)
+
+  const loadingInstance1 = ElLoading.service({ fullscreen: true,text:"下载中..." })
+  // currentfile.value = file;
+  listByIds(file.ossId).then((res) => {
+    fetch(res.data[0].url)
+      .then(response => response.blob())
+      .then(blob => {
+        loadingInstance1.close();
+        const link = document.createElement('a');
+        link.href = URL.createObjectURL(blob);
+        link.download = file.originalName;
+        link.target = "_blank"; // 可选,如果希望在新窗口中下载文件,请取消注释此行
+        link.click();
+      });
+
+
+    // window.open( res.data[0].url);
+  });
 }
 
 

+ 2 - 2
vite.config.ts

@@ -26,8 +26,8 @@ export default defineConfig(({ mode, command }: ConfigEnv): UserConfig => {
       open: true,
       proxy: {
         [env.VITE_APP_BASE_API]: {
-          // target: 'http://localhost:8080',
-          target: 'https://filesystem.njdnyjs.com/api',
+          target: 'http://localhost:8080',
+          // target: 'https://filesystem.njdnyjs.com/api',
           changeOrigin: true,
           ws: true,
           rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')