浏览代码

添加一键导出

zero 1 月之前
父节点
当前提交
b9fd0d9aee
共有 3 个文件被更改,包括 59 次插入4 次删除
  1. 12 0
      src/services/api.ts
  2. 44 1
      src/views/NewsList.vue
  3. 3 3
      src/views/ReportDetail.vue

+ 12 - 0
src/services/api.ts

@@ -356,4 +356,16 @@ export const reportApi = {
       throw error
     }
   },
+  
+  //一键导出上月资讯报告
+  oneClickExportReport: async (): Promise<unknown> => {
+    try {
+      const url = `/xiaoshi/ppa/report/oneClickExport`
+      const response = await apiClient.get<unknown>(url)
+      return response
+    } catch (error) {
+      console.error(`Error from one click export report:`, error)
+      throw error
+    }
+  },
 }

+ 44 - 1
src/views/NewsList.vue

@@ -9,6 +9,7 @@
           </div>
           <div class="actions">
             <el-button type="primary" :icon="Refresh" @click="fetchNews">刷新</el-button>
+            <el-button @click="oneClickExportReport" type="primary" :loading="isExporting">{{ isExporting ? '下载中...' : '一键导出上月资讯报告' }}</el-button>
           </div>
         </div>
       </template>
@@ -292,7 +293,7 @@
 
 <script setup lang="ts">
 import { ref, onMounted, reactive, nextTick } from 'vue'
-import { ElMessage, ElMessageBox } from 'element-plus'
+import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
 import { Collection, Refresh } from '@element-plus/icons-vue'
 import type { NewsItem, Category, Report } from '@/types'
 import { format } from 'date-fns'
@@ -617,6 +618,48 @@ const formatDate = (date: Date, formatStr = 'yyyy-MM-dd') => {
   return format(new Date(date), formatStr)
 }
 
+const isExporting = ref(false);
+
+const oneClickExportReport = async () => {
+  isExporting.value = true;
+  try {
+    const response = await reportApi.oneClickExportReport()
+    ElMessage.success('一键导出上月资讯报告成功')
+    if (response.code == 200) {
+      const guid = response.data
+      //执行下载
+      downLoad2(guid)
+    }
+  } catch (error) {
+    ElMessage.error('一键导出上月资讯报告失败')
+  } finally {
+    isExporting.value = false;
+  }
+}
+
+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
+  }
+}
+
+
 // Lifecycle
 onMounted(() => {
   fetchNews()

+ 3 - 3
src/views/ReportDetail.vue

@@ -102,7 +102,7 @@
                 </div>
 
                 <div class="news-footer">
-                  <div class="news-date">{{ formatDate(news.publicTime) }}</div>
+                  <div class="news-date">{{ formatDate(news.publicTime,'yyyy-MM-dd') }}</div>
                   <div
                     class="news-category"
                     v-if="!editingNewsId || editingNewsId !== news.articleId"
@@ -313,8 +313,8 @@ const goBack = () => {
   router.push('/reports')
 }
 
-const formatDate = (date: Date) => {
-  return format(new Date(date), 'yyyy-MM-dd HH:mm:ss')
+const formatDate = (date: Date,formatStr:string = 'yyyy-MM-dd HH:mm:ss') => {
+  return format(new Date(date), formatStr)
 }
 
 // Lifecycle