|
|
@ -40,7 +40,7 @@ |
|
|
|
<slot name="adcc_ope"> </slot> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="other__ope"> |
|
|
|
<div class="other__ope" v-if="show_form_other_btn" > |
|
|
|
<slot name="other_ope"> |
|
|
|
<template v-for="[key, config] in other_ope_list" :key="key"> |
|
|
|
<el-tooltip :content="key"> |
|
|
@ -163,8 +163,10 @@ import { vBottomLoading } from "./directives"; |
|
|
|
|
|
|
|
import { useTable } from "./hooks"; |
|
|
|
import { useRefs } from "@/hooks/useRefs"; |
|
|
|
import { debounce } from "lodash"; |
|
|
|
|
|
|
|
import { handleExport } from "@/utils/lib/excel"; |
|
|
|
import request from '@/api/config' |
|
|
|
|
|
|
|
defineOptions({ |
|
|
|
name: "MTable", |
|
|
@ -183,6 +185,7 @@ const $props = withDefaults(defineProps<TableConfigPropType<any>>(), { |
|
|
|
show_form: true, |
|
|
|
show_form_ope_btn: true, |
|
|
|
show_pagination: true, |
|
|
|
show_form_other_btn: false, |
|
|
|
}); |
|
|
|
|
|
|
|
const $route = useRoute(); |
|
|
@ -195,6 +198,7 @@ const { |
|
|
|
table_data, |
|
|
|
pagination, |
|
|
|
loading, |
|
|
|
handleLoadDownloadData, |
|
|
|
} = useTable($props.table_config, $props.pagination_config); |
|
|
|
|
|
|
|
const columnType = ["index", "selection", "expand", "radio"]; |
|
|
@ -217,7 +221,8 @@ const merge_table_config = computed(() => { |
|
|
|
"handleLoadData", |
|
|
|
"handleProcseeData", |
|
|
|
"handleProcessParam", |
|
|
|
"defaultValue" |
|
|
|
"defaultValue", |
|
|
|
"handleLoadDownloadData", |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
@ -315,14 +320,65 @@ const handleExportToExcel = () => { |
|
|
|
const enums = toRaw(unref(enumMap)); |
|
|
|
const data = toRaw(unref(table_data)); |
|
|
|
const sheet_name = title ?? $route.meta.title; |
|
|
|
export_loading.value = true; |
|
|
|
handleExport(columns, data, enums, sheet_name) |
|
|
|
.then((res) => { |
|
|
|
const message = res ? "导出成功" : "导出失败"; |
|
|
|
const type = res ? "success" : "error"; |
|
|
|
if (handleLoadDownloadData) { |
|
|
|
handleFetchDataAAA(); |
|
|
|
} else { |
|
|
|
export_loading.value = true; |
|
|
|
handleExport(columns, data, enums, sheet_name) |
|
|
|
.then((res) => { |
|
|
|
const message = res ? "导出成功" : "导出失败"; |
|
|
|
const type = res ? "success" : "error"; |
|
|
|
ElMessage({ type, message }); |
|
|
|
}) |
|
|
|
.finally(() => (export_loading.value = false)); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
const handleFetchDataAAA = debounce(async (parama = {}) => { |
|
|
|
// 获取参数 |
|
|
|
const { params, show_pagination, show_form, title } = $props; |
|
|
|
const sheet_name = title ?? $route.meta.title; |
|
|
|
const { handleProcessParam } = $props.table_config; |
|
|
|
|
|
|
|
const pagination_param: Record<string, any> = show_pagination |
|
|
|
? pick(pagination, "currentPage", "pageSize") |
|
|
|
: {}; |
|
|
|
|
|
|
|
const form_params = show_form ? params : {}; |
|
|
|
|
|
|
|
const param = handleProcessParam |
|
|
|
? handleProcessParam(toRaw(form_params || {}), toRaw(pagination_param)) |
|
|
|
: { ...form_params, ...pagination_param }; |
|
|
|
if (param == false) return; |
|
|
|
|
|
|
|
if (!handleLoadDownloadData) return; |
|
|
|
|
|
|
|
loading.value = true; |
|
|
|
try { |
|
|
|
const response: any = await handleLoadDownloadData(param); |
|
|
|
// const response: any = await request.post(`/event/export-event-details`, param, { responseType: 'blob' }) |
|
|
|
handleExportDownloadExcel(sheet_name, response) |
|
|
|
} catch (error: any) { |
|
|
|
const message = error ? "导出成功" : "导出失败"; |
|
|
|
const type = error ? "success" : "error"; |
|
|
|
ElMessage({ type, message }); |
|
|
|
} finally { |
|
|
|
loading.value = false; |
|
|
|
} |
|
|
|
}, 300); |
|
|
|
|
|
|
|
const handleExportDownloadExcel = (title: string, response: any) => { |
|
|
|
// let response = handleLoadDownloadData(param); |
|
|
|
const blob = new Blob([response], { |
|
|
|
type: 'application/octet-stream', |
|
|
|
}) |
|
|
|
.finally(() => (export_loading.value = false)); |
|
|
|
const link = document.createElement('a') //创建a标签 |
|
|
|
link.download = decodeURIComponent(title + '.xlsx') |
|
|
|
link.style.display = 'none' |
|
|
|
link.href = URL.createObjectURL(blob) |
|
|
|
document.body.appendChild(link) |
|
|
|
link.click() //执行下载 |
|
|
|
document.body.removeChild(link) |
|
|
|
}; |
|
|
|
|
|
|
|
const handleResetFields = () => { |
|
|
|