Procházet zdrojové kódy

数据采集增加数据导出

qinhb před 5 měsíci
rodič
revize
b715e4c8be
2 změnil soubory, kde provedl 45 přidání a 2 odebrání
  1. 10 0
      src/api/device/index.ts
  2. 35 2
      src/views/device/data/index.vue

+ 10 - 0
src/api/device/index.ts

@@ -1,4 +1,5 @@
 import request from "@/utils/request";
+import {OrderInfoQuery} from "@/api/order/types";
 
 /**
  * 设备维护
@@ -131,4 +132,13 @@ export function meteringUpdate(params: any) {
   });
 }
 
+export function exportDataList(queryParams: any) {
+  return request({
+    url: "/api/v1/device/data/export",
+    method: "post",
+    data: queryParams,
+    responseType: "arraybuffer",
+  });
+}
+
 

+ 35 - 2
src/views/device/data/index.vue

@@ -17,14 +17,21 @@
         @current-change="dataList"
         @selection-change="selectionChange"
     >
+      <template #menu-right="{}">
+        <el-button
+            class="ml-3"
+            @click="handleExport"
+        >
+          <template #icon> <i-ep-download /> </template>导出
+        </el-button>
+      </template>
     </avue-crud>
   </div>
 </template>
 <script setup>
 import { ref, getCurrentInstance } from "vue";
 import { useCrud } from "@/hooks/userCrud";
-import buttonPermission from "@/common/configs/buttonPermission";
-import {queryDeviceList,queryTypeAliasList} from "@/api/device";
+import {queryDeviceList,queryTypeAliasList,exportDataList} from "@/api/device";
 import { useCommonStoreHook } from "@/store";
 const { isShowTable, tableType } = toRefs(useCommonStoreHook());
 const loading = ref(false);
@@ -42,6 +49,32 @@ const { selectionChange, multipleDelete } = Methords; //选中和批量删除事
 const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
 const crudRef = ref(null); //crudRef.value 获取avue-crud对象
 const deviceList = ref([])
+const handleExport = () => {
+  exportDataList(search.value).then((response) => {
+    downFile(response);
+  });
+};
+
+/** 文件下载 */
+const downFile = (response) => {
+  const fileData = response.data;
+  const fileName = decodeURI(
+      response.headers["content-disposition"].split(";")[1].split("=")[1]
+  );
+  const fileType =
+      "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8";
+  const blob = new Blob([fileData], { type: fileType });
+  const downloadUrl = window.URL.createObjectURL(blob);
+  const downloadLink = document.createElement("a");
+  downloadLink.href = downloadUrl;
+  downloadLink.download = fileName;
+  document.body.appendChild(downloadLink);
+  downloadLink.click();
+  document.body.removeChild(downloadLink);
+  window.URL.revokeObjectURL(downloadUrl);
+};
+
+
 const searchPage = (params, done) =>{
   if(!search.value.deviceNo){
     ElMessage.warning("请先选择设备进行查询");