Files
ecom-dmb/ecom-dmb-frontend/apps/web-antd/src/views/org/company/index.vue
T

415 lines
10 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { CompanyDTO, CompanyVO } from '#/api/company';
import type { PageQueryDTO } from '#/types/common';
import { computed, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteCompanyApi,
getCompanyPageApi,
} from '#/api/company';
import CompanyMenuDrawer from '#/components/CompanyMenuDrawer.vue';
import CompanyPermissionDrawer from '#/components/CompanyPermissionDrawer.vue';
import CompanyFormModal from './components/CompanyFormModal.vue';
defineOptions({ name: 'CompanyManagement' });
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
// 响应式数据
const loading = ref(false);
const companyFormModalRef = ref();
const companyMenuDrawerRef = ref();
const companyPermissionDrawerRef = ref();
// 搜索表单
const searchForm = ref({
name: '',
email: '',
status: undefined as number | undefined,
expired: undefined as string | undefined,
});
// 状态选项
const statusOptions = [
{ label: '禁用', value: 0 },
{ label: '正常', value: 1 },
];
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
title: '序号',
},
{
field: 'name',
title: '公司名称',
minWidth: 200,
showOverflow: 'tooltip' as const,
},
{
field: 'address',
title: '公司地址',
minWidth: 250,
showOverflow: 'tooltip' as const,
},
{
field: 'ownerName',
title: '拥有者姓名',
minWidth: 120,
},
{
field: 'ownerPhone',
title: '拥有者电话',
minWidth: 150,
},
{
field: 'email',
title: '邮箱',
minWidth: 200,
showOverflow: 'tooltip' as const,
},
{
title: 'Logo',
minWidth: 100,
slots: { default: 'logo' },
},
{
title: '状态',
minWidth: 100,
slots: { default: 'status' },
},
{
title: '过期状态',
minWidth: 100,
slots: { default: 'expired' },
},
{
title: '订阅到期时间',
minWidth: 180,
slots: { default: 'expireTime' },
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
},
{
title: '操作',
minWidth: 200,
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: 'auto',
border: true,
stripe: true,
rowConfig: { isHover: true },
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
// 配置远程加载
proxyConfig: {
ajax: {
query: async ({ page }) => {
try {
loading.value = true;
// 处理 expired 字段的转换
let expiredValue: boolean | undefined;
if (searchForm.value.expired === 'true') {
expiredValue = true;
} else if (searchForm.value.expired === 'false') {
expiredValue = false;
} else {
expiredValue = undefined;
}
const params: PageQueryDTO<CompanyDTO.CompanyFiltersDTO> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
name: searchForm.value.name || undefined,
email: searchForm.value.email || undefined,
status: searchForm.value.status,
expired: expiredValue,
},
};
const data = await getCompanyPageApi(params);
return {
items: data.records,
total: data.total,
};
} catch (error) {
console.error('获取公司列表失败:', error);
message.error('获取公司列表失败');
return {
items: [],
total: 0,
};
} finally {
loading.value = false;
}
},
},
},
};
// 搜索表单配置
const gridReloadRef = ref<(() => void) | null>(null);
const formOptions = computed(() => ({
schema: [
{
component: 'Input',
componentProps: {
placeholder: '请输入公司名称(回车搜索)',
onPressEnter: () => gridReloadRef.value?.(),
},
fieldName: 'name',
label: '公司名称',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入拥有者姓名(回车搜索)',
onPressEnter: () => gridReloadRef.value?.(),
},
fieldName: 'ownerName',
label: '拥有者姓名',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入拥有者电话(回车搜索)',
onPressEnter: () => gridReloadRef.value?.(),
},
fieldName: 'ownerPhone',
label: '拥有者电话',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入邮箱(回车搜索)',
onPressEnter: () => gridReloadRef.value?.(),
},
fieldName: 'email',
label: '邮箱',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择状态',
options: statusOptions,
allowClear: true,
onChange: () => gridReloadRef.value?.(),
},
fieldName: 'status',
label: '状态',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择过期状态',
options: [
{ label: '已过期', value: 'true' },
{ label: '正常', value: 'false' },
],
allowClear: true,
onChange: () => gridReloadRef.value?.(),
},
fieldName: 'expired',
label: '过期状态',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// 刷新表格数据
function refreshTable() {
if (gridApi) {
gridApi.reload();
}
}
// 处理添加公司
function handleAdd() {
companyFormModalRef.value?.open(false);
}
// 处理编辑公司
function handleEdit(record: CompanyVO.CompanyInfoVO) {
companyFormModalRef.value?.open(true, record);
}
// 处理删除公司
async function handleDelete(record: CompanyVO.CompanyInfoVO) {
try {
await deleteCompanyApi(record.id);
message.success('删除成功');
refreshTable();
} catch (error) {
console.error('删除公司失败:', error);
message.error('删除公司失败');
}
}
// 处理模态框成功回调
function handleModalSuccess() {
refreshTable();
}
// 处理菜单管理
function handleMenuManage(record: any) {
companyMenuDrawerRef.value?.open(record);
}
// 处理权限管理
function handlePermissionManage(record: any) {
companyPermissionDrawerRef.value?.open(record);
}
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '公司管理',
});
gridReloadRef.value = () => gridApi.reload();
</script>
<template>
<Page title="公司管理" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理公司信息,包括公司基本信息、联系方式和订阅状态
</div>
</template>
<!-- VbenVxeGrid 表格 -->
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon />
添加公司
</Button>
</Space>
</template>
<!-- Logo列 -->
<template #logo="{ row }: { row: any }">
<div v-if="row.logo">
<img
:src="row.logo"
:alt="row.name"
style="
width: 40px;
height: 40px;
object-fit: cover;
border-radius: 4px;
"
/>
</div>
<span v-else style="color: #999">暂无Logo</span>
</template>
<!-- 状态列 -->
<template #status="{ row }: { row: any }">
<Tag :color="row.status === 1 ? 'green' : 'red'">
{{ row.status === 1 ? '正常' : '禁用' }}
</Tag>
</template>
<!-- 过期状态列 -->
<template #expired="{ row }: { row: any }">
<Tag v-if="row.expired === true" color="red">已过期</Tag>
<Tag v-else-if="row.expired === false" color="green">正常</Tag>
<span v-else style="color: #999">未知</span>
</template>
<!-- 订阅到期时间列 -->
<template #expireTime="{ row }: { row: any }">
<span v-if="!row.expireTime" style="color: #999">未设置</span>
<span v-else :style="{ color: row.expired ? '#ff4d4f' : '#52c41a' }">
{{ row.expireTime }}
</span>
</template>
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Button size="small" type="primary" @click="handleMenuManage(row)">
菜单
</Button>
<Button
size="small"
type="primary"
ghost
@click="handlePermissionManage(row)"
>
权限
</Button>
<Popconfirm
title="确定要删除这个公司吗?"
@confirm="handleDelete(row)"
>
<Button size="small" danger> 删除 </Button>
</Popconfirm>
</Space>
</template>
</Grid>
<!-- 公司表单模态框 -->
<CompanyFormModal ref="companyFormModalRef" @success="handleModalSuccess" />
<!-- 公司菜单管理抽屉 -->
<CompanyMenuDrawer ref="companyMenuDrawerRef" />
<CompanyPermissionDrawer ref="companyPermissionDrawerRef" />
</Page>
</template>