mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 03:49:19 +08:00
小修小补
This commit is contained in:
+350
@@ -0,0 +1,350 @@
|
||||
<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" :rules="[{ required: true, message: '请选择状态' }]">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</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, Select, DatePicker, Button, message } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import dayjs from 'dayjs';
|
||||
import {
|
||||
uploadCompanyLogoApi,
|
||||
createCompanyApi,
|
||||
updateCompanyApi,
|
||||
type CompanyVO,
|
||||
type CompanyDTO
|
||||
} from '#/api/org';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建相机图标组件
|
||||
const CameraIcon = createIconifyIcon('mdi:camera');
|
||||
|
||||
// 内部状态管理
|
||||
const visible = ref(false);
|
||||
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); // 图片加载错误状态
|
||||
|
||||
// 表单数据
|
||||
const formData = ref({
|
||||
name: '',
|
||||
address: '',
|
||||
contactPerson: '',
|
||||
contactPhone: '',
|
||||
email: '',
|
||||
logoImageId: undefined as number | undefined,
|
||||
status: 1,
|
||||
expireTime: undefined as any,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '正常', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
];
|
||||
|
||||
// 模态框标题
|
||||
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 || '',
|
||||
contactPerson: currentCompanyData.value.contactPerson || '',
|
||||
contactPhone: currentCompanyData.value.contactPhone || '',
|
||||
email: currentCompanyData.value.email || '',
|
||||
logoImageId: undefined,
|
||||
status: currentCompanyData.value.status,
|
||||
expireTime: currentCompanyData.value.expireTime ? dayjs(currentCompanyData.value.expireTime) : undefined,
|
||||
};
|
||||
|
||||
// 设置原始Logo URL
|
||||
originalLogoUrl.value = currentCompanyData.value.logo || '';
|
||||
} else {
|
||||
// 创建模式
|
||||
formData.value = {
|
||||
name: '',
|
||||
address: '',
|
||||
contactPerson: '',
|
||||
contactPhone: '',
|
||||
email: '',
|
||||
logoImageId: undefined,
|
||||
status: 1,
|
||||
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 = { ...formData.value };
|
||||
|
||||
// 处理日期格式
|
||||
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('创建成功');
|
||||
}
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('保存公司失败:', error);
|
||||
message.error('保存公司失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理取消
|
||||
function handleCancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(editMode: boolean = false, companyData?: CompanyVO.CompanyInfoVO | null) {
|
||||
isEdit.value = editMode;
|
||||
currentCompanyData.value = companyData || null;
|
||||
|
||||
resetForm(); // 先重置表单
|
||||
initFormData(); // 再初始化数据
|
||||
|
||||
visible.value = true;
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
|
||||
// 选择logo文件
|
||||
function selectLogoFile() {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = 'image/*';
|
||||
input.style.display = 'none';
|
||||
document.body.appendChild(input);
|
||||
|
||||
input.onchange = (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);
|
||||
return;
|
||||
}
|
||||
|
||||
const isLt2M = file.size / 1024 / 1024 < 2;
|
||||
if (!isLt2M) {
|
||||
message.error('图片大小不能超过 2MB');
|
||||
document.body.removeChild(input);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置新选择的文件
|
||||
newLogoFile.value = file;
|
||||
imageLoadError.value = false; // 重置图片加载错误状态
|
||||
message.success('Logo选择成功');
|
||||
}
|
||||
|
||||
document.body.removeChild(input);
|
||||
};
|
||||
|
||||
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);
|
||||
console.log('Logo上传成功:', response);
|
||||
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>
|
||||
@@ -0,0 +1,375 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Input, Select, Table, message, Tag } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
deleteCompanyApi,
|
||||
getCompanyPageApi,
|
||||
type CompanyVO,
|
||||
type CompanyDTO
|
||||
} from '#/api/org';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import CompanyFormModal from './components/CompanyFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'CompanyManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const companyList = ref<CompanyVO.CompanyInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const companyFormModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
contactPerson: '',
|
||||
contactPhone: '',
|
||||
email: '',
|
||||
status: undefined as number | undefined,
|
||||
expired: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 表单数据(已移至CompanyFormModal组件)
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '正常', value: 1 },
|
||||
];
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '公司名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '公司地址',
|
||||
dataIndex: 'address',
|
||||
key: 'address',
|
||||
width: 250,
|
||||
},
|
||||
{
|
||||
title: '联系人',
|
||||
dataIndex: 'contactPerson',
|
||||
key: 'contactPerson',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: '联系电话',
|
||||
dataIndex: 'contactPhone',
|
||||
key: 'contactPhone',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '邮箱',
|
||||
dataIndex: 'email',
|
||||
key: 'email',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: 'Logo',
|
||||
dataIndex: 'logo',
|
||||
key: 'logo',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
|
||||
if (record.logo) {
|
||||
return h('img', {
|
||||
src: record.logo,
|
||||
alt: record.name,
|
||||
style: { width: '40px', height: '40px', objectFit: 'cover', borderRadius: '4px' },
|
||||
});
|
||||
}
|
||||
return h('span', { style: { color: '#999' } }, '暂无Logo');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
|
||||
const statusMap = {
|
||||
0: { text: '禁用', color: 'red' },
|
||||
1: { text: '正常', color: 'green' },
|
||||
};
|
||||
const status = statusMap[record.status as keyof typeof statusMap] || { text: '未知', color: 'default' };
|
||||
return h(Tag, { color: status.color }, () => status.text);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '过期状态',
|
||||
dataIndex: 'expired',
|
||||
key: 'expired',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
|
||||
if (record.expired === true) {
|
||||
return h(Tag, { color: 'red' }, () => '已过期');
|
||||
} else if (record.expired === false) {
|
||||
return h(Tag, { color: 'green' }, () => '正常');
|
||||
}
|
||||
return h('span', { style: { color: '#999' } }, '未知');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '订阅到期时间',
|
||||
dataIndex: 'expireTime',
|
||||
key: 'expireTime',
|
||||
width: 180,
|
||||
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
|
||||
if (!record.expireTime) {
|
||||
return h('span', { style: { color: '#999' } }, '未设置');
|
||||
}
|
||||
const isExpired = record.expired;
|
||||
return h('span', {
|
||||
style: { color: isExpired ? '#ff4d4f' : '#52c41a' },
|
||||
}, record.expireTime);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchCompanyList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
contactPerson: '',
|
||||
contactPhone: '',
|
||||
email: '',
|
||||
status: undefined,
|
||||
expired: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchCompanyList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchCompanyList();
|
||||
}
|
||||
|
||||
// 处理添加公司
|
||||
function handleAdd() {
|
||||
companyFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑公司
|
||||
function handleEdit(record: CompanyVO.CompanyInfoVO) {
|
||||
companyFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 组件卸载标志
|
||||
let isUnmounted = false;
|
||||
|
||||
// 获取公司列表
|
||||
async function fetchCompanyList() {
|
||||
if (isUnmounted) return;
|
||||
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<CompanyDTO.CompanyFiltersDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
contactPerson: searchForm.value.contactPerson || undefined,
|
||||
contactPhone: searchForm.value.contactPhone || undefined,
|
||||
email: searchForm.value.email || undefined,
|
||||
status: searchForm.value.status,
|
||||
expired: searchForm.value.expired === 'true' ? true : searchForm.value.expired === 'false' ? false : undefined,
|
||||
},
|
||||
};
|
||||
const data = await getCompanyPageApi(params);
|
||||
|
||||
if (isUnmounted) return;
|
||||
|
||||
companyList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
if (isUnmounted) return;
|
||||
|
||||
console.error('获取公司列表失败:', error);
|
||||
message.error('获取公司列表失败');
|
||||
} finally {
|
||||
if (!isUnmounted) {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理删除公司
|
||||
async function handleDelete(record: CompanyVO.CompanyInfoVO) {
|
||||
try {
|
||||
await deleteCompanyApi(record.id);
|
||||
|
||||
if (isUnmounted) return;
|
||||
|
||||
message.success('删除成功');
|
||||
await fetchCompanyList();
|
||||
} catch (error) {
|
||||
if (isUnmounted) return;
|
||||
|
||||
console.error('删除公司失败:', error);
|
||||
message.error('删除公司失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功回调
|
||||
async function handleModalSuccess() {
|
||||
await fetchCompanyList();
|
||||
}
|
||||
|
||||
// Logo相关方法已移至CompanyFormModal组件
|
||||
|
||||
// 初始化
|
||||
fetchCompanyList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="公司管理">
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理公司信息,包括公司基本信息、联系方式和订阅状态
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
添加公司
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">公司名称</label>
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入公司名称"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">联系人</label>
|
||||
<Input
|
||||
v-model:value="searchForm.contactPerson"
|
||||
placeholder="请输入联系人"
|
||||
style="width: 150px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">联系电话</label>
|
||||
<Input
|
||||
v-model:value="searchForm.contactPhone"
|
||||
placeholder="请输入联系电话"
|
||||
style="width: 150px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">邮箱</label>
|
||||
<Input
|
||||
v-model:value="searchForm.email"
|
||||
placeholder="请输入邮箱"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
placeholder="请选择状态"
|
||||
style="width: 120px;"
|
||||
:options="statusOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">过期状态</label>
|
||||
<Select
|
||||
v-model:value="searchForm.expired"
|
||||
placeholder="请选择过期状态"
|
||||
style="width: 120px;"
|
||||
:options="[
|
||||
{ label: '已过期', value: 'true' },
|
||||
{ label: '正常', value: 'false' }
|
||||
]"
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: end;">
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="companyList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
|
||||
<!-- 公司表单模态框 -->
|
||||
<CompanyFormModal
|
||||
ref="companyFormModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createDepartmentApi,
|
||||
updateDepartmentApi,
|
||||
type DepartmentVO,
|
||||
type DepartmentDTO
|
||||
} from '#/api/org';
|
||||
|
||||
interface Props {
|
||||
departmentList: DepartmentVO.DepartmentInfoVO[];
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const visible = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentDepartmentData = ref<DepartmentVO.DepartmentInfoVO | null>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<DepartmentDTO.CreateDepartmentDTO>({
|
||||
name: '',
|
||||
parentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
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 => {
|
||||
// 编辑时排除自己和自己的子部门
|
||||
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: 1,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
// 处理模态框关闭
|
||||
function handleCancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value && currentDepartmentData.value) {
|
||||
await updateDepartmentApi(currentDepartmentData.value.id, formData.value);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createDepartmentApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
} 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,
|
||||
};
|
||||
}
|
||||
|
||||
visible.value = true;
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
:open="visible"
|
||||
:title="modalTitle"
|
||||
width="500px"
|
||||
:confirm-loading="loading"
|
||||
@ok="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<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">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
+293
@@ -0,0 +1,293 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, h, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Input, Select, Table, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
deleteDepartmentApi,
|
||||
getDepartmentPageApi,
|
||||
type DepartmentVO,
|
||||
type DepartmentDTO
|
||||
} from '#/api/org';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import DepartmentModal from './components/DepartmentModal.vue';
|
||||
|
||||
defineOptions({ name: 'DepartmentManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const departmentList = ref<DepartmentVO.DepartmentInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const departmentModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const 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;
|
||||
});
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '部门名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '父部门',
|
||||
dataIndex: 'parentId',
|
||||
key: 'parentId',
|
||||
width: 150,
|
||||
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
|
||||
if (!record.parentId) return '根部门';
|
||||
const parent = findParentDepartment(departmentList.value, record.parentId);
|
||||
return parent ? parent.name : '未知';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
|
||||
return h('span', {
|
||||
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
|
||||
}, record.status === 1 ? '启用' : '禁用');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 查找父部门
|
||||
function findParentDepartment(departments: DepartmentVO.DepartmentInfoVO[], parentId: number): DepartmentVO.DepartmentInfoVO | null {
|
||||
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;
|
||||
}
|
||||
|
||||
// 获取部门列表
|
||||
async function fetchDepartmentList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<DepartmentDTO.DepartmentFiltersDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
parentId: searchForm.value.parentId,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getDepartmentPageApi(params);
|
||||
departmentList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取部门列表失败:', error);
|
||||
message.error('获取部门列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchDepartmentList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
parentId: undefined,
|
||||
status: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchDepartmentList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchDepartmentList();
|
||||
}
|
||||
|
||||
// 处理添加部门
|
||||
function handleAdd() {
|
||||
departmentModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑部门
|
||||
function handleEdit(record: DepartmentVO.DepartmentInfoVO) {
|
||||
departmentModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除部门
|
||||
async function handleDelete(record: DepartmentVO.DepartmentInfoVO) {
|
||||
try {
|
||||
await deleteDepartmentApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchDepartmentList();
|
||||
} catch (error) {
|
||||
console.error('删除部门失败:', error);
|
||||
message.error('删除部门失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功回调
|
||||
async function handleModalSuccess() {
|
||||
await fetchDepartmentList();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
fetchDepartmentList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="部门管理">
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理部门信息,支持层级结构,可以创建子部门
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
添加部门
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">部门名称</label>
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入部门名称"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">父部门</label>
|
||||
<Select
|
||||
v-model:value="searchForm.parentId"
|
||||
placeholder="请选择父部门"
|
||||
style="width: 200px;"
|
||||
:options="parentDepartmentOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
placeholder="请选择状态"
|
||||
style="width: 120px;"
|
||||
:options="statusOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: end;">
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="departmentList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
|
||||
<!-- 部门模态框组件 -->
|
||||
<DepartmentModal
|
||||
ref="departmentModalRef"
|
||||
:department-list="departmentList"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createPositionApi,
|
||||
updatePositionApi,
|
||||
type PositionVO,
|
||||
type PositionDTO
|
||||
} from '#/api/org';
|
||||
|
||||
interface Props {
|
||||
departmentOptions: Array<{ label: string; value: number }>;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const visible = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentPositionData = ref<PositionVO.PositionInfoVO | null>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<PositionDTO.CreatePositionDTO>({
|
||||
name: '',
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
];
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑岗位' : '添加岗位');
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
name: '',
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
// 处理模态框关闭
|
||||
function handleCancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value && currentPositionData.value) {
|
||||
await updatePositionApi(currentPositionData.value.id, formData.value);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createPositionApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('保存岗位失败:', error);
|
||||
message.error('保存岗位失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(editMode: boolean = false, positionData?: PositionVO.PositionInfoVO | null) {
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
visible.value = true;
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
:open="visible"
|
||||
:title="modalTitle"
|
||||
width="500px"
|
||||
:confirm-loading="loading"
|
||||
@ok="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<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">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,259 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Input, Select, Table, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
deletePositionApi,
|
||||
getPositionPageApi,
|
||||
type PositionVO,
|
||||
type PositionDTO
|
||||
} from '#/api/org';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import PositionModal from './components/PositionModal.vue';
|
||||
|
||||
defineOptions({ name: 'PositionManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const positionList = ref<PositionVO.PositionInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const positionModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
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 },
|
||||
]);
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '岗位名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '岗位编码',
|
||||
dataIndex: 'code',
|
||||
key: 'code',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: '所属部门',
|
||||
dataIndex: 'departmentId',
|
||||
key: 'departmentId',
|
||||
width: 150,
|
||||
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
|
||||
if (!record.departmentId) return '-';
|
||||
const dept = departmentOptions.value.find(d => d.value === record.departmentId);
|
||||
return dept ? dept.label : '未知部门';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
|
||||
return h('span', {
|
||||
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
|
||||
}, record.status === 1 ? '启用' : '禁用');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 获取岗位列表
|
||||
async function fetchPositionList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<PositionDTO.PositionFiltersDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getPositionPageApi(params);
|
||||
positionList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取岗位列表失败:', error);
|
||||
message.error('获取岗位列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchPositionList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
status: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchPositionList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchPositionList();
|
||||
}
|
||||
|
||||
// 处理添加岗位
|
||||
function handleAdd() {
|
||||
positionModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑岗位
|
||||
function handleEdit(record: PositionVO.PositionInfoVO) {
|
||||
positionModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除岗位
|
||||
async function handleDelete(record: PositionVO.PositionInfoVO) {
|
||||
try {
|
||||
await deletePositionApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchPositionList();
|
||||
} catch (error) {
|
||||
console.error('删除岗位失败:', error);
|
||||
message.error('删除岗位失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功回调
|
||||
async function handleModalSuccess() {
|
||||
await fetchPositionList();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
fetchPositionList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="岗位管理">
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理岗位信息,包括岗位名称、编码、所属部门和描述
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
添加岗位
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">岗位名称</label>
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入岗位名称"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
placeholder="请选择状态"
|
||||
style="width: 120px;"
|
||||
:options="statusOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: end;">
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="positionList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
|
||||
<!-- 岗位模态框组件 -->
|
||||
<PositionModal
|
||||
ref="positionModalRef"
|
||||
:department-options="departmentOptions"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user