zhuliu 1 mese fa
parent
commit
dc95557181

+ 12 - 0
src/services/api.ts

@@ -273,4 +273,16 @@ export const reportApi = {
       throw error
     }
   },
+
+  //获取报告模板
+  getReportTemplate: async (): Promise<unknown> => {
+    try {
+      const url = `/xiaoshi/ppa/report/selectReportTemplate`
+      const response = await apiClient.get<unknown>(url)
+      return response
+    } catch (error) {
+      console.error(`获取报告模板失败:`, error)
+      throw error
+    }
+  },
 }

+ 11 - 43
src/views/report/ReportDetail.vue

@@ -102,7 +102,7 @@
                 </div>
 
                 <div class="news-footer">
-                  <div class="news-date">{{ formatDate(news.publicTime,'yyyy-MM-dd') }}</div>
+                  <div class="news-date">{{ formatDate(news.publicTime, 'yyyy-MM-dd') }}</div>
                   <div
                     class="news-category"
                     v-if="!editingNewsId || editingNewsId !== news.articleId"
@@ -116,6 +116,8 @@
         </div>
       </div>
     </el-card>
+
+    <reportTemplateDialog ref="reportTemplateRef"></reportTemplateDialog>
   </div>
 </template>
 
@@ -126,7 +128,8 @@ import { useRoute, useRouter } from 'vue-router'
 import type { NewsItem, Report, Category } from '@/types'
 import { format } from 'date-fns'
 import { reportApi, categoryApi, newsApi } from '@/services/api'
-
+import reportTemplateDialog from './components/dialog/reportTemplate.vue'
+const reportTemplateRef = ref<InstanceType<typeof reportTemplateDialog>>()
 // Router
 const route = useRoute()
 const router = useRouter()
@@ -244,47 +247,12 @@ const saveEdit = async () => {
 }
 
 const exportReportInfo = async () => {
-  try {
-    const reportId = parseInt(route.params.id as string)
-    const response = await reportApi.exportReportInfo({ reportId: reportId })
-    ElMessage.success('导出报告成功')
-    if (response.code == 200) {
-      const guid = response.data
-      //执行下载
-      downLoad2(guid, report.value.reportName)
-    }
-  } catch (error) {
-    ElMessage.error('导出报告失败')
-  }
-}
-
-//获取下载地址
-const getDownloadPath = (guid: string) => {
-  if (!guid) {
-    return ''
-  }
-  return `/api/fileManager/downloadFile?fileId=${guid}`
-}
-
-const downLoad2 = (guid: string, fileName = 'download') => {
-  //获取下载地址
-  const href = getDownloadPath(guid)
-  if (!href) {
-    return
+  const params = {
+    reportId: parseInt(route.params.id as string),
+    reportName: report.value.reportName,
   }
-  const anchor = document.createElement('a')
-  if ('download' in anchor) {
-    anchor.href = href
-    anchor.setAttribute('download', fileName)
-    anchor.className = 'download-js-link'
-    anchor.innerHTML = 'downloading...'
-    anchor.style.display = 'none'
-    document.body.appendChild(anchor)
-    setTimeout(function () {
-      anchor.click()
-      document.body.removeChild(anchor)
-    }, 66)
-    return true
+  if (reportTemplateRef.value) {
+    reportTemplateRef.value.open(params)
   }
 }
 
@@ -313,7 +281,7 @@ const goBack = () => {
   router.push('/reports')
 }
 
-const formatDate = (date: Date,formatStr:string = 'yyyy-MM-dd HH:mm:ss') => {
+const formatDate = (date: Date, formatStr: string = 'yyyy-MM-dd HH:mm:ss') => {
   return format(new Date(date), formatStr)
 }
 

+ 147 - 0
src/views/report/components/dialog/reportTemplate.vue

@@ -0,0 +1,147 @@
+<template>
+  <div>
+    <el-dialog v-model="visible" title="报告模板" width="500" :before-close="handleClose">
+      <el-table
+        ref="singleTableRef"
+        highlight-current-row
+        :data="tableData"
+        style="width: 100%"
+        @current-change="handleCurrentChange"
+      >
+        <el-table-column type="index" label="序号" width="80">
+          <template #default="scope">
+            <div>
+              <el-radio-group v-model="templateId">
+                <el-radio :value="scope.row.id" size="large">{{ scope.$index + 1 }}</el-radio>
+              </el-radio-group>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column property="templateName" label="模板名称"></el-table-column>
+      </el-table>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button @click="handleClose">取 消</el-button>
+          <el-button type="primary" @click="submit" :loading="btnLoading"> 确 认 </el-button>
+        </div>
+      </template>
+    </el-dialog>
+  </div>
+</template>
+<script setup lang="ts">
+import { ref } from 'vue'
+import { ElMessage } from 'element-plus'
+import type { TableInstance } from 'element-plus'
+const currentRow = ref()
+const singleTableRef = ref<TableInstance>()
+import { reportApi } from '@/services/api'
+
+const visible = ref(false)
+interface reportTemplate {
+  id: number
+  templateName: string
+  templatePath: string
+  createId: number
+  createTime: Date
+}
+const tableData = ref<reportTemplate[]>([])
+const templateId = ref()
+const btnLoading = ref(false)
+
+const handleClose = () => {
+  currentRow.value = null
+  singleTableRef.value?.setCurrentRow(null)
+  templateId.value = null
+  visible.value = false
+}
+
+const parentParams = ref({})
+
+const handleCurrentChange = (val: reportTemplate | undefined) => {
+  currentRow.value = val
+  if (val) {
+    templateId.value = val.id
+  } else {
+    templateId.value = null
+  }
+}
+
+const open = (obj: object | null) => {
+  parentParams.value = obj || {}
+  if (!tableData.value.length) {
+    getTemplateList()
+  }
+  visible.value = true
+}
+
+const downLoad2 = (guid: string, fileName = 'download') => {
+  //获取下载地址
+  const href = getDownloadPath(guid)
+  if (!href) {
+    return
+  }
+  const anchor = document.createElement('a')
+  if ('download' in anchor) {
+    anchor.href = href
+    anchor.setAttribute('download', fileName)
+    anchor.className = 'download-js-link'
+    anchor.innerHTML = 'downloading...'
+    anchor.style.display = 'none'
+    document.body.appendChild(anchor)
+    setTimeout(function () {
+      anchor.click()
+      document.body.removeChild(anchor)
+    }, 66)
+    return true
+  }
+}
+
+//获取下载地址
+const getDownloadPath = (guid: string) => {
+  if (!guid) {
+    return ''
+  }
+  return `/api/fileManager/downloadFile?fileId=${guid}`
+}
+
+const submit = async () => {
+  if (!templateId.value) {
+    ElMessage.warning('请选择一个模板')
+    return
+  }
+  try {
+    const params = {
+      ...parentParams.value,
+      templateId: templateId.value,
+    }
+    btnLoading.value = true
+    const response = await reportApi.exportReportInfo(params)
+    ElMessage.success('导出报告成功')
+    if (response.code == 200) {
+      const guid = response.data
+      //执行下载
+      downLoad2(guid, parentParams.value.reportName)
+      btnLoading.value = true
+      handleClose()
+    }
+  } catch (error) {
+    ElMessage.error('导出报告失败')
+    btnLoading.value = true
+  }
+}
+
+const getTemplateList = async () => {
+  try {
+    const response = await reportApi.getReportTemplate()
+    if (response.code == 200) {
+      tableData.value = response.data || []
+    }
+  } catch (error) {
+    ElMessage.error('获取报告模板失败')
+  }
+}
+
+defineExpose({
+  open,
+})
+</script>