<template> <div class="eibs-tab"> <el-row style="margin-bottom: 10px;"> <el-col :span="24" style="margin-top: 10px;margin-bottom: 10px;"> <c-button class="medium_bcs" style="margin-left: 20" size="medium" type="primary" @click="reflush">刷新</c-button> </el-col> </el-row> <el-col :span="24" style="margin-top: 10px"> <div style="height: 90%"> <c-col :span="24"> <el-table id='infrptBSTableRef' ref="infrptBSTableRef" v-loading="load" :data="tableData" style="width:100%" height="calc(100vh - 300px)" size="small" :border="true" :highlight-current-row="true" > <el-table-column v-for="(item,key) in tableColumns" :key="key" :label="item.label" :prop="item.prop" :fixed="item.fixed" sortable="custom" :show-overflow-tooltip="true" :min-width="item.width" > <template slot-scope="scope"> <div style="text-align: left">{{scope.row[item.prop]}}</div> </template> </el-table-column> <el-table-column fixed="right" label="操作" width="150px"> <template slot="header"> <c-col :span="11" style="text-align: center"> <span>操作</span> </c-col> </template> <template slot-scope="scope"> <c-button style="margin-left: 0" type='primary' size="small" @click="toDownload(scope.row)" slot="reference">下载 </c-button> </template> </el-table-column> </el-table> <el-pagination layout="total" :total="pagination.total" :page-size="pagination.pageSize" :current-page="pagination.pageNum" @size-change="handleSizeChange" @current-change="currentChange"> </el-pagination> </c-col> </div> </el-col> </div> </template> <script> import CodeTable from "~/config/CodeTable"; import event from "../event"; import Api from "~/service/Api" export default { inject: ["root"], props: ["model", "codes"], mixins:[event], components: {}, data() { return { tableColumns: [ { prop:"curFileName", label: "月末批量文件列表", isShow: true, width: 1000 }, ], load: false, tableData: [ ], pagination: { pageNum: 1, pageSize: 10, total: 0 }, handleVisible: false, handleModel: {}, }; }, mounted() { this.formSubmit(); }, computed: { }, methods: { formSubmit() { this.reflush(); }, async reflush(){ const loading = this.loading() let res = await Api.post("/public/intrpt/getFileList"); if (res.respCode == SUCCESS) { this.tableData = res.data this.pagination.total = res.data.length } loading.close() }, async toDownload(row){ let params = { path: row.oriFileName } let res = await Api.post("/manager/fileupdown/fileDown", params); if (res.respCode == "AAAAAA") { //res.data 内容为 TextResultVo if (res.data.data) { let type, code = res.data; const loading = this.loading() this.base64ToBlob(code, type,row.curFileName) loading.close() this.$notify({ title: "成功", message: "文件下载成功!", type: "success", }); } else { this.$notify({ title: '失败', message: '文件下载失败!', type: 'error', }); } } }, base64ToBlob(code, type,curFileName) { if (type == 'application/pdf') { code.data = code.data.replace(/[\n\r]/g, "") } const raw = window.atob(code.data); const rawLength = raw.length; const uInt8Array = new Uint8Array(rawLength); for (let i = 0; i < rawLength; ++i) { uInt8Array[i] = raw.charCodeAt(i); } const blob = new Blob([uInt8Array], { type: type }); // const fileURL = URL.createObjectURL(blob); // window.open(fileURL) let fileName = curFileName; var downloadElement = document.createElement('a'); var href = window.URL.createObjectURL(blob); downloadElement.href = href; downloadElement.download = fileName; document.body.appendChild(downloadElement); downloadElement.click(); document.body.removeChild(downloadElement); window.URL.revokeObjectURL(href); }, // pageSize改变 handleSizeChange(val) { this.pagination.pageNum = 1; this.pagination.pageSize = val; this.handleSearch(); }, async currentChange(num) { this.pagination.pageNum = num; this.handleSearch(); }, } }; </script> <style scoped> </style>