feat(credit): 新增客户导入与数据导出功能

- 在信用客户模块中添加了导入客户的功能,支持通过文件上传方式导入客户数据
- 实现了多个信用相关模块的数据导出功能,包括企业、司法案件、风险关系、供应商及用户模块
- 更新了搜索组件以支持导出事件,并在各模块中实现了具体的导出逻辑
- 简化了部分表单项的标签显示并移除了冗余字段,优化了用户体验
- 修复了一些潜在的代码格式问题和不必要的注释块
This commit is contained in:
2025-12-22 14:35:07 +08:00
parent ecd571c60b
commit f9c94a0590
4 changed files with 220 additions and 62 deletions

View File

@@ -0,0 +1,94 @@
<!-- 客户导入弹窗 -->
<template>
<ele-modal
:width="520"
:footer="null"
title="客户批量导入"
:visible="visible"
@update:visible="updateVisible"
>
<a-spin :spinning="loading">
<a-upload-dragger
accept=".xls,.xlsx"
:show-upload-list="false"
:customRequest="doUpload"
style="padding: 24px 0; margin-bottom: 16px"
>
<p class="ant-upload-drag-icon">
<cloud-upload-outlined />
</p>
<p class="ant-upload-hint">将文件拖到此处或点击上传</p>
</a-upload-dragger>
</a-spin>
<div class="ele-text-center">
<span>只能上传xlsxlsx文件</span>
<a :href="templateUrl" download="客户导入模板.xlsx"> 下载导入模板 </a>
</div>
</ele-modal>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { message } from 'ant-design-vue/es';
import { CloudUploadOutlined } from '@ant-design/icons-vue';
import { importCreditCustomer } from '@/api/credit/creditCustomer';
import { API_BASE_URL } from '@/config/setting';
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
defineProps<{
// 是否打开弹窗
visible: boolean;
}>();
// 导入请求状态
const loading = ref(false);
// 模板下载地址,保持与当前接口域名一致
const templateUrl = computed(() => {
const base = (localStorage.getItem('ApiUrl') || API_BASE_URL || '').replace(
/\/$/,
''
);
return `${base}/credit/credit-customer/import/template`;
});
/* 上传 */
const doUpload = ({ file }) => {
if (
![
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
].includes(file.type)
) {
message.error('只能选择 excel 文件');
return false;
}
if (file.size / 1024 / 1024 > 10) {
message.error('大小不能超过 10MB');
return false;
}
loading.value = true;
importCreditCustomer(file)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
return false;
};
/* 更新 visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
</script>

View File

@@ -156,20 +156,15 @@
price: undefined,
publicDate: undefined,
dataSource: undefined,
comments: undefined,
recommend: undefined,
sortNumber: undefined,
status: undefined,
deleted: undefined,
userId: undefined,
tenantId: undefined,
createTime: undefined,
updateTime: undefined,
creditCustomerId: undefined,
creditCustomerName: '',
status: 0,
comments: '',
sortNumber: 100
comments: ''
});
/* 更新visible */

View File

