Bläddra i källkod

上传按钮控制,pdf2word

liuQiang 1 år sedan
förälder
incheckning
17b898ade6

+ 6 - 1
src/components/LeftList/LeftList.vue

@@ -10,7 +10,7 @@
       :default-expanded-keys="curArr"
     >
       <template #default="{ node, data }">
-        <span class="custom-tree-node" @click="checkoutNode(node, data)">
+        <span class="custom-tree-node" @click="checkoutNode(node, data)" @click.right="rightFn(node, data,$event)">
           <img :src="setImg(data.remark)" alt="" />
           <span class="node_title">{{ node.label }}</span>
           <span class="fileNum">{{
@@ -146,6 +146,11 @@ const getTopDir = async () => {
   //     console.log("curArr.value", curArr.value);
   //   });
 };
+const rightFn = (node, data,e)=>{
+  console.log("node", node);
+  console.log("data", data);
+  console.log("e", e);
+}
 watch(
   () => props.ListtreeData,
   (newValue, oldValue) => {

+ 1 - 1
src/components/ListShow/ListShow.vue

@@ -109,7 +109,7 @@ const changeSearchType = (name) => {
 };
 //搜索框模糊搜索事件
 const fileBlur = () => {
-  const arr = typeData.value;
+  const arr = typeData.value || props.fileList;
   tableData.value = arr.filter((item) => {
     if (item.fileName.includes(searchFire.value)) {
       return item;

+ 169 - 152
src/components/Pdf2Word/Pdf2Word.vue

@@ -38,6 +38,7 @@
           <el-upload
             class="avatar-uploader"
             :http-request="test"
+            accept=".pdf, .PDF"
             :show-file-list="false"
             :before-upload="beforeUp"
           >
@@ -117,174 +118,190 @@
     :fileUserTreeData="treeData"
     @fileChangeMsg="fileChangeMsg"
   ></PicTree>
-  <div v-loading.fullscreen="loadingPreview" v-if="loadingPreview" class="lodingBox"></div>
+  <div
+    v-loading.fullscreen="loadingPreview"
+    v-if="loadingPreview"
+    class="lodingBox"
+  ></div>
 </template>
 
 <script setup>
-import { onMounted, ref, toRaw, watch, inject } from 'vue'
-import { ElMessage } from 'element-plus'
-import Clipboard from 'clipboard'
-import Loading from '@/components/Loading/Loading.vue'
-import PicTree from '@/components/PicTree/PicTree.vue' //选择文件发送的列表
-import { picTree, pdfTree } from '@/api/search/search.js'
-import { ocrRemark, preview } from '@/api/common/common.js'
-import { getInfo } from '@/api/biz/info.js'
-import Cookies from 'js-cookie'
-import axios from 'axios'
-const textData = ref('') //解析出来的文字
-const showImg = ref() //上传的图片
-const isOpen = ref(props.openFile)
-const thisStep = ref('start') //解析进度 start,loading,end,
-const openFile = ref(false) //控制tree显示
-const treeData = ref() //树节点数据
-const actionUrl = ref(`${window.location.origin}${import.meta.env.VITE_APP_BASE_API}/biz/info/pdf2word`)
+import { onMounted, ref, toRaw, watch, inject } from "vue";
+import { ElMessage } from "element-plus";
+import Clipboard from "clipboard";
+import Loading from "@/components/Loading/Loading.vue";
+import PicTree from "@/components/PicTree/PicTree.vue"; //选择文件发送的列表
+import { picTree, pdfTree } from "@/api/search/search.js";
+import { ocrRemark, preview } from "@/api/common/common.js";
+import { getInfo } from "@/api/biz/info.js";
+import Cookies from "js-cookie";
+import axios from "axios";
+const textData = ref(""); //解析出来的文字
+const showImg = ref(); //上传的图片
+const isOpen = ref(props.openFile);
+const thisStep = ref("start"); //解析进度 start,loading,end,
+const openFile = ref(false); //控制tree显示
+const treeData = ref(); //树节点数据
+const actionUrl = ref(
+  `${window.location.origin}${
+    import.meta.env.VITE_APP_BASE_API
+  }/biz/info/pdf2word`
+);
 const headersObj = ref({
-  Authorization: Cookies.get('Admin-Token')
-})
+  Authorization: Cookies.get("Admin-Token"),
+});
 // const actionUrl = ref(`${window.location.origin}/upload`);
-const loadingPreview = ref(false)
-const addFolderAdd = inject('addFolderAdd')
+const loadingPreview = ref(false);
+const addFolderAdd = inject("addFolderAdd");
 
 const props = defineProps({
   openFile: {
     type: Boolean,
-    default: false
-  }
-})
+    default: false,
+  },
+});
 watch(
   () => props.openFile,
   (newValue) => {
     // console.log(111);
-    isOpen.value = newValue
+    isOpen.value = newValue;
   }
-)
+);
 
-const test=function(file){
-  console.log('file',file);
-	const url=`${window.location.origin}${import.meta.env.VITE_APP_BASE_API}/biz/info/pdf2word`;
-	 return axios({
-	        method:'post',
-	        url:url,
-	        responseType:'blob',
-          data:file,
-          headers:{
-            "Authorization":Cookies.get('Admin-Token'),
-            'Content-Type': 'multipart/form-data'
-          }
-	    }).then(function(res){
-        console.log('testres',res);
-	        // if(res.headers['content-disposition'] !== undefined){
-	            let blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' })
-	            let fileName = decodeURI(res.headers['content-disposition']) 
-	          if (fileName) { 
-	            // fileName = fileName.substring(fileName.indexOf('=') + 1)
-	            // fileName = fileName.substring(0,fileName.lastIndexOf('.'))
-				// alert(fileName)
-	          }
-	          const elink = document.createElement('a') 
-            console.log('fileName',fileName);
-	          elink.download = fileName.replace(new RegExp('"', 'g'), '')+'.docx'
-	          elink.style.display = 'none'
-	          elink.href = URL.createObjectURL(blob) 
-	          document.body.appendChild(elink) 
-	          elink.click() 
-	          URL.revokeObjectURL(elink.href) 
-	          document.body.removeChild(elink) 
-            loadingPreview.value = false
-	        // }
-	    })
-}
-const fileId2Word=function(fileId){
-  console.log('fileId',fileId);
-	const url=`${window.location.origin}${import.meta.env.VITE_APP_BASE_API}/biz/info/pdf2word/${fileId}`;
-	 return axios({
-	        method:'get',
-	        url:url,
-	        responseType:'blob',
-          headers:{
-            "Authorization":Cookies.get('Admin-Token'),
-            'Content-Type': 'multipart/form-data'
-          }
-	    }).then(function(res){
-        console.log('testres',res);
-	        // if(res.headers['content-disposition'] !== undefined){
-	            let blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' })
-	            let fileName = decodeURI(res.headers['content-disposition']) 
-	          if (fileName) { 
-	            // fileName = fileName.substring(fileName.indexOf('=') + 1)
-	            // fileName = fileName.substring(0,fileName.lastIndexOf('.'))
-				// alert(fileName)
-	          }
-	          const elink = document.createElement('a') 
-            console.log('fileName',fileName);
-	          elink.download = fileName.replace(new RegExp('"', 'g'), '')+'.docx'
-	          elink.style.display = 'none'
-	          elink.href = URL.createObjectURL(blob) 
-	          document.body.appendChild(elink) 
-	          elink.click() 
-	          URL.revokeObjectURL(elink.href) 
-	          document.body.removeChild(elink) 
-            loadingPreview.value = false
-	        // }
-	    })
-}
+const test = function (file) {
+  console.log("file", file);
+  const url = `${window.location.origin}${
+    import.meta.env.VITE_APP_BASE_API
+  }/biz/info/pdf2word`;
+  return axios({
+    method: "post",
+    url: url,
+    responseType: "blob",
+    data: file,
+    headers: {
+      Authorization: Cookies.get("Admin-Token"),
+      "Content-Type": "multipart/form-data",
+    },
+  }).then(function (res) {
+    console.log("testres", res);
+    if (res.headers["content-disposition"] !== undefined) {
+      let blob = new Blob([res.data], {
+        type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+      });
+      let fileName = decodeURI(res.headers["content-disposition"]);
+      if (fileName) {
+        fileName = fileName.substring(fileName.indexOf("=") + 1);
+        fileName = fileName.substring(0, fileName.lastIndexOf("."));
+        // alert(fileName)
+      }
+      const elink = document.createElement("a");
+      console.log("fileName", fileName);
+      elink.download = fileName.replace(new RegExp('"', "g"), "") + ".docx";
+      elink.style.display = "none";
+      elink.href = URL.createObjectURL(blob);
+      document.body.appendChild(elink);
+      elink.click();
+      URL.revokeObjectURL(elink.href);
+      document.body.removeChild(elink);
+      loadingPreview.value = false;
+    }
+  });
+};
+const fileId2Word = function (fileId) {
+  console.log("fileId", fileId);
+  const url = `${window.location.origin}${
+    import.meta.env.VITE_APP_BASE_API
+  }/biz/info/pdf2word/${fileId}`;
+  return axios({
+    method: "get",
+    url: url,
+    responseType: "blob",
+    headers: {
+      Authorization: Cookies.get("Admin-Token"),
+      "Content-Type": "multipart/form-data",
+    },
+  }).then(function (res) {
+    console.log("testres", res);
+    if (res.headers["content-disposition"] !== undefined) {
+      let blob = new Blob([res.data], {
+        type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+      });
+      let fileName = decodeURI(res.headers["content-disposition"]);
+      if (fileName) {
+        fileName = fileName.substring(fileName.indexOf("=") + 1);
+        fileName = fileName.substring(0, fileName.lastIndexOf("."));
+        // alert(fileName)
+      }
+      const elink = document.createElement("a");
+      console.log("fileName", fileName);
+      elink.download = fileName.replace(new RegExp('"', "g"), "") + ".docx";
+      elink.style.display = "none";
+      elink.href = URL.createObjectURL(blob);
+      document.body.appendChild(elink);
+      elink.click();
+      URL.revokeObjectURL(elink.href);
+      document.body.removeChild(elink);
+      loadingPreview.value = false;
+    }
+  });
+};
 
-onMounted(async () => {})
+onMounted(async () => {});
 
 const handleAvatarSuccess = (msg, file) => {
   // console.log('re', msg)
-  const flieData = toRaw(file)
+  const flieData = toRaw(file);
   // console.log('file', flieData)
   // setTimeout(() => {
   //   downLoadfile(flieData.raw,file);
   // }, 500);
-  const blob = new Blob([msg]) //excel,pdf等
-  const href = URL.createObjectURL(blob) //创建新的URL表示指定的blob对象
-  const a = document.createElement('a') //创建a标签
-  a.style.display = 'none'
-  a.href = href // 指定下载链接
-  a.download = file.name + '.docx' //指定下载文件名
-  a.click() //触发下载
-  URL.revokeObjectURL(a.href) //释放URL对象
-  ElMessage({ message: '转换成功,已下载到本地', type: 'success' })
-  loadingPreview.value = false
-}
+  const blob = new Blob([msg]); //excel,pdf等
+  const href = URL.createObjectURL(blob); //创建新的URL表示指定的blob对象
+  const a = document.createElement("a"); //创建a标签
+  a.style.display = "none";
+  a.href = href; // 指定下载链接
+  a.download = file.name + ".docx"; //指定下载文件名
+  a.click(); //触发下载
+  URL.revokeObjectURL(a.href); //释放URL对象
+  ElMessage({ message: "转换成功,已下载到本地", type: "success" });
+  loadingPreview.value = false;
+};
 //文件上传前的钩子
 const beforeUp = (raw) => {
   // console.log('raw',raw);
   // showImg.value = URL.createObjectURL(raw);
-  loadingPreview.value = true
+  loadingPreview.value = true;
   // thisStep.value = "loading";
-}
+};
 // 复制功能调用的方法
 const copyQbUrl = () => {
-  let clipboard = new Clipboard('.copy-qb', {
+  let clipboard = new Clipboard(".copy-qb", {
     text: () => {
-      return textData.value
-    }
-  })
-  clipboard.on('success', () => {
+      return textData.value;
+    },
+  });
+  clipboard.on("success", () => {
     // console.log('success');
-    ElMessage({ message: '复制成功', type: 'success' })
-    clipboard.destroy()
-  })
-  clipboard.on('error', () => {
+    ElMessage({ message: "复制成功", type: "success" });
+    clipboard.destroy();
+  });
+  clipboard.on("error", () => {
     // console.log('err');
-    clipboard.destroy()
-  })
-}
+    clipboard.destroy();
+  });
+};
 // 选取文库图片
 const addlibraryImg = async () => {
-  const res = await pdfTree()
-  console.log('res', res)
-  treeData.value = res
-  openFile.value = true
-}
+  const res = await pdfTree();
+  console.log("res", res);
+  treeData.value = res;
+  openFile.value = true;
+};
 //确定选中图片
 const fileChangeMsg = async (val) => {
-  console.log('val', toRaw(val))
-  loadingPreview.value = true
-  fileId2Word(val.remark)
+  console.log("val", toRaw(val));
+  loadingPreview.value = true;
+  fileId2Word(val.remark);
   // const res = await getInfo(val.id)
   // const data = toRaw(val)
   // const imgRes = await preview(data.id)
@@ -295,40 +312,40 @@ const fileChangeMsg = async (val) => {
   // textData.value = res.msg
   // console.log("res", res);
   // console.log("imgRes", imgRes);
-}
+};
 const reClick = () => {
-  thisStep.value = 'start'
-  textData.value = null
-  showImg.value = null
-}
+  thisStep.value = "start";
+  textData.value = null;
+  showImg.value = null;
+};
 // 文件下载
 const downLoadfile = (res, file) => {
   // console.log('downLoadfileres',res);
-  var reader = new FileReader()
+  var reader = new FileReader();
   reader.onloadend = function (event) {
     //event 就是你要的返回内容
     //因为返回的报错格式是字符串,手动转换成对象,转换成功表示请求失败
     //转换失败就意味着你拿到的result是文件流,那么直接手动下载就好
     try {
-      let data = JSON.parse(event.target.result)
+      let data = JSON.parse(event.target.result);
     } catch (err) {
-      const time = Date.now()
+      const time = Date.now();
       // console.log('time',time);
-      const link = document.createElement('a') // 创建a标签
-      let blob = new Blob([res])
-      link.style.display = 'none'
-      link.href = URL.createObjectURL(blob) // 创建下载的链接
+      const link = document.createElement("a"); // 创建a标签
+      let blob = new Blob([res]);
+      link.style.display = "none";
+      link.href = URL.createObjectURL(blob); // 创建下载的链接
       // link.setAttribute("download", clickRow.value.fileName); // 给下载后的文件命名
-      link.setAttribute('download', file.name + '.docx') // 给下载后的文件命名
-      document.body.appendChild(link)
-      link.click() // 点击下载
-      document.body.removeChild(link) //  完成移除元素
-      window.URL.revokeObjectURL(link.href) // 释放blob对象
+      link.setAttribute("download", file.name + ".docx"); // 给下载后的文件命名
+      document.body.appendChild(link);
+      link.click(); // 点击下载
+      document.body.removeChild(link); //  完成移除元素
+      window.URL.revokeObjectURL(link.href); // 释放blob对象
     }
-  }
+  };
   // console.log('downLoadfileres',res);
-  reader.readAsText(res)
-}
+  reader.readAsText(res);
+};
 </script>
 
 <style lang="scss" scoped>
@@ -472,7 +489,7 @@ const downLoadfile = (res, file) => {
     .light_box {
       width: 500px;
       height: 500px;
-      background-image: url('@/assets/images/light_boder.png');
+      background-image: url("@/assets/images/light_boder.png");
       background-repeat: no-repeat;
       background-size: contain;
       position: relative;

+ 1 - 1
src/views/HomePage/HomePage.vue

@@ -15,7 +15,7 @@
           </div>
         </div>
         <div class="ORC_box" @click="toidentifyFont">
-          <span class="text">ORC工具</span>
+          <span class="text">OCR工具</span>
         </div>
         <div class="sacn_box" @click="scannerFile">
           <span class="text">扫描工具</span>