Kaynağa Gözat

对接指标管理导出和指标数据导出

yanglzh 1 ay önce
ebeveyn
işleme
bc8964eab3

+ 2 - 0
src/api/datahub/index.ts

@@ -130,5 +130,7 @@ export default {
     publish: (code: string) => post('/indicator/publish', { code }),
     unpublish: (code: string) => post('/indicator/unpublish', { code }),
     getDimensionValues: (params: object) => get('/indicator/getDimensionValues', params),
+    export: (params: object) => file('/indicator/export', params),
+    exportData: (params: object) => file('/indicator/exportData', params),
   }
 }

+ 21 - 6
src/views/system/datahub/indicator/component/data.vue

@@ -22,7 +22,7 @@
         </el-form-item>
         <el-form-item label="">
           <el-button type="primary" :icon="Filter" @click="fetchList(1)">筛选</el-button>
-          <!-- <el-button @click="exportData">导出</el-button> -->
+          <el-button @click="exportData" :icon="Download" :loading="exportLoading">导出</el-button>
         </el-form-item>
       </el-form>
 
@@ -48,13 +48,15 @@
 </template>
 
 <script lang="ts" setup>
-import { reactive, ref, computed } from "vue";
+import { reactive, ref } from "vue";
 import { ElMessage } from "element-plus";
-import { Filter } from "@element-plus/icons-vue";
+import { Filter, Download } from "@element-plus/icons-vue";
 import api from "/@/api/datahub";
+import downloadFile from "/@/utils/download";
 
 const visible = ref(false);
 const loading = ref(false);
+const exportLoading = ref(false);
 const dimensions = ref<any[]>([]);
 const dimensionsValues = ref<any[]>([]);
 const dimensionsKey = ref("");
@@ -66,8 +68,7 @@ const detail = reactive<any>({}); // 详情含 unit/维度等
 const list = ref<any[]>([]);
 const total = ref(0);
 
-// 查询参数(对应后端文档)
-const query = reactive({
+const baseQuery = {
   searchValue: "",
   keyWord: "",
   dimensions: "",
@@ -76,7 +77,10 @@ const query = reactive({
   dateRange: [],
   pageNum: 1,
   pageSize: 10,
-});
+};
+
+// 查询参数(对应后端文档)
+const query = reactive(JSON.parse(JSON.stringify(baseQuery)));
 
 function handleDimensionChange(value: string) {
   if (!value) {
@@ -132,6 +136,9 @@ function fetchList(p?: number) {
 }
 
 function open(row: any) {
+  Object.assign(query, JSON.parse(JSON.stringify(baseQuery)));
+  dimensionsKey.value = "";
+  dimensionsValue.value = "";
   code.value = row?.code || "";
   title.value = `${row?.name || "-"} (${code.value})`;
   visible.value = true;
@@ -141,6 +148,14 @@ function open(row: any) {
   fetchDetail().then(() => fetchList(1));
 }
 
+function exportData() {
+  exportLoading.value = true;
+  api.indicator
+    .exportData(buildParams())
+    .then((res: any) => downloadFile(res, title.value + "指标数据导出.xlsx"))
+    .finally(() => (exportLoading.value = false));
+}
+
 defineExpose({ open });
 </script>
 

+ 16 - 13
src/views/system/datahub/indicator/index.vue

@@ -3,7 +3,7 @@
     <el-card shadow="never">
       <el-form :model="params" inline ref="queryRef" @keyup.enter="getList">
         <el-form-item>
-          <el-input v-model="params.keyword" placeholder="输入指标名称、编码或描述" style="width: 300px" clearable />
+          <el-input v-model="params.name" placeholder="输入指标名称、编码或描述" style="width: 300px" clearable />
         </el-form-item>
         <el-form-item>
           <el-cascader :options="typeOptions" :props="{ checkStrictly: true, emitPath: false, value: 'code', label: 'name' }" placeholder="请选择指标类型" clearable class="w100" v-model="params.type">
@@ -29,6 +29,10 @@
             <el-icon><ele-FolderAdd /></el-icon>
             新增指标
           </el-button>
+          <el-button class="ml10" @click="exportData()" :loading="exportLoading">
+            <el-icon><ele-Download /></el-icon>
+            导出
+          </el-button>
         </el-form-item>
       </el-form>
 
@@ -86,11 +90,13 @@ import EditIndicator from "./component/edit.vue";
 import DetailDialog from "./component/detail.vue";
 import DataDialog from "./component/data.vue";
 import apiSystem from "/@/api/system";
+import downloadFile from "/@/utils/download";
 
 const editFormRef = ref();
 const detailRef = ref();
 const dataRef = ref();
 const queryRef = ref();
+const exportLoading = ref(false);
 
 const typeOptions = ref([]);
 
@@ -102,7 +108,7 @@ apiSystem.getInfoByKey("sys.indicator.type.tagCode").then((res: any) => {
 });
 
 const { params, tableData, getList, loading } = useSearch(api.indicator.getList, "data", {
-  keyword: "",
+  name: "",
   type: "",
   status: "-1",
 });
@@ -146,17 +152,14 @@ const onRowDel = (row: any) => {
   });
 };
 
-const formatStatus = (s: string) => {
-  if (s === "enabled") return "启用";
-  if (s === "draft") return "草稿";
-  if (s === "disabled") return "停用";
-  return s || "-";
-};
-const statusTagType = (s: string) => {
-  if (s === "enabled") return "success";
-  if (s === "draft") return "info";
-  if (s === "disabled") return "warning";
-  return "info";
+const exportData = () => {
+  exportLoading.value = true;
+  api.indicator
+    .export(params)
+    .then((res: any) => downloadFile(res, "指标管理列表导出.xlsx"))
+    .finally(() => {
+      exportLoading.value = false;
+    });
 };
 </script>