浏览代码

修改请求接口及部分逻辑

yangg 5 月之前
父节点
当前提交
97700a5ddf
共有 2 个文件被更改,包括 81 次插入15 次删除
  1. 10 0
      src/api/document.js
  2. 71 15
      src/views/project/components/dataList.vue

+ 10 - 0
src/api/document.js

@@ -184,3 +184,13 @@ export function htmlPDFWord(data) {
     data
     data
   })
   })
 }
 }
+
+/* 预览 */
+
+export function searchlistDocTemplate(data) {
+  return request({
+    url: '/document/searchlistDocTemplate',
+    method: 'post',
+    data
+  })
+}

+ 71 - 15
src/views/project/components/dataList.vue

@@ -245,10 +245,10 @@
               type="primary"
               type="primary"
               @click="previewTemplate(scope.row)"
               @click="previewTemplate(scope.row)"
             >预览</el-button>
             >预览</el-button>
-            <el-button
+           <!--  <el-button
               type="primary"
               type="primary"
               @click="replaceTemplate(scope.row)"
               @click="replaceTemplate(scope.row)"
-            >替换</el-button>
+            >替换</el-button> -->
             <el-dropdown
             <el-dropdown
               style="margin-left: 10px"
               style="margin-left: 10px"
               trigger="click"
               trigger="click"
@@ -371,7 +371,9 @@ import {
   htmlWordNew,
   htmlWordNew,
   createDocument,
   createDocument,
   searchlistDoc,
   searchlistDoc,
-  getDocumentInfo
+  getDocumentInfo,
+  updateDocument,
+  searchlistDocTemplate
 } from '@/api/document'
 } from '@/api/document'
 import { searchCustomer } from '@/api/customer'
 import { searchCustomer } from '@/api/customer'
 import { searchProduct } from '@/api/product'
 import { searchProduct } from '@/api/product'
