Parcourir la source

orc,扫描,树

liuQiang il y a 1 an
Parent
commit
86a623cbba

+ 7 - 0
src/api/search/search.js

@@ -20,4 +20,11 @@ export function picTree(query) {
     method: 'get',
     params: query
   })
+}
+export function pdfTree(query) {
+  return request({
+    url: '/biz/dir/pdf-tree',
+    method: 'get',
+    params: query
+  })
 }

+ 56 - 24
src/components/Pdf2Word/Pdf2Word.vue

@@ -10,6 +10,7 @@
             :drag="true"
             :action="actionUrl"
             :headers="headersObj"
+            accept=".pdf, .PDF"
             :show-file-list="false"
             :on-success="handleAvatarSuccess"
             :before-upload="beforeUp"
@@ -44,7 +45,7 @@
             :on-success="handleAvatarSuccess"
           >
             <img src="@/assets/images/FrameYun.png" class="avatar" />
-            <span>点击按钮上传文件</span>
+            <span>点击按钮选择文件</span>
           </el-upload>
         </div>
         <div class="sunmit_btn" @click="addlibraryImg">添加文库文件</div>
@@ -118,7 +119,7 @@ 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 } from "@/api/search/search.js";
+import { picTree, pdfTree } from "@/api/search/search.js";
 import { ocrRemark, preview } from "@/api/common/common.js";
 import Cookies from "js-cookie";
 const textData = ref(""); //解析出来的文字
@@ -128,11 +129,13 @@ 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}/api/upload`
+  `${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");
@@ -150,30 +153,31 @@ watch(
     isOpen.value = newValue;
   }
 );
-onMounted(async () => {
- 
-});
+onMounted(async () => {});
 const handleAvatarSuccess = (msg, file) => {
-  // console.log("re", msg);
+  console.log("re", msg);
   const flieData = toRaw(file);
-  // console.log("file", flieData);
-  // showImg.value = URL.createObjectURL(flieData.raw);
-  if (msg.code === 200) {
-    textData.value = msg.msg;
-    thisStep.value = "end";
-  } else {
-    thisStep.value = "start";
-    textData.value = null;
-    showImg.value = null;
-    ElMessage({ message: "识别失败", type: "error" });
-  }
-  console.log("textData", textData.value);
+  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+ ".pdf"; //指定下载文件名
+  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);
-  thisStep.value = "loading";
+  // showImg.value = URL.createObjectURL(raw);
+  loadingPreview.value = true
+  // thisStep.value = "loading";
 };
 // 复制功能调用的方法
 const copyQbUrl = () => {
@@ -194,7 +198,7 @@ const copyQbUrl = () => {
 };
 // 选取文库图片
 const addlibraryImg = async () => {
-  const res = await picTree();
+  const res = await pdfTree();
   console.log("res", res);
   treeData.value = res;
   openFile.value = true;
@@ -217,6 +221,34 @@ const reClick = () => {
   textData.value = null;
   showImg.value = null;
 };
+// 文件下载
+const downLoadfile = (res, file) => {
+  // console.log('downLoadfileres',res);
+  var reader = new FileReader();
+  reader.onloadend = function (event) {
+    //event 就是你要的返回内容
+    //因为返回的报错格式是字符串,手动转换成对象,转换成功表示请求失败
+    //转换失败就意味着你拿到的result是文件流,那么直接手动下载就好
+    try {
+      let data = JSON.parse(event.target.result);
+    } catch (err) {
+      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); // 创建下载的链接
+      // 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对象
+    }
+  };
+  // console.log('downLoadfileres',res);
+  reader.readAsText(res);
+};
 </script>
   
   <style lang="scss" scoped>

+ 14 - 0
src/layout/indexCommon.vue

@@ -586,6 +586,20 @@ const clickTab = (item) => {
           });
         return
       }
+       // 去Pdf2Word单独判断
+      if (toFileData.value.name == "Pdf转Word" || toFileData.value.label == "Pdf转Word") {
+        // console.log("clickRowId.value", JSON.stringify(toRaw(toFileData.value).clickRowId));
+        editableTabsValue.value = toFileData.value.path
+        isAlive.value = true
+          router.push({
+            name: toFileData.value.path,
+            state: {
+              // row: JSON.stringify(toRaw(toFileData.value.clickRowId)),
+              clickRowId: JSON.stringify(toRaw(toFileData.value).clickRowId),
+            },
+          });
+        return
+      }
       // 去个人中心识别单独判断
       if (toFileData.value.name == "个人中心" || toFileData.value.label == "个人中心") {
         // console.log("clickRowId.value", JSON.stringify(toRaw(toFileData.value).clickRowId));

+ 1 - 1
src/router/index.js

@@ -31,7 +31,7 @@ import main from '@/layout/components/AppMain.vue'
 // 公共路由
 export const constantRoutes = [{
 	path: '/redirect',
-	component: Layout,
+	// component: Layout,
 	hidden: true,
 	children: [{
 		path: '/redirect/:path(.*)',