|
|
@@ -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()
|