prettier: 代码格式化

This commit is contained in:
ah--desktop
2025-10-31 22:42:03 +08:00
parent 91ee49f45f
commit dfc6de49e0
62 changed files with 6814 additions and 5256 deletions
@@ -1,31 +1,37 @@
<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
import type {
SuperAccountDTO,
SuperAccountVO,
} from '#/api/organization/account-super';
import {
super_createAccountApi,
import { computed, ref, watch } from 'vue';
import { Form, Input, message, Modal, Select } from 'ant-design-vue';
import {
super_createAccountApi,
super_updateAccountApi,
type SuperAccountVO,
type SuperAccountDTO
} from '#/api/organization/account-super';
interface Emits {
(e: 'success'): void;
}
const emit = defineEmits<Emits>();
defineOptions({ name: 'SuperAccountFormModal' });
const emit = defineEmits<Emits>();
// 响应式数据
const formRef = ref();
const loading = ref(false);
const visible = ref(false);
const isEdit = ref(false);
const currentAccountData = ref<SuperAccountVO.AccountInfoVO | null>(null);
const currentAccountData = ref<null | SuperAccountVO.AccountInfoVO>(null);
// 表单数据
const formData = ref<SuperAccountDTO.SuperCreateAccountDTO & { status?: number }>({
const formData = ref<
SuperAccountDTO.SuperCreateAccountDTO & { status?: number }
>({
loginCode: '',
password: '',
realName: '',
@@ -40,7 +46,7 @@ const formData = ref<SuperAccountDTO.SuperCreateAccountDTO & { status?: number }
});
// 模态框标题
const modalTitle = computed(() => isEdit.value ? '编辑账户' : '添加账户');
const modalTitle = computed(() => (isEdit.value ? '编辑账户' : '添加账户'));
// 状态选项
const statusOptions = [
@@ -74,12 +80,12 @@ function handleCancel() {
}
// 暴露给父组件的方法
function open(accountData?: SuperAccountVO.AccountInfoVO | null) {
function open(accountData?: null | SuperAccountVO.AccountInfoVO) {
isEdit.value = !!accountData;
currentAccountData.value = accountData || null;
resetForm();
if (accountData) {
formData.value = {
loginCode: accountData.loginCode,
@@ -95,7 +101,7 @@ function open(accountData?: SuperAccountVO.AccountInfoVO | null) {
status: accountData.status,
};
}
visible.value = true;
}
@@ -104,21 +110,22 @@ async function handleSubmit() {
try {
await formRef.value?.validate();
loading.value = true;
if (isEdit.value && currentAccountData.value) {
const { password, ...updateData } = formData.value;
const { password: _, ...updateData } = formData.value;
await super_updateAccountApi(currentAccountData.value.id, updateData);
message.success('更新成功');
} else {
await super_createAccountApi(formData.value);
message.success('创建成功');
}
visible.value = false;
emit('success');
} catch (error: any) {
console.error('保存账户失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '保存账户失败';
const errorMessage =
error?.response?.data?.message || error?.message || '保存账户失败';
message.error(errorMessage);
} finally {
loading.value = false;
@@ -153,63 +160,112 @@ defineExpose({
:label-col="{ span: 6 }"
:wrapper-col="{ span: 18 }"
>
<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
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
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: '请输入真实姓名' }]">
<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: '请输入有效的手机号' }
]">
<Form.Item
label="手机号"
name="phone"
:rules="[{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' }]"
>
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
</Form.Item>
<Form.Item label="公司ID" name="companyId" :rules="[{ required: true, message: '请输入公司ID' }]">
<Input v-model:value="formData.companyId" type="number" placeholder="请输入公司ID" />
<Form.Item
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" />
<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" />
<Input
v-model:value="formData.positionId"
type="number"
placeholder="请输入岗位ID"
/>
</Form.Item>
<Form.Item label="角色" name="role" :rules="[{ required: true, message: '请输入角色' }]">
<Form.Item
label="角色"
name="role"
:rules="[{ required: true, message: '请输入角色' }]"
>
<Select
v-model:value="formData.role"
placeholder="请选择角色"
:options="[
{ label: '超级管理员', value: 'super' },
{ label: '管理员', value: 'admin' },
{ label: '普通用户', value: 'user' }
{ label: '普通用户', value: 'user' },
]"
/>
</Form.Item>
<Form.Item label="头像图片ID" name="avatarImageId">
<Input v-model:value="formData.avatarImageId" type="number" placeholder="请输入头像图片ID" />
<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"
@@ -217,7 +273,6 @@ defineExpose({
:options="statusOptions"
/>
</Form.Item>
</Form>
</Modal>
</template>
@@ -1,40 +1,45 @@
<script lang="ts" setup>
import { ref, computed } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, message, Space, Tag } from 'ant-design-vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {
super_deleteAccountApi,
super_getAccountPageApi,
type SuperAccountVO,
type SuperAccountDTO
import type {
SuperAccountDTO,
SuperAccountVO,
} from '#/api/organization/account-super';
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, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
super_deleteAccountApi,
super_getAccountPageApi,
} from '#/api/organization/account-super';
import SuperAccountFormModal from './components/SuperAccountFormModal.vue';
defineOptions({ name: 'SuperAccountManagement' });
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
defineOptions({ name: 'SuperAccountManagement' });
// 响应式数据
const loading = ref(false);
const accountFormModalRef = ref();
// 搜索表单
const searchForm = ref({
loginCode: undefined as undefined | string,
realName: undefined as undefined | string,
phone: undefined as undefined | string,
companyId: undefined as undefined | number,
departmentId: undefined as undefined | number,
positionId: undefined as undefined | number,
role: undefined as undefined | string,
status: undefined as undefined | number,
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,
});
// 状态选项
@@ -150,7 +155,25 @@ const gridOptions: VxeGridProps<any> = {
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
// 配置远程加载
proxyConfig: {
@@ -170,7 +193,8 @@ const gridOptions: VxeGridProps<any> = {
};
} catch (error: any) {
console.error('查询数据失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '查询数据失败';
const errorMessage =
error?.response?.data?.message || error?.message || '查询数据失败';
message.error(errorMessage);
return {
items: [],
@@ -220,7 +244,8 @@ const handleDelete = async (row: SuperAccountVO.AccountInfoVO) => {
refreshTable();
} catch (error: any) {
console.error('删除失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '删除失败';
const errorMessage =
error?.response?.data?.message || error?.message || '删除失败';
message.error(errorMessage);
}
};
@@ -234,15 +259,16 @@ const handleBatchDelete = async () => {
}
try {
const deletePromises = selectedRows.map((row: SuperAccountVO.AccountInfoVO) =>
super_deleteAccountApi(row.id)
const deletePromises = selectedRows.map(
(row: SuperAccountVO.AccountInfoVO) => super_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 || '批量删除失败';
const errorMessage =
error?.response?.data?.message || error?.message || '批量删除失败';
message.error(errorMessage);
}
};
@@ -284,9 +310,7 @@ const getStatusColor = (status: number) => {
</template>
<!-- VbenVxeGrid 表格 -->
<Grid
:loading="loading"
>
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
@@ -294,11 +318,7 @@ const getStatusColor = (status: number) => {
<PlusIcon />
添加账户
</Button>
<Button
v-if="hasSelected"
danger
@click="handleBatchDelete"
>
<Button v-if="hasSelected" danger @click="handleBatchDelete">
批量删除
</Button>
</Space>
@@ -310,21 +330,20 @@ const getStatusColor = (status: number) => {
{{ getStatusText(row.status) }}
</Tag>
</template>
<!-- 操作列 -->
<template #action="{ row }">
<Space>
<Button size="small" @click="handleEdit(row)">
编辑
</Button>
<Button size="small" danger @click="handleDelete(row)">
删除
</Button>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Button size="small" danger @click="handleDelete(row)"> 删除 </Button>
</Space>
</template>
</Grid>
<!-- 账户表单弹窗 -->
<SuperAccountFormModal ref="accountFormModalRef" @success="handleModalSuccess" />
<SuperAccountFormModal
ref="accountFormModalRef"
@success="handleModalSuccess"
/>
</Page>
</template>
@@ -1,22 +1,23 @@
<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
import type { AccountDTO, AccountVO } from '#/api/organization/account';
import {
admin_createAccountApi,
import { computed, ref, watch } from 'vue';
import { Form, Input, message, Modal, Select } from 'ant-design-vue';
import {
admin_createAccountApi,
admin_updateAccountApi,
type AccountVO,
type AccountDTO
} from '#/api/organization/account';
interface Emits {
(e: 'success'): void;
}
const emit = defineEmits<Emits>();
defineOptions({ name: 'AccountFormModal' });
const emit = defineEmits<Emits>();
// 响应式数据
const formRef = ref();
const loading = ref(false);
@@ -38,7 +39,7 @@ const formData = ref<AccountDTO.CreateAccountDTO & { status?: number }>({
});
// 模态框标题
const modalTitle = computed(() => isEdit.value ? '编辑账户' : '添加账户');
const modalTitle = computed(() => (isEdit.value ? '编辑账户' : '添加账户'));
// 状态选项
const statusOptions = [
@@ -73,9 +74,9 @@ function handleCancel() {
function open(accountData?: AccountVO.AccountInfoVO | null) {
isEdit.value = !!accountData;
currentAccountData.value = accountData || null;
resetForm();
if (accountData) {
formData.value = {
loginCode: accountData.loginCode,
@@ -89,7 +90,7 @@ function open(accountData?: AccountVO.AccountInfoVO | null) {
status: accountData.status,
};
}
visible.value = true;
}
@@ -98,21 +99,22 @@ async function handleSubmit() {
try {
await formRef.value?.validate();
loading.value = true;
if (isEdit.value && currentAccountData.value) {
const { password, ...updateData } = formData.value;
const { password: _, ...updateData } = formData.value;
await admin_updateAccountApi(currentAccountData.value.id, updateData);
message.success('更新成功');
} else {
await admin_createAccountApi(formData.value);
message.success('创建成功');
}
visible.value = false;
emit('success');
} catch (error: any) {
console.error('保存账户失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '保存账户失败';
const errorMessage =
error?.response?.data?.message || error?.message || '保存账户失败';
message.error(errorMessage);
} finally {
loading.value = false;
@@ -147,48 +149,96 @@ defineExpose({
:label-col="{ span: 6 }"
:wrapper-col="{ span: 18 }"
>
<Form.Item label="登录账号" name="loginCode" :rules="[
{ required: true, message: '请输入登录账号' },
{ min: 4, max: 20, message: '登录账号长度为4-20个字符' },
{ pattern: /^[a-zA-Z0-9_]+$/, message: '登录账号只能包含字母、数字和下划线' }
]">
<Input v-model:value="formData.loginCode" placeholder="请输入登录账号" />
<Form.Item
label="登录账号"
name="loginCode"
:rules="[
{ required: true, message: '请输入登录账号' },
{ min: 4, max: 20, message: '登录账号长度为4-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: 8, max: 20, message: '密码长度为8-20个字符' },
{ pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]{8,}$/, message: '密码必须包含大小写字母、数字,长度至少8位' }
]">
<Input v-model:value="formData.password" type="password" placeholder="请输入密码" />
<Form.Item
v-if="!isEdit"
label="密码"
name="password"
:rules="[
{ required: true, message: '请输入密码' },
{ min: 8, max: 20, message: '密码长度为8-20个字符' },
{
pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]{8,}$/,
message: '密码必须包含大小写字母、数字,长度至少8位',
},
]"
>
<Input
v-model:value="formData.password"
type="password"
placeholder="请输入密码"
/>
</Form.Item>
<Form.Item label="真实姓名" name="realName" :rules="[{ required: true, message: '请输入真实姓名' }]">
<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: '请输入有效的手机号' }
]">
<Form.Item
label="手机号"
name="phone"
:rules="[{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' }]"
>
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
</Form.Item>
<Form.Item label="部门ID" name="departmentId" :rules="[{ required: true, message: '请输入部门ID' }]">
<Input v-model:value="formData.departmentId" type="number" placeholder="请输入部门ID" />
<Form.Item
label="部门ID"
name="departmentId"
:rules="[{ required: true, message: '请输入部门ID' }]"
>
<Input
v-model:value="formData.departmentId"
type="number"
placeholder="请输入部门ID"
/>
</Form.Item>
<Form.Item label="岗位ID" name="positionId" :rules="[{ required: true, message: '请输入岗位ID' }]">
<Input v-model:value="formData.positionId" type="number" placeholder="请输入岗位ID" />
<Form.Item
label="岗位ID"
name="positionId"
:rules="[{ required: true, message: '请输入岗位ID' }]"
>
<Input
v-model:value="formData.positionId"
type="number"
placeholder="请输入岗位ID"
/>
</Form.Item>
<Form.Item label="头像图片ID" name="avatarImageId">
<Input v-model:value="formData.avatarImageId" type="number" placeholder="请输入头像图片ID" />
<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"
@@ -196,7 +246,6 @@ defineExpose({
:options="statusOptions"
/>
</Form.Item>
</Form>
</Modal>
</template>
@@ -1,40 +1,42 @@
<script lang="ts" setup>
import { ref, computed } from 'vue';
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 { Button, message, Space, Tag } from 'ant-design-vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {
admin_deleteAccountApi,
import { Button, message, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
admin_deleteAccountApi,
admin_getAccountPageApi,
type AccountVO,
type AccountDTO
} from '#/api/organization/account';
import type { PageQueryDTO } from '#/types/common';
import AccountFormModal from './components/AccountFormModal.vue';
defineOptions({ name: 'CompanyAccountManagement' });
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
defineOptions({ name: 'CompanyAccountManagement' });
// 响应式数据
const loading = ref(false);
const accountFormModalRef = ref();
// 搜索表单
const searchForm = ref({
loginCode: undefined as undefined | string,
realName: undefined as undefined | string,
phone: undefined as undefined | string,
companyId: undefined as undefined | number,
departmentId: undefined as undefined | number,
positionId: undefined as undefined | number,
role: undefined as undefined | string,
status: undefined as undefined | number,
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,
});
// 状态选项
@@ -150,7 +152,25 @@ const gridOptions: VxeGridProps<any> = {
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
// 配置远程加载
proxyConfig: {
@@ -170,7 +190,8 @@ const gridOptions: VxeGridProps<any> = {
};
} catch (error: any) {
console.error('查询数据失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '查询数据失败';
const errorMessage =
error?.response?.data?.message || error?.message || '查询数据失败';
message.error(errorMessage);
return {
items: [],
@@ -220,7 +241,8 @@ const handleDelete = async (row: AccountVO.AccountInfoVO) => {
refreshTable();
} catch (error: any) {
console.error('删除失败:', error);
const errorMessage = error?.response?.data?.message || error?.message || '删除失败';
const errorMessage =
error?.response?.data?.message || error?.message || '删除失败';
message.error(errorMessage);
}
};
@@ -234,15 +256,16 @@ const handleBatchDelete = async () => {
}
try {
const deletePromises = selectedRows.map((row: AccountVO.AccountInfoVO) =>
admin_deleteAccountApi(row.id)
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 || '批量删除失败';
const errorMessage =
error?.response?.data?.message || error?.message || '批量删除失败';
message.error(errorMessage);
}
};
@@ -273,7 +296,6 @@ const getStatusColor = (status: number) => {
function handleModalSuccess() {
refreshTable();
}
</script>
<template>
@@ -285,9 +307,7 @@ function handleModalSuccess() {
</template>
<!-- VbenVxeGrid 表格 -->
<Grid
:loading="loading"
>
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
@@ -295,11 +315,7 @@ function handleModalSuccess() {
<PlusIcon />
添加账户
</Button>
<Button
v-if="hasSelected"
danger
@click="handleBatchDelete"
>
<Button v-if="hasSelected" danger @click="handleBatchDelete">
批量删除
</Button>
</Space>
@@ -311,16 +327,12 @@ function handleModalSuccess() {
{{ getStatusText(row.status) }}
</Tag>
</template>
<!-- 操作列 -->
<template #action="{ row }">
<Space>
<Button size="small" @click="handleEdit(row)">
编辑
</Button>
<Button size="small" danger @click="handleDelete(row)">
删除
</Button>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Button size="small" danger @click="handleDelete(row)"> 删除 </Button>
</Space>
</template>
</Grid>
@@ -1,113 +1,25 @@
<template>
<Modal
:open="visible"
:title="modalTitle"
width="600px"
:confirm-loading="loading"
@ok="handleSubmit"
@cancel="handleCancel"
>
<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>
<Form.Item label="公司地址" name="address">
<Input v-model:value="formData.address" placeholder="请输入公司地址" />
</Form.Item>
<Form.Item label="联系人" name="contactPerson">
<Input v-model:value="formData.contactPerson" placeholder="请输入联系人" />
</Form.Item>
<Form.Item label="联系电话" name="contactPhone" :rules="[{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码' }]">
<Input v-model:value="formData.contactPhone" 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>
<script lang="ts" setup>
import { computed, ref, onUnmounted } from 'vue';
import { Form, Input, Modal, DatePicker, Button, message, Switch } from 'ant-design-vue';
import type { CompanyDTO, CompanyVO } from '#/api/organization/company';
import { computed, onUnmounted, ref } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import {
Button,
DatePicker,
Form,
Input,
message,
Modal,
Switch,
} from 'ant-design-vue';
import dayjs from 'dayjs';
import {
uploadCompanyLogoApi,
createCompanyApi,
import {
createCompanyApi,
updateCompanyApi,
type CompanyVO,
type CompanyDTO
uploadCompanyLogoApi,
} from '#/api/organization/company';
interface Emits {
@@ -158,7 +70,7 @@ const formData = ref<FormData>({
// 开关组件不需要选项数组
// 模态框标题
const modalTitle = computed(() => isEdit.value ? '编辑公司' : '添加公司');
const modalTitle = computed(() => (isEdit.value ? '编辑公司' : '添加公司'));
// 当前显示的logo URL(优先显示新选择的)
const currentLogoUrl = computed(() => {
@@ -180,9 +92,11 @@ function initFormData() {
email: currentCompanyData.value.email || '',
logoImageId: undefined,
status: currentCompanyData.value.status === 1, // 转换为boolean
expireTime: currentCompanyData.value.expireTime ? dayjs(currentCompanyData.value.expireTime) : undefined,
expireTime: currentCompanyData.value.expireTime
? dayjs(currentCompanyData.value.expireTime)
: undefined,
};
// 设置原始Logo URL
originalLogoUrl.value = currentCompanyData.value.logo || '';
} else {
@@ -199,7 +113,7 @@ function initFormData() {
};
originalLogoUrl.value = '';
}
// 重置新选择的logo和图片加载状态
newLogoFile.value = null;
imageLoadError.value = false;
@@ -218,18 +132,20 @@ async function handleSubmit() {
try {
await formRef.value?.validate();
loading.value = true;
// 准备提交数据
const submitData = {
const submitData = {
...formData.value,
status: formData.value.status ? 1 : 0 // 转换boolean为number
status: formData.value.status ? 1 : 0, // 转换boolean为number
};
// 处理日期格式
if (submitData.expireTime) {
submitData.expireTime = submitData.expireTime.format('YYYY-MM-DD HH:mm:ss');
submitData.expireTime = submitData.expireTime.format(
'YYYY-MM-DD HH:mm:ss',
);
}
// 如果有新选择的logo,先上传获取ID
if (newLogoFile.value) {
const logoImageId = await uploadLogoAndGetId();
@@ -240,16 +156,19 @@ async function handleSubmit() {
// 创建模式且没有选择Logo,移除logoImageId字段
delete submitData.logoImageId;
}
// 调用API
if (isEdit.value && currentCompanyData.value) {
await updateCompanyApi(currentCompanyData.value.id, submitData as CompanyDTO.UpdateCompanyDTO);
await updateCompanyApi(
currentCompanyData.value.id,
submitData as CompanyDTO.UpdateCompanyDTO,
);
message.success('更新成功');
} else {
await createCompanyApi(submitData as CompanyDTO.CreateCompanyDTO);
message.success('创建成功');
}
visible.value = false;
emit('success');
} catch (error) {
@@ -266,13 +185,16 @@ function handleCancel() {
}
// 暴露给父组件的方法
function open(editMode: boolean = false, companyData?: CompanyVO.CompanyInfoVO | null) {
function open(
editMode: boolean = false,
companyData?: CompanyVO.CompanyInfoVO | null,
) {
isEdit.value = editMode;
currentCompanyData.value = companyData || null;
resetForm(); // 先重置表单
initFormData(); // 再初始化数据
visible.value = true;
}
@@ -287,35 +209,35 @@ function selectLogoFile() {
input.type = 'file';
input.accept = 'image/*';
input.style.display = 'none';
document.body.appendChild(input);
input.onchange = (e) => {
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('只能上传图片文件');
document.body.removeChild(input);
input.remove();
return;
}
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
message.error('图片大小不能超过 2MB');
document.body.removeChild(input);
input.remove();
return;
}
// 设置新选择的文件
newLogoFile.value = file;
imageLoadError.value = false; // 重置图片加载错误状态
message.success('Logo选择成功');
}
document.body.removeChild(input);
};
input.remove();
});
input.click();
}
@@ -331,10 +253,9 @@ async function uploadLogoAndGetId(): Promise<number | undefined> {
if (!newLogoFile.value) {
return undefined;
}
try {
const response = await uploadCompanyLogoApi(newLogoFile.value);
console.log('Logo上传成功:', response);
return response.id;
} catch (error) {
console.error('Logo上传失败:', error);
@@ -350,7 +271,6 @@ function handleImageError(event: Event) {
message.error('图片加载失败,请重新选择');
}
// 组件卸载时清理
onUnmounted(() => {
if (newLogoFile.value) {
@@ -359,3 +279,174 @@ onUnmounted(() => {
}
});
</script>
<template>
<Modal
:open="visible"
:title="modalTitle"
width="600px"
:confirm-loading="loading"
@ok="handleSubmit"
@cancel="handleCancel"
>
<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>
<Form.Item label="公司地址" name="address">
<Input v-model:value="formData.address" placeholder="请输入公司地址" />
</Form.Item>
<Form.Item label="联系人" name="contactPerson">
<Input
v-model:value="formData.contactPerson"
placeholder="请输入联系人"
/>
</Form.Item>
<Form.Item
label="联系电话"
name="contactPhone"
:rules="[{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码' }]"
>
<Input
v-model:value="formData.contactPhone"
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>
@@ -1,27 +1,29 @@
<script lang="ts" setup>
import { ref, computed } from 'vue';
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 { Button, message, Space, Tag } from 'ant-design-vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {
deleteCompanyApi,
import { Button, message, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteCompanyApi,
getCompanyPageApi,
type CompanyVO,
type CompanyDTO
} from '#/api/organization/company';
import type { PageQueryDTO } from '#/types/common';
import CompanyFormModal from './components/CompanyFormModal.vue';
import CompanyMenuDrawer from '#/components/CompanyMenuDrawer.vue';
import CompanyFormModal from './components/CompanyFormModal.vue';
defineOptions({ name: 'CompanyManagement' });
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
defineOptions({ name: 'CompanyManagement' });
// 响应式数据
const loading = ref(false);
const companyFormModalRef = ref();
@@ -125,7 +127,25 @@ const gridOptions: VxeGridProps<any> = {
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
// 配置远程加载
proxyConfig: {
@@ -133,6 +153,15 @@ const gridOptions: VxeGridProps<any> = {
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,
@@ -142,7 +171,7 @@ const gridOptions: VxeGridProps<any> = {
contactPhone: searchForm.value.contactPhone || undefined,
email: searchForm.value.email || undefined,
status: searchForm.value.status,
expired: searchForm.value.expired === 'true' ? true : searchForm.value.expired === 'false' ? false : undefined,
expired: expiredValue,
},
};
const data = await getCompanyPageApi(params);
@@ -216,7 +245,7 @@ const formOptions = computed(() => ({
placeholder: '请选择过期状态',
options: [
{ label: '已过期', value: 'true' },
{ label: '正常', value: 'false' }
{ label: '正常', value: 'false' },
],
allowClear: true,
},
@@ -286,9 +315,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
</template>
<!-- VbenVxeGrid 表格 -->
<Grid
:loading="loading"
>
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
@@ -302,13 +329,18 @@ const [Grid, gridApi] = useVbenVxeGrid({
<!-- Logo列 -->
<template #logo="{ row }: { row: any }">
<div v-if="row.logo">
<img
:src="row.logo"
<img
:src="row.logo"
:alt="row.name"
style="width: 40px; height: 40px; object-fit: cover; border-radius: 4px;"
style="
width: 40px;
height: 40px;
object-fit: cover;
border-radius: 4px;
"
/>
</div>
<span v-else style="color: #999;">暂无Logo</span>
<span v-else style="color: #999">暂无Logo</span>
</template>
<!-- 状态列 -->
@@ -322,12 +354,12 @@ const [Grid, gridApi] = useVbenVxeGrid({
<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>
<span v-else style="color: #999">未知</span>
</template>
<!-- 订阅到期时间列 -->
<template #expireTime="{ row }: { row: any }">
<span v-if="!row.expireTime" style="color: #999;">未设置</span>
<span v-if="!row.expireTime" style="color: #999">未设置</span>
<span v-else :style="{ color: row.expired ? '#ff4d4f' : '#52c41a' }">
{{ row.expireTime }}
</span>
@@ -336,25 +368,18 @@ const [Grid, gridApi] = useVbenVxeGrid({
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)">
编辑
</Button>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Button size="small" type="primary" @click="handleMenuManage(row)">
菜单
</Button>
<Button size="small" danger @click="handleDelete(row)">
删除
</Button>
<Button size="small" danger @click="handleDelete(row)"> 删除 </Button>
</Space>
</template>
</Grid>
<!-- 公司表单模态框 -->
<CompanyFormModal
ref="companyFormModalRef"
@success="handleModalSuccess"
/>
<CompanyFormModal ref="companyFormModalRef" @success="handleModalSuccess" />
<!-- 公司菜单管理抽屉 -->
<CompanyMenuDrawer ref="companyMenuDrawerRef" />
</Page>
@@ -1,11 +1,13 @@
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { Form, Input, Modal, Select, message, Switch } from 'ant-design-vue';
import type { DepartmentVO } from '#/api/organization/department';
import {
createDepartmentApi,
import { computed, ref } from 'vue';
import { Form, Input, message, Modal, Select, Switch } from 'ant-design-vue';
import {
createDepartmentApi,
updateDepartmentApi,
type DepartmentVO
} from '#/api/organization/department';
interface Props {
@@ -47,16 +49,25 @@ const formData = ref<FormData>({
// 父部门选项
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 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))) {
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}`,
@@ -67,13 +78,16 @@ const parentDepartmentOptions = computed(() => {
}
});
};
addDepartmentOptions(props.departmentList);
return options;
});
// 检查是否为子部门
function isChildDepartment(department: DepartmentVO.DepartmentInfoVO, parentId: number): boolean {
function isChildDepartment(
department: DepartmentVO.DepartmentInfoVO,
parentId: number,
): boolean {
if (department.children) {
for (const child of department.children) {
if (child.id === parentId || isChildDepartment(child, parentId)) {
@@ -85,7 +99,7 @@ function isChildDepartment(department: DepartmentVO.DepartmentInfoVO, parentId:
}
// 模态框标题
const modalTitle = computed(() => isEdit.value ? '编辑部门' : '添加部门');
const modalTitle = computed(() => (isEdit.value ? '编辑部门' : '添加部门'));
// 重置表单
function resetForm() {
@@ -108,13 +122,13 @@ async function handleSubmit() {
try {
await formRef.value?.validate();
loading.value = true;
// 转换boolean值为number值
const submitData = {
...formData.value,
status: formData.value.status ? 1 : 0
status: formData.value.status ? 1 : 0,
};
if (isEdit.value && currentDepartmentData.value) {
await updateDepartmentApi(currentDepartmentData.value.id, submitData);
message.success('更新成功');
@@ -122,7 +136,7 @@ async function handleSubmit() {
await createDepartmentApi(submitData);
message.success('创建成功');
}
visible.value = false;
emit('success');
} catch (error) {
@@ -134,12 +148,15 @@ async function handleSubmit() {
}
// 暴露给父组件的方法
function open(editMode: boolean = false, departmentData?: DepartmentVO.DepartmentInfoVO | null) {
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,
@@ -148,7 +165,7 @@ function open(editMode: boolean = false, departmentData?: DepartmentVO.Departmen
status: departmentData.status === 1, // 转换为boolean
};
}
visible.value = true;
}
@@ -181,15 +198,23 @@ defineExpose({
allow-clear
/>
</Form.Item>
<Form.Item label="部门名称" name="name" :rules="[{ required: true, message: '请输入部门名称' }]">
<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" />
<Input.TextArea
v-model:value="formData.remark"
placeholder="请输入部门描述"
:rows="3"
/>
</Form.Item>
<Form.Item label="状态" name="status">
<Switch
v-model:checked="formData.status"
@@ -1,26 +1,31 @@
<script lang="ts" setup>
import { ref, computed } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, message, Space, Tag } from 'ant-design-vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {
deleteDepartmentApi,
getDepartmentPageApi,
type DepartmentVO,
type DepartmentDTO
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, 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');
defineOptions({ name: 'DepartmentManagement' });
// 响应式数据
const loading = ref(false);
const departmentModalRef = ref();
@@ -41,10 +46,15 @@ const statusOptions = [
// 父部门选项
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 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}`,
@@ -55,7 +65,7 @@ const parentDepartmentOptions = computed(() => {
}
});
};
addDepartmentOptions(departmentList.value);
return options;
});
@@ -116,7 +126,25 @@ const gridOptions: VxeGridProps<any> = {
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
// 配置远程加载
proxyConfig: {
@@ -156,7 +184,10 @@ const gridOptions: VxeGridProps<any> = {
};
// 查找父部门
function findParentDepartment(departments: DepartmentVO.DepartmentInfoVO[], parentId: number): DepartmentVO.DepartmentInfoVO | null {
function findParentDepartment(
departments: DepartmentVO.DepartmentInfoVO[],
parentId: number,
): DepartmentVO.DepartmentInfoVO | null {
for (const dept of departments) {
if (dept.id === parentId) {
return dept;
@@ -258,9 +289,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
</template>
<!-- VbenVxeGrid 表格 -->
<Grid
:loading="loading"
>
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
@@ -275,7 +304,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template #parentDepartment="{ row }: { row: any }">
<span v-if="!row.parentId">根部门</span>
<span v-else>
{{ findParentDepartment(departmentList, row.parentId)?.name || '未知' }}
{{
findParentDepartment(departmentList, row.parentId)?.name || '未知'
}}
</span>
</template>
@@ -289,12 +320,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)">
编辑
</Button>
<Button size="small" danger @click="handleDelete(row)">
删除
</Button>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Button size="small" danger @click="handleDelete(row)"> 删除 </Button>
</Space>
</template>
</Grid>
@@ -1,52 +1,69 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { Button, Card, Input, message, Pagination, Select, Spin, Tree, Flex } from 'ant-design-vue'
import { Page } from '@vben/common-ui'
import { getPositionPageApi } from '#/api/organization/position'
import { getCompanyMenuTreeApi } from '#/api/organization/company-menu'
import { getPositionCompanyMenuIdsApi, batchUpdatePositionCompanyMenusApi } from '#/api/organization/position-permission'
import type { PositionVO } from '#/api/organization/position/types'
import type { CompanyMenuVO } from '#/api/organization/company-menu/types'
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 {
batchUpdatePositionCompanyMenusApi,
getPositionCompanyMenuIdsApi,
} 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 positionList = ref<PositionVO.PositionInfoVO[]>([]);
const positionLoading = ref(false);
const positionPagination = ref({
current: 1,
pageSize: 10,
total: 0,
})
});
// 当前选中的岗位
const currentPosition = ref<PositionVO.PositionInfoVO | null>(null)
const currentPosition = ref<null | PositionVO.PositionInfoVO>(null);
// 公司菜单树数据
const companyMenuTree = ref<CompanyMenuVO.CompanyMenuInfo[]>([])
const menuTreeLoading = ref(false)
const companyMenuTree = ref<CompanyMenuVO.CompanyMenuInfo[]>([]);
const menuTreeLoading = ref(false);
// 岗位权限菜单ID列表
const positionMenuIds = ref<number[]>([])
const permissionLoading = ref(false)
const positionMenuIds = ref<number[]>([]);
const permissionLoading = ref(false);
// 选中的菜单ID(用于树形控件)
const checkedKeys = ref<number[]>([])
const expandedKeys = ref<number[]>([])
const checkedKeys = ref<number[]>([]);
const expandedKeys = ref<number[]>([]);
// 不区分超管与普通菜单
// 搜索岗位列表
async function searchPositions() {
positionLoading.value = true
positionLoading.value = true;
try {
const params = {
page: positionPagination.value.current,
@@ -55,113 +72,118 @@ async function searchPositions() {
name: searchForm.value.name || undefined,
status: searchForm.value.status,
},
}
const result = await getPositionPageApi(params)
positionList.value = result.records
positionPagination.value.total = result.total
};
const result = await getPositionPageApi(params);
positionList.value = result.records;
positionPagination.value.total = result.total;
} catch (error: any) {
message.error(error?.message || '获取岗位列表失败')
message.error(error?.message || '获取岗位列表失败');
} finally {
positionLoading.value = false
positionLoading.value = false;
}
}
// 加载公司菜单树
async function loadCompanyMenuTree() {
menuTreeLoading.value = true
menuTreeLoading.value = true;
try {
const result = await getCompanyMenuTreeApi()
companyMenuTree.value = result
const result = await getCompanyMenuTreeApi();
companyMenuTree.value = result;
// 自动展开所有节点
expandedKeys.value = getAllMenuIds(result)
expandedKeys.value = getAllMenuIds(result);
} catch (error: any) {
message.error(error?.message || '获取菜单树失败')
message.error(error?.message || '获取菜单树失败');
} finally {
menuTreeLoading.value = false
menuTreeLoading.value = false;
}
}
// 获取所有菜单ID(递归)
function getAllMenuIds(menus: CompanyMenuVO.CompanyMenuInfo[]): number[] {
const ids: number[] = []
const ids: number[] = [];
function traverse(menuList: CompanyMenuVO.CompanyMenuInfo[]) {
menuList.forEach(menu => {
ids.push(menu.id)
menuList.forEach((menu) => {
ids.push(menu.id);
if (menu.children && menu.children.length > 0) {
traverse(menu.children)
traverse(menu.children);
}
})
});
}
traverse(menus)
return ids
traverse(menus);
return ids;
}
// 将菜单数据转换为Tree组件需要的格式
function convertToTreeData(menus: CompanyMenuVO.CompanyMenuInfo[]): any[] {
return menus.map(menu => ({
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,
}))
children:
menu.children && menu.children.length > 0
? convertToTreeData(menu.children)
: undefined,
}));
}
// 选择岗位
async function selectPosition(position: PositionVO.PositionInfoVO) {
currentPosition.value = position
await loadPositionPermissions()
currentPosition.value = position;
await loadPositionPermissions();
}
// 加载岗位权限
async function loadPositionPermissions() {
if (!currentPosition.value?.id) return
permissionLoading.value = true
if (!currentPosition.value?.id) return;
permissionLoading.value = true;
try {
const result = await getPositionCompanyMenuIdsApi(currentPosition.value.id)
positionMenuIds.value = result
const result = await getPositionCompanyMenuIdsApi(currentPosition.value.id);
positionMenuIds.value = result;
// 清理根节点,只保留叶子节点
const leafMenuIds = cleanRootNodes(result)
checkedKeys.value = leafMenuIds
const leafMenuIds = cleanRootNodes(result);
checkedKeys.value = leafMenuIds;
} catch (error: any) {
message.error(error?.message || '获取岗位权限失败')
message.error(error?.message || '获取岗位权限失败');
} finally {
permissionLoading.value = false
permissionLoading.value = false;
}
}
// 清理根节点,只保留叶子节点
function cleanRootNodes(menuIds: number[]): number[] {
return menuIds.filter((menuId) => {
const menu = findMenuById(menuId)
if (!menu) return false
const menu = findMenuById(menuId);
if (!menu) return false;
// 检查是否有其他菜单将此菜单作为父菜单
const hasChildren = hasMenuChildren(menuId)
const hasChildren = hasMenuChildren(menuId);
// 只保留叶子节点(没有子节点的菜单)
return !hasChildren
})
return !hasChildren;
});
}
// 根据ID查找菜单
function findMenuById(menuId: number): CompanyMenuVO.CompanyMenuInfo | null {
function search(menus: CompanyMenuVO.CompanyMenuInfo[]): CompanyMenuVO.CompanyMenuInfo | null {
function search(
menus: CompanyMenuVO.CompanyMenuInfo[],
): CompanyMenuVO.CompanyMenuInfo | null {
for (const menu of menus) {
if (menu.id === menuId) return menu
if (menu.id === menuId) return menu;
if (menu.children && menu.children.length > 0) {
const found = search(menu.children)
if (found) return found
const found = search(menu.children);
if (found) return found;
}
}
return null
return null;
}
return search(companyMenuTree.value)
return search(companyMenuTree.value);
}
// 检查菜单是否有子菜单
@@ -169,208 +191,231 @@ 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
if (menu.children.some((child) => child.id === menuId)) return true;
if (search(menu.children)) return true;
}
}
return false
return false;
}
return search(companyMenuTree.value)
return search(companyMenuTree.value);
}
// 确保提交时包含必要的父菜单ID(递归添加所有层级的父菜单)
function ensureParentMenuIds(menuIds: number[]): number[] {
const result = new Set(menuIds)
const result = new Set(menuIds);
// 递归添加所有父菜单ID
function addAllParentIds(menuId: number) {
const menu = findMenuById(menuId)
const menu = findMenuById(menuId);
if (menu && menu.parentId) {
result.add(menu.parentId)
result.add(menu.parentId);
// 递归添加父菜单的父菜单
addAllParentIds(menu.parentId)
addAllParentIds(menu.parentId);
}
}
// 为每个选中的菜单添加其所有父菜单ID
menuIds.forEach((menuId) => {
addAllParentIds(menuId)
})
return [...result]
addAllParentIds(menuId);
});
return [...result];
}
// 保存岗位权限
async function savePositionPermissions() {
if (!currentPosition.value?.id) return
if (!currentPosition.value?.id) return;
try {
// 确保提交时包含必要的父菜单ID
const finalMenuIds = ensureParentMenuIds(checkedKeys.value)
await batchUpdatePositionCompanyMenusApi(currentPosition.value.id, finalMenuIds)
message.success('权限配置保存成功')
const finalMenuIds = ensureParentMenuIds(checkedKeys.value);
await batchUpdatePositionCompanyMenusApi(
currentPosition.value.id,
finalMenuIds,
);
message.success('权限配置保存成功');
// 重新加载权限数据
await loadPositionPermissions()
await loadPositionPermissions();
} catch (error: any) {
message.error(error?.message || '保存失败')
message.error(error?.message || '保存失败');
}
}
// 一键全选
function handleSelectAll() {
// 获取所有可选择的菜单ID(排除禁用的)
let selectableMenus = getAllSelectableMenus()
const selectableMenus = getAllSelectableMenus();
// 只选择叶子节点(没有子节点的菜单)
const leafMenus = selectableMenus.filter((menu) => {
return !hasMenuChildren(menu.id)
})
return !hasMenuChildren(menu.id);
});
// 全选所有叶子节点
checkedKeys.value = leafMenus.map((menu) => menu.id)
checkedKeys.value = leafMenus.map((menu) => menu.id);
}
// 取消全选
function handleSelectNone() {
// 取消所有叶子节点的选中状态
const allLeafMenuIds = getAllSelectableMenus()
.filter((menu) => !hasMenuChildren(menu.id))
.map((menu) => menu.id)
checkedKeys.value = checkedKeys.value.filter((id) => !allLeafMenuIds.includes(id))
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[] = []
const result: CompanyMenuVO.CompanyMenuInfo[] = [];
function traverse(menus: CompanyMenuVO.CompanyMenuInfo[]) {
menus.forEach(menu => {
if (menu.status === 1) { // 只包含启用的菜单
result.push(menu)
menus.forEach((menu) => {
if (menu.status === 1) {
// 只包含启用的菜单
result.push(menu);
}
if (menu.children && menu.children.length > 0) {
traverse(menu.children)
traverse(menu.children);
}
})
});
}
traverse(companyMenuTree.value)
return result
traverse(companyMenuTree.value);
return result;
}
// 处理树形控件的选中变化
function handleTreeCheckChange(checkedKeysValue: any) {
checkedKeys.value = checkedKeysValue
checkedKeys.value = checkedKeysValue;
}
// 计算统计信息
const stats = computed(() => {
const totalMenus = getAllSelectableMenus().length
const positionMenus = positionMenuIds.value.length
const selectedMenus = ensureParentMenuIds(checkedKeys.value).length
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()
};
positionPagination.value.current = 1;
searchPositions();
}
// 分页变化
function handlePageChange(page: number, pageSize: number) {
positionPagination.value.current = page
positionPagination.value.pageSize = pageSize
searchPositions()
positionPagination.value.current = page;
positionPagination.value.pageSize = pageSize;
searchPositions();
}
// 初始化
onMounted(() => {
searchPositions()
loadCompanyMenuTree()
})
searchPositions();
loadCompanyMenuTree();
});
</script>
<template>
<Page
:auto-content-height="true"
>
<Page :auto-content-height="true">
<Flex gap="middle" class="h-full">
<!-- 左栏:岗位列表 -->
<Card title="岗位列表" class="h-full flex flex-col max-w-[400px]" :bodyStyle="{ height: '100%', display: 'flex', flexDirection: 'column',gap: '10px' }">
<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>
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">
<!-- 岗位列表 -->
<Flex vertical class="flex-1">
<Spin :spinning="positionLoading">
<Card
v-for="position in positionList"
:key="position.id"
hoverable
size="small"
:bodyStyle="{ padding: '10px 12px' }"
:class="[
'group mb-2 cursor-pointer transition-all duration-200',
(currentPosition?.id === position.id) && 'ring-1 ring-primary shadow'
]"
@click="selectPosition(position)"
>
<div class="flex items-start justify-between gap-2">
<div class="min-w-0">
<div class="flex items-center gap-2 mb-1">
<span
class="inline-block h-2 w-2 rounded-full"
:class="position.status === 1 ? 'bg-green-500' : 'bg-red-500'"
/>
<span class="text-sm font-semibold text-[var(--text-primary)] truncate">{{ position.name }}</span>
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>
<div class="text-xs text-[var(--text-secondary)] mb-1">编码:{{ position.code }}</div>
<div v-if="position.remark" class="text-xs text-[var(--text-secondary)] truncate">{{ position.remark }}</div>
<Tag :color="position.status === 1 ? 'green' : 'red'">
{{ position.status === 1 ? '启用' : '禁用' }}
</Tag>
</div>
<Tag :color="position.status === 1 ? 'green' : 'red'">
{{ position.status === 1 ? '启用' : '禁用' }}
</Tag>
</div>
</Card>
</Spin>
</Flex>
<!-- 分页器 -->
<Flex justify="center">
<Flex justify="center">
<Pagination
v-model:current="positionPagination.current"
v-model:page-size="positionPagination.pageSize"
@@ -380,78 +425,97 @@ onMounted(() => {
:show-total="(total) => `共 ${total} 条`"
@change="handlePageChange"
/>
</Flex>
</Flex>
</Flex>
</Card>
<!-- 右栏:权限管理 -->
<Card title="权限管理" class="h-full flex flex-col flex-1" :bodyStyle="{ height: '100%' }">
<template v-if="currentPosition">
<!-- 岗位信息 + 统计与操作 -->
<div class="p-4 rounded mb-4 bg-gray-50 dark:bg-neutral-800">
<div class="flex items-center justify-between gap-2 mb-3">
<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>
<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-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="font-semibold text-sm">{{ stats.total }}</span>
</span>
<span class="flex items-center gap-1">
<span class="text-[var(--text-secondary)]">已配置:</span>
<span class="font-semibold text-sm text-[var(--success)]">{{ stats.position }}</span>
</span>
<span class="flex items-center gap-1">
<span class="text-[var(--text-secondary)]">当前选择:</span>
<span class="font-semibold text-sm text-[var(--primary)]">{{ stats.selected }}</span>
</span>
<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-1 overflow-y-auto min-h-0">
<Spin :spinning="permissionLoading">
<Tree
v-model:checked-keys="checkedKeys"
v-model:expanded-keys="expandedKeys"
:tree-data="convertToTreeData(companyMenuTree)"
checkable
block-node
class="border rounded"
@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="text-red-600 bg-red-50 dark:bg-red-900/30 text-xs px-1.5 py-0.5 rounded">
已禁用
</span>
<span v-if="disabled" class="text-red-600 bg-red-50 dark:bg-red-900/30 text-xs px-1.5 py-0.5 rounded">
不可选择
</span>
</div>
</template>
</Tree>
</Spin>
</div>
</template>
<div v-else class="flex-1 flex items-center justify-center h-full">
<div class="text-center text-gray-500">
<div class="text-5xl mb-4">👈</div>
<div class="text-base">请先选择一个岗位</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>
</Card>
<!-- 菜单树 -->
<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">
@@ -1,11 +1,13 @@
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { Form, Input, Modal, Select, message, Switch } from 'ant-design-vue';
import type { PositionVO } from '#/api/organization/position';
import {
createPositionApi,
import { computed, ref } from 'vue';
import { Form, Input, message, Modal, Select, Switch } from 'ant-design-vue';
import {
createPositionApi,
updatePositionApi,
type PositionVO
} from '#/api/organization/position';
interface Props {
@@ -25,7 +27,7 @@ const formRef = ref();
const loading = ref(false);
const visible = ref(false);
const isEdit = ref(false);
const currentPositionData = ref<PositionVO.PositionInfoVO | null>(null);
const currentPositionData = ref<null | PositionVO.PositionInfoVO>(null);
// 内部表单数据类型
interface FormData {
@@ -48,7 +50,7 @@ const formData = ref<FormData>({
// 开关组件不需要选项数组
// 模态框标题
const modalTitle = computed(() => isEdit.value ? '编辑岗位' : '添加岗位');
const modalTitle = computed(() => (isEdit.value ? '编辑岗位' : '添加岗位'));
// 重置表单
function resetForm() {
@@ -72,13 +74,13 @@ async function handleSubmit() {
try {
await formRef.value?.validate();
loading.value = true;
// 转换boolean值为number值
const submitData = {
...formData.value,
status: formData.value.status ? 1 : 0
status: formData.value.status ? 1 : 0,
};
if (isEdit.value && currentPositionData.value) {
await updatePositionApi(currentPositionData.value.id, submitData);
message.success('更新成功');
@@ -86,7 +88,7 @@ async function handleSubmit() {
await createPositionApi(submitData);
message.success('创建成功');
}
visible.value = false;
emit('success');
} catch (error) {
@@ -98,12 +100,15 @@ async function handleSubmit() {
}
// 暴露给父组件的方法
function open(editMode: boolean = false, positionData?: PositionVO.PositionInfoVO | null) {
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,
@@ -113,7 +118,7 @@ function open(editMode: boolean = false, positionData?: PositionVO.PositionInfoV
status: positionData.status === 1, // 转换为boolean
};
}
visible.value = true;
}
@@ -138,14 +143,18 @@ defineExpose({
:label-col="{ span: 6 }"
:wrapper-col="{ span: 18 }"
>
<Form.Item label="岗位名称" name="name" :rules="[{ required: true, message: '请输入岗位名称' }]">
<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"
@@ -154,11 +163,15 @@ defineExpose({
allow-clear
/>
</Form.Item>
<Form.Item label="描述" name="remark">
<Input.TextArea v-model:value="formData.remark" placeholder="请输入岗位描述" :rows="3" />
<Input.TextArea
v-model:value="formData.remark"
placeholder="请输入岗位描述"
:rows="3"
/>
</Form.Item>
<Form.Item label="状态" name="status">
<Switch
v-model:checked="formData.status"
@@ -1,26 +1,28 @@
<script lang="ts" setup>
import { ref, computed } from 'vue';
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 { Button, message, Space, Tag } from 'ant-design-vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {
deletePositionApi,
import { Button, message, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deletePositionApi,
getPositionPageApi,
type PositionVO,
type PositionDTO
} from '#/api/organization/position';
import type { PageQueryDTO } from '#/types/common';
import PositionModal from './components/PositionModal.vue';
defineOptions({ name: 'PositionManagement' });
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
defineOptions({ name: 'PositionManagement' });
// 响应式数据
const loading = ref(false);
const positionModalRef = ref();
@@ -106,7 +108,25 @@ const gridOptions: VxeGridProps<any> = {
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
// 配置远程加载
proxyConfig: {
@@ -221,9 +241,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
</template>
<!-- VbenVxeGrid 表格 -->
<Grid
:loading="loading"
>
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
@@ -238,7 +256,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template #department="{ row }: { row: any }">
<span v-if="!row.departmentId">-</span>
<span v-else>
{{ departmentOptions.find(d => d.value === row.departmentId)?.label || '未知部门' }}
{{
departmentOptions.find((d) => d.value === row.departmentId)
?.label || '未知部门'
}}
</span>
</template>
@@ -252,12 +273,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)">
编辑
</Button>
<Button size="small" danger @click="handleDelete(row)">
删除
</Button>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Button size="small" danger @click="handleDelete(row)"> 删除 </Button>
</Space>
</template>
</Grid>