export const downloadFile = async (url:string, fileName:string,param_str:string) => {
const response = await GHTTP.get(`${url}?${param_str}`,{ responseType: 'blob' })
const blob = new Blob([response], { type: 'application/octet-stream' })
const urlObject = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = urlObject;
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
<el-button v-if="popData.length > 0" @click="onExport()">导出</el-button>
const exportRef = ref()
const onExport = () => {
console.log('storeOrderId.value',storeOrderId.value);
// return
let url = '/storeOrderDetail/exportStoreOrderDetailList'
let name='采购订单材料列表导出.xlsx'
let param = {
storeOrderId:storeOrderId.value
}
let param_str = objectToStringParam(param)
exportRef.value.sonClick(url, name, param_str)
}
<BatchExport ref="exportRef"></BatchExport>
<template>
<el-dialog v-model="centerDialogVisible" title="导出" width="500" center>
<h3 style="margin: 10px 0; text-align: center;">你确定导出{{ filename.split('.')[0] }}么?</h3>
<template #footer>
<div class="dialog-footer">
<el-button v-onceClick @click="centerDialogVisible = false">取消</el-button>
<el-button type="primary" v-onceClick @click="Download">
确定导出
</el-button>
</div>
</template>
</el-dialog>
</template>
<script setup lang='ts'>
import { ref, reactive } from 'vue'
import GHTTP from "@/composables/GHTTP";
import { downloadFile } from "@/composables/share"
const centerDialogVisible = ref(false)
const fileurl = ref('')
const filename = ref('')
const object_str = ref('')
const sonClick = (url:string,name:string,param_str?:string) => {
centerDialogVisible.value = true
fileurl.value = url
filename.value = name
if(param_str) object_str.value = param_str
}
const Download = () => {
centerDialogVisible.value = false
downloadFile(fileurl.value,filename.value,object_str.value)
}
defineExpose({ sonClick })
</script>
<style lang='scss' scoped></style>