feat(credit): 添加小程序客户用户信息展示功能

- 在模型中增加昵称、头像、手机号字段
- 实现用户信息表格列,展示头像、昵称和手机号
- 添加用户信息样式布局
- 更新导出数据配置,包含新的用户信息字段
- 调整表格列宽度和对齐方式以优化显示效果
This commit is contained in:
2026-03-16 23:37:23 +08:00
parent 41a1fcb4ed
commit 1b115edabe
2 changed files with 397 additions and 332 deletions

View File

@@ -40,6 +40,12 @@ export interface CreditMpCustomer {
deleted?: number; deleted?: number;
// 用户ID // 用户ID
userId?: number; userId?: number;
// 昵称
nickname?: string;
// 头像
avatar?: string;
// 手机号
phone?: string;
// 租户id // 租户id
tenantId?: number; tenantId?: number;
// 创建时间 // 创建时间

View File

@@ -1,362 +1,421 @@
<template> <template>
<a-page-header :title="getPageTitle()" @back="() => $router.go(-1)"> <a-page-header :title="getPageTitle()" @back="() => $router.go(-1)">
<a-card :bordered="false" :body-style="{ padding: '16px' }"> <a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table <ele-pro-table
ref="tableRef" ref="tableRef"
row-key="id" row-key="id"
:columns="columns" :columns="columns"
:datasource="datasource" :datasource="datasource"
:customRow="customRow" :customRow="customRow"
v-model:selection="selection" v-model:selection="selection"
tool-class="ele-toolbar-form" tool-class="ele-toolbar-form"
class="sys-org-table" class="sys-org-table"
> >
<template #toolbar> <template #toolbar>
<search <search
@search="reload" @search="reload"
:selection="selection" :selection="selection"
@add="openEdit" @add="openEdit"
@remove="removeBatch" @remove="removeBatch"
@batchMove="openMove" @batchMove="openMove"
@exportData="exportData" @exportData="exportData"
/> />
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'userInfo'">
<div class="user-info">
<a-avatar :size="48" :src="record.avatar">
<template v-if="!record.avatar" #icon>
<UserOutlined/>
</template>
</a-avatar>
<div class="user-details">
<h4 class="username">{{ record.nickname }}</h4>
<p class="user-phone">{{ record.phone }}</p>
</div>
</div>
</template> </template>
<template #bodyCell="{ column, record }"> <template v-if="column.key === 'image'">
<template v-if="column.key === 'image'"> <a-image :src="record.image" :width="50"/>
<a-image :src="record.image" :width="50" />
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 0" color="green">显示</a-tag>
<a-tag v-if="record.status === 1" color="red">隐藏</a-tag>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a-popconfirm
title="确定要删除此记录吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template> </template>
</ele-pro-table> <template v-if="column.key === 'files'">
</a-card> <a-space>
<a-image
v-for="(file, index) in record.files"
:key="index"
:src="file"
:width="50"
/>
</a-space>
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 0" color="green">显示</a-tag>
<a-tag v-if="record.status === 1" color="red">隐藏</a-tag>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical"/>
<a-popconfirm
title="确定要删除此记录吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
</a-card>
<!-- 编辑弹窗 --> <!-- 编辑弹窗 -->
<CreditMpCustomerEdit v-model:visible="showEdit" :data="current" @done="reload" /> <CreditMpCustomerEdit v-model:visible="showEdit" :data="current" @done="reload"/>
</a-page-header> </a-page-header>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { createVNode, ref, computed } from 'vue'; import {createVNode, ref, computed} from 'vue';
import { message, Modal } from 'ant-design-vue'; import {message, Modal} from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'; import {ExclamationCircleOutlined, UserOutlined} from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro'; import type {EleProTable} from 'ele-admin-pro';
import { toDateString } from 'ele-admin-pro'; import {toDateString} from 'ele-admin-pro';
import type { import type {
DatasourceFunction, DatasourceFunction,
ColumnItem ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types'; } from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue'; import Search from './components/search.vue';
import {getPageTitle} from '@/utils/common'; import {getPageTitle} from '@/utils/common';
import CreditMpCustomerEdit from './components/creditMpCustomerEdit.vue'; import CreditMpCustomerEdit from './components/creditMpCustomerEdit.vue';
import { import {
pageCreditMpCustomer, pageCreditMpCustomer,
listCreditMpCustomer, listCreditMpCustomer,
removeCreditMpCustomer, removeCreditMpCustomer,
removeBatchCreditMpCustomer removeBatchCreditMpCustomer
} from '@/api/credit/creditMpCustomer'; } from '@/api/credit/creditMpCustomer';
import type { CreditMpCustomer, CreditMpCustomerParam } from '@/api/credit/creditMpCustomer/model'; import type {CreditMpCustomer, CreditMpCustomerParam} from '@/api/credit/creditMpCustomer/model';
import { exportCreditData } from '../utils/export'; import {exportCreditData} from '../utils/export';
// 表格实例 // 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null); const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据 // 表格选中数据
const selection = ref<CreditMpCustomer[]>([]); const selection = ref<CreditMpCustomer[]>([]);
// 当前编辑数据 // 当前编辑数据
const current = ref<CreditMpCustomer | null>(null); const current = ref<CreditMpCustomer | null>(null);
// 是否显示编辑弹窗 // 是否显示编辑弹窗
const showEdit = ref(false); const showEdit = ref(false);
// 是否显示批量移动弹窗 // 是否显示批量移动弹窗
const showMove = ref(false); const showMove = ref(false);
// 加载状态 // 加载状态
const loading = ref(true); const loading = ref(true);
// 搜索关键词 // 搜索关键词
const searchText = ref(''); const searchText = ref('');
// 表格数据源 // 表格数据源
const datasource: DatasourceFunction = ({ const datasource: DatasourceFunction = ({
page,
limit,
where = {},
orders,
filters
}) => {
const params: CreditMpCustomerParam = {...(where as CreditMpCustomerParam)};
if (filters) {
(params as any).status = filters.status;
}
return pageCreditMpCustomer({
...params,
...orders,
page, page,
limit, limit
where = {},
orders,
filters
}) => {
const params: CreditMpCustomerParam = { ...(where as CreditMpCustomerParam) };
if (filters) {
(params as any).status = filters.status;
}
return pageCreditMpCustomer({
...params,
...orders,
page,
limit
});
};
// 完整的列配置(包含所有字段)
const allColumns = ref<ColumnItem[]>([
{
title: 'ID',
dataIndex: 'id',
key: 'id',
width: 90,
},
{
title: '拖欠方',
dataIndex: 'toUser',
key: 'toUser'
},
{
title: '拖欠金额',
dataIndex: 'price',
key: 'price'
},
{
title: '拖欠年数',
dataIndex: 'years',
key: 'years'
},
// {
// title: '链接',
// dataIndex: 'url',
// key: 'url',
// ellipsis: true
// },
// {
// title: '状态',
// dataIndex: 'statusTxt',
// key: 'statusTxt'
// },
// {
// title: '所在省份',
// dataIndex: 'province',
// key: 'province',
// ellipsis: true
// },
{
title: '所在城市',
dataIndex: 'city',
key: 'city',
ellipsis: true
},
// {
// title: '所在辖区',
// dataIndex: 'region',
// key: 'region',
// ellipsis: true
// },
{
title: '附件',
dataIndex: 'files',
key: 'files',
ellipsis: true
},
// {
// title: '是否有数据',
// dataIndex: 'hasData',
// key: 'hasData',
// width: 120
// },
// {
// title: '备注',
// dataIndex: 'comments',
// key: 'comments',
// ellipsis: true
// },
// {
// title: '是否推荐',
// dataIndex: 'recommend',
// key: 'recommend',
// width: 120
// },
{
title: '排序',
dataIndex: 'sortNumber',
key: 'sortNumber',
width: 120
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
width: 120
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
width: 200,
align: 'center',
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd HH:mm:ss')
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
// 默认显示的核心列最多5个主要字段
const defaultVisibleColumns = [
'id',
'toUser',
'price',
'years',
'city',
// 'status',
'createTime',
'action'
];
// 根据默认可见列过滤显示的列
const columns = computed(() => {
return allColumns.value.filter(col =>
defaultVisibleColumns.includes(col.dataIndex) || col.key === 'action'
);
}); });
};
/* 搜索 */ // 完整的列配置(包含所有字段)
const reload = (where?: CreditMpCustomerParam) => { const allColumns = ref<ColumnItem[]>([
if (where && Object.prototype.hasOwnProperty.call(where, 'keywords')) { {
searchText.value = where.keywords ?? ''; title: 'ID',
} dataIndex: 'id',
const targetWhere = where ?? { keywords: searchText.value || undefined }; key: 'id',
selection.value = []; width: 90,
tableRef?.value?.reload({ where: targetWhere }); },
}; {
title: '用户信息',
dataIndex: 'userInfo',
key: 'userInfo',
width: 300,
},
{
title: '拖欠方',
dataIndex: 'toUser',
key: 'toUser'
},
{
title: '拖欠金额',
dataIndex: 'price',
key: 'price',
width: 120,
align: 'center',
customRender: ({ text }) => '¥' + text
},
{
title: '拖欠年数',
dataIndex: 'years',
key: 'years',
align: 'center'
},
// {
// title: '链接',
// dataIndex: 'url',
// key: 'url',
// ellipsis: true
// },
// {
// title: '状态',
// dataIndex: 'statusTxt',
// key: 'statusTxt'
// },
// {
// title: '所在省份',
// dataIndex: 'province',
// key: 'province',
// ellipsis: true
// },
{
title: '所在城市',
dataIndex: 'city',
key: 'city',
align: 'center'
},
// {
// title: '所在辖区',
// dataIndex: 'region',
// key: 'region',
// ellipsis: true
// },
{
title: '附件',
dataIndex: 'files',
key: 'files',
align: 'center'
},
// {
// title: '是否有数据',
// dataIndex: 'hasData',
// key: 'hasData',
// width: 120
// },
// {
// title: '备注',
// dataIndex: 'comments',
// key: 'comments',
// ellipsis: true
// },
// {
// title: '是否推荐',
// dataIndex: 'recommend',
// key: 'recommend',
// width: 120
// },
/* 打开编辑弹窗 */ {
const openEdit = (row?: CreditMpCustomer) => { title: '排序',
current.value = row ?? null; dataIndex: 'sortNumber',
showEdit.value = true; key: 'sortNumber',
}; width: 120
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
width: 120
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
width: 200,
align: 'center',
sorter: true,
ellipsis: true,
customRender: ({text}) => toDateString(text, 'yyyy-MM-dd HH:mm:ss')
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
/* 打开批量移动弹窗 */ // 默认显示的核心列最多5个主要字段
const openMove = () => { const defaultVisibleColumns = [
showMove.value = true; 'id',
}; 'userInfo',
'toUser',
'price',
'years',
'city',
'files',
// 'status',
'createTime',
'action'
];
/* 导出 */ // 根据默认可见列过滤显示的列
const exportData = () => { const columns = computed(() => {
exportCreditData<CreditMpCustomer>({ return allColumns.value.filter(col =>
filename: '小程序端客户列表', defaultVisibleColumns.includes(col.dataIndex) || col.key === 'action'
includeCompanyName: false, );
columns: [ });
{ title: 'ID', dataIndex: 'id' },
{ title: '拖欠方', dataIndex: 'toUser' },
{ title: '拖欠金额', dataIndex: 'price' },
{ title: '拖欠年数', dataIndex: 'years' },
{ title: '链接', dataIndex: 'url' },
{ title: '状态', dataIndex: 'statusTxt' },
{ title: '所在省份', dataIndex: 'province' },
{ title: '所在城市', dataIndex: 'city' },
{ title: '所在辖区', dataIndex: 'region' },
{ title: '文件路径', dataIndex: 'files' },
{ title: '是否有数据', dataIndex: 'hasData' },
{ 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: () =>
listCreditMpCustomer({
keywords: searchText.value || undefined
})
});
};
/* 删除单个 */ /* 搜索 */
const remove = (row: CreditMpCustomer) => { const reload = (where?: CreditMpCustomerParam) => {
const hide = message.loading('请求中..', 0); if (where && Object.prototype.hasOwnProperty.call(where, 'keywords')) {
removeCreditMpCustomer(row.id) searchText.value = where.keywords ?? '';
.then((msg) => { }
hide(); const targetWhere = where ?? {keywords: searchText.value || undefined};
message.success(msg); selection.value = [];
reload(); tableRef?.value?.reload({where: targetWhere});
};
/* 打开编辑弹窗 */
const openEdit = (row?: CreditMpCustomer) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 导出 */
const exportData = () => {
exportCreditData<CreditMpCustomer>({
filename: '小程序端客户列表',
includeCompanyName: false,
columns: [
{title: 'ID', dataIndex: 'id'},
{title: '拖欠方', dataIndex: 'toUser'},
{title: '拖欠金额', dataIndex: 'price'},
{title: '拖欠年数', dataIndex: 'years'},
{title: '链接', dataIndex: 'url'},
{title: '状态', dataIndex: 'statusTxt'},
{title: '所在省份', dataIndex: 'province'},
{title: '所在城市', dataIndex: 'city'},
{title: '所在辖区', dataIndex: 'region'},
{title: '文件路径', dataIndex: 'files'},
{title: '是否有数据', dataIndex: 'hasData'},
{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: () =>
listCreditMpCustomer({
keywords: searchText.value || undefined
}) })
.catch((e) => { });
hide(); };
message.error(e.message);
});
};
/* 批量删除 */ /* 删除单个 */
const removeBatch = () => { const remove = (row: CreditMpCustomer) => {
if (!selection.value.length) { const hide = message.loading('请求中..', 0);
message.error('请至少选择一条数据'); removeCreditMpCustomer(row.id)
return; .then((msg) => {
} hide();
Modal.confirm({ message.success(msg);
title: '提示', reload();
content: '确定要删除选中的记录吗?', })
icon: createVNode(ExclamationCircleOutlined), .catch((e) => {
maskClosable: true, hide();
onOk: () => { message.error(e.message);
const hide = message.loading('请求中..', 0);
removeBatchCreditMpCustomer(selection.value.map((d) => d.id))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
}); });
}; };
/* 查询 */ /* 批量删除 */
const query = () => { const removeBatch = () => {
loading.value = true; if (!selection.value.length) {
}; message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchCreditMpCustomer(selection.value.map((d) => d.id))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
/* 自定义行属性 */ /* 查询 */
const customRow = (record: CreditMpCustomer) => { const query = () => {
return { loading.value = true;
// 行点击事件 };
onClick: () => {
// console.log(record); /* 自定义行属性 */
}, const customRow = (record: CreditMpCustomer) => {
// 行双击事件 return {
onDblclick: () => { // 行点击事件
openEdit(record); onClick: () => {
} // console.log(record);
}; },
// 行双击事件
onDblclick: () => {
openEdit(record);
}
}; };
query(); };
query();
</script> </script>
<script lang="ts"> <script lang="ts">
export default { export default {
name: 'CreditMpCustomer' name: 'CreditMpCustomer'
}; };
</script> </script>
<style lang="less" scoped></style> <style lang="less" scoped>
.user-info {
display: flex;
align-items: center;
padding: 6px;
.user-details {
margin-left: 6px;
flex: 1;
.username {
margin: 0;
color: #333;
font-size: 16px;
font-weight: 500;
}
.user-phone {
margin: 0;
color: #666;
font-size: 14px;
}
}
}
</style>