@@ -552,9 +554,23 @@ export default {
 
 
     // 更新导出方法
     // 更新导出方法
     async exportDocumentWithHtmlDocx(template) {
     async exportDocumentWithHtmlDocx(template) {
-      console.log(template);
+     /*  console.log(template); */
+     const res = await searchlistDocTemplate({
+        /* page: 1,
+        pageSize: 10, */
+        project_id:this.currentData.id,
+        id: template.id
+      })
+      if(res.status!==200) return
+      let templateData
       try {
       try {
-        const templateData = JSON.parse(template.data || '[]')
+        if(res.data.documents.length!==0){
+           templateData = JSON.parse(res.data.documents[0].data || '[]')
+        }else{
+        const template_Data = await getDocumentInfo({id:template.id})
+          if(template_Data.status!==200) return
+           templateData = JSON.parse(template_Data.data.data || '[]')
+        }
         const contentContainer = document.createElement('div')
         const contentContainer = document.createElement('div')
         contentContainer.className = 'content'
         contentContainer.className = 'content'
 
 
@@ -1715,7 +1731,7 @@ export default {
     viewBoundTemplates(row) {
     viewBoundTemplates(row) {
       this.currentData = row
       this.currentData = row
       this.boundTemplateLoading = true
       this.boundTemplateLoading = true
-      searchTemplateList({ ids: row.documentIds.join(',') || 0 })
+      searchTemplateListNoData({ ids: row.documentIds.join(',') || 0 })
         .then((res) => {
         .then((res) => {
           if (res.status === 200) {
           if (res.status === 200) {
             this.boundTemplateList = res.data
             this.boundTemplateList = res.data
@@ -1728,18 +1744,20 @@ export default {
     },
     },
 
 
     async previewTemplate(template) {
     async previewTemplate(template) {
+      console.log(template);
       this.currentTemplate = template
       this.currentTemplate = template
       /* this.loadDocumentVersions(template); */
       /* this.loadDocumentVersions(template); */
-      const res = await searchlistDoc({
-        page: 1,
-        pageSize: 10,
-        template_id: template.id
+      const res = await searchlistDocTemplate({
+        /* page: 1,
+        pageSize: 10, */
+        project_id:this.currentData.id,
+        id: template.id
       })
       })
 
 
       if (res.status === 200) {
       if (res.status === 200) {
         /* this.documentVersions = res.data.dataList[0]; */
         /* this.documentVersions = res.data.dataList[0]; */
-        if (res.data.dataList.length !== 0) {
-          const url = `#/document/viewCreate?articleId=${res.data.dataList[0].id}&type=document`
+        if (res.data.documents.length !== 0) {
+          const url = `#/document/viewCreate?articleId=${res.data.documents[0].id}&type=document`
           window.open(url, '_blank')
           window.open(url, '_blank')
         } else {
         } else {
           const a = document.createElement('a')
           const a = document.createElement('a')
@@ -1814,12 +1832,25 @@ export default {
         // 依次处理每个选中的模版
         // 依次处理每个选中的模版
         for (const template of this.selectedBoundTemplates) {
         for (const template of this.selectedBoundTemplates) {
           this.docAttr = template
           this.docAttr = template
-
+          const res = await searchlistDocTemplate({
+            /* page: 1,
+            pageSize: 10, */
+            project_id:this.currentData.id,
+            id: template.id
+          })
+          if(res.status!== 200) return
           // 检查模板数据格式
           // 检查模板数据格式
           let templateData
           let templateData
           try {
           try {
             // 优先尝试使用 data 字段
             // 优先尝试使用 data 字段
-            templateData = JSON.parse(template.data || '[]')
+            if(res.data.documents.length!==0){
+                templateData = JSON.parse(res.data.documents[0].data || '[]')
+            }else{
+              const template_Data = await getDocumentInfo({id:template.id})
+                if(template_Data.status!==200) return
+                templateData = JSON.parse(template_Data.data.data || '[]')
+            }
+          
           } catch (e) {
           } catch (e) {
             // 如果解析失败,尝试使用 content 字段
             // 如果解析失败,尝试使用 content 字段
             templateData = template.content
             templateData = template.content
@@ -2006,7 +2037,7 @@ export default {
     },
     },
 
 
     /* 更新  */
     /* 更新  */
-    onUpload() {
+   async onUpload() {
       const _this = this
       const _this = this
       if (_this.TemList.length <= 0) {
       if (_this.TemList.length <= 0) {
         _this.$message.error('增加组件')
         _this.$message.error('增加组件')
@@ -2016,6 +2047,14 @@ export default {
         _this.$message.error('请填写模版标题')
         _this.$message.error('请填写模版标题')
         return
         return
       }
       }
+      const res = await searchlistDocTemplate({
+        /* page: 1,
+        pageSize: 10, */
+        project_id:this.currentData.id,
+        id: _this.docAttr.id
+      })
+      if(res.status!==200) return
+    if(res.data.documents.length==0){
       _this.docAttr.title = _this.docAttr.title + new Date().getTime()
       _this.docAttr.title = _this.docAttr.title + new Date().getTime()
       _this.docAttr.links = JSON.stringify(_this.docAttr.linkProduct)
       _this.docAttr.links = JSON.stringify(_this.docAttr.linkProduct)
       _this.docAttr.projects = JSON.stringify(_this.docAttr.linkProject)
       _this.docAttr.projects = JSON.stringify(_this.docAttr.linkProject)
@@ -2034,6 +2073,23 @@ export default {
           pageSize: 999
           pageSize: 999
         })
         })
       })
       })
+    }else{
+      updateDocument({
+        id:res.data.documents[0].id,
+         data :JSON.stringify(_this.TemList),
+         title:res.data.documents[0].title,
+         status:5,
+         document_type:res.data.documents[0].document_type,
+         is_template:0,
+         template_id:res.data.documents[0].template_id,
+         user_id:res.data.documents[0].user_id
+        }).then(res=>{
+        if (res.status != 200) return 
+        _this.$message.success('文档更新成功')
+      })
+    }
+
+     
     },
     },
 
 
     // 添加统一的内容处理方法
     // 添加统一的内容处理方法