feat(approval): 单据查询导出按钮 (#26)
This commit is contained in:
@@ -13,6 +13,22 @@
|
||||
:scroll="{ x: 1500 }"
|
||||
cache-key="proApprovalInstanceTable"
|
||||
>
|
||||
<template #toolbar>
|
||||
<a-space>
|
||||
<a-button
|
||||
v-permission="'approval:instance:export'"
|
||||
type="primary"
|
||||
class="ele-btn-icon"
|
||||
:loading="exporting"
|
||||
@click="handleExport"
|
||||
>
|
||||
<template #icon>
|
||||
<download-outlined />
|
||||
</template>
|
||||
<span>导出</span>
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'docType'">
|
||||
<a-tag :color="record.docType === 'completion' ? 'blue' : 'purple'">
|
||||
@@ -43,6 +59,8 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { DownloadOutlined } from '@ant-design/icons-vue';
|
||||
import { message } from 'ant-design-vue';
|
||||
import type { EleProTable } from 'ele-admin-pro/es';
|
||||
import { toDateString } from 'ele-admin-pro/es';
|
||||
import type {
|
||||
@@ -51,7 +69,7 @@
|
||||
} from 'ele-admin-pro/es/ele-pro-table/types';
|
||||
import Search from './components/search.vue';
|
||||
import Detail from './components/detail.vue';
|
||||
import { pageInstances } from '@/api/approval/instance';
|
||||
import { exportInstances, pageInstances } from '@/api/approval/instance';
|
||||
import type {
|
||||
ApprovalItem,
|
||||
ApprovalQueryParam
|
||||
@@ -65,6 +83,11 @@
|
||||
// 当前查看的单据id
|
||||
const currentId = ref<number | undefined>(undefined);
|
||||
|
||||
// 当前筛选条件(导出复用同一套条件)
|
||||
const queryWhere = ref<ApprovalQueryParam>({});
|
||||
// 导出请求状态
|
||||
const exporting = ref(false);
|
||||
|
||||
// 表格数据源
|
||||
const datasource: DatasourceFunction = ({ page, limit, where }) => {
|
||||
return pageInstances({
|
||||
@@ -171,7 +194,27 @@
|
||||
|
||||
/* 刷新表格 */
|
||||
const reload = (where?: ApprovalQueryParam) => {
|
||||
tableRef?.value?.reload({ page: 1, where: where ?? {} });
|
||||
queryWhere.value = where ?? {};
|
||||
tableRef?.value?.reload({ page: 1, where: queryWhere.value });
|
||||
};
|
||||
|
||||
/* 导出当前筛选结果 */
|
||||
const handleExport = () => {
|
||||
exporting.value = true;
|
||||
exportInstances(queryWhere.value)
|
||||
.then((res) => {
|
||||
if (res.data?.url) {
|
||||
window.open(res.data.url);
|
||||
} else {
|
||||
message.error('导出失败:未返回文件地址');
|
||||
}
|
||||
})
|
||||
.catch((e: Error) => {
|
||||
message.error(e.message || '导出失败');
|
||||
})
|
||||
.finally(() => {
|
||||
exporting.value = false;
|
||||
});
|
||||
};
|
||||
|
||||
/* 打开详情 */
|
||||
|
||||
Reference in New Issue
Block a user