feat : 台账模板下载

This commit is contained in:
2024-07-26 19:46:06 +08:00
parent d92bcfe0aa
commit 58c3419b35
2 changed files with 35 additions and 1 deletions

View File

@@ -179,3 +179,15 @@ export const exportExcel = (data) => {
}
);
};
//台账模板下载
export const ledgerTemplateDownload = () => {
return axios.get(
`${import.meta.env.VITE_BASE_URL}/workflow/mosr/project/implementation/download/template`,
{
responseType: 'blob',
headers: {
Authorization: getToken()
}
}
);
};

View File

@@ -20,6 +20,7 @@
<div style="display: flex">
<el-button color="#DED0B2" @click="exportExcelHandler">导出</el-button>
<import-excel :projectId="projectId" v-if="buttonShow" @success="importTheExpenseLedger"/>
<el-button color="#DED0B2" v-if="buttonShow" @click="handleImportTemplateDownload">模板下载</el-button>
<el-button color="#DED0B2" v-if="buttonShow" @click="handleUploadFee">上传费用</el-button>
<el-button color="#DED0B2" v-if="buttonShow" @click="handleUpdateTable">表格更新</el-button>
</div>
@@ -36,7 +37,7 @@
import fvSelect from '@/fvcomponents/fvSelect/index.vue'
import {toThousands} from '@/utils/changePrice.js'
import {getBaseInfoApi} from "@/components/steps/api";
import {searchUpdateLedgerData, exportExcel} from "@/api/project-manage";
import {searchUpdateLedgerData, exportExcel,ledgerTemplateDownload} from "@/api/project-manage";
// import ImportExcel from "../../../components/ImportExcel";
const router = useRouter()
@@ -272,6 +273,27 @@ init()
const importTheExpenseLedger = () => {
tableIns.value.refresh()
}
//导入模板下载
const handleImportTemplateDownload=()=>{
ledgerTemplateDownload().then(res => {
let link = document.createElement('a')
try {
let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'});
let _fileName = "台账模板.xlsx"//文件名,中文无法解析的时候会显示 _(下划线),生产环境获取不到
link.style.display='none';
// 兼容不同浏览器的URL对象
const url = window.URL || window.webkitURL || window.moxURL;
link.href=url.createObjectURL(blob);
link.setAttribute('download', _fileName.substring(_fileName.lastIndexOf('_')+1))
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
url.revokeObjectURL(link.href);//销毁url对象
}catch (e) {
console.log('下载的文件出错',e)
}
})
}
const handleUploadFee = () => {
router.push({
name: 'Implementation/uploadFee',