mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 21:49:19 +08:00
refactor: 调整页面组件位置
This commit is contained in:
+287
@@ -0,0 +1,287 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CompanyVO } from '#/api/organization/company/types';
|
||||
import type {
|
||||
SuperAccountDTO,
|
||||
SuperAccountVO,
|
||||
} from '#/api/organization/account-super';
|
||||
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, message, Select } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
super_createAccountApi,
|
||||
super_updateAccountApi,
|
||||
} from '#/api/organization/account-super';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'SuperAccountFormModal' });
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[500px]',
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentAccountData = ref<null | SuperAccountVO.AccountInfoVO>(null);
|
||||
const presetCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
|
||||
|
||||
const formData = ref<
|
||||
SuperAccountDTO.SuperCreateAccountDTO & { status?: number }
|
||||
>({
|
||||
loginCode: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
companyId: 0,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
isSuper: 0,
|
||||
avatarImageId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
});
|
||||
|
||||
const modalTitle = computed(() => (isEdit.value ? '编辑账户' : '添加账户'));
|
||||
|
||||
const statusOptions = [
|
||||
{ label: '正常', value: 1 },
|
||||
{ label: '停用', value: 0 },
|
||||
];
|
||||
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
loginCode: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
companyId: presetCompany.value?.id ?? 0,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
isSuper: 0,
|
||||
avatarImageId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
function open(
|
||||
accountData?: null | SuperAccountVO.AccountInfoVO,
|
||||
company?: CompanyVO.CompanyInfoVO | null,
|
||||
) {
|
||||
isEdit.value = !!accountData;
|
||||
currentAccountData.value = accountData || null;
|
||||
presetCompany.value = company || null;
|
||||
|
||||
resetForm();
|
||||
|
||||
if (accountData) {
|
||||
formData.value = {
|
||||
loginCode: accountData.loginCode,
|
||||
password: '',
|
||||
realName: accountData.realName,
|
||||
phone: accountData.phone || '',
|
||||
companyId: accountData.companyId || presetCompany.value?.id || 0,
|
||||
departmentId: accountData.departmentId,
|
||||
positionId: accountData.positionId,
|
||||
isSuper: accountData.isSuper ?? 0,
|
||||
avatarImageId: accountData.avatarImageId,
|
||||
remark: accountData.remark || '',
|
||||
status: accountData.status ?? 1,
|
||||
};
|
||||
} else if (presetCompany.value) {
|
||||
formData.value.companyId = presetCompany.value.id;
|
||||
}
|
||||
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value && currentAccountData.value) {
|
||||
const { password: _, ...updateData } = formData.value;
|
||||
await super_updateAccountApi(currentAccountData.value.id, updateData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await super_createAccountApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
} catch (error: any) {
|
||||
console.error('保存账户失败:', error);
|
||||
message.error(
|
||||
error?.response?.data?.message || error?.message || '保存账户失败',
|
||||
);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => modalApi.useStore()?.value?.isOpen,
|
||||
(newVal) => {
|
||||
if (!newVal) {
|
||||
presetCompany.value = null;
|
||||
resetForm();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="modalTitle" :confirm-loading="loading">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item v-if="presetCompany" label="所属公司">
|
||||
<Input :value="presetCompany.name" disabled />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="登录账号"
|
||||
name="loginCode"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入登录账号' },
|
||||
{ min: 3, max: 20, message: '登录账号长度为3-20个字符' },
|
||||
{
|
||||
pattern: /^[a-zA-Z0-9_]+$/,
|
||||
message: '登录账号只能包含字母、数字和下划线',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.loginCode"
|
||||
placeholder="请输入登录账号"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
v-if="!isEdit"
|
||||
label="密码"
|
||||
name="password"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入密码' },
|
||||
{ min: 6, max: 20, message: '密码长度为6-20个字符' },
|
||||
]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.password"
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="真实姓名"
|
||||
name="realName"
|
||||
:rules="[{ required: true, message: '请输入真实姓名' }]"
|
||||
>
|
||||
<Input v-model:value="formData.realName" placeholder="请输入真实姓名" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input v-model:value="formData.remark" placeholder="请输入备注" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="手机号"
|
||||
name="phone"
|
||||
:rules="[{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' }]"
|
||||
>
|
||||
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
v-if="!presetCompany"
|
||||
label="公司ID"
|
||||
name="companyId"
|
||||
:rules="[{ required: true, message: '请输入公司ID' }]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.companyId"
|
||||
type="number"
|
||||
placeholder="请输入公司ID"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="部门ID" name="departmentId">
|
||||
<Input
|
||||
v-model:value="formData.departmentId"
|
||||
type="number"
|
||||
placeholder="请输入部门ID"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="职位ID" name="positionId">
|
||||
<Input
|
||||
v-model:value="formData.positionId"
|
||||
type="number"
|
||||
placeholder="请输入职位ID"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="是否超管"
|
||||
name="isSuper"
|
||||
:rules="[{ required: true, message: '请选择是否超管' }]"
|
||||
>
|
||||
<Select
|
||||
v-model:value="formData.isSuper"
|
||||
placeholder="请选择是否超管"
|
||||
:options="[
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
]"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="头像图片ID" name="avatarImageId">
|
||||
<Input
|
||||
v-model:value="formData.avatarImageId"
|
||||
type="number"
|
||||
placeholder="请输入头像图片ID"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="isEdit" label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,561 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { CompanyVO } from '#/api/organization/company/types';
|
||||
import type {
|
||||
SuperAccountDTO,
|
||||
SuperAccountVO,
|
||||
} from '#/api/organization/account-super';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Empty,
|
||||
Flex,
|
||||
Input,
|
||||
message,
|
||||
Pagination,
|
||||
Popconfirm,
|
||||
Select,
|
||||
Space,
|
||||
Spin,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getCompanyPageApi } from '#/api/organization/company';
|
||||
import {
|
||||
super_deleteAccountApi,
|
||||
super_getAccountPageApi,
|
||||
} from '#/api/organization/account-super';
|
||||
|
||||
import SuperAccountFormModal from './components/SuperAccountFormModal.vue';
|
||||
import {
|
||||
SIDEBAR_LIST_SHELL_CLASS,
|
||||
sidebarListRowClass,
|
||||
} from '#/utils/sidebar-list-styles';
|
||||
|
||||
defineOptions({ name: 'SuperAccountManagement' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const BuildingIcon = createIconifyIcon('lucide:building-2');
|
||||
|
||||
const loading = ref(false);
|
||||
const accountFormModalRef = ref();
|
||||
|
||||
const companySearchForm = ref({
|
||||
name: '',
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
const companyList = ref<CompanyVO.CompanyInfoVO[]>([]);
|
||||
const companyLoading = ref(false);
|
||||
const companyPagination = ref({
|
||||
current: 1,
|
||||
pageSize: 20,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
const currentCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
|
||||
|
||||
const searchForm = ref({
|
||||
loginCode: undefined as string | undefined,
|
||||
realName: undefined as string | undefined,
|
||||
phone: undefined as string | undefined,
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
const statusOptions = [
|
||||
{ label: '正常', value: 1 },
|
||||
{ label: '停用', value: 0 },
|
||||
];
|
||||
|
||||
const selectedCompanyLabel = computed(() => {
|
||||
if (!currentCompany.value) {
|
||||
return '全部账户';
|
||||
}
|
||||
return currentCompany.value.name;
|
||||
});
|
||||
|
||||
const gridOptions: VxeGridProps<SuperAccountVO.AccountInfoVO> = {
|
||||
columns: [
|
||||
{ type: 'seq' as const, minWidth: 56, title: '序号' },
|
||||
{
|
||||
field: 'loginCode',
|
||||
title: '登录账号',
|
||||
minWidth: 120,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'realName',
|
||||
title: '真实姓名',
|
||||
minWidth: 120,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'phone',
|
||||
title: '手机号',
|
||||
minWidth: 120,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'companyName',
|
||||
title: '公司',
|
||||
minWidth: 140,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'departmentName',
|
||||
title: '部门',
|
||||
minWidth: 120,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'positionName',
|
||||
title: '职位',
|
||||
minWidth: 120,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'isSuperName',
|
||||
title: '超管',
|
||||
minWidth: 100,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 80,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 160,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 140,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: '100%',
|
||||
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;
|
||||
const params: PageQueryDTO<SuperAccountDTO.AccountFilterDTO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
loginCode: searchForm.value.loginCode || undefined,
|
||||
realName: searchForm.value.realName || undefined,
|
||||
phone: searchForm.value.phone || undefined,
|
||||
status: searchForm.value.status,
|
||||
companyId: currentCompany.value?.id,
|
||||
},
|
||||
};
|
||||
const response = await super_getAccountPageApi(params);
|
||||
return {
|
||||
items: response.records,
|
||||
total: response.total,
|
||||
};
|
||||
} catch (error: any) {
|
||||
message.error(
|
||||
error?.response?.data?.message || error?.message || '查询数据失败',
|
||||
);
|
||||
return { items: [], total: 0 };
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
showSearchForm: false,
|
||||
tableTitle: '账户列表',
|
||||
});
|
||||
|
||||
async function searchCompanies() {
|
||||
companyLoading.value = true;
|
||||
try {
|
||||
const result = await getCompanyPageApi({
|
||||
page: companyPagination.value.current,
|
||||
pageSize: companyPagination.value.pageSize,
|
||||
filters: {
|
||||
name: companySearchForm.value.name || undefined,
|
||||
status: companySearchForm.value.status,
|
||||
},
|
||||
});
|
||||
companyList.value = result.records;
|
||||
companyPagination.value.total = result.total;
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取公司列表失败');
|
||||
} finally {
|
||||
companyLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function resetCompanySearch() {
|
||||
companySearchForm.value = { name: '', status: undefined };
|
||||
companyPagination.value.current = 1;
|
||||
searchCompanies();
|
||||
}
|
||||
|
||||
function handleCompanyPageChange(page: number, pageSize: number) {
|
||||
companyPagination.value.current = page;
|
||||
companyPagination.value.pageSize = pageSize;
|
||||
searchCompanies();
|
||||
}
|
||||
|
||||
function selectCompanyAll() {
|
||||
currentCompany.value = null;
|
||||
}
|
||||
|
||||
function selectCompany(company: CompanyVO.CompanyInfoVO) {
|
||||
currentCompany.value = company;
|
||||
}
|
||||
|
||||
function refreshTable() {
|
||||
gridApi?.reload();
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
if (!currentCompany.value) {
|
||||
message.warning('请先选择具体公司,或在公司行点击「添加」');
|
||||
return;
|
||||
}
|
||||
accountFormModalRef.value?.open(undefined, currentCompany.value);
|
||||
}
|
||||
|
||||
function handleAddForCompany(company: CompanyVO.CompanyInfoVO) {
|
||||
selectCompany(company);
|
||||
accountFormModalRef.value?.open(undefined, company);
|
||||
}
|
||||
|
||||
function handleEdit(row: SuperAccountVO.AccountInfoVO) {
|
||||
accountFormModalRef.value?.open(row, currentCompany.value);
|
||||
}
|
||||
|
||||
async function handleDelete(row: SuperAccountVO.AccountInfoVO) {
|
||||
try {
|
||||
await super_deleteAccountApi(row.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error: any) {
|
||||
message.error(
|
||||
error?.response?.data?.message || error?.message || '删除失败',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
function getStatusText(status: number) {
|
||||
const statusMap: Record<number, string> = {
|
||||
0: '停用',
|
||||
1: '正常',
|
||||
};
|
||||
return statusMap[status] || '未知';
|
||||
}
|
||||
|
||||
function getStatusColor(status: number) {
|
||||
const colorMap: Record<number, string> = {
|
||||
0: 'orange',
|
||||
1: 'green',
|
||||
};
|
||||
return colorMap[status] || 'default';
|
||||
}
|
||||
|
||||
function companyRowClass(id: number | 'all') {
|
||||
const active =
|
||||
id === 'all'
|
||||
? currentCompany.value === null
|
||||
: currentCompany.value?.id === id;
|
||||
const layout =
|
||||
id === 'all'
|
||||
? 'mb-1.5 flex w-full cursor-pointer items-center gap-2 text-left'
|
||||
: 'group flex w-full cursor-pointer items-center gap-2';
|
||||
return sidebarListRowClass(active, layout);
|
||||
}
|
||||
|
||||
watch(currentCompany, () => {
|
||||
gridApi.reload();
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
searchCompanies();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="超级账户管理" :auto-content-height="true">
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
左侧选择公司筛选右侧账户;首项「全部账户」展示所有账户,可在公司行快捷新增。
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon class="mr-2 h-4 w-4" />
|
||||
新增账户
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<Flex gap="middle" class="h-full min-h-0">
|
||||
<!-- 左:公司 -->
|
||||
<Card
|
||||
class="flex h-full w-[420px] shrink-0 flex-col"
|
||||
:body-style="{
|
||||
height: '100%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: '8px',
|
||||
minHeight: 0,
|
||||
padding: '12px',
|
||||
}"
|
||||
>
|
||||
<template #title>
|
||||
<span class="flex items-center gap-2 text-base font-semibold">
|
||||
<BuildingIcon class="h-4 w-4" />
|
||||
公司
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<Flex wrap="wrap" align="center" class="shrink-0 gap-2">
|
||||
<Input
|
||||
v-model:value="companySearchForm.name"
|
||||
placeholder="公司名称"
|
||||
allow-clear
|
||||
class="min-w-[140px] flex-1"
|
||||
@press-enter="searchCompanies"
|
||||
/>
|
||||
<Select
|
||||
v-model:value="companySearchForm.status"
|
||||
placeholder="状态"
|
||||
allow-clear
|
||||
class="w-[88px]"
|
||||
:options="[
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
]"
|
||||
/>
|
||||
<Button type="primary" size="small" @click="searchCompanies">
|
||||
搜索
|
||||
</Button>
|
||||
<Button size="small" @click="resetCompanySearch">重置</Button>
|
||||
</Flex>
|
||||
|
||||
<Spin :spinning="companyLoading" class="flex min-h-0 flex-1 flex-col">
|
||||
<div :class="SIDEBAR_LIST_SHELL_CLASS">
|
||||
<button
|
||||
type="button"
|
||||
:class="companyRowClass('all')"
|
||||
@click="selectCompanyAll"
|
||||
>
|
||||
<span class="min-w-0 flex-1 truncate">全部账户</span>
|
||||
<span class="shrink-0 text-xs font-normal text-muted-foreground">
|
||||
全部记录
|
||||
</span>
|
||||
</button>
|
||||
<Empty
|
||||
v-if="!companyLoading && companyList.length === 0"
|
||||
class="py-8"
|
||||
description="暂无公司"
|
||||
/>
|
||||
<div v-else class="space-y-1">
|
||||
<div
|
||||
v-for="company in companyList"
|
||||
:key="company.id"
|
||||
:class="companyRowClass(company.id)"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="min-w-0 flex-1 truncate text-left"
|
||||
@click="selectCompany(company)"
|
||||
>
|
||||
<span class="block truncate">{{ company.name }}</span>
|
||||
<span
|
||||
class="mt-0.5 block truncate text-xs font-normal text-muted-foreground"
|
||||
>
|
||||
{{ company.status === 1 ? '启用' : '禁用' }}
|
||||
</span>
|
||||
</button>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
class="!h-7 shrink-0 !px-1 !text-xs font-semibold opacity-80 group-hover:opacity-100"
|
||||
@click.stop="handleAddForCompany(company)"
|
||||
>
|
||||
<PlusIcon class="mr-0.5 inline h-3.5 w-3.5" />
|
||||
添加
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Flex justify="center" class="mt-2 shrink-0 pt-1">
|
||||
<Pagination
|
||||
v-model:current="companyPagination.current"
|
||||
v-model:page-size="companyPagination.pageSize"
|
||||
:total="companyPagination.total"
|
||||
size="small"
|
||||
:show-size-changer="true"
|
||||
:show-quick-jumper="true"
|
||||
@change="handleCompanyPageChange"
|
||||
/>
|
||||
</Flex>
|
||||
</Spin>
|
||||
</Card>
|
||||
|
||||
<!-- 右:账户列表 -->
|
||||
<Card
|
||||
class="flex h-full min-h-0 min-w-0 flex-1 flex-col"
|
||||
:body-style="{
|
||||
height: '100%',
|
||||
minHeight: 0,
|
||||
padding: 0,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
}"
|
||||
>
|
||||
<template #title>
|
||||
<span class="text-base font-semibold">账户列表</span>
|
||||
</template>
|
||||
<template #extra>
|
||||
<Space wrap size="small" class="max-w-[min(100%,42rem)]">
|
||||
<Input
|
||||
v-model:value="searchForm.loginCode"
|
||||
allow-clear
|
||||
placeholder="登录账号"
|
||||
class="w-[120px]"
|
||||
@press-enter="refreshTable"
|
||||
/>
|
||||
<Input
|
||||
v-model:value="searchForm.realName"
|
||||
allow-clear
|
||||
placeholder="姓名"
|
||||
class="w-[100px]"
|
||||
@press-enter="refreshTable"
|
||||
/>
|
||||
<Input
|
||||
v-model:value="searchForm.phone"
|
||||
allow-clear
|
||||
placeholder="手机号"
|
||||
class="w-[120px]"
|
||||
@press-enter="refreshTable"
|
||||
/>
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
allow-clear
|
||||
placeholder="状态"
|
||||
class="min-w-[88px]"
|
||||
:options="statusOptions"
|
||||
@change="refreshTable"
|
||||
/>
|
||||
<Button size="small" @click="refreshTable">查询</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<div
|
||||
class="shrink-0 border-t border-border px-4 py-2 text-xs text-muted-foreground"
|
||||
>
|
||||
当前:{{ selectedCompanyLabel }}
|
||||
<template v-if="currentCompany">
|
||||
<Tag
|
||||
class="ml-2"
|
||||
:color="currentCompany.status === 1 ? 'green' : 'red'"
|
||||
>
|
||||
{{ currentCompany.status === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="min-h-0 flex-1 overflow-hidden px-2 pb-2 pt-0 sm:px-3 sm:pb-3"
|
||||
>
|
||||
<Grid :loading="loading" class="h-full min-h-0">
|
||||
<template #toolbar-tools>
|
||||
<span class="text-xs text-muted-foreground">
|
||||
使用上方筛选条件查询;表格在区域内滚动
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template #status="{ row }">
|
||||
<Tag :color="getStatusColor(row.status)">
|
||||
{{ getStatusText(row.status) }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)">编辑</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个账户吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
</Card>
|
||||
</Flex>
|
||||
|
||||
<SuperAccountFormModal
|
||||
ref="accountFormModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
+389
@@ -0,0 +1,389 @@
|
||||
<script lang="ts" setup>
|
||||
import type { AccountDTO, AccountVO } from '#/api/organization/account';
|
||||
import type { DepartmentVO } from '#/api/organization/department';
|
||||
import type { PositionVO } from '#/api/organization/position';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Cascader, Form, Input, message, Select } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
admin_createAccountApi,
|
||||
admin_updateAccountApi,
|
||||
} from '#/api/organization/account';
|
||||
import { getDepartmentTreeApi } from '#/api/organization/department';
|
||||
import { getPositionPageApi } from '#/api/organization/position';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'AccountFormModal' });
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[500px]',
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentAccountData = ref<AccountVO.AccountInfoVO | null>(null);
|
||||
const departmentOptionsLoading = ref(false);
|
||||
const positionOptionsLoading = ref(false);
|
||||
const selectorsLoaded = ref(false);
|
||||
|
||||
interface DepartmentCascaderOption {
|
||||
children?: DepartmentCascaderOption[];
|
||||
label: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
interface PositionSelectOption {
|
||||
departmentId?: number;
|
||||
label: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<AccountDTO.CreateAccountDTO & { status?: number }>({
|
||||
password: '',
|
||||
phone: '',
|
||||
realName: '',
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
remark: '',
|
||||
});
|
||||
const departmentPath = ref<number[]>([]);
|
||||
const departmentTreeOptions = ref<DepartmentCascaderOption[]>([]);
|
||||
const allPositionOptions = ref<PositionSelectOption[]>([]);
|
||||
|
||||
const positionOptions = computed(() => {
|
||||
const selectedDepartmentId = formData.value.departmentId;
|
||||
if (!selectedDepartmentId) return allPositionOptions.value;
|
||||
return allPositionOptions.value.filter(
|
||||
(item) => !item.departmentId || item.departmentId === selectedDepartmentId,
|
||||
);
|
||||
});
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => (isEdit.value ? '编辑账户' : '添加账户'));
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '正常', value: 0 },
|
||||
{ label: '删除', value: 1 },
|
||||
{ label: '停用', value: 2 },
|
||||
{ label: '冻结', value: 3 },
|
||||
];
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
password: '',
|
||||
phone: '',
|
||||
realName: '',
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
remark: '',
|
||||
};
|
||||
departmentPath.value = [];
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
// 处理模态框关闭
|
||||
function handleCancel() {
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function buildDepartmentTreeOptions(
|
||||
departments: DepartmentVO.DepartmentInfoVO[],
|
||||
): DepartmentCascaderOption[] {
|
||||
return departments.map((item) => ({
|
||||
children:
|
||||
item.children && item.children.length > 0
|
||||
? buildDepartmentTreeOptions(item.children)
|
||||
: undefined,
|
||||
label: item.name,
|
||||
value: item.id,
|
||||
}));
|
||||
}
|
||||
|
||||
function findDepartmentPathById(
|
||||
options: DepartmentCascaderOption[],
|
||||
departmentId: number,
|
||||
currentPath: number[] = [],
|
||||
): null | number[] {
|
||||
for (const option of options) {
|
||||
const nextPath = [...currentPath, option.value];
|
||||
if (option.value === departmentId) return nextPath;
|
||||
if (option.children?.length) {
|
||||
const result = findDepartmentPathById(
|
||||
option.children,
|
||||
departmentId,
|
||||
nextPath,
|
||||
);
|
||||
if (result) return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function loadDepartmentOptions() {
|
||||
try {
|
||||
departmentOptionsLoading.value = true;
|
||||
const data = await getDepartmentTreeApi();
|
||||
departmentTreeOptions.value = buildDepartmentTreeOptions(data || []);
|
||||
} catch (error) {
|
||||
console.error('获取部门树失败:', error);
|
||||
message.error('获取部门树失败');
|
||||
departmentTreeOptions.value = [];
|
||||
} finally {
|
||||
departmentOptionsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPositionOptions() {
|
||||
try {
|
||||
positionOptionsLoading.value = true;
|
||||
const params: PageQueryDTO = {
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
};
|
||||
const data = await getPositionPageApi(params);
|
||||
const list = data.records || [];
|
||||
allPositionOptions.value = list.map((item: PositionVO.PositionInfoVO) => ({
|
||||
departmentId: item.departmentId,
|
||||
label: item.name,
|
||||
value: item.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取职位列表失败:', error);
|
||||
message.error('获取职位列表失败');
|
||||
allPositionOptions.value = [];
|
||||
} finally {
|
||||
positionOptionsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureSelectorOptionsLoaded() {
|
||||
if (selectorsLoaded.value) return;
|
||||
await Promise.all([loadDepartmentOptions(), loadPositionOptions()]);
|
||||
selectorsLoaded.value = true;
|
||||
}
|
||||
|
||||
function syncDepartmentPathByDepartmentId() {
|
||||
if (!formData.value.departmentId) {
|
||||
departmentPath.value = [];
|
||||
return;
|
||||
}
|
||||
const path = findDepartmentPathById(
|
||||
departmentTreeOptions.value,
|
||||
formData.value.departmentId,
|
||||
);
|
||||
departmentPath.value = path || [];
|
||||
}
|
||||
|
||||
function handleDepartmentChange(value: number[]) {
|
||||
departmentPath.value = value || [];
|
||||
const selectedDepartmentId = departmentPath.value.at(-1) || 0;
|
||||
const previousDepartmentId = formData.value.departmentId;
|
||||
formData.value.departmentId = selectedDepartmentId;
|
||||
|
||||
if (
|
||||
previousDepartmentId !== selectedDepartmentId &&
|
||||
formData.value.positionId &&
|
||||
!positionOptions.value.some(
|
||||
(item) => item.value === formData.value.positionId,
|
||||
)
|
||||
) {
|
||||
formData.value.positionId = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async function open(accountData?: AccountVO.AccountInfoVO | null) {
|
||||
await ensureSelectorOptionsLoaded();
|
||||
isEdit.value = !!accountData;
|
||||
currentAccountData.value = accountData || null;
|
||||
|
||||
resetForm();
|
||||
|
||||
if (accountData) {
|
||||
formData.value = {
|
||||
password: '', // 编辑时密码为空
|
||||
phone: accountData.phone || '',
|
||||
realName: accountData.realName,
|
||||
departmentId: accountData.departmentId,
|
||||
positionId: accountData.positionId || undefined,
|
||||
remark: accountData.remark || '',
|
||||
status: accountData.status,
|
||||
};
|
||||
}
|
||||
|
||||
syncDepartmentPathByDepartmentId();
|
||||
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value && currentAccountData.value) {
|
||||
const { password: _, ...updateData } = formData.value;
|
||||
await admin_updateAccountApi(currentAccountData.value.id, updateData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await admin_createAccountApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
} catch (error: any) {
|
||||
console.error('保存账户失败:', error);
|
||||
const errorMessage =
|
||||
error?.response?.data?.message || error?.message || '保存账户失败';
|
||||
message.error(errorMessage);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 监听 modal 关闭状态
|
||||
watch(
|
||||
() => modalApi.useStore()?.value?.isOpen,
|
||||
(newVal) => {
|
||||
if (!newVal) {
|
||||
resetForm();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => formData.value.departmentId,
|
||||
() => {
|
||||
if (
|
||||
formData.value.positionId &&
|
||||
!positionOptions.value.some(
|
||||
(item) => item.value === formData.value.positionId,
|
||||
)
|
||||
) {
|
||||
formData.value.positionId = undefined;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="modalTitle" :confirm-loading="loading">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item
|
||||
label="手机号"
|
||||
name="phone"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入手机号' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' },
|
||||
]"
|
||||
>
|
||||
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
v-if="!isEdit"
|
||||
label="密码"
|
||||
name="password"
|
||||
:rules="[
|
||||
{ min: 6, max: 20, message: '密码长度为6-20个字符' },
|
||||
]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.password"
|
||||
type="password"
|
||||
placeholder="新用户必填;手机号已存在可留空"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="真实姓名"
|
||||
name="realName"
|
||||
:rules="[{ required: true, message: '请输入真实姓名' }]"
|
||||
>
|
||||
<Input v-model:value="formData.realName" placeholder="请输入真实姓名" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="所属部门"
|
||||
name="departmentId"
|
||||
:rules="[{ required: true, message: '请选择所属部门' }]"
|
||||
>
|
||||
<Cascader
|
||||
:value="departmentPath"
|
||||
:options="departmentTreeOptions"
|
||||
:loading="departmentOptionsLoading"
|
||||
placeholder="请选择所属部门"
|
||||
:field-names="{
|
||||
label: 'label',
|
||||
value: 'value',
|
||||
children: 'children',
|
||||
}"
|
||||
change-on-select
|
||||
class="w-full"
|
||||
@change="(value) => handleDepartmentChange((value || []) as number[])"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="职位"
|
||||
name="positionId"
|
||||
:rules="[{ required: true, message: '请选择职位' }]"
|
||||
>
|
||||
<Select
|
||||
v-model:value="formData.positionId"
|
||||
:loading="positionOptionsLoading"
|
||||
:options="positionOptions"
|
||||
placeholder="请选择职位"
|
||||
:disabled="positionOptionsLoading"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input v-model:value="formData.remark" placeholder="请输入备注" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="isEdit" label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,367 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { AccountDTO, AccountVO } from '#/api/organization/account';
|
||||
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 {
|
||||
admin_deleteAccountApi,
|
||||
admin_getAccountPageApi,
|
||||
} from '#/api/organization/account';
|
||||
|
||||
import AccountFormModal from './components/AccountFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'CompanyAccountManagement' });
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const accountFormModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
loginCode: undefined as string | undefined,
|
||||
realName: undefined as string | undefined,
|
||||
phone: undefined as string | undefined,
|
||||
companyId: undefined as number | undefined,
|
||||
departmentId: undefined as number | undefined,
|
||||
positionId: undefined as number | undefined,
|
||||
role: undefined as string | undefined,
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '正常', value: 0 },
|
||||
{ label: '删除', value: 1 },
|
||||
{ label: '停用', value: 2 },
|
||||
{ label: '冻结', value: 3 },
|
||||
];
|
||||
|
||||
// 搜索表单配置
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
const formOptions = computed(() => ({
|
||||
schemas: [
|
||||
{
|
||||
fieldName: 'loginCode',
|
||||
label: '登录账号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入登录账号(回车搜索)',
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'realName',
|
||||
label: '真实姓名',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入真实姓名(回车搜索)',
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'phone',
|
||||
label: '手机号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入手机号(回车搜索)',
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: statusOptions,
|
||||
placeholder: '请选择状态',
|
||||
onChange: () => gridReloadRef.value?.(),
|
||||
},
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'loginCode',
|
||||
title: '登录账号',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'realName',
|
||||
title: '真实姓名',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'phone',
|
||||
title: '手机号',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'companyName',
|
||||
title: '公司',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'departmentName',
|
||||
title: '部门',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'positionName',
|
||||
title: '职位',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'role',
|
||||
title: '角色',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 80,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 120,
|
||||
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;
|
||||
const params: PageQueryDTO<AccountDTO.AccountFilterDTO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...searchForm.value,
|
||||
};
|
||||
const response = await admin_getAccountPageApi(params);
|
||||
return {
|
||||
items: response.records,
|
||||
total: response.total,
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error('查询数据失败:', error);
|
||||
const errorMessage =
|
||||
error?.response?.data?.message || error?.message || '查询数据失败';
|
||||
message.error(errorMessage);
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 表格实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '账户管理',
|
||||
});
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
// 计算属性
|
||||
const hasSelected = computed(() => {
|
||||
const vxeTable = (gridApi as any).grid;
|
||||
return vxeTable?.getCheckboxRecords?.()?.length > 0;
|
||||
});
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
const handleAdd = () => {
|
||||
accountFormModalRef.value?.open();
|
||||
};
|
||||
|
||||
const handleEdit = (row: AccountVO.AccountInfoVO) => {
|
||||
accountFormModalRef.value?.open(row);
|
||||
};
|
||||
|
||||
const handleDelete = async (row: AccountVO.AccountInfoVO) => {
|
||||
try {
|
||||
await admin_deleteAccountApi(row.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error: any) {
|
||||
console.error('删除失败:', error);
|
||||
const errorMessage =
|
||||
error?.response?.data?.message || error?.message || '删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
const handleBatchDelete = async () => {
|
||||
const vxeTable = (gridApi as any).grid;
|
||||
const selectedRows = vxeTable?.getCheckboxRecords?.();
|
||||
if (!selectedRows?.length) {
|
||||
message.warning('请选择要删除的数据');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const deletePromises = selectedRows.map((row: AccountVO.AccountInfoVO) =>
|
||||
admin_deleteAccountApi(row.id),
|
||||
);
|
||||
await Promise.all(deletePromises);
|
||||
message.success(`成功删除 ${selectedRows.length} 条记录`);
|
||||
refreshTable();
|
||||
} catch (error: any) {
|
||||
console.error('批量删除失败:', error);
|
||||
const errorMessage =
|
||||
error?.response?.data?.message || error?.message || '批量删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取状态文本
|
||||
const getStatusText = (status: number) => {
|
||||
const statusMap = {
|
||||
0: '正常',
|
||||
1: '删除',
|
||||
2: '停用',
|
||||
3: '冻结',
|
||||
};
|
||||
return statusMap[status as keyof typeof statusMap] || '未知';
|
||||
};
|
||||
|
||||
// 获取状态颜色
|
||||
const getStatusColor = (status: number) => {
|
||||
const colorMap = {
|
||||
0: 'green',
|
||||
1: 'red',
|
||||
2: 'orange',
|
||||
3: 'purple',
|
||||
};
|
||||
return colorMap[status as keyof typeof colorMap] || 'default';
|
||||
};
|
||||
|
||||
// 处理模态框成功回调
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
</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>
|
||||
<Button v-if="hasSelected" danger @click="handleBatchDelete">
|
||||
批量删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 状态列 -->
|
||||
<template #status="{ row }">
|
||||
<Tag :color="getStatusColor(row.status)">
|
||||
{{ getStatusText(row.status) }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个账户吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 账户表单弹窗 -->
|
||||
<AccountFormModal ref="accountFormModalRef" @success="handleModalSuccess" />
|
||||
</Page>
|
||||
</template>
|
||||
+471
@@ -0,0 +1,471 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CompanyDTO, CompanyVO } from '#/api/organization/company';
|
||||
|
||||
import { computed, onUnmounted, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
Button,
|
||||
DatePicker,
|
||||
Form,
|
||||
Input,
|
||||
message,
|
||||
Switch,
|
||||
} from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
createCompanyApi,
|
||||
updateCompanyApi,
|
||||
uploadCompanyLogoApi,
|
||||
} from '#/api/organization/company';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[600px]',
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
// 创建相机图标组件
|
||||
const CameraIcon = createIconifyIcon('mdi:camera');
|
||||
|
||||
// 内部状态管理
|
||||
const isEdit = ref(false);
|
||||
const currentCompanyData = ref<CompanyVO.CompanyInfoVO | null>(null);
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const newLogoFile = ref<File | null>(null); // 新选择的logo文件
|
||||
const originalLogoUrl = ref(''); // 原始logo URL
|
||||
const imageLoadError = ref(false); // 图片加载错误状态
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
name: string;
|
||||
address: string;
|
||||
email: string;
|
||||
ownerName: string;
|
||||
ownerPhone: string;
|
||||
logoImageId?: number;
|
||||
status: boolean;
|
||||
expireTime: any;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<FormData>({
|
||||
name: '',
|
||||
address: '',
|
||||
email: '',
|
||||
ownerName: '',
|
||||
ownerPhone: '',
|
||||
logoImageId: undefined,
|
||||
status: true,
|
||||
expireTime: undefined,
|
||||
});
|
||||
|
||||
// 开关组件不需要选项数组
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => (isEdit.value ? '编辑公司' : '添加公司'));
|
||||
|
||||
// 当前显示的logo URL(优先显示新选择的)
|
||||
const currentLogoUrl = computed(() => {
|
||||
if (newLogoFile.value) {
|
||||
return URL.createObjectURL(newLogoFile.value);
|
||||
}
|
||||
return originalLogoUrl.value;
|
||||
});
|
||||
|
||||
// 初始化表单数据
|
||||
function initFormData() {
|
||||
if (isEdit.value && currentCompanyData.value) {
|
||||
// 编辑模式
|
||||
formData.value = {
|
||||
name: currentCompanyData.value.name,
|
||||
address: currentCompanyData.value.address || '',
|
||||
email: currentCompanyData.value.email || '',
|
||||
ownerName: '',
|
||||
ownerPhone: '',
|
||||
logoImageId: undefined,
|
||||
status: currentCompanyData.value.status === 1, // 转换为boolean
|
||||
expireTime: currentCompanyData.value.expireTime
|
||||
? dayjs(currentCompanyData.value.expireTime)
|
||||
: undefined,
|
||||
};
|
||||
|
||||
// 设置原始Logo URL
|
||||
originalLogoUrl.value = currentCompanyData.value.logo || '';
|
||||
} else {
|
||||
// 创建模式
|
||||
formData.value = {
|
||||
name: '',
|
||||
address: '',
|
||||
email: '',
|
||||
ownerName: '',
|
||||
ownerPhone: '',
|
||||
logoImageId: undefined,
|
||||
status: true,
|
||||
expireTime: undefined,
|
||||
};
|
||||
originalLogoUrl.value = '';
|
||||
}
|
||||
|
||||
// 重置新选择的logo和图片加载状态
|
||||
newLogoFile.value = null;
|
||||
imageLoadError.value = false;
|
||||
}
|
||||
|
||||
// 重置表单(在open方法中调用)
|
||||
function resetForm() {
|
||||
formRef.value?.resetFields();
|
||||
newLogoFile.value = null;
|
||||
originalLogoUrl.value = '';
|
||||
imageLoadError.value = false;
|
||||
}
|
||||
|
||||
// 处理提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
// 准备提交数据
|
||||
const submitData: any = {
|
||||
...formData.value,
|
||||
status: formData.value.status ? 1 : 0, // 转换boolean为number
|
||||
};
|
||||
// 编辑时排除拥有者字段
|
||||
if (isEdit.value) {
|
||||
delete submitData.ownerName;
|
||||
delete submitData.ownerPhone;
|
||||
}
|
||||
|
||||
// 处理日期格式
|
||||
if (submitData.expireTime) {
|
||||
submitData.expireTime = submitData.expireTime.format(
|
||||
'YYYY-MM-DD HH:mm:ss',
|
||||
);
|
||||
}
|
||||
|
||||
// 如果有新选择的logo,先上传获取ID
|
||||
if (newLogoFile.value) {
|
||||
const logoImageId = await uploadLogoAndGetId();
|
||||
if (logoImageId) {
|
||||
submitData.logoImageId = logoImageId;
|
||||
}
|
||||
} else if (!isEdit.value) {
|
||||
// 创建模式且没有选择Logo,移除logoImageId字段
|
||||
delete submitData.logoImageId;
|
||||
}
|
||||
|
||||
// 调用API
|
||||
if (isEdit.value && currentCompanyData.value) {
|
||||
await updateCompanyApi(
|
||||
currentCompanyData.value.id,
|
||||
submitData as CompanyDTO.UpdateCompanyDTO,
|
||||
);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createCompanyApi(submitData as CompanyDTO.CreateCompanyDTO);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
} catch (error) {
|
||||
console.error('保存公司失败:', error);
|
||||
message.error('保存公司失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理取消
|
||||
function handleCancel() {
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(
|
||||
editMode: boolean = false,
|
||||
companyData?: CompanyVO.CompanyInfoVO | null,
|
||||
) {
|
||||
isEdit.value = editMode;
|
||||
currentCompanyData.value = companyData || null;
|
||||
|
||||
resetForm(); // 先重置表单
|
||||
initFormData(); // 再初始化数据
|
||||
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
|
||||
// 选择logo文件
|
||||
function selectLogoFile() {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = 'image/*';
|
||||
input.style.display = 'none';
|
||||
document.body.append(input);
|
||||
|
||||
input.addEventListener('change', (e) => {
|
||||
const file = (e.target as HTMLInputElement).files?.[0];
|
||||
if (file) {
|
||||
// 验证文件
|
||||
const isImage = file.type.startsWith('image/');
|
||||
if (!isImage) {
|
||||
message.error('只能上传图片文件');
|
||||
input.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
const isLt2M = file.size / 1024 / 1024 < 2;
|
||||
if (!isLt2M) {
|
||||
message.error('图片大小不能超过 2MB');
|
||||
input.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置新选择的文件
|
||||
newLogoFile.value = file;
|
||||
imageLoadError.value = false; // 重置图片加载错误状态
|
||||
message.success('Logo选择成功');
|
||||
}
|
||||
|
||||
input.remove();
|
||||
});
|
||||
|
||||
input.click();
|
||||
}
|
||||
|
||||
// 重置新选择的logo
|
||||
function removeNewLogo() {
|
||||
newLogoFile.value = null;
|
||||
imageLoadError.value = false; // 重置图片加载错误状态
|
||||
message.success('已重置logo');
|
||||
}
|
||||
|
||||
// 上传Logo并获取图片ID
|
||||
async function uploadLogoAndGetId(): Promise<number | undefined> {
|
||||
if (!newLogoFile.value) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await uploadCompanyLogoApi(newLogoFile.value);
|
||||
return response.id;
|
||||
} catch (error) {
|
||||
console.error('Logo上传失败:', error);
|
||||
message.error('Logo上传失败');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// 图片加载错误处理
|
||||
function handleImageError(event: Event) {
|
||||
console.error('图片加载失败:', event);
|
||||
imageLoadError.value = true;
|
||||
message.error('图片加载失败,请重新选择');
|
||||
}
|
||||
|
||||
// 组件卸载时清理
|
||||
onUnmounted(() => {
|
||||
if (newLogoFile.value) {
|
||||
const url = URL.createObjectURL(newLogoFile.value);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="modalTitle" :confirm-loading="loading">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="公司Logo" name="logoImageId">
|
||||
<div style="display: flex; align-items: center; gap: 16px">
|
||||
<!-- Logo预览区域 -->
|
||||
<div style="position: relative; display: inline-block">
|
||||
<!-- 有图片时显示图片 -->
|
||||
<img
|
||||
v-if="currentLogoUrl && !imageLoadError"
|
||||
:src="currentLogoUrl"
|
||||
alt="公司Logo"
|
||||
style="
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #d9d9d9;
|
||||
background-color: #f5f5f5;
|
||||
"
|
||||
@error="handleImageError"
|
||||
/>
|
||||
<!-- 无图片或加载失败时显示空状态 -->
|
||||
<div
|
||||
v-else
|
||||
style="
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
border: 1px dashed #d9d9d9;
|
||||
border-radius: 8px;
|
||||
background-color: #fafafa;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
line-height: 1.2;
|
||||
"
|
||||
>
|
||||
<div
|
||||
style="
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
"
|
||||
>
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px" />
|
||||
<div>上传Logo</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 点击更换遮罩 -->
|
||||
<div
|
||||
style="
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s;
|
||||
cursor: pointer;
|
||||
"
|
||||
@mouseenter="($event.target as HTMLElement).style.opacity = '1'"
|
||||
@mouseleave="($event.target as HTMLElement).style.opacity = '0'"
|
||||
@click="selectLogoFile"
|
||||
>
|
||||
<div
|
||||
style="
|
||||
color: white;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
"
|
||||
>
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px" />
|
||||
<div style="font-size: 12px">
|
||||
{{
|
||||
currentLogoUrl && !imageLoadError ? '更换Logo' : '上传Logo'
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 重置按钮 -->
|
||||
<div v-if="newLogoFile">
|
||||
<Button size="small" @click="removeNewLogo">重置</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="公司名称"
|
||||
name="name"
|
||||
:rules="[{ required: true, message: '请输入公司名称' }]"
|
||||
>
|
||||
<Input v-model:value="formData.name" placeholder="请输入公司名称" />
|
||||
</Form.Item>
|
||||
|
||||
<!-- 仅创建时显示:拥有者信息 -->
|
||||
<template v-if="!isEdit">
|
||||
<Form.Item
|
||||
label="拥有者姓名"
|
||||
name="ownerName"
|
||||
:rules="[{ required: true, message: '请输入公司拥有者姓名' }]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.ownerName"
|
||||
placeholder="请输入公司拥有者姓名"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="拥有者电话"
|
||||
name="ownerPhone"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入公司拥有者电话' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码' },
|
||||
]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.ownerPhone"
|
||||
placeholder="请输入公司拥有者电话"
|
||||
/>
|
||||
</Form.Item>
|
||||
</template>
|
||||
|
||||
<Form.Item label="公司地址" name="address">
|
||||
<Input v-model:value="formData.address" placeholder="请输入公司地址" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="邮箱"
|
||||
name="email"
|
||||
:rules="[{ type: 'email', message: '请输入正确的邮箱地址' }]"
|
||||
>
|
||||
<Input v-model:value="formData.email" placeholder="请输入邮箱" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="正常"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="订阅到期时间" name="expireTime">
|
||||
<DatePicker
|
||||
v-model:value="formData.expireTime"
|
||||
placeholder="请选择订阅到期时间"
|
||||
style="width: 100%"
|
||||
show-time
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,414 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { CompanyDTO, CompanyVO } from '#/api/organization/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/organization/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>
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
<script lang="ts" setup>
|
||||
import type { DepartmentVO } from '#/api/organization/department';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, message, Select, Switch } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createDepartmentApi,
|
||||
updateDepartmentApi,
|
||||
} from '#/api/organization/department';
|
||||
|
||||
interface Props {
|
||||
departmentList: DepartmentVO.DepartmentInfoVO[];
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[500px]',
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentDepartmentData = ref<DepartmentVO.DepartmentInfoVO | null>(null);
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
name: string;
|
||||
parentId?: number;
|
||||
remark: string;
|
||||
status: boolean;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<FormData>({
|
||||
name: '',
|
||||
parentId: undefined,
|
||||
remark: '',
|
||||
status: true,
|
||||
});
|
||||
|
||||
// 开关组件不需要选项数组
|
||||
|
||||
// 父部门选项
|
||||
const parentDepartmentOptions = computed(() => {
|
||||
const options: Array<{ label: string; value: number | undefined }> = [
|
||||
{ label: '根部门', value: undefined },
|
||||
];
|
||||
|
||||
const addDepartmentOptions = (
|
||||
departments: DepartmentVO.DepartmentInfoVO[],
|
||||
level = 0,
|
||||
) => {
|
||||
departments.forEach((dept) => {
|
||||
// 编辑时排除自己和自己的子部门
|
||||
if (
|
||||
isEdit.value &&
|
||||
currentDepartmentData.value &&
|
||||
(dept.id === currentDepartmentData.value.id ||
|
||||
isChildDepartment(dept, currentDepartmentData.value.id))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const prefix = ' '.repeat(level);
|
||||
options.push({
|
||||
label: `${prefix}${dept.name}`,
|
||||
value: dept.id,
|
||||
});
|
||||
if (dept.children && dept.children.length > 0) {
|
||||
addDepartmentOptions(dept.children, level + 1);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
addDepartmentOptions(props.departmentList);
|
||||
return options;
|
||||
});
|
||||
|
||||
// 检查是否为子部门
|
||||
function isChildDepartment(
|
||||
department: DepartmentVO.DepartmentInfoVO,
|
||||
parentId: number,
|
||||
): boolean {
|
||||
if (department.children) {
|
||||
for (const child of department.children) {
|
||||
if (child.id === parentId || isChildDepartment(child, parentId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => (isEdit.value ? '编辑部门' : '添加部门'));
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
name: '',
|
||||
parentId: undefined,
|
||||
remark: '',
|
||||
status: true,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
// 处理模态框关闭
|
||||
function handleCancel() {
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
// 转换boolean值为number值
|
||||
const submitData = {
|
||||
...formData.value,
|
||||
status: formData.value.status ? 1 : 0,
|
||||
};
|
||||
|
||||
if (isEdit.value && currentDepartmentData.value) {
|
||||
await updateDepartmentApi(currentDepartmentData.value.id, submitData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createDepartmentApi(submitData);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
} catch (error) {
|
||||
console.error('保存部门失败:', error);
|
||||
message.error('保存部门失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(
|
||||
editMode: boolean = false,
|
||||
departmentData?: DepartmentVO.DepartmentInfoVO | null,
|
||||
) {
|
||||
isEdit.value = editMode;
|
||||
currentDepartmentData.value = departmentData || null;
|
||||
|
||||
resetForm();
|
||||
|
||||
if (editMode && departmentData) {
|
||||
formData.value = {
|
||||
name: departmentData.name,
|
||||
parentId: departmentData.parentId,
|
||||
remark: departmentData.remark || '',
|
||||
status: departmentData.status === 1, // 转换为boolean
|
||||
};
|
||||
}
|
||||
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="modalTitle" :confirm-loading="loading">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="父部门" name="parentId">
|
||||
<Select
|
||||
v-model:value="formData.parentId"
|
||||
placeholder="请选择父部门"
|
||||
:options="parentDepartmentOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="部门名称"
|
||||
name="name"
|
||||
:rules="[{ required: true, message: '请输入部门名称' }]"
|
||||
>
|
||||
<Input v-model:value="formData.name" placeholder="请输入部门名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="描述" name="remark">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.remark"
|
||||
placeholder="请输入部门描述"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,348 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type {
|
||||
DepartmentDTO,
|
||||
DepartmentVO,
|
||||
} from '#/api/organization/department';
|
||||
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 {
|
||||
deleteDepartmentApi,
|
||||
getDepartmentPageApi,
|
||||
} from '#/api/organization/department';
|
||||
|
||||
import DepartmentModal from './components/DepartmentModal.vue';
|
||||
|
||||
defineOptions({ name: 'DepartmentManagement' });
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const departmentModalRef = ref();
|
||||
const departmentList = ref<DepartmentVO.DepartmentInfoVO[]>([]);
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
parentId: undefined as number | undefined,
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
];
|
||||
|
||||
// 父部门选项
|
||||
const parentDepartmentOptions = computed(() => {
|
||||
const options: Array<{ label: string; value: number | undefined }> = [
|
||||
{ label: '根部门', value: undefined },
|
||||
];
|
||||
|
||||
const addDepartmentOptions = (
|
||||
departments: DepartmentVO.DepartmentInfoVO[],
|
||||
level = 0,
|
||||
) => {
|
||||
departments.forEach((dept) => {
|
||||
const prefix = ' '.repeat(level);
|
||||
options.push({
|
||||
label: `${prefix}${dept.name}`,
|
||||
value: dept.id,
|
||||
});
|
||||
if (dept.children && dept.children.length > 0) {
|
||||
addDepartmentOptions(dept.children, level + 1);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
addDepartmentOptions(departmentList.value);
|
||||
return options;
|
||||
});
|
||||
|
||||
// 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,
|
||||
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;
|
||||
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;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 查找父部门
|
||||
function findParentDepartment(
|
||||
departments: DepartmentVO.DepartmentInfoVO[],
|
||||
parentId: number,
|
||||
): DepartmentVO.DepartmentInfoVO | null {
|
||||
for (const dept of departments) {
|
||||
if (dept.id === parentId) {
|
||||
return dept;
|
||||
}
|
||||
if (dept.children) {
|
||||
const found = findParentDepartment(dept.children, parentId);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 搜索表单配置
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入部门名称(回车搜索)',
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
},
|
||||
fieldName: 'name',
|
||||
label: '部门名称',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择父部门',
|
||||
options: parentDepartmentOptions,
|
||||
allowClear: true,
|
||||
onChange: () => gridReloadRef.value?.(),
|
||||
},
|
||||
fieldName: 'parentId',
|
||||
label: '父部门',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: statusOptions,
|
||||
allowClear: true,
|
||||
onChange: () => gridReloadRef.value?.(),
|
||||
},
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理添加部门
|
||||
function handleAdd() {
|
||||
departmentModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑部门
|
||||
function handleEdit(record: DepartmentVO.DepartmentInfoVO) {
|
||||
departmentModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除部门
|
||||
async function handleDelete(record: DepartmentVO.DepartmentInfoVO) {
|
||||
try {
|
||||
await deleteDepartmentApi(record.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除部门失败:', error);
|
||||
message.error('删除部门失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功回调
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 创建 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>
|
||||
|
||||
<!-- 父部门列 -->
|
||||
<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>
|
||||
<Popconfirm
|
||||
title="确定要删除这个部门吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 部门模态框组件 -->
|
||||
<DepartmentModal
|
||||
ref="departmentModalRef"
|
||||
:department-list="departmentList"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,396 @@
|
||||
<script setup lang="ts">
|
||||
import type { PositionVO } from '#/api/organization/position/types';
|
||||
import type { PermissionVO } from '#/api/system/permission/types';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Flex,
|
||||
Input,
|
||||
message,
|
||||
Pagination,
|
||||
Select,
|
||||
Spin,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { getPositionPageApi } from '#/api/organization/position';
|
||||
import {
|
||||
batchUpdatePositionPermissionsApi,
|
||||
getPositionPermissionIdsApi,
|
||||
} from '#/api/organization/position-permission-assign/apis';
|
||||
import { getCompanyVisiblePermissionTreeApi } from '#/api/system/permission';
|
||||
|
||||
import TreeNodeContent from '#/views/system/company-permission-manage/components/TreeNodeContent.vue';
|
||||
|
||||
defineOptions({ name: 'PositionPermissionAssignPage' });
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({ name: '', status: undefined as number | undefined });
|
||||
|
||||
// 职位列表
|
||||
const positionList = ref<PositionVO.PositionInfoVO[]>([]);
|
||||
const positionLoading = ref(false);
|
||||
const positionPagination = ref({ current: 1, pageSize: 10, total: 0 });
|
||||
|
||||
// 当前选中的职位
|
||||
const currentPosition = ref<null | PositionVO.PositionInfoVO>(null);
|
||||
|
||||
// 权限树数据
|
||||
const permissionTree = ref<PermissionVO.PermissionInfoVO[]>([]);
|
||||
const permissionLoading = ref(false);
|
||||
|
||||
// 职位原始已分配的权限ID
|
||||
const assignedPermissionIds = ref<number[]>([]);
|
||||
// 用户当前选中的权限ID
|
||||
const selectedPermissionIds = ref<number[]>([]);
|
||||
|
||||
// 展开状态
|
||||
const expandedIds = ref<Set<number>>(new Set());
|
||||
|
||||
// 统计
|
||||
const stats = computed(() => ({
|
||||
total: countLeafPermissions(permissionTree.value),
|
||||
assigned: assignedPermissionIds.value.length,
|
||||
selected: selectedPermissionIds.value.length,
|
||||
changed: !sameArray(selectedPermissionIds.value, assignedPermissionIds.value),
|
||||
}));
|
||||
|
||||
function sameArray(a: number[], b: number[]): boolean {
|
||||
if (a.length !== b.length) return false;
|
||||
const sa = new Set(a);
|
||||
return b.every((id) => sa.has(id));
|
||||
}
|
||||
|
||||
// 搜索职位列表
|
||||
async function searchPositions() {
|
||||
positionLoading.value = true;
|
||||
try {
|
||||
const result = await getPositionPageApi({
|
||||
page: positionPagination.value.current,
|
||||
pageSize: positionPagination.value.pageSize,
|
||||
filters: { name: searchForm.value.name || undefined, status: searchForm.value.status },
|
||||
});
|
||||
positionList.value = result.records;
|
||||
positionPagination.value.total = result.total;
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取职位列表失败');
|
||||
} finally {
|
||||
positionLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 选择职位(切换公司时重载权限树,同公司内只更新已选状态)
|
||||
async function selectPosition(position: PositionVO.PositionInfoVO) {
|
||||
const isCompanyChanged = currentPosition.value?.companyId !== position.companyId;
|
||||
currentPosition.value = position;
|
||||
await loadAssignedPermissions();
|
||||
if (isCompanyChanged) {
|
||||
await loadPermissionTree();
|
||||
}
|
||||
}
|
||||
|
||||
// 加载职位已分配的权限ID
|
||||
async function loadAssignedPermissions() {
|
||||
if (!currentPosition.value?.id) return;
|
||||
permissionLoading.value = true;
|
||||
try {
|
||||
const result = await getPositionPermissionIdsApi(currentPosition.value.id);
|
||||
assignedPermissionIds.value = result || [];
|
||||
selectedPermissionIds.value = [...assignedPermissionIds.value];
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取职位权限失败');
|
||||
} finally {
|
||||
permissionLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 加载权限树(公司的可见权限树,职位只能分配公司已有的权限)
|
||||
async function loadPermissionTree() {
|
||||
if (!currentPosition.value?.companyId) return;
|
||||
try {
|
||||
const result = await getCompanyVisiblePermissionTreeApi();
|
||||
permissionTree.value = result || [];
|
||||
expandedIds.value = new Set(result?.map((n: PermissionVO.PermissionInfoVO) => n.id) || []);
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取权限树失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 保存权限分配(只保存叶子权限节点,模块节点仅作视觉分组)
|
||||
async function savePermissions() {
|
||||
if (!currentPosition.value?.id) return;
|
||||
// 过滤掉模块节点,只保留叶子权限
|
||||
const leafIds = selectedPermissionIds.value.filter((id) => {
|
||||
const node = findNode(permissionTree.value, id);
|
||||
return node && (!node.children || node.children.length === 0);
|
||||
});
|
||||
try {
|
||||
await batchUpdatePositionPermissionsApi(currentPosition.value.id, leafIds);
|
||||
message.success('权限分配保存成功');
|
||||
assignedPermissionIds.value = [...leafIds];
|
||||
selectedPermissionIds.value = [...leafIds];
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
function resetSearch() {
|
||||
searchForm.value = { name: '', status: undefined };
|
||||
positionPagination.value.current = 1;
|
||||
searchPositions();
|
||||
}
|
||||
|
||||
function handlePageChange(page: number, pageSize: number) {
|
||||
positionPagination.value.current = page;
|
||||
positionPagination.value.pageSize = pageSize;
|
||||
searchPositions();
|
||||
}
|
||||
|
||||
// 统计叶子权限数
|
||||
function countLeafPermissions(nodes: PermissionVO.PermissionInfoVO[]): number {
|
||||
let count = 0;
|
||||
for (const node of nodes) {
|
||||
if (node.children && node.children.length > 0) count += countLeafPermissions(node.children);
|
||||
else count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// 获取所有叶子权限ID
|
||||
function getAllLeafIds(nodes: PermissionVO.PermissionInfoVO[]): number[] {
|
||||
const result: number[] = [];
|
||||
for (const node of nodes) {
|
||||
if (!node.children || node.children.length === 0) result.push(node.id);
|
||||
else result.push(...getAllLeafIds(node.children));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 全选
|
||||
function selectAll() {
|
||||
selectedPermissionIds.value = getAllLeafIds(permissionTree.value);
|
||||
}
|
||||
|
||||
// 取消全选
|
||||
function selectNone() {
|
||||
selectedPermissionIds.value = [];
|
||||
}
|
||||
|
||||
// 单个 checkbox 变化
|
||||
function onCheck(permissionId: number, checked: boolean) {
|
||||
if (checked) {
|
||||
const toAdd = new Set<number>([permissionId]);
|
||||
getParentChain(permissionTree.value, permissionId).forEach((id) => toAdd.add(id));
|
||||
getDescendantIds(permissionTree.value, permissionId).forEach((id) => toAdd.add(id));
|
||||
const newSet = new Set(selectedPermissionIds.value);
|
||||
toAdd.forEach((id) => newSet.add(id));
|
||||
selectedPermissionIds.value = Array.from(newSet);
|
||||
} else {
|
||||
const toRemove = new Set<number>([permissionId, ...getDescendantIds(permissionTree.value, permissionId)]);
|
||||
selectedPermissionIds.value = selectedPermissionIds.value.filter((id) => !toRemove.has(id));
|
||||
}
|
||||
}
|
||||
|
||||
// 递归获取父节点链
|
||||
function getParentChain(nodes: PermissionVO.PermissionInfoVO[], targetId: number, path: number[] = []): number[] {
|
||||
for (const node of nodes) {
|
||||
if (node.id === targetId) return [...path, node.id];
|
||||
if (node.children) {
|
||||
const found = getParentChain(node.children, targetId, [...path, node.id]);
|
||||
if (found.length > 0) return found;
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
// 递归获取某节点下所有子孙ID
|
||||
function getDescendantIds(nodes: PermissionVO.PermissionInfoVO[], permissionId: number): number[] {
|
||||
const node = findNode(nodes, permissionId);
|
||||
if (!node || !node.children) return [];
|
||||
const result: number[] = [];
|
||||
function collect(n: PermissionVO.PermissionInfoVO) {
|
||||
if (n.children) {
|
||||
for (const child of n.children) {
|
||||
result.push(child.id);
|
||||
collect(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const child of node.children) {
|
||||
result.push(child.id);
|
||||
collect(child);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 递归查找节点
|
||||
function findNode(nodes: PermissionVO.PermissionInfoVO[], id: number): PermissionVO.PermissionInfoVO | null {
|
||||
for (const node of nodes) {
|
||||
if (node.id === id) return node;
|
||||
if (node.children) {
|
||||
const found = findNode(node.children, id);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 展开/收起
|
||||
function toggleExpand(nodeId: number) {
|
||||
const newSet = new Set(expandedIds.value);
|
||||
if (newSet.has(nodeId)) newSet.delete(nodeId);
|
||||
else newSet.add(nodeId);
|
||||
expandedIds.value = newSet;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
searchPositions();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page :auto-content-height="true">
|
||||
<Flex gap="middle" class="h-full">
|
||||
<!-- 左栏:职位列表 -->
|
||||
<Card
|
||||
title="职位列表"
|
||||
class="flex h-full max-w-[400px] flex-col"
|
||||
:body-style="{ height: '100%', display: 'flex', flexDirection: 'column', gap: '10px' }"
|
||||
>
|
||||
<Flex class="flex-wrap gap-2">
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入职位名称"
|
||||
allow-clear
|
||||
style="width: 200px; margin-right: 8px"
|
||||
/>
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
placeholder="请选择状态"
|
||||
allow-clear
|
||||
style="width: 120px; margin-right: 8px"
|
||||
>
|
||||
<Select.Option :value="1">启用</Select.Option>
|
||||
<Select.Option :value="0">禁用</Select.Option>
|
||||
</Select>
|
||||
<Button type="primary" @click="searchPositions">搜索</Button>
|
||||
<Button @click="resetSearch">重置</Button>
|
||||
</Flex>
|
||||
|
||||
<Flex vertical class="flex-1">
|
||||
<Spin :spinning="positionLoading">
|
||||
<div class="flex-1">
|
||||
<Card
|
||||
v-for="position in positionList"
|
||||
:key="position.id"
|
||||
hoverable
|
||||
size="small"
|
||||
:body-style="{ padding: '10px 12px' }"
|
||||
class="mb-2 cursor-pointer transition-all duration-200"
|
||||
:class="[currentPosition?.id === position.id && 'ring-primary shadow ring-1']"
|
||||
@click="selectPosition(position)"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<div class="min-w-0">
|
||||
<div class="mb-1 flex items-center gap-2">
|
||||
<span
|
||||
class="inline-block h-2 w-2 rounded-full"
|
||||
:class="position.status === 1 ? 'bg-green-500' : 'bg-red-500'"
|
||||
></span>
|
||||
<span class="truncate text-sm font-semibold text-[var(--text-primary)]">
|
||||
{{ position.name }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="text-xs text-[var(--text-secondary)]">编码:{{ position.code }}</div>
|
||||
</div>
|
||||
<Tag :color="position.status === 1 ? 'green' : 'red'">
|
||||
{{ position.status === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</Spin>
|
||||
|
||||
<Flex justify="center" class="mt-2">
|
||||
<Pagination
|
||||
v-model:current="positionPagination.current"
|
||||
v-model:page-size="positionPagination.pageSize"
|
||||
:total="positionPagination.total"
|
||||
:show-size-changer="true"
|
||||
:show-quick-jumper="true"
|
||||
@change="handlePageChange"
|
||||
/>
|
||||
</Flex>
|
||||
</Flex>
|
||||
</Card>
|
||||
|
||||
<!-- 右栏:职位权限分配 -->
|
||||
<Card
|
||||
title="职位权限分配"
|
||||
class="flex h-full flex-1 flex-col"
|
||||
:body-style="{ height: '100%' }"
|
||||
>
|
||||
<template v-if="currentPosition">
|
||||
<!-- 头部 -->
|
||||
<div class="mb-4 rounded bg-gray-50 p-4 dark:bg-neutral-800">
|
||||
<div class="mb-3 flex items-center justify-between gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-base font-semibold">{{ currentPosition.name }}</span>
|
||||
<Tag :color="currentPosition.status === 1 ? 'green' : 'red'">
|
||||
{{ currentPosition.status === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button @click="selectNone">取消全选</Button>
|
||||
<Button type="primary" @click="selectAll">一键全选</Button>
|
||||
<Button type="primary" :disabled="!stats.changed" @click="savePermissions">
|
||||
保存权限
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-6 text-xs text-gray-500">
|
||||
<span>编码:{{ currentPosition.code }}</span>
|
||||
<span>全部叶子权限:<span class="font-semibold">{{ stats.total }}</span></span>
|
||||
<span>已分配:<span class="font-semibold text-green-600">{{ stats.assigned }}</span></span>
|
||||
<span>当前选择:<span class="font-semibold" :class="stats.changed ? 'text-orange-500' : 'text-green-600'">{{ stats.selected }}</span></span>
|
||||
<span v-if="stats.changed" class="text-orange-500">(有未保存的更改)</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 权限树 -->
|
||||
<div class="min-h-0 flex-1 overflow-y-auto">
|
||||
<Spin :spinning="permissionLoading">
|
||||
<div v-if="permissionTree.length > 0" class="py-2">
|
||||
<TreeNodeContent
|
||||
v-for="node in permissionTree"
|
||||
:key="node.id"
|
||||
:node="node"
|
||||
:level="0"
|
||||
:expanded-ids="expandedIds"
|
||||
:selected-ids="selectedPermissionIds"
|
||||
@toggle="toggleExpand"
|
||||
@check="onCheck"
|
||||
/>
|
||||
</div>
|
||||
<div v-else-if="!permissionLoading" class="py-8 text-center text-gray-500">
|
||||
暂无可分配的权限
|
||||
</div>
|
||||
</Spin>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-else class="flex h-full flex-1 items-center justify-center text-gray-500">
|
||||
<div class="text-center">
|
||||
<div class="mb-4 text-5xl">👈</div>
|
||||
<div class="text-base">请先选择一个职位</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</Flex>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,521 @@
|
||||
<script setup lang="ts">
|
||||
import type { CompanyMenuVO } from '#/api/organization/company-menu/types';
|
||||
import type { PositionVO } from '#/api/organization/position/types';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Flex,
|
||||
Input,
|
||||
message,
|
||||
Pagination,
|
||||
Select,
|
||||
Spin,
|
||||
Tree,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { getCompanyMenuTreeApi } from '#/api/organization/company-menu';
|
||||
import { getPositionPageApi } from '#/api/organization/position';
|
||||
import {
|
||||
batchUpdatePositionMenusApi,
|
||||
getPositionMenuIdsApi,
|
||||
} from '#/api/organization/position-permission';
|
||||
|
||||
defineOptions({
|
||||
name: 'PositionPermissionPage',
|
||||
});
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 职位列表
|
||||
const positionList = ref<PositionVO.PositionInfoVO[]>([]);
|
||||
const positionLoading = ref(false);
|
||||
const positionPagination = ref({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
// 当前选中的职位
|
||||
const currentPosition = ref<null | PositionVO.PositionInfoVO>(null);
|
||||
|
||||
// 公司菜单树数据
|
||||
const companyMenuTree = ref<CompanyMenuVO.CompanyMenuInfo[]>([]);
|
||||
const menuTreeLoading = ref(false);
|
||||
|
||||
// 职位权限菜单ID列表
|
||||
const positionMenuIds = ref<number[]>([]);
|
||||
const permissionLoading = ref(false);
|
||||
|
||||
// 选中的菜单ID(用于树形控件)
|
||||
const checkedKeys = ref<number[]>([]);
|
||||
const expandedKeys = ref<number[]>([]);
|
||||
|
||||
// 不区分超管与普通菜单
|
||||
|
||||
// 搜索职位列表
|
||||
async function searchPositions() {
|
||||
positionLoading.value = true;
|
||||
try {
|
||||
const params = {
|
||||
page: positionPagination.value.current,
|
||||
pageSize: positionPagination.value.pageSize,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
|
||||
const result = await getPositionPageApi(params);
|
||||
positionList.value = result.records;
|
||||
positionPagination.value.total = result.total;
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取职位列表失败');
|
||||
} finally {
|
||||
positionLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 加载公司菜单树
|
||||
async function loadCompanyMenuTree() {
|
||||
menuTreeLoading.value = true;
|
||||
try {
|
||||
const result = await getCompanyMenuTreeApi();
|
||||
companyMenuTree.value = result;
|
||||
// 自动展开所有节点
|
||||
expandedKeys.value = getAllMenuIds(result);
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取菜单树失败');
|
||||
} finally {
|
||||
menuTreeLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取所有菜单ID(递归)
|
||||
function getAllMenuIds(menus: CompanyMenuVO.CompanyMenuInfo[]): number[] {
|
||||
const ids: number[] = [];
|
||||
function traverse(menuList: CompanyMenuVO.CompanyMenuInfo[]) {
|
||||
menuList.forEach((menu) => {
|
||||
ids.push(menu.id);
|
||||
if (menu.children && menu.children.length > 0) {
|
||||
traverse(menu.children);
|
||||
}
|
||||
});
|
||||
}
|
||||
traverse(menus);
|
||||
return ids;
|
||||
}
|
||||
|
||||
// 将菜单数据转换为Tree组件需要的格式
|
||||
function convertToTreeData(menus: CompanyMenuVO.CompanyMenuInfo[]): any[] {
|
||||
return menus.map((menu) => ({
|
||||
key: menu.id,
|
||||
title: menu.name,
|
||||
type: menu.type,
|
||||
superMenu: menu.superMenu,
|
||||
status: menu.status,
|
||||
disabled: menu.status === 0,
|
||||
children:
|
||||
menu.children && menu.children.length > 0
|
||||
? convertToTreeData(menu.children)
|
||||
: undefined,
|
||||
}));
|
||||
}
|
||||
|
||||
// 选择职位
|
||||
async function selectPosition(position: PositionVO.PositionInfoVO) {
|
||||
currentPosition.value = position;
|
||||
await loadPositionPermissions();
|
||||
}
|
||||
|
||||
// 加载职位权限
|
||||
async function loadPositionPermissions() {
|
||||
if (!currentPosition.value?.id) return;
|
||||
|
||||
permissionLoading.value = true;
|
||||
try {
|
||||
const result = await getPositionMenuIdsApi(currentPosition.value.id);
|
||||
positionMenuIds.value = result;
|
||||
|
||||
// 清理根节点,只保留叶子节点
|
||||
const leafMenuIds = cleanRootNodes(result);
|
||||
checkedKeys.value = leafMenuIds;
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取职位菜单失败');
|
||||
} finally {
|
||||
permissionLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 清理根节点,只保留叶子节点
|
||||
function cleanRootNodes(menuIds: number[]): number[] {
|
||||
return menuIds.filter((menuId) => {
|
||||
const menu = findMenuById(menuId);
|
||||
if (!menu) return false;
|
||||
|
||||
// 检查是否有其他菜单将此菜单作为父菜单
|
||||
const hasChildren = hasMenuChildren(menuId);
|
||||
|
||||
// 只保留叶子节点(没有子节点的菜单)
|
||||
return !hasChildren;
|
||||
});
|
||||
}
|
||||
|
||||
// 根据ID查找菜单
|
||||
function findMenuById(menuId: number): CompanyMenuVO.CompanyMenuInfo | null {
|
||||
function search(
|
||||
menus: CompanyMenuVO.CompanyMenuInfo[],
|
||||
): CompanyMenuVO.CompanyMenuInfo | null {
|
||||
for (const menu of menus) {
|
||||
if (menu.id === menuId) return menu;
|
||||
if (menu.children && menu.children.length > 0) {
|
||||
const found = search(menu.children);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return search(companyMenuTree.value);
|
||||
}
|
||||
|
||||
// 检查菜单是否有子菜单
|
||||
function hasMenuChildren(menuId: number): boolean {
|
||||
function search(menus: CompanyMenuVO.CompanyMenuInfo[]): boolean {
|
||||
for (const menu of menus) {
|
||||
if (menu.children && menu.children.length > 0) {
|
||||
if (menu.children.some((child) => child.id === menuId)) return true;
|
||||
if (search(menu.children)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return search(companyMenuTree.value);
|
||||
}
|
||||
|
||||
// 确保提交时包含必要的父菜单ID(递归添加所有层级的父菜单)
|
||||
function ensureParentMenuIds(menuIds: number[]): number[] {
|
||||
const result = new Set(menuIds);
|
||||
|
||||
// 递归添加所有父菜单ID
|
||||
function addAllParentIds(menuId: number) {
|
||||
const menu = findMenuById(menuId);
|
||||
if (menu && menu.parentId) {
|
||||
result.add(menu.parentId);
|
||||
// 递归添加父菜单的父菜单
|
||||
addAllParentIds(menu.parentId);
|
||||
}
|
||||
}
|
||||
|
||||
// 为每个选中的菜单添加其所有父菜单ID
|
||||
menuIds.forEach((menuId) => {
|
||||
addAllParentIds(menuId);
|
||||
});
|
||||
|
||||
return [...result];
|
||||
}
|
||||
|
||||
// 保存职位权限
|
||||
async function savePositionPermissions() {
|
||||
if (!currentPosition.value?.id) return;
|
||||
|
||||
try {
|
||||
// 确保提交时包含必要的父菜单ID
|
||||
const finalMenuIds = ensureParentMenuIds(checkedKeys.value);
|
||||
await batchUpdatePositionMenusApi(currentPosition.value.id, finalMenuIds);
|
||||
message.success('权限配置保存成功');
|
||||
|
||||
// 重新加载权限数据
|
||||
await loadPositionPermissions();
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '保存菜单失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 一键全选
|
||||
function handleSelectAll() {
|
||||
// 获取所有可选择的菜单ID(排除禁用的)
|
||||
const selectableMenus = getAllSelectableMenus();
|
||||
|
||||
// 只选择叶子节点(没有子节点的菜单)
|
||||
const leafMenus = selectableMenus.filter((menu) => {
|
||||
return !hasMenuChildren(menu.id);
|
||||
});
|
||||
|
||||
// 全选所有叶子节点
|
||||
checkedKeys.value = leafMenus.map((menu) => menu.id);
|
||||
}
|
||||
|
||||
// 取消全选
|
||||
function handleSelectNone() {
|
||||
// 取消所有叶子节点的选中状态
|
||||
const allLeafMenuIds = new Set(
|
||||
getAllSelectableMenus()
|
||||
.filter((menu) => !hasMenuChildren(menu.id))
|
||||
.map((menu) => menu.id),
|
||||
);
|
||||
|
||||
checkedKeys.value = checkedKeys.value.filter((id) => !allLeafMenuIds.has(id));
|
||||
}
|
||||
|
||||
// 获取所有可选择的菜单
|
||||
function getAllSelectableMenus(): CompanyMenuVO.CompanyMenuInfo[] {
|
||||
const result: CompanyMenuVO.CompanyMenuInfo[] = [];
|
||||
|
||||
function traverse(menus: CompanyMenuVO.CompanyMenuInfo[]) {
|
||||
menus.forEach((menu) => {
|
||||
if (menu.status === 1) {
|
||||
// 只包含启用的菜单
|
||||
result.push(menu);
|
||||
}
|
||||
if (menu.children && menu.children.length > 0) {
|
||||
traverse(menu.children);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
traverse(companyMenuTree.value);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 处理树形控件的选中变化
|
||||
function handleTreeCheckChange(checkedKeysValue: any) {
|
||||
checkedKeys.value = checkedKeysValue;
|
||||
}
|
||||
|
||||
// 计算统计信息
|
||||
const stats = computed(() => {
|
||||
const totalMenus = getAllSelectableMenus().length;
|
||||
const positionMenus = positionMenuIds.value.length;
|
||||
const selectedMenus = ensureParentMenuIds(checkedKeys.value).length;
|
||||
return {
|
||||
total: totalMenus,
|
||||
position: positionMenus,
|
||||
selected: selectedMenus,
|
||||
};
|
||||
});
|
||||
|
||||
// 重置搜索
|
||||
function resetSearch() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
status: undefined,
|
||||
};
|
||||
positionPagination.value.current = 1;
|
||||
searchPositions();
|
||||
}
|
||||
|
||||
// 分页变化
|
||||
function handlePageChange(page: number, pageSize: number) {
|
||||
positionPagination.value.current = page;
|
||||
positionPagination.value.pageSize = pageSize;
|
||||
searchPositions();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
searchPositions();
|
||||
loadCompanyMenuTree();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page :auto-content-height="true">
|
||||
<Flex gap="middle" class="h-full">
|
||||
<!-- 左栏:职位列表 -->
|
||||
<Card
|
||||
title="职位列表"
|
||||
class="flex h-full max-w-[400px] flex-col"
|
||||
:body-style="{
|
||||
height: '100%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: '10px',
|
||||
}"
|
||||
>
|
||||
<!-- 搜索区域 -->
|
||||
<Flex class="flex-wrap gap-2">
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入职位名称"
|
||||
allow-clear
|
||||
style="width: 200px; margin-right: 8px"
|
||||
/>
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
placeholder="请选择状态"
|
||||
allow-clear
|
||||
style="width: 120px; margin-right: 8px"
|
||||
>
|
||||
<Select.Option :value="1">启用</Select.Option>
|
||||
<Select.Option :value="0">禁用</Select.Option>
|
||||
</Select>
|
||||
<Button type="primary" @click="searchPositions"> 搜索 </Button>
|
||||
<Button @click="resetSearch"> 重置 </Button>
|
||||
</Flex>
|
||||
|
||||
<!-- 职位列表区域 -->
|
||||
<Flex vertical class="flex-1">
|
||||
<!-- 职位列表 -->
|
||||
<Flex vertical class="flex-1">
|
||||
<Spin :spinning="positionLoading">
|
||||
<Card
|
||||
v-for="position in positionList"
|
||||
:key="position.id"
|
||||
hoverable
|
||||
size="small"
|
||||
:body-style="{ padding: '10px 12px' }"
|
||||
class="group mb-2 cursor-pointer transition-all duration-200"
|
||||
:class="[
|
||||
currentPosition?.id === position.id &&
|
||||
'ring-primary shadow ring-1',
|
||||
]"
|
||||
@click="selectPosition(position)"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<div class="min-w-0">
|
||||
<div class="mb-1 flex items-center gap-2">
|
||||
<span
|
||||
class="inline-block h-2 w-2 rounded-full"
|
||||
:class="
|
||||
position.status === 1 ? 'bg-green-500' : 'bg-red-500'
|
||||
"
|
||||
></span>
|
||||
<span
|
||||
class="truncate text-sm font-semibold text-[var(--text-primary)]"
|
||||
>
|
||||
{{ position.name }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mb-1 text-xs text-[var(--text-secondary)]">
|
||||
编码:{{ position.code }}
|
||||
</div>
|
||||
<div
|
||||
v-if="position.remark"
|
||||
class="truncate text-xs text-[var(--text-secondary)]"
|
||||
>
|
||||
{{ position.remark }}
|
||||
</div>
|
||||
</div>
|
||||
<Tag :color="position.status === 1 ? 'green' : 'red'">
|
||||
{{ position.status === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</div>
|
||||
</Card>
|
||||
</Spin>
|
||||
</Flex>
|
||||
<!-- 分页器 -->
|
||||
<Flex justify="center">
|
||||
<Pagination
|
||||
v-model:current="positionPagination.current"
|
||||
v-model:page-size="positionPagination.pageSize"
|
||||
:total="positionPagination.total"
|
||||
:show-size-changer="true"
|
||||
:show-quick-jumper="true"
|
||||
:show-total="(total) => `共 ${total} 条`"
|
||||
@change="handlePageChange"
|
||||
/>
|
||||
</Flex>
|
||||
</Flex>
|
||||
</Card>
|
||||
|
||||
<!-- 右栏:权限管理 -->
|
||||
<Card
|
||||
title="职位菜单分配"
|
||||
class="flex h-full flex-1 flex-col"
|
||||
:body-style="{ height: '100%' }"
|
||||
>
|
||||
<template v-if="currentPosition">
|
||||
<!-- 职位信息 + 统计与操作 -->
|
||||
<div class="mb-4 rounded bg-gray-50 p-4 dark:bg-neutral-800">
|
||||
<div class="mb-3 flex items-center justify-between gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-base font-semibold">{{
|
||||
currentPosition.name
|
||||
}}</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button @click="handleSelectNone">取消全选</Button>
|
||||
<Button type="primary" @click="handleSelectAll">
|
||||
一键全选
|
||||
</Button>
|
||||
<Button type="primary" @click="savePositionPermissions">
|
||||
保存菜单
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-6 text-xs text-gray-500">
|
||||
<span>编码:{{ currentPosition.code }}</span>
|
||||
<span class="flex items-center gap-1">
|
||||
<span class="text-[var(--text-secondary)]">系统菜单:</span>
|
||||
<span class="text-sm font-semibold">{{ stats.total }}</span>
|
||||
</span>
|
||||
<span class="flex items-center gap-1">
|
||||
<span class="text-[var(--text-secondary)]">已配置:</span>
|
||||
<span class="text-sm font-semibold text-[var(--success)]">{{
|
||||
stats.position
|
||||
}}</span>
|
||||
</span>
|
||||
<span class="flex items-center gap-1">
|
||||
<span class="text-[var(--text-secondary)]">当前选择:</span>
|
||||
<span class="text-sm font-semibold text-[var(--primary)]">{{
|
||||
stats.selected
|
||||
}}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 菜单树 -->
|
||||
<div class="min-h-0 flex-1 overflow-y-auto">
|
||||
<Spin :spinning="permissionLoading">
|
||||
<Tree
|
||||
v-model:checked-keys="checkedKeys"
|
||||
v-model:expanded-keys="expandedKeys"
|
||||
:tree-data="convertToTreeData(companyMenuTree)"
|
||||
checkable
|
||||
block-node
|
||||
class="rounded border"
|
||||
@check="handleTreeCheckChange"
|
||||
>
|
||||
<template #title="{ title, status, disabled }">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-medium">{{ title }}</span>
|
||||
<span
|
||||
v-if="status === 0"
|
||||
class="rounded bg-red-50 px-1.5 py-0.5 text-xs text-red-600 dark:bg-red-900/30"
|
||||
>
|
||||
已禁用
|
||||
</span>
|
||||
<span
|
||||
v-if="disabled"
|
||||
class="rounded bg-red-50 px-1.5 py-0.5 text-xs text-red-600 dark:bg-red-900/30"
|
||||
>
|
||||
不可选择
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</Tree>
|
||||
</Spin>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-else class="flex h-full flex-1 items-center justify-center">
|
||||
<div class="text-center text-gray-500">
|
||||
<div class="mb-4 text-5xl">👈</div>
|
||||
<div class="text-base">请先选择一个职位</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</Flex>
|
||||
<!-- <div class="flex h-full gap-4 max-lg:flex-col">
|
||||
|
||||
</div> -->
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,190 @@
|
||||
<script lang="ts" setup>
|
||||
import type { PositionVO } from '#/api/organization/position';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, message, Select, Switch } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createPositionApi,
|
||||
updatePositionApi,
|
||||
} from '#/api/organization/position';
|
||||
|
||||
interface Props {
|
||||
departmentOptions: Array<{ label: string; value: number }>;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[500px]',
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentPositionData = ref<null | PositionVO.PositionInfoVO>(null);
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
name: string;
|
||||
code: string;
|
||||
departmentId?: number;
|
||||
remark: string;
|
||||
status: boolean;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<FormData>({
|
||||
name: '',
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: true,
|
||||
});
|
||||
|
||||
// 开关组件不需要选项数组
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => (isEdit.value ? '编辑职位' : '添加职位'));
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
name: '',
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: true,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
// 处理模态框关闭
|
||||
function handleCancel() {
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
// 转换boolean值为number值
|
||||
const submitData = {
|
||||
...formData.value,
|
||||
status: formData.value.status ? 1 : 0,
|
||||
};
|
||||
|
||||
if (isEdit.value && currentPositionData.value) {
|
||||
await updatePositionApi(currentPositionData.value.id, submitData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createPositionApi(submitData);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
} catch (error) {
|
||||
console.error('保存职位失败:', error);
|
||||
message.error('保存职位失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(
|
||||
editMode: boolean = false,
|
||||
positionData?: null | PositionVO.PositionInfoVO,
|
||||
) {
|
||||
isEdit.value = editMode;
|
||||
currentPositionData.value = positionData || null;
|
||||
|
||||
resetForm();
|
||||
|
||||
if (editMode && positionData) {
|
||||
formData.value = {
|
||||
name: positionData.name,
|
||||
code: positionData.code || '',
|
||||
departmentId: positionData.departmentId,
|
||||
remark: positionData.remark || '',
|
||||
status: positionData.status === 1, // 转换为boolean
|
||||
};
|
||||
}
|
||||
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="modalTitle" :confirm-loading="loading">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item
|
||||
label="职位名称"
|
||||
name="name"
|
||||
:rules="[{ required: true, message: '请输入职位名称' }]"
|
||||
>
|
||||
<Input v-model:value="formData.name" placeholder="请输入职位名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="职位编码" name="code">
|
||||
<Input v-model:value="formData.code" placeholder="请输入职位编码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="所属部门" name="departmentId">
|
||||
<Select
|
||||
v-model:value="formData.departmentId"
|
||||
placeholder="请选择所属部门"
|
||||
:options="departmentOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="描述" name="remark">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.remark"
|
||||
placeholder="请输入职位描述"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,295 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { PositionDTO, PositionVO } from '#/api/organization/position';
|
||||
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 {
|
||||
deletePositionApi,
|
||||
getPositionPageApi,
|
||||
} from '#/api/organization/position';
|
||||
|
||||
import PositionModal from './components/PositionModal.vue';
|
||||
|
||||
defineOptions({ name: 'PositionManagement' });
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const positionModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
];
|
||||
|
||||
// 部门选项(这里需要根据实际情况获取部门列表)
|
||||
const departmentOptions = ref([
|
||||
{ label: '技术部', value: 1 },
|
||||
{ label: '产品部', value: 2 },
|
||||
{ label: '运营部', value: 3 },
|
||||
{ label: '市场部', value: 4 },
|
||||
]);
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '职位名称',
|
||||
minWidth: 150,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
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,
|
||||
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;
|
||||
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 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 handleAdd() {
|
||||
positionModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑职位
|
||||
function handleEdit(record: PositionVO.PositionInfoVO) {
|
||||
positionModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除职位
|
||||
async function handleDelete(record: PositionVO.PositionInfoVO) {
|
||||
try {
|
||||
await deletePositionApi(record.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除职位失败:', error);
|
||||
message.error('删除职位失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功回调
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '职位管理',
|
||||
});
|
||||
</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>
|
||||
|
||||
<!-- 所属部门列 -->
|
||||
<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>
|
||||
<Popconfirm
|
||||
title="确定要删除这个职位吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 职位模态框组件 -->
|
||||
<PositionModal
|
||||
ref="positionModalRef"
|
||||
:department-options="departmentOptions"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user