From f812a5d9c4a973930a79581e0c1de91a7054b547 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期二, 29 七月 2025 14:57:01 +0800
Subject: [PATCH] 中间数据产品 1. 新增报告生成提示; 2. 新增报告文件下载; 3. 修复报告页面展示时,相同名称的列数据无法正确展示的问题;
---
src/components/bg-task/FYBgTaskCard.vue | 25 ++++--
src/api/fysp/dataproductApi.js | 2
src/stores/bgtaskStore.js | 36 +++++++++
src/components.d.ts | 1
src/components/bg-task/FYBgTaskDialog.vue | 27 ++++--
src/views/fysp/data-product/components/BaseDataProduct.vue | 111 ++++++++++++++++++---------
6 files changed, 146 insertions(+), 56 deletions(-)
diff --git a/src/api/fysp/dataproductApi.js b/src/api/fysp/dataproductApi.js
index 994fc55..fbd31ce 100644
--- a/src/api/fysp/dataproductApi.js
+++ b/src/api/fysp/dataproductApi.js
@@ -18,7 +18,7 @@
}
// 鏂囨。宸插瓨鍦紝杩斿洖鏂囦欢鏁版嵁娴�
else {
- return res.data
+ return res
// const name = Base64.decode(res.headers.get('filename'));
// const url = window.URL.createObjectURL(res.data);
// const link = document.createElement('a');
diff --git a/src/components.d.ts b/src/components.d.ts
index cd88150..460929c 100644
--- a/src/components.d.ts
+++ b/src/components.d.ts
@@ -57,6 +57,7 @@
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
ElRow: typeof import('element-plus/es')['ElRow']
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
+ ElSegmented: typeof import('element-plus/es')['ElSegmented']
ElSelect: typeof import('element-plus/es')['ElSelect']
ElSpace: typeof import('element-plus/es')['ElSpace']
ElStep: typeof import('element-plus/es')['ElStep']
diff --git a/src/components/bg-task/FYBgTaskCard.vue b/src/components/bg-task/FYBgTaskCard.vue
index 5853db3..7c38efa 100644
--- a/src/components/bg-task/FYBgTaskCard.vue
+++ b/src/components/bg-task/FYBgTaskCard.vue
@@ -4,7 +4,9 @@
<el-row justify="space-between">
<div>
<div><el-text tag="b" size="large">鍚庡彴浠诲姟</el-text></div>
- <el-text size="small" type="info">鏄剧ず褰撳墠姝e湪杩涜鐨勫悗鍙拌�楁椂浠诲姟鐘舵��</el-text>
+ <el-text size="small" type="info"
+ >鏄剧ず褰撳墠姝e湪杩涜鐨勫悗鍙拌�楁椂浠诲姟鐘舵��</el-text
+ >
</div>
<el-button
icon="Refresh"
@@ -46,11 +48,13 @@
import { useFetchData } from '@/composables/fetchData';
import bgtaskApi from '@/api/fysp/bgtaskApi';
import { enumBgTask, BG_TASK_TYPE, BG_TASK_STATUS } from '@/enum/bgTask';
+import { useBgtaskStore } from '@/stores/bgtaskStore';
export default {
setup() {
const { loading, fetchData } = useFetchData();
- return { loading, fetchData };
+ const { registerOnFetchTask } = useBgtaskStore();
+ return { loading, fetchData, registerOnFetchTask };
},
props: {
modelValue: Number
@@ -80,16 +84,20 @@
addTask() {},
newTestTask() {
this.fetchData((page, pageSize) => {
- return bgtaskApi.newTestTask(`Test-Task-${++this.taskIndex}`).then((res) => {
- this.taskList.push(res.data);
- });
+ return bgtaskApi
+ .newTestTask(`Test-Task-${++this.taskIndex}`)
+ .then((res) => {
+ this.taskList.push(res.data);
+ });
});
},
startNewTestTask() {
this.fetchData((page, pageSize) => {
- return bgtaskApi.startNewTestTask(`Test-Task-${++this.taskIndex}`).then((res) => {
- this.taskList.push(res.data);
- });
+ return bgtaskApi
+ .startNewTestTask(`Test-Task-${++this.taskIndex}`)
+ .then((res) => {
+ this.taskList.push(res.data);
+ });
});
},
@@ -153,6 +161,7 @@
},
mounted() {
this.fetchTask();
+ this.registerOnFetchTask(this.fetchTask);
// setInterval(() => {
// this.fetchTask();
// }, 10000);
diff --git a/src/components/bg-task/FYBgTaskDialog.vue b/src/components/bg-task/FYBgTaskDialog.vue
index 8139e47..f274ac1 100644
--- a/src/components/bg-task/FYBgTaskDialog.vue
+++ b/src/components/bg-task/FYBgTaskDialog.vue
@@ -1,9 +1,16 @@
<template>
- <el-popover placement="bottom" :width="600" trigger="click">
+ <el-popover
+ placement="bottom"
+ :width="600"
+ trigger="click"
+ v-model:visible="bgtaskStore.dialogShow"
+ >
<template #reference>
<el-badge :value="runningNum" :hidden="runningNum == 0" class="m-r-16">
<el-button circle>
- <el-icon v-if="runningNum > 0" color="red" class="is-loading"><Clock /></el-icon>
+ <el-icon v-if="runningNum > 0" color="red" class="is-loading"
+ ><Clock
+ /></el-icon>
<el-icon v-else><Clock /></el-icon>
</el-button>
</el-badge>
@@ -12,13 +19,13 @@
<FYBgTaskCard v-model="runningNum"></FYBgTaskCard>
</el-popover>
</template>
-<script>
-export default {
- data() {
- return {
- runningNum: 0
- };
- }
-};
+<script setup>
+import { ref } from 'vue';
+import { useBgtaskStore } from '@/stores/bgtaskStore';
+
+const bgtaskStore = useBgtaskStore();
+
+const runningNum = ref(0);
+
</script>
<style scoped></style>
diff --git a/src/stores/bgtaskStore.js b/src/stores/bgtaskStore.js
new file mode 100644
index 0000000..12f3814
--- /dev/null
+++ b/src/stores/bgtaskStore.js
@@ -0,0 +1,36 @@
+import { defineStore } from 'pinia';
+import { ref } from 'vue';
+
+export const useBgtaskStore = defineStore('bgtask', () => {
+ // 寮瑰嚭妗嗘樉绀�
+ const dialogShow = ref(false);
+
+ const events = [];
+
+ function toggleShow(show) {
+ if (typeof show === 'boolean') {
+ dialogShow.value = show;
+ } else {
+ dialogShow.value = !dialogShow.value;
+ }
+ }
+
+ function registerOnFetchTask(func) {
+ events.push(func);
+ }
+
+ function fetchTask() {
+ events.forEach((e) => {
+ if (typeof e === 'function') {
+ e();
+ }
+ });
+ }
+
+ return {
+ dialogShow,
+ toggleShow,
+ registerOnFetchTask,
+ fetchTask
+ };
+});
diff --git a/src/views/fysp/data-product/components/BaseDataProduct.vue b/src/views/fysp/data-product/components/BaseDataProduct.vue
index 7054740..8f462ba 100644
--- a/src/views/fysp/data-product/components/BaseDataProduct.vue
+++ b/src/views/fysp/data-product/components/BaseDataProduct.vue
@@ -23,11 +23,11 @@
</template>
<template #buttons>
<CompReportDownloadDialog
- name="闂涓庢暣鏀规眹鎬诲垎鏋愪笌鍔ㄦ�佽窡韪竻鍗�"
+ :name="fileName"
:locations="formSearch.locations"
:scenetype="formSearch.scenetype"
:time="formSearch.time"
- @submit="handleSearch"
+ @submit="(e) => handleSearch(e, true)"
></CompReportDownloadDialog>
</template>
</FYSearchBar>
@@ -57,27 +57,27 @@
<el-table-column
v-for="(item, index) in activeExcelData.head"
:key="index"
- :prop="item.name"
+ :prop="item.prop"
:label="item.name"
>
<template v-if="item.children" #default="{ row }">
- <span v-html="row[item.name]"></span>
+ <span v-html="row[item.prop]"></span>
<el-table-column
v-for="(item1, index1) in item.children"
:key="index1"
- :prop="item1.name"
+ :prop="item1.prop"
:label="item1.name"
>
<template v-if="item1.children" #default="scope1">
- <span v-html="scope1.row[item1.name]"></span>
+ <span v-html="scope1.row[item1.prop]"></span>
<el-table-column
v-for="(item2, index2) in item1.children"
:key="index2"
- :prop="item2.name"
+ :prop="item2.prop"
:label="item2.name"
>
<template v-if="item2.children" #default="scope2">
- <span v-html="scope2.row[item2.name]"></span>
+ <span v-html="scope2.row[item2.prop]"></span>
</template>
</el-table-column>
</template>
@@ -102,12 +102,16 @@
//寮曞叆鐩稿叧鏍峰紡
import '@vue-office/excel/lib/index.css';
-import { ref, onMounted } from 'vue';
+import { ref, onMounted, computed } from 'vue';
import dayjs from 'dayjs';
import * as XLSX from 'xlsx';
import * as ExcelJS from 'exceljs';
import dataproductApi from '@/api/fysp/dataproductApi';
import CompReportDownloadDialog from './CompReportDownloadDialog.vue';
+import { Base64 } from 'js-base64';
+import { useBgtaskStore } from '@/stores/bgtaskStore';
+
+const bgtaskStore = useBgtaskStore();
const emit = defineEmits(['search']);
@@ -125,6 +129,19 @@
headNum: {
type: Number,
default: 1
+ }
+});
+
+const fileName = computed(() => {
+ switch (props.productType) {
+ case 1:
+ return '闂涓庢暣鏀规眹鎬诲垎鏋愪笌鍔ㄦ�佽窡韪竻鍗�';
+ case 2:
+ return '瑙勮寖鎬ц瘎浼颁笌鍒嗘瀽娓呭崟';
+ case 3:
+ return '闂涓庢暣鏀瑰垎甯冨垎鏋愭竻鍗�';
+ default:
+ return '鎶ュ憡娓呭崟';
}
});
@@ -158,7 +175,7 @@
getTable(activeSheet.value);
}
-function handleSearch(forceUpdate) {
+function handleSearch(forceUpdate, isDownload) {
const locations = formSearch.value.locations;
const time = formSearch.value.time;
const scenetype = formSearch.value.scenetype;
@@ -178,30 +195,47 @@
dataproductApi
.downloadProduct(area, props.productType, forceUpdate ? forceUpdate : false)
.then(async (res) => {
- // const data = new Uint8Array(res);
- res.arrayBuffer().then((data) => {
- workbook = XLSX.read(data, { type: 'array' });
- sheetNames.value = workbook.SheetNames;
- activeSheet.value = sheetNames.value[0];
- getTable(activeSheet.value);
- });
+ if (res == false) {
+ alert('鎶ュ憡鐢熸垚涓紝鍙湪鍚庡彴浠诲姟鏌ョ湅鐢熸垚杩涘害');
+ bgtaskStore.dialogShow = true;
+ bgtaskStore.fetchTask();
+ } else {
+ if (isDownload) {
+ const name = Base64.decode(res.headers.get('filename'));
+ const url = window.URL.createObjectURL(res.data);
+ const link = document.createElement('a');
+ link.href = url;
+ link.setAttribute('download', name);
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ window.URL.revokeObjectURL(url);
+ } else {
+ res.data.arrayBuffer().then((data) => {
+ workbook = XLSX.read(data, { type: 'array' });
+ sheetNames.value = workbook.SheetNames;
+ activeSheet.value = sheetNames.value[0];
+ getTable(activeSheet.value);
+ });
+ }
- // const workbook = new ExcelJS.Workbook();
- // await workbook.xlsx.load(res);
- // workbook.eachSheet(function (worksheet, sheetId) {
- // console.log(worksheet.name);
- // });
- // const sheet1 = workbook.worksheets[0]
- // const row = sheet1.getRow(1)
- // console.log(row);
+ // const workbook = new ExcelJS.Workbook();
+ // await workbook.xlsx.load(res);
+ // workbook.eachSheet(function (worksheet, sheetId) {
+ // console.log(worksheet.name);
+ // });
+ // const sheet1 = workbook.worksheets[0]
+ // const row = sheet1.getRow(1)
+ // console.log(row);
- // console.log(res);
- // console.log(new ArrayBuffer(res));
- // res.arrayBuffer().then(r=>{
- // excel.value = r
- // })
+ // console.log(res);
+ // console.log(new ArrayBuffer(res));
+ // res.arrayBuffer().then(r=>{
+ // excel.value = r
+ // })
- // excel.value = new ArrayBuffer(res)
+ // excel.value = new ArrayBuffer(res)
+ }
})
.finally(() => (loading.value = false));
}
@@ -229,7 +263,7 @@
// console.log(tableData);
const t = strToTableObj(tableData);
- console.log(t);
+ // console.log(t);
// console.log(head);
// console.log(data);
excelDatas.value.set(sheetName, t);
@@ -296,14 +330,17 @@
const row = rows[i];
if (lastHead.length == 0) {
row.forEach((r, y) => {
- lastHead.push({ name: r });
- dataKeys.push(r);
+ const prop = r == '' ? r : `id-${r}-${y}`;
+ lastHead.push({ name: r, prop });
+ dataKeys.push(prop);
});
} else {
const newHead = [];
row.forEach((r, y) => {
+ const prop = `id-${r}-${y}`;
if (dataKeys[y] == '') {
- dataKeys[y] = r;
+ // lastHead[y] = { name: r, prop };
+ dataKeys[y] = prop;
}
const last = lastHead[y];
@@ -311,7 +348,7 @@
console.log(last);
}
if (last.name == '') {
- newHead.push({ name: r });
+ newHead.push({ name: r, prop });
offset++;
} else if (r != '') {
newHead.push({
@@ -320,7 +357,7 @@
});
offset = 1;
} else {
- newHead.push({ name: '' });
+ newHead.push({ name: '', prop });
let _index = newHead.length - 1 - offset;
_index = _index >= 0 ? _index : 0;
newHead[_index].children.push(last);
--
Gitblit v1.9.3