@@ -7,34 +7,100 @@
</template>
<span>添加</span>
</a-button>
<a-button class="ele-btn-icon" @click="openImport">
<template #icon>
<CloudUploadOutlined />
</template>
<span>导入</span>
</a-button>
<a-button class="ele-btn-icon" @click="exportData">
<template #icon>
<CloudDownloadOutlined />
</template>
<span>导出</span>
</a-button>
<a-button
danger
class="ele-btn-icon"
:disabled="!selection?.length"
@click="remove"
>
<template #icon>
<DeleteOutlined />
</template>
<span>批量删除</span>
</a-button>
<a-input-search
allow-clear
v-model:value="keywords"
placeholder="请输入关键词"
style="width: 220px"
@search="handleSearch"
@pressEnter="handleSearch"
/>
</a-space>
</template>
<script lang="ts" setup>
import { PlusOutlined } from '@ant-design/icons-vue';
import type { GradeParam } from '@/api/user/grade/model';
import { watch } from 'vue';
import { computed, ref, watch } from 'vue';
import {
PlusOutlined,
CloudUploadOutlined,
CloudDownloadOutlined,
DeleteOutlined
} from '@ant-design/icons-vue';
import type {
CreditCustomer,
CreditCustomerParam
} from '@/api/credit/creditCustomer/model';
const props = withDefaults(
defineProps<{
// 选中的角色
selection?: [];
selection?: CreditCustomer[];
}>(),
{}
{
selection: () => []
}
);
const emit = defineEmits<{
(e: 'search', where?: GradeParam): void;
(e: 'search', where?: CreditCustomerParam): void;
(e: 'add'): void;
(e: 'remove'): void;
(e: 'batchMove'): void;
(e: 'importData'): void;
(e: 'exportData'): void;
}>();
const keywords = ref('');
const selection = computed(() => props.selection || []);
// 新增
const add = () => {
emit('add');
};
// 搜索
const handleSearch = () => {
emit('search', { keywords: keywords.value });
};
// 导入
const openImport = () => {
emit('importData');
};
// 导出
const exportData = () => {
emit('exportData');
};
// 批量删除
const remove = () => {
emit('remove');
};
watch(
() => props.selection,
() => {}

View File

@@ -7,6 +7,7 @@
:columns="columns"
:datasource="datasource"
:customRow="customRow"
v-model:selection="selection"
tool-class="ele-toolbar-form"
class="sys-org-table"
>
@@ -17,6 +18,8 @@
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
@importData="openImport"
@exportData="exportData"
/>
</template>
<template #bodyCell="{ column, record }">
@@ -49,6 +52,8 @@
:data="current"
@done="reload"
/>
<!-- 导入弹窗 -->
<CreditCustomerImport v-model:visible="showImport" @done="reload" />
</a-page-header>
</template>
@@ -67,6 +72,7 @@
import CreditCustomerEdit from './components/creditCustomerEdit.vue';
import {
pageCreditCustomer,
listCreditCustomer,
removeCreditCustomer,
removeBatchCreditCustomer
} from '@/api/credit/creditCustomer';
@@ -74,6 +80,8 @@
CreditCustomer,
CreditCustomerParam
} from '@/api/credit/creditCustomer/model';
import { exportCreditData } from '../utils/export';
import CreditCustomerImport from './components/credit-customer-import.vue';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
@@ -84,24 +92,29 @@
const current = ref<CreditCustomer | null>(null);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 是否显示导入弹窗
const showImport = ref(false);
// 是否显示批量移动弹窗
const showMove = ref(false);
// 加载状态
const loading = ref(true);
// 搜索关键词
const searchText = ref('');
// 表格数据源
const datasource: DatasourceFunction = ({
page,
limit,
where,
where = {},
orders,
filters
}) => {
const params: CreditCustomerParam = { ...(where as CreditCustomerParam) };
if (filters) {
where.status = filters.status;
(params as any).status = filters.status;
}
return pageCreditCustomer({
...where,
...params,
...orders,
page,
limit
@@ -146,42 +159,6 @@
key: 'dataSource',
ellipsis: true
},
{
title: '备注',
dataIndex: 'comments',
key: 'comments',
ellipsis: true
},
{
title: '是否推荐',
dataIndex: 'recommend',
key: 'recommend',
width: 120
},
{
title: '排序(数字越小越靠前)',
dataIndex: 'sortNumber',
key: 'sortNumber',
width: 120
},
{
title: '状态, 0正常, 1冻结',
dataIndex: 'status',
key: 'status',
width: 120
},
{
title: '是否删除, 0否, 1是',
dataIndex: 'deleted',
key: 'deleted',
width: 120
},
{
title: '用户ID',
dataIndex: 'userId',
key: 'userId',
width: 120
},
{
title: '创建时间',
dataIndex: 'createTime',
@@ -192,16 +169,6 @@
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd HH:mm:ss')
},
{
title: '修改时间',
dataIndex: 'updateTime',
key: 'updateTime',
width: 200,
align: 'center',
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd HH:mm:ss')
},
{
title: '操作',
key: 'action',
@@ -214,8 +181,12 @@
/* 搜索 */
const reload = (where?: CreditCustomerParam) => {
if (where && Object.prototype.hasOwnProperty.call(where, 'keywords')) {
searchText.value = where.keywords ?? '';
}
const targetWhere = where ?? { keywords: searchText.value || undefined };
selection.value = [];
tableRef?.value?.reload({ where: where });
tableRef?.value?.reload({ where: targetWhere });
};
/* 打开编辑弹窗 */
@@ -224,11 +195,43 @@
showEdit.value = true;
};
/* 打开导入弹窗 */
const openImport = () => {
showImport.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 导出 */
const exportData = () => {
exportCreditData<CreditCustomer>({
filename: '客户列表',
columns: [
{ title: 'ID', dataIndex: 'id' },
{ title: '客户', dataIndex: 'name' },
{ title: '状态', dataIndex: 'statusTxt' },
{ title: '销售金额(万元)', dataIndex: 'price' },
{ title: '公开日期', dataIndex: 'publicDate' },
{ title: '数据来源', dataIndex: 'dataSource' },
{ title: '备注', dataIndex: 'comments' },
{ title: '是否推荐', dataIndex: 'recommend' },
{ title: '排序(数字越小越靠前)', dataIndex: 'sortNumber' },
{ title: '状态, 0正常, 1冻结', dataIndex: 'status' },
{ title: '是否删除, 0否, 1是', dataIndex: 'deleted' },
{ title: '用户ID', dataIndex: 'userId' },
{ title: '创建时间', dataIndex: 'createTime' },
{ title: '修改时间', dataIndex: 'updateTime' }
],
fetchData: () =>
listCreditCustomer({
keywords: searchText.value || undefined
})
});
};
/* 删除单个 */
const remove = (row: CreditCustomer) => {
const hide = message.loading('请求中..', 0);