完善创建公司初始化数据相关

This commit is contained in:
ah--desktop
2025-10-11 00:21:01 +08:00
parent d45ac21647
commit d4a2af0063
23 changed files with 1542 additions and 1093 deletions
@@ -1,8 +1,11 @@
<script lang="ts" setup>
import { h, ref } from 'vue';
import { ref, computed } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, Input, Select, Table, message, Tag } from 'ant-design-vue';
import { Button, message, Space, Tag } from 'ant-design-vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {
deleteCompanyApi,
@@ -13,14 +16,13 @@ import {
import type { PageQueryDTO } from '#/types/common';
import CompanyFormModal from './components/CompanyFormModal.vue';
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
defineOptions({ name: 'CompanyManagement' });
// 响应式数据
const loading = ref(false);
const companyList = ref<CompanyVO.CompanyInfoVO[]>([]);
const total = ref(0);
const current = ref(1);
const pageSize = ref(10);
const companyFormModalRef = ref();
// 搜索表单
@@ -33,158 +35,203 @@ const searchForm = ref({
expired: undefined as string | undefined,
});
// 表单数据(已移至CompanyFormModal组件)
// 状态选项
const statusOptions = [
{ label: '禁用', value: 0 },
{ label: '正常', value: 1 },
];
// 表格列配置
const columns = [
{
title: '公司名称',
dataIndex: 'name',
key: 'name',
width: 200,
// 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: 'contactPerson',
title: '联系人',
minWidth: 120,
},
{
field: 'contactPhone',
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,
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
{
title: '公司地址',
dataIndex: 'address',
key: 'address',
width: 250,
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
},
{
title: '联系人',
dataIndex: 'contactPerson',
key: 'contactPerson',
width: 120,
},
{
title: '联系电话',
dataIndex: 'contactPhone',
key: 'contactPhone',
width: 150,
},
{
title: '邮箱',
dataIndex: 'email',
key: 'email',
width: 200,
},
{
title: 'Logo',
dataIndex: 'logo',
key: 'logo',
width: 100,
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
if (record.logo) {
return h('img', {
src: record.logo,
alt: record.name,
style: { width: '40px', height: '40px', objectFit: 'cover', borderRadius: '4px' },
});
}
return h('span', { style: { color: '#999' } }, '暂无Logo');
// 配置远程加载
proxyConfig: {
ajax: {
query: async ({ page }) => {
try {
loading.value = true;
const params: PageQueryDTO<CompanyDTO.CompanyFiltersDTO> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
name: searchForm.value.name || undefined,
contactPerson: searchForm.value.contactPerson || undefined,
contactPhone: searchForm.value.contactPhone || undefined,
email: searchForm.value.email || undefined,
status: searchForm.value.status,
expired: searchForm.value.expired === 'true' ? true : searchForm.value.expired === 'false' ? false : undefined,
},
};
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;
}
},
},
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
width: 100,
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
const statusMap = {
0: { text: '禁用', color: 'red' },
1: { text: '正常', color: 'green' },
};
const status = statusMap[record.status as keyof typeof statusMap] || { text: '未知', color: 'default' };
return h(Tag, { color: status.color }, () => status.text);
},
},
{
title: '过期状态',
dataIndex: 'expired',
key: 'expired',
width: 100,
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
if (record.expired === true) {
return h(Tag, { color: 'red' }, () => '已过期');
} else if (record.expired === false) {
return h(Tag, { color: 'green' }, () => '正常');
}
return h('span', { style: { color: '#999' } }, '未知');
},
},
{
title: '订阅到期时间',
dataIndex: 'expireTime',
key: 'expireTime',
width: 180,
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
if (!record.expireTime) {
return h('span', { style: { color: '#999' } }, '未设置');
}
const isExpired = record.expired;
return h('span', {
style: { color: isExpired ? '#ff4d4f' : '#52c41a' },
}, record.expireTime);
},
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
width: 180,
},
{
title: '操作',
key: 'action',
width: 200,
fixed: 'right' as const,
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
return h('div', { style: 'display: flex; gap: 8px;' }, [
h(Button, {
size: 'small',
onClick: () => handleEdit(record),
}, { default: () => '编辑' }),
h(Button, {
size: 'small',
danger: true,
onClick: () => handleDelete(record),
}, { default: () => '删除' }),
]);
},
},
];
};
// 搜索表单配置
const formOptions = computed(() => ({
schema: [
{
component: 'Input',
componentProps: {
placeholder: '请输入公司名称',
},
fieldName: 'name',
label: '公司名称',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入联系人',
},
fieldName: 'contactPerson',
label: '联系人',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入联系电话',
},
fieldName: 'contactPhone',
label: '联系电话',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入邮箱',
},
fieldName: 'email',
label: '邮箱',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择状态',
options: statusOptions,
allowClear: true,
},
fieldName: 'status',
label: '状态',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择过期状态',
options: [
{ label: '已过期', value: 'true' },
{ label: '正常', value: 'false' }
],
allowClear: true,
},
fieldName: 'expired',
label: '过期状态',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// 处理搜索
function handleSearch() {
current.value = 1;
fetchCompanyList();
}
// 处理重置
function handleReset() {
searchForm.value = {
name: '',
contactPerson: '',
contactPhone: '',
email: '',
status: undefined,
expired: undefined,
};
current.value = 1;
fetchCompanyList();
}
// 处理分页变化
function handleTableChange(pagination: any) {
current.value = pagination.current;
pageSize.value = pagination.pageSize;
fetchCompanyList();
// 刷新表格数据
function refreshTable() {
if (gridApi) {
gridApi.reload();
}
}
// 处理添加公司
@@ -197,174 +244,100 @@ function handleEdit(record: CompanyVO.CompanyInfoVO) {
companyFormModalRef.value?.open(true, record);
}
// 组件卸载标志
let isUnmounted = false;
// 获取公司列表
async function fetchCompanyList() {
if (isUnmounted) return;
try {
loading.value = true;
const params: PageQueryDTO<CompanyDTO.CompanyFiltersDTO> = {
page: current.value,
pageSize: pageSize.value,
filters: {
name: searchForm.value.name || undefined,
contactPerson: searchForm.value.contactPerson || undefined,
contactPhone: searchForm.value.contactPhone || undefined,
email: searchForm.value.email || undefined,
status: searchForm.value.status,
expired: searchForm.value.expired === 'true' ? true : searchForm.value.expired === 'false' ? false : undefined,
},
};
const data = await getCompanyPageApi(params);
if (isUnmounted) return;
companyList.value = data.records;
total.value = data.total;
} catch (error) {
if (isUnmounted) return;
console.error('获取公司列表失败:', error);
message.error('获取公司列表失败');
} finally {
if (!isUnmounted) {
loading.value = false;
}
}
}
// 处理删除公司
async function handleDelete(record: CompanyVO.CompanyInfoVO) {
try {
await deleteCompanyApi(record.id);
if (isUnmounted) return;
message.success('删除成功');
await fetchCompanyList();
refreshTable();
} catch (error) {
if (isUnmounted) return;
console.error('删除公司失败:', error);
message.error('删除公司失败');
}
}
// 处理模态框成功回调
async function handleModalSuccess() {
await fetchCompanyList();
function handleModalSuccess() {
refreshTable();
}
// Logo相关方法已移至CompanyFormModal组件
// 初始化
fetchCompanyList();
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '公司管理',
});
</script>
<template>
<Page title="公司管理">
<Page title="公司管理" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理公司信息,包括公司基本信息、联系方式和订阅状态
</div>
</template>
<template #extra>
<Button type="primary" @click="handleAdd">
添加公司
</Button>
</template>
<!-- 搜索表单 -->
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">公司名称</label>
<Input
v-model:value="searchForm.name"
placeholder="请输入公司名称"
style="width: 200px;"
@press-enter="handleSearch"
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">联系人</label>
<Input
v-model:value="searchForm.contactPerson"
placeholder="请输入联系人"
style="width: 150px;"
@press-enter="handleSearch"
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">联系电话</label>
<Input
v-model:value="searchForm.contactPhone"
placeholder="请输入联系电话"
style="width: 150px;"
@press-enter="handleSearch"
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">邮箱</label>
<Input
v-model:value="searchForm.email"
placeholder="请输入邮箱"
style="width: 200px;"
@press-enter="handleSearch"
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
<Select
v-model:value="searchForm.status"
placeholder="请选择状态"
style="width: 120px;"
:options="statusOptions"
allow-clear
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">过期状态</label>
<Select
v-model:value="searchForm.expired"
placeholder="请选择过期状态"
style="width: 120px;"
:options="[
{ label: '已过期', value: 'true' },
{ label: '正常', value: 'false' }
]"
allow-clear
/>
</div>
<div style="display: flex; gap: 8px; align-items: end;">
<Button type="primary" @click="handleSearch">搜索</Button>
<Button @click="handleReset">重置</Button>
</div>
</div>
</div>
<!-- 数据表格 -->
<Table
:columns="columns"
:data-source="companyList"
<!-- VbenVxeGrid 表格 -->
<Grid
:loading="loading"
:pagination="{
current: current,
pageSize: pageSize,
total: total,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
}"
row-key="id"
@change="handleTableChange"
/>
>
<!-- 工具栏工具 -->
<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" danger @click="handleDelete(row)">
删除
</Button>
</Space>
</template>
</Grid>
<!-- 公司表单模态框 -->
<CompanyFormModal
@@ -1,8 +1,11 @@
<script lang="ts" setup>
import { computed, h, ref } from 'vue';
import { ref, computed } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, Input, Select, Table, message } from 'ant-design-vue';
import { Button, message, Space, Tag } from 'ant-design-vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {
deleteDepartmentApi,
@@ -13,15 +16,15 @@ import {
import type { PageQueryDTO } from '#/types/common';
import DepartmentModal from './components/DepartmentModal.vue';
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
defineOptions({ name: 'DepartmentManagement' });
// 响应式数据
const loading = ref(false);
const departmentList = ref<DepartmentVO.DepartmentInfoVO[]>([]);
const total = ref(0);
const current = ref(1);
const pageSize = ref(10);
const departmentModalRef = ref();
const departmentList = ref<DepartmentVO.DepartmentInfoVO[]>([]);
// 搜索表单
const searchForm = ref({
@@ -57,68 +60,100 @@ const parentDepartmentOptions = computed(() => {
return options;
});
// 表格列配置
const columns = [
{
title: '部门名称',
dataIndex: 'name',
key: 'name',
width: 200,
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
title: '序号',
},
{
field: 'name',
title: '部门名称',
minWidth: 200,
showOverflow: 'tooltip' as const,
},
{
title: '父部门',
minWidth: 150,
slots: { default: 'parentDepartment' },
},
{
field: 'remark',
title: '描述',
minWidth: 200,
showOverflow: 'tooltip' as const,
},
{
title: '状态',
minWidth: 100,
slots: { default: 'status' },
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
},
{
title: '操作',
minWidth: 200,
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: 'auto',
border: true,
stripe: true,
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
{
title: '父部门',
dataIndex: 'parentId',
key: 'parentId',
width: 150,
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
if (!record.parentId) return '根部门';
const parent = findParentDepartment(departmentList.value, record.parentId);
return parent ? parent.name : '未知';
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
},
// 配置远程加载
proxyConfig: {
ajax: {
query: async ({ page }) => {
try {
loading.value = true;
const params: PageQueryDTO<DepartmentDTO.DepartmentFiltersDTO> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
name: searchForm.value.name || undefined,
parentId: searchForm.value.parentId,
status: searchForm.value.status,
},
};
const data = await getDepartmentPageApi(params);
// 更新部门列表用于父部门选项
departmentList.value = data.records;
return {
items: data.records,
total: data.total,
};
} catch (error) {
console.error('获取部门列表失败:', error);
message.error('获取部门列表失败');
return {
items: [],
total: 0,
};
} finally {
loading.value = false;
}
},
},
},
{
title: '描述',
dataIndex: 'remark',
key: 'remark',
width: 200,
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
width: 100,
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
return h('span', {
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
}, record.status === 1 ? '启用' : '禁用');
},
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
width: 180,
},
{
title: '操作',
key: 'action',
width: 200,
fixed: 'right' as const,
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
return h('div', { style: 'display: flex; gap: 8px;' }, [
h(Button, {
size: 'small',
onClick: () => handleEdit(record),
}, { default: () => '编辑' }),
h(Button, {
size: 'small',
danger: true,
onClick: () => handleDelete(record),
}, { default: () => '删除' }),
]);
},
},
];
};
// 查找父部门
function findParentDepartment(departments: DepartmentVO.DepartmentInfoVO[], parentId: number): DepartmentVO.DepartmentInfoVO | null {
@@ -134,54 +169,50 @@ function findParentDepartment(departments: DepartmentVO.DepartmentInfoVO[], pare
return null;
}
// 获取部门列表
async function fetchDepartmentList() {
try {
loading.value = true;
const params: PageQueryDTO<DepartmentDTO.DepartmentFiltersDTO> = {
page: current.value,
pageSize: pageSize.value,
filters: {
name: searchForm.value.name || undefined,
parentId: searchForm.value.parentId,
status: searchForm.value.status,
// 搜索表单配置
const formOptions = computed(() => ({
schema: [
{
component: 'Input',
componentProps: {
placeholder: '请输入部门名称',
},
};
const data = await getDepartmentPageApi(params);
departmentList.value = data.records;
total.value = data.total;
} catch (error) {
console.error('获取部门列表失败:', error);
message.error('获取部门列表失败');
} finally {
loading.value = false;
fieldName: 'name',
label: '部门名称',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择父部门',
options: parentDepartmentOptions.value,
allowClear: true,
},
fieldName: 'parentId',
label: '父部门',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择状态',
options: statusOptions,
allowClear: true,
},
fieldName: 'status',
label: '状态',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// 刷新表格数据
function refreshTable() {
if (gridApi) {
gridApi.reload();
}
}
// 处理搜索
function handleSearch() {
current.value = 1;
fetchDepartmentList();
}
// 处理重置
function handleReset() {
searchForm.value = {
name: '',
parentId: undefined,
status: undefined,
};
current.value = 1;
fetchDepartmentList();
}
// 处理分页变化
function handleTableChange(pagination: any) {
current.value = pagination.current;
pageSize.value = pagination.pageSize;
fetchDepartmentList();
}
// 处理添加部门
function handleAdd() {
departmentModalRef.value?.open(false);
@@ -197,7 +228,7 @@ async function handleDelete(record: DepartmentVO.DepartmentInfoVO) {
try {
await deleteDepartmentApi(record.id);
message.success('删除成功');
await fetchDepartmentList();
refreshTable();
} catch (error) {
console.error('删除部门失败:', error);
message.error('删除部门失败');
@@ -205,83 +236,68 @@ async function handleDelete(record: DepartmentVO.DepartmentInfoVO) {
}
// 处理模态框成功回调
async function handleModalSuccess() {
await fetchDepartmentList();
function handleModalSuccess() {
refreshTable();
}
// 初始化
fetchDepartmentList();
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '部门管理',
});
</script>
<template>
<Page title="部门管理">
<Page title="部门管理" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理部门信息,支持层级结构,可以创建子部门
</div>
</template>
<template #extra>
<Button type="primary" @click="handleAdd">
添加部门
</Button>
</template>
<!-- 搜索表单 -->
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">部门名称</label>
<Input
v-model:value="searchForm.name"
placeholder="请输入部门名称"
style="width: 200px;"
@press-enter="handleSearch"
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">父部门</label>
<Select
v-model:value="searchForm.parentId"
placeholder="请选择父部门"
style="width: 200px;"
:options="parentDepartmentOptions"
allow-clear
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
<Select
v-model:value="searchForm.status"
placeholder="请选择状态"
style="width: 120px;"
:options="statusOptions"
allow-clear
/>
</div>
<div style="display: flex; gap: 8px; align-items: end;">
<Button type="primary" @click="handleSearch">搜索</Button>
<Button @click="handleReset">重置</Button>
</div>
</div>
</div>
<!-- 数据表格 -->
<Table
:columns="columns"
:data-source="departmentList"
<!-- VbenVxeGrid 表格 -->
<Grid
:loading="loading"
:pagination="{
current: current,
pageSize: pageSize,
total: total,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
}"
row-key="id"
@change="handleTableChange"
/>
>
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon />
添加部门
</Button>
</Space>
</template>
<!-- 父部门列 -->
<template #parentDepartment="{ row }: { row: any }">
<span v-if="!row.parentId">根部门</span>
<span v-else>
{{ findParentDepartment(departmentList, row.parentId)?.name || '未知' }}
</span>
</template>
<!-- 状态列 -->
<template #status="{ row }: { row: any }">
<Tag :color="row.status === 1 ? 'green' : 'red'">
{{ row.status === 1 ? '启用' : '禁用' }}
</Tag>
</template>
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)">
编辑
</Button>
<Button size="small" danger @click="handleDelete(row)">
删除
</Button>
</Space>
</template>
</Grid>
<!-- 部门模态框组件 -->
<DepartmentModal
@@ -1,8 +1,11 @@
<script lang="ts" setup>
import { h, ref } from 'vue';
import { ref, computed } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, Input, Select, Table, message } from 'ant-design-vue';
import { Button, message, Space, Tag } from 'ant-design-vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {
deletePositionApi,
@@ -13,14 +16,13 @@ import {
import type { PageQueryDTO } from '#/types/common';
import PositionModal from './components/PositionModal.vue';
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
defineOptions({ name: 'PositionManagement' });
// 响应式数据
const loading = ref(false);
const positionList = ref<PositionVO.PositionInfoVO[]>([]);
const total = ref(0);
const current = ref(1);
const pageSize = ref(10);
const positionModalRef = ref();
// 搜索表单
@@ -43,121 +45,137 @@ const departmentOptions = ref([
{ label: '市场部', value: 4 },
]);
// 表格列配置
const columns = [
{
title: '岗位名称',
dataIndex: 'name',
key: 'name',
width: 150,
},
{
title: '岗位编码',
dataIndex: 'code',
key: 'code',
width: 120,
},
{
title: '所属部门',
dataIndex: 'departmentId',
key: 'departmentId',
width: 150,
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
if (!record.departmentId) return '-';
const dept = departmentOptions.value.find(d => d.value === record.departmentId);
return dept ? dept.label : '未知部门';
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
title: '序号',
},
},
{
title: '描述',
dataIndex: 'remark',
key: 'remark',
width: 200,
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
width: 100,
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
return h('span', {
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
}, record.status === 1 ? '启用' : '禁用');
{
field: 'name',
title: '岗位名称',
minWidth: 150,
showOverflow: 'tooltip' as const,
},
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
width: 180,
},
{
title: '操作',
key: 'action',
width: 200,
fixed: 'right' as const,
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
return h('div', { style: 'display: flex; gap: 8px;' }, [
h(Button, {
size: 'small',
onClick: () => handleEdit(record),
}, { default: () => '编辑' }),
h(Button, {
size: 'small',
danger: true,
onClick: () => handleDelete(record),
}, { default: () => '删除' }),
]);
{
field: 'code',
title: '岗位编码',
minWidth: 120,
},
{
title: '所属部门',
minWidth: 150,
slots: { default: 'department' },
},
{
field: 'remark',
title: '描述',
minWidth: 200,
showOverflow: 'tooltip' as const,
},
{
title: '状态',
minWidth: 100,
slots: { default: 'status' },
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
},
{
title: '操作',
minWidth: 200,
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: 'auto',
border: true,
stripe: true,
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
];
// 获取岗位列表
async function fetchPositionList() {
try {
loading.value = true;
const params: PageQueryDTO<PositionDTO.PositionFiltersDTO> = {
page: current.value,
pageSize: pageSize.value,
filters: {
name: searchForm.value.name || undefined,
status: searchForm.value.status,
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
},
// 配置远程加载
proxyConfig: {
ajax: {
query: async ({ page }) => {
try {
loading.value = true;
const params: PageQueryDTO<PositionDTO.PositionFiltersDTO> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
name: searchForm.value.name || undefined,
status: searchForm.value.status,
},
};
const data = await getPositionPageApi(params);
return {
items: data.records,
total: data.total,
};
} catch (error) {
console.error('获取岗位列表失败:', error);
message.error('获取岗位列表失败');
return {
items: [],
total: 0,
};
} finally {
loading.value = false;
}
},
};
const data = await getPositionPageApi(params);
positionList.value = data.records;
total.value = data.total;
} catch (error) {
console.error('获取岗位列表失败:', error);
message.error('获取岗位列表失败');
} finally {
loading.value = false;
},
},
};
// 搜索表单配置
const formOptions = computed(() => ({
schema: [
{
component: 'Input',
componentProps: {
placeholder: '请输入岗位名称',
},
fieldName: 'name',
label: '岗位名称',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择状态',
options: statusOptions,
allowClear: true,
},
fieldName: 'status',
label: '状态',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// 刷新表格数据
function refreshTable() {
if (gridApi) {
gridApi.reload();
}
}
// 处理搜索
function handleSearch() {
current.value = 1;
fetchPositionList();
}
// 处理重置
function handleReset() {
searchForm.value = {
name: '',
status: undefined,
};
current.value = 1;
fetchPositionList();
}
// 处理分页变化
function handleTableChange(pagination: any) {
current.value = pagination.current;
pageSize.value = pagination.pageSize;
fetchPositionList();
}
// 处理添加岗位
function handleAdd() {
positionModalRef.value?.open(false);
@@ -173,7 +191,7 @@ async function handleDelete(record: PositionVO.PositionInfoVO) {
try {
await deletePositionApi(record.id);
message.success('删除成功');
await fetchPositionList();
refreshTable();
} catch (error) {
console.error('删除岗位失败:', error);
message.error('删除岗位失败');
@@ -181,73 +199,68 @@ async function handleDelete(record: PositionVO.PositionInfoVO) {
}
// 处理模态框成功回调
async function handleModalSuccess() {
await fetchPositionList();
function handleModalSuccess() {
refreshTable();
}
// 初始化
fetchPositionList();
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '岗位管理',
});
</script>
<template>
<Page title="岗位管理">
<Page title="岗位管理" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理岗位信息,包括岗位名称、编码、所属部门和描述
</div>
</template>
<template #extra>
<Button type="primary" @click="handleAdd">
添加岗位
</Button>
</template>
<!-- 搜索表单 -->
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">岗位名称</label>
<Input
v-model:value="searchForm.name"
placeholder="请输入岗位名称"
style="width: 200px;"
@press-enter="handleSearch"
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
<Select
v-model:value="searchForm.status"
placeholder="请选择状态"
style="width: 120px;"
:options="statusOptions"
allow-clear
/>
</div>
<div style="display: flex; gap: 8px; align-items: end;">
<Button type="primary" @click="handleSearch">搜索</Button>
<Button @click="handleReset">重置</Button>
</div>
</div>
</div>
<!-- 数据表格 -->
<Table
:columns="columns"
:data-source="positionList"
<!-- VbenVxeGrid 表格 -->
<Grid
:loading="loading"
:pagination="{
current: current,
pageSize: pageSize,
total: total,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
}"
row-key="id"
@change="handleTableChange"
/>
>
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon />
添加岗位
</Button>
</Space>
</template>
<!-- 所属部门列 -->
<template #department="{ row }: { row: any }">
<span v-if="!row.departmentId">-</span>
<span v-else>
{{ departmentOptions.find(d => d.value === row.departmentId)?.label || '未知部门' }}
</span>
</template>
<!-- 状态列 -->
<template #status="{ row }: { row: any }">
<Tag :color="row.status === 1 ? 'green' : 'red'">
{{ row.status === 1 ? '启用' : '禁用' }}
</Tag>
</template>
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)">
编辑
</Button>
<Button size="small" danger @click="handleDelete(row)">
删除
</Button>
</Space>
</template>
</Grid>
<!-- 岗位模态框组件 -->
<PositionModal