refactor(admin): 部门管理树形页控件换用 Element Plus
This commit is contained in:
1 parent
ec47e012a7
commit
9dd7184aa7
5 files changed
+494
-411
No files matched your search
+1
-1
@@ -672,7 +672,7 @@
|
||||
| 管理端运营总览 | 「数据报表」新增「运营总览」入口:展示对话量/活跃用户/活跃应用/好评率、对话趋势与环比、Top 应用与低使用应用、低评分回答与未处理反馈,复用 chat_logs/feedbacks/general_feedbacks/agents/应用授权数据 | 已实现(数据处理) | P1 |
|
||||
| 管理端问题分析 | 「数据报表」新增「问题分析」入口,第一版为页面骨架与空状态,不伪造数据 | 已实现(骨架) | P2 |
|
||||
| 管理端时间范围统一 | 「数据报表」各数据页时间范围筛选器统一为「近 7 天 / 30 天 / 90 天」,并同步四语言文案 | 已实现 | P1 |
|
||||
| 管理端部门管理(组织树) | 部门管理改为树形组织结构(对应 OA 组织架构,层级来源对齐 ERP HRAO:hrao01 编码 / hrao02 名称 / hrao06 上级 / hrao09 同级排序 / hrao08 隐藏标记):`departments` 表增加 `parent_id`(邻接表)/ `sort_order` / `is_hidden`(迁移 `dp1a2b3c4d5e6`),`name` 全局唯一放开为「同一上级下唯一」;页面为树形表格,树顶公司层为前端按 `company` 字段虚拟分组不入库;节点支持添加子部门/编辑/删除(有下级或有员工禁删)、搜索命中自动展开、全部展开/收起;员工展示改为 OA 组织结构口径(左树右成员面板):树表员工计数列剔除,点击部门节点右侧分页展示成员名单(关键词搜索姓名/工号/邮箱/手机、每页 20/50/100 可调,「含下级部门」口径可切换,成员接口 `members` 支持 keyword/page/page_size);新增错误码 `DEPT.*` 四语言。ERP 一次性导入脚本已提供(`backend/scripts/import_departments_from_hrao.py`:DBeaver 导出 HRAO_FILE CSV + 公司映射取自 HRAA_FILE,dry-run 默认、`--apply` 按编码 upsert 合并、悬空/成环/重名告警兜底),已于 2026-10-08 执行首次全量导入(366 部门 / 7 公司,本地 56 行全部按编码命中更新);持续同步仍未做 | 已实现 | P1 |
|
||||
| 管理端部门管理(组织树) | 部门管理改为树形组织结构(对应 OA 组织架构,层级来源对齐 ERP HRAO:hrao01 编码 / hrao02 名称 / hrao06 上级 / hrao09 同级排序 / hrao08 隐藏标记):`departments` 表增加 `parent_id`(邻接表)/ `sort_order` / `is_hidden`(迁移 `dp1a2b3c4d5e6`),`name` 全局唯一放开为「同一上级下唯一」;页面为左树右成员面板(OA 组织结构口径,控件已按 Element Plus 迁移规范 Element 化:ElTable/ElPagination/ElTag/ElDialog/ElMessageBox,树行为自定义层级结构),树顶公司层为前端按 `company` 字段虚拟分组不入库;节点支持添加子部门/编辑/删除(有下级或有员工禁删)、搜索命中自动展开、全部展开/收起;员工展示改为 OA 组织结构口径(左树右成员面板):树表员工计数列剔除,点击部门节点右侧分页展示成员名单(关键词搜索姓名/工号/邮箱/手机、每页 20/50/100 可调,「含下级部门」口径可切换,成员接口 `members` 支持 keyword/page/page_size);新增错误码 `DEPT.*` 四语言。ERP 一次性导入脚本已提供(`backend/scripts/import_departments_from_hrao.py`:DBeaver 导出 HRAO_FILE CSV + 公司映射取自 HRAA_FILE,dry-run 默认、`--apply` 按编码 upsert 合并、悬空/成环/重名告警兜底),已于 2026-10-08 执行首次全量导入(366 部门 / 7 公司,本地 56 行全部按编码命中更新);持续同步仍未做 | 已实现 | P1 |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ section.admin-table-section 一张圆角卡片,页面上只此一层
|
||||
| 用户管理 | 列表、筛选、三个业务弹窗、删除和改角色确认已按 §3、§4 对齐。筛选宽度和两列表单写在页面里。 |
|
||||
| 知识库分组 | 列表骨架、行内链接按钮、删除确认、创建分组、Dify 设置和健康检查已对齐。 |
|
||||
| 应用配置 | 列表、状态标签、测试弹窗、授权弹窗、删除确认和 680px 创建/编辑表单内部已对齐。保存仍走原来的 `save` 事件。 |
|
||||
| 部门管理 | 列表已用 `AdminListPage`。搜索、表头排序、行内链接、480px 表单、员工名单和删除确认已按 §3、§4 对齐。列表仍是本地过滤和排序,没有分页。 |
|
||||
| 部门管理 | 已改为左树右成员面板的组织树页(非 AdminListPage 列表骨架,页面头注释有说明)。树行内链接按钮、成员 ElTable/ElPagination/ElTag、680px 表单(含上级部门/同级排序/隐藏标记)和 ElMessageBox 删除确认已按 §4 对齐;成员分页走服务端。 |
|
||||
| 公告管理 | 列表已用 `AdminListPage`。发布/编辑是 680px 对话框,详情是描述列表,删除确认已对齐。 |
|
||||
| 关联服务 | 列表已用 `AdminListPage`。启用用 `ElSwitch`,表单 480px,删除确认已对齐。 |
|
||||
| 知识库分组 | 外层不再套第二张卡片,列表骨架改为 `AdminListPage`。 |
|
||||
|
||||
@@ -1,33 +1,40 @@
|
||||
/**
|
||||
* features/admin/modules/departments/DepartmentsPage.vue
|
||||
* 用途:部门管理独立页面——左树(公司虚拟分组 + 部门层级)右成员面板(OA 组织结构口径)。
|
||||
* 依赖:useDepartmentsAdmin、DepartmentFormModal、DeleteConfirmDialog。
|
||||
* 逻辑:路由 /admin/departments;左侧点击部门节点后,右侧按分页 + 关键词展示该部门成员
|
||||
* (含下级口径可切换);原「员工」计数列已剔除,成员展示方式对齐 OA 组织结构页。
|
||||
* 依赖:useDepartmentsAdmin、DepartmentFormModal、element-plus、@element-plus/icons-vue。
|
||||
* 逻辑:路由 /admin/departments。左侧点击部门节点后,右侧按分页 + 关键词展示该部门成员
|
||||
* (含下级口径可切换);删除确认走 ElMessageBox。控件按 ELEMENT_MIGRATION.md 全量 Element 化,
|
||||
* 树本身是自定义层级结构,不是 ElTable/ElTree 列表页,故不走 AdminListPage 骨架。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElButton, ElCheckbox, ElConfigProvider, ElEmpty, ElIcon, ElInput, ElLoading, ElPagination, ElTable, ElTableColumn, ElTag } from 'element-plus';
|
||||
import {
|
||||
Building2,
|
||||
ChevronDown,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
ArrowDown,
|
||||
ArrowRight,
|
||||
Delete,
|
||||
Edit,
|
||||
EyeOff,
|
||||
FolderPlus,
|
||||
ListTree,
|
||||
Expand,
|
||||
Fold,
|
||||
FolderAdd,
|
||||
Hide,
|
||||
OfficeBuilding,
|
||||
Plus,
|
||||
Search,
|
||||
Trash2,
|
||||
Users,
|
||||
} from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
} from '@element-plus/icons-vue';
|
||||
import DepartmentFormModal from './components/DepartmentFormModal.vue';
|
||||
import { useDepartmentsAdmin } from './composables/useDepartmentsAdmin';
|
||||
import { useElementProvider } from '@/features/admin/composables/useElementProvider';
|
||||
import type { AdminDepartmentTreeNode } from '@/features/admin/types/admin.types';
|
||||
import 'element-plus/dist/index.css';
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||
import '@/features/admin/styles/element-trial.css';
|
||||
|
||||
const vLoading = ElLoading.directive;
|
||||
|
||||
const { t, te } = useI18n();
|
||||
const { elementLocale } = useElementProvider();
|
||||
|
||||
const {
|
||||
displayRows,
|
||||
@@ -37,8 +44,6 @@ const {
|
||||
isLoading,
|
||||
isSaving,
|
||||
showFormModal,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
loadAll,
|
||||
toggleNode,
|
||||
toggleCompany,
|
||||
@@ -49,8 +54,6 @@ const {
|
||||
closeFormModal,
|
||||
saveDepartment,
|
||||
deleteDepartment,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
selectedDeptId,
|
||||
selectedDept,
|
||||
selectedDeptPath,
|
||||
@@ -67,6 +70,18 @@ const {
|
||||
setMemberPageSize,
|
||||
} = useDepartmentsAdmin();
|
||||
|
||||
/** 成员面板总页数(由 total / page_size 推导)。 */
|
||||
const memberTotalPages = computed(() => {
|
||||
const data = memberData.value;
|
||||
if (!data || data.page_size <= 0) return 1;
|
||||
return Math.max(1, Math.ceil(data.total / data.page_size));
|
||||
});
|
||||
|
||||
/** 左树空状态文案:搜索无结果或尚无部门。 */
|
||||
const treeEmptyText = computed(() => (
|
||||
searchQuery.value.trim() ? t('admin.dept.noSearchResults') : t('admin.dept.noDepts')
|
||||
));
|
||||
|
||||
/** 成员状态 → 本地化标签;未知状态回退显示原值。 */
|
||||
const statusLabel = (status?: string): string => {
|
||||
if (!status) return '-';
|
||||
@@ -74,12 +89,12 @@ const statusLabel = (status?: string): string => {
|
||||
return te(key) ? t(key) : status;
|
||||
};
|
||||
|
||||
/** 成员面板总页数(由 total / page_size 推导)。 */
|
||||
const memberTotalPages = computed(() => {
|
||||
const data = memberData.value;
|
||||
if (!data || data.page_size <= 0) return 1;
|
||||
return Math.max(1, Math.ceil(data.total / data.page_size));
|
||||
});
|
||||
/** 成员状态 → ElTag 类型:启用 success,待审核 warning,其余 info。 */
|
||||
const statusTagType = (status?: string): 'success' | 'warning' | 'info' => {
|
||||
if (status === 'active') return 'success';
|
||||
if (status === 'pending') return 'warning';
|
||||
return 'info';
|
||||
};
|
||||
|
||||
/** 公司虚拟分组行 key 去前缀,得到分组 key(用于展开状态)。 */
|
||||
const companyGroupKey = (rowKey: string): string => rowKey.slice('company:'.length);
|
||||
@@ -90,257 +105,189 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-table-section animate-fade-in-up">
|
||||
<div v-if="isLoading" class="flex items-center justify-center py-20">
|
||||
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-brand-600" />
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<ElConfigProvider :locale="elementLocale">
|
||||
<section class="admin-table-section">
|
||||
<header class="admin-table-header admin-table-header--stacked">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.dept.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.dept.subtitle') }}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-brand-600 text-white rounded-xl hover:bg-brand-700 transition-all shadow-lg shadow-brand-200 active:scale-95 text-sm font-medium"
|
||||
@click="openCreateModal()"
|
||||
>
|
||||
<Plus class="w-4 h-4" />
|
||||
<span>{{ t('admin.dept.add') }}</span>
|
||||
</button>
|
||||
<ElButton type="primary" :icon="Plus" @click="openCreateModal()">
|
||||
{{ t('admin.dept.add') }}
|
||||
</ElButton>
|
||||
</header>
|
||||
|
||||
<!-- 筛选条:左树搜索 + 展开/收起,一条分隔线与内容区分开 -->
|
||||
<div class="admin-dept-filter">
|
||||
<ElInput
|
||||
v-model="searchQuery"
|
||||
class="admin-dept-filter__search"
|
||||
:prefix-icon="Search"
|
||||
clearable
|
||||
:placeholder="t('admin.dept.searchPlaceholder')"
|
||||
/>
|
||||
<ElButton text :icon="Expand" :title="t('admin.dept.expandAll')" @click="expandAll" />
|
||||
<ElButton text :icon="Fold" :title="t('admin.dept.collapseAll')" @click="collapseAll" />
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col lg:flex-row gap-4 items-start">
|
||||
<div v-loading="isLoading" class="admin-dept-body">
|
||||
<!-- 左侧:组织树(公司虚拟分组 + 层级缩进) -->
|
||||
<div class="w-full lg:w-[340px] shrink-0 rounded-2xl border border-subtle bg-surface flex flex-col gap-3 p-4 lg:max-h-[calc(100vh-230px)] overflow-hidden">
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="relative flex-1 min-w-0">
|
||||
<Search class="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted pointer-events-none" />
|
||||
<input
|
||||
v-model="searchQuery"
|
||||
type="search"
|
||||
class="admin-table-filter-input w-full pl-9"
|
||||
:placeholder="t('admin.dept.searchPlaceholder')"
|
||||
<div class="admin-dept-tree">
|
||||
<ElEmpty v-if="displayRows.length === 0" :description="treeEmptyText" :image-size="80" />
|
||||
<template v-for="row in displayRows" :key="row.key">
|
||||
<!-- 公司虚拟分组行(不入库,前端按 company 字段归堆) -->
|
||||
<div
|
||||
v-if="row.kind === 'company'"
|
||||
class="admin-dept-tree__row admin-dept-tree__row--company"
|
||||
@click="toggleCompany(companyGroupKey(row.key))"
|
||||
>
|
||||
<ElIcon class="admin-dept-tree__chevron">
|
||||
<component :is="row.expanded ? ArrowDown : ArrowRight" />
|
||||
</ElIcon>
|
||||
<ElIcon class="admin-dept-tree__company-icon"><OfficeBuilding /></ElIcon>
|
||||
<span class="admin-dept-tree__name" :title="row.company">{{ row.company }}</span>
|
||||
<ElButton
|
||||
link
|
||||
type="primary"
|
||||
:icon="FolderAdd"
|
||||
:title="t('admin.dept.addChild')"
|
||||
@click.stop="openCreateModal(null, row.company)"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="p-2 text-muted hover:text-primary hover:bg-subtle rounded-lg transition-colors shrink-0"
|
||||
:title="t('admin.dept.expandAll')"
|
||||
@click="expandAll"
|
||||
><ListTree class="w-4 h-4" /></button>
|
||||
<button
|
||||
type="button"
|
||||
class="p-2 text-muted hover:text-primary hover:bg-subtle rounded-lg transition-colors shrink-0"
|
||||
:title="t('admin.dept.collapseAll')"
|
||||
@click="collapseAll"
|
||||
><ChevronDown class="w-4 h-4" /></button>
|
||||
</div>
|
||||
|
||||
<div class="overflow-y-auto min-h-0 -mx-1 px-1 space-y-0.5">
|
||||
<div v-if="displayRows.length === 0" class="py-12 text-center text-sm text-muted">
|
||||
{{ searchQuery.trim() ? t('admin.dept.noSearchResults') : t('admin.dept.noDepts') }}
|
||||
</div>
|
||||
<template v-for="row in displayRows" :key="row.key">
|
||||
<!-- 公司虚拟分组行(不入库,前端按 company 字段归堆) -->
|
||||
<div
|
||||
v-if="row.kind === 'company'"
|
||||
class="group flex items-center gap-1.5 py-2 pr-1 rounded-lg cursor-pointer select-none hover:bg-subtle/70"
|
||||
@click="toggleCompany(companyGroupKey(row.key))"
|
||||
<!-- 部门行(层级缩进;点击选中 → 右侧出成员面板) -->
|
||||
<div
|
||||
v-else
|
||||
class="admin-dept-tree__row"
|
||||
:class="{ 'is-selected': selectedDeptId === row.node!.id }"
|
||||
:style="{ paddingLeft: `${(row.depth - 1) * 16 + 4}px` }"
|
||||
@click="selectDept(row.node!)"
|
||||
>
|
||||
<button
|
||||
v-if="row.hasChildren"
|
||||
type="button"
|
||||
class="admin-dept-tree__toggle"
|
||||
:title="row.expanded ? t('admin.dept.collapse') : t('admin.dept.expand')"
|
||||
@click.stop="toggleNode(row.node!.id)"
|
||||
>
|
||||
<component
|
||||
:is="row.expanded ? ChevronDown : ChevronRight"
|
||||
class="w-4 h-4 text-muted shrink-0"
|
||||
/>
|
||||
<Building2 class="w-4 h-4 text-brand-600 shrink-0" />
|
||||
<span class="font-semibold text-primary text-sm truncate" :title="row.company">{{ row.company }}</span>
|
||||
<span class="flex-1" />
|
||||
<button
|
||||
type="button"
|
||||
class="p-1.5 text-emerald-600 hover:bg-emerald-50 rounded-lg transition-colors shrink-0"
|
||||
<ElIcon>
|
||||
<component :is="row.expanded ? ArrowDown : ArrowRight" />
|
||||
</ElIcon>
|
||||
</button>
|
||||
<span v-else class="admin-dept-tree__toggle" />
|
||||
<span class="admin-dept-tree__name" :title="row.node!.name">{{ row.node!.name }}</span>
|
||||
<ElTag
|
||||
v-if="row.node!.is_hidden"
|
||||
type="warning"
|
||||
effect="light"
|
||||
size="small"
|
||||
:icon="Hide"
|
||||
:title="t('admin.dept.fields.hiddenHint')"
|
||||
>
|
||||
{{ t('admin.dept.tags.hidden') }}
|
||||
</ElTag>
|
||||
<span class="admin-dept-tree__spacer" />
|
||||
<span class="admin-dept-tree__actions" @click.stop>
|
||||
<ElButton
|
||||
link
|
||||
type="primary"
|
||||
:icon="FolderAdd"
|
||||
:title="t('admin.dept.addChild')"
|
||||
@click.stop="openCreateModal(null, row.company)"
|
||||
>
|
||||
<FolderPlus class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
<!-- 部门行(层级缩进;点击选中 → 右侧出成员面板) -->
|
||||
<div
|
||||
v-else
|
||||
class="group flex items-center gap-1.5 py-2 pr-1 rounded-lg cursor-pointer select-none transition-colors"
|
||||
:class="selectedDeptId === row.node!.id ? 'bg-brand-50 dark:bg-brand-900/30' : 'hover:bg-subtle/70'"
|
||||
:style="{ paddingLeft: `${(row.depth - 1) * 16 + 4}px` }"
|
||||
@click="selectDept(row.node!)"
|
||||
>
|
||||
<button
|
||||
v-if="row.hasChildren"
|
||||
type="button"
|
||||
class="p-0.5 text-muted hover:text-primary rounded transition-colors shrink-0"
|
||||
:title="row.expanded ? t('admin.dept.collapse') : t('admin.dept.expand')"
|
||||
@click.stop="toggleNode(row.node!.id)"
|
||||
>
|
||||
<component :is="row.expanded ? ChevronDown : ChevronRight" class="w-4 h-4" />
|
||||
</button>
|
||||
<span v-else class="w-5 shrink-0" />
|
||||
<span class="font-medium text-sm truncate" :class="selectedDeptId === row.node!.id ? 'text-brand-700' : 'text-primary'" :title="row.node!.name">{{ row.node!.name }}</span>
|
||||
<span
|
||||
v-if="row.node!.is_hidden"
|
||||
class="inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] bg-amber-50 text-amber-700 shrink-0"
|
||||
:title="t('admin.dept.fields.hiddenHint')"
|
||||
><EyeOff class="w-3 h-3" />{{ t('admin.dept.tags.hidden') }}</span>
|
||||
<span class="flex-1" />
|
||||
<span class="hidden group-hover:flex items-center gap-0.5 shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
class="p-1 text-emerald-600 hover:bg-emerald-50 rounded-lg transition-colors"
|
||||
:title="t('admin.dept.addChild')"
|
||||
@click.stop="openCreateModal(row.node as AdminDepartmentTreeNode)"
|
||||
>
|
||||
<FolderPlus class="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="p-1 text-indigo-600 hover:bg-indigo-50 rounded-lg transition-colors"
|
||||
:title="t('admin.dept.actions.edit')"
|
||||
@click.stop="openEditModal(row.node!)"
|
||||
>
|
||||
<Edit class="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="p-1 text-red-600 hover:bg-red-50 rounded-lg transition-colors"
|
||||
:title="t('admin.dept.actions.delete')"
|
||||
@click.stop="deleteDepartment(row.node!.id)"
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
@click="openCreateModal(row.node as AdminDepartmentTreeNode)"
|
||||
/>
|
||||
<ElButton
|
||||
link
|
||||
type="primary"
|
||||
:icon="Edit"
|
||||
:title="t('admin.dept.actions.edit')"
|
||||
@click="openEditModal(row.node!)"
|
||||
/>
|
||||
<ElButton
|
||||
link
|
||||
type="danger"
|
||||
:icon="Delete"
|
||||
:title="t('admin.dept.actions.delete')"
|
||||
@click="deleteDepartment(row.node!.id)"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- 右侧:选中部门的成员面板(OA 口径) -->
|
||||
<div class="flex-1 min-w-0 w-full rounded-2xl border border-subtle bg-surface flex flex-col lg:max-h-[calc(100vh-230px)] overflow-hidden">
|
||||
<div class="admin-dept-members">
|
||||
<template v-if="!selectedDept">
|
||||
<div class="flex-1 flex flex-col items-center justify-center py-24 text-muted">
|
||||
<Users class="w-10 h-10 mb-3 opacity-50" />
|
||||
<p class="text-sm">{{ t('admin.dept.members.hint') }}</p>
|
||||
</div>
|
||||
<ElEmpty class="admin-dept-members__empty" :description="t('admin.dept.members.hint')" :image-size="80" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<header class="px-5 py-4 border-b border-subtle flex items-start justify-between gap-4 flex-wrap">
|
||||
<div class="min-w-0">
|
||||
<h3 class="text-base font-bold text-primary truncate">{{ selectedDept.name }}</h3>
|
||||
<p class="text-xs text-muted mt-0.5 truncate" :title="selectedDeptPath.join(' / ')">
|
||||
{{ selectedDeptPath.join(' / ') }}
|
||||
</p>
|
||||
<header class="admin-dept-members__header">
|
||||
<div class="admin-dept-members__title">
|
||||
<h3>{{ selectedDept.name }}</h3>
|
||||
<p :title="selectedDeptPath.join(' / ')">{{ selectedDeptPath.join(' / ') }}</p>
|
||||
</div>
|
||||
<label class="flex items-center gap-2 text-sm text-muted cursor-pointer select-none shrink-0">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="accent-brand-600 w-4 h-4"
|
||||
:checked="memberIncludeDescendants"
|
||||
@change="setMemberIncludeDescendants(($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
<ElCheckbox
|
||||
:model-value="memberIncludeDescendants"
|
||||
@change="setMemberIncludeDescendants($event as boolean)"
|
||||
>
|
||||
{{ t('admin.dept.members.includeDescendants') }}
|
||||
</label>
|
||||
</ElCheckbox>
|
||||
</header>
|
||||
|
||||
<div class="px-5 py-3 border-b border-subtle">
|
||||
<div class="relative max-w-sm">
|
||||
<Search class="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted pointer-events-none" />
|
||||
<input
|
||||
:value="memberKeyword"
|
||||
type="search"
|
||||
class="admin-table-filter-input w-full pl-9"
|
||||
:placeholder="t('admin.dept.members.searchPlaceholder')"
|
||||
@input="setMemberKeyword(($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
</div>
|
||||
<div class="admin-dept-members__toolbar">
|
||||
<ElInput
|
||||
:model-value="memberKeyword"
|
||||
class="admin-dept-members__search"
|
||||
:prefix-icon="Search"
|
||||
clearable
|
||||
:placeholder="t('admin.dept.members.searchPlaceholder')"
|
||||
@input="setMemberKeyword(String($event))"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="min-h-0 flex-1 overflow-y-auto">
|
||||
<table class="w-full table-fixed text-sm">
|
||||
<colgroup>
|
||||
<col class="w-[24%]" />
|
||||
<col class="w-[26%]" />
|
||||
<col class="w-[16%]" />
|
||||
<col class="w-[18%]" />
|
||||
<col class="w-[16%]" />
|
||||
</colgroup>
|
||||
<!-- sticky 放在 th 上(thead 级 sticky 在部分浏览器不生效,行会从表头上方滚出) -->
|
||||
<thead class="text-xs text-muted">
|
||||
<tr>
|
||||
<th class="px-5 py-3 text-left font-medium sticky top-0 z-10 admin-table-sticky-head">{{ t('admin.dept.members.columns.name') }}</th>
|
||||
<th class="px-5 py-3 text-left font-medium sticky top-0 z-10 admin-table-sticky-head">{{ t('admin.dept.members.columns.contact') }}</th>
|
||||
<th class="px-5 py-3 text-left font-medium sticky top-0 z-10 admin-table-sticky-head">{{ t('admin.dept.members.columns.employeeId') }}</th>
|
||||
<th class="px-5 py-3 text-left font-medium sticky top-0 z-10 admin-table-sticky-head">{{ t('admin.dept.members.columns.department') }}</th>
|
||||
<th class="px-5 py-3 text-left font-medium sticky top-0 z-10 admin-table-sticky-head">{{ t('admin.dept.members.columns.status') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="memberLoading">
|
||||
<td colspan="5" class="px-5 py-10 text-center text-muted">
|
||||
<div class="animate-spin rounded-full h-7 w-7 border-b-2 border-brand-600 mx-auto" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-else-if="!memberData || memberData.members.length === 0">
|
||||
<td colspan="5" class="px-5 py-10 text-center text-muted">{{ t('admin.dept.members.empty') }}</td>
|
||||
</tr>
|
||||
<template v-else>
|
||||
<tr v-for="member in memberData.members" :key="member.id" class="border-t border-subtle hover:bg-subtle/40">
|
||||
<td class="px-5 py-3">
|
||||
<div class="font-medium text-primary truncate">{{ member.real_name || member.username }}</div>
|
||||
<div class="text-xs text-muted truncate">{{ member.username }}</div>
|
||||
</td>
|
||||
<td class="px-5 py-3 text-muted truncate">{{ member.phone_number || member.email || '-' }}</td>
|
||||
<td class="px-5 py-3 text-muted font-mono truncate">{{ member.employee_id || '-' }}</td>
|
||||
<td class="px-5 py-3 text-muted truncate">{{ member.department || '-' }}</td>
|
||||
<td class="px-5 py-3">
|
||||
<span class="inline-flex px-2 py-0.5 rounded-full text-xs bg-blue-50 text-blue-600 whitespace-nowrap">{{ statusLabel(member.status) }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<ElTable
|
||||
v-loading="memberLoading"
|
||||
:data="memberData?.members ?? []"
|
||||
row-key="id"
|
||||
stripe
|
||||
:empty-text="t('admin.dept.members.empty')"
|
||||
class="admin-dept-members__table"
|
||||
>
|
||||
<ElTableColumn :label="t('admin.dept.members.columns.name')" min-width="160">
|
||||
<template #default="{ row }">
|
||||
<div class="admin-dept-member__name">{{ row.real_name || row.username }}</div>
|
||||
<div class="admin-dept-member__sub">{{ row.username }}</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('admin.dept.members.columns.contact')" min-width="170">
|
||||
<template #default="{ row }">{{ row.phone_number || row.email || '-' }}</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn prop="employee_id" :label="t('admin.dept.members.columns.employeeId')" min-width="110" />
|
||||
<ElTableColumn prop="department" :label="t('admin.dept.members.columns.department')" min-width="130" />
|
||||
<ElTableColumn :label="t('admin.dept.members.columns.status')" width="90">
|
||||
<template #default="{ row }">
|
||||
<ElTag :type="statusTagType(row.status)" effect="light" size="small">
|
||||
{{ statusLabel(row.status) }}
|
||||
</ElTag>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
|
||||
<footer v-if="memberData" class="px-5 py-3 border-t border-subtle flex items-center justify-between gap-3 flex-wrap text-sm text-muted">
|
||||
<span>{{ t('admin.dept.members.total', { total: memberData.total }) }}</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<!-- 全局样式已为 select 绘制背景箭头(右缘 8~29px),pr-10 让文字止于 40px,避开箭头区 -->
|
||||
<select
|
||||
:value="memberPageSize"
|
||||
class="admin-table-filter-input pr-10 cursor-pointer"
|
||||
@change="setMemberPageSize(Number(($event.target as HTMLSelectElement).value))"
|
||||
>
|
||||
<option :value="20">20</option>
|
||||
<option :value="50">50</option>
|
||||
<option :value="100">100</option>
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
class="p-1.5 rounded-lg hover:bg-subtle disabled:opacity-40 disabled:pointer-events-none"
|
||||
:disabled="memberPage <= 1"
|
||||
:title="t('admin.dept.members.prevPage')"
|
||||
@click="setMemberPage(memberPage - 1)"
|
||||
><ChevronLeft class="w-4 h-4" /></button>
|
||||
<span class="whitespace-nowrap">{{ memberPage }} / {{ memberTotalPages }}</span>
|
||||
<button
|
||||
type="button"
|
||||
class="p-1.5 rounded-lg hover:bg-subtle disabled:opacity-40 disabled:pointer-events-none"
|
||||
:disabled="memberPage >= memberTotalPages"
|
||||
:title="t('admin.dept.members.nextPage')"
|
||||
@click="setMemberPage(memberPage + 1)"
|
||||
><ChevronRight class="w-4 h-4" /></button>
|
||||
</div>
|
||||
<footer v-if="memberData" class="admin-dept-members__footer">
|
||||
<ElPagination
|
||||
background
|
||||
layout="total, sizes, prev, pager, next"
|
||||
:total="memberData.total"
|
||||
:current-page="memberPage"
|
||||
:page-size="memberPageSize"
|
||||
:page-sizes="[20, 50, 100]"
|
||||
@current-change="setMemberPage"
|
||||
@size-change="setMemberPageSize"
|
||||
/>
|
||||
<span class="admin-dept-members__pages">{{ memberPage }} / {{ memberTotalPages }}</span>
|
||||
</footer>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
|
||||
<DepartmentFormModal
|
||||
:visible="showFormModal"
|
||||
@@ -350,12 +297,156 @@ onMounted(() => {
|
||||
@close="closeFormModal"
|
||||
@save="saveDepartment"
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
@cancel="closeDeleteConfirm"
|
||||
@confirm="confirmDelete"
|
||||
/>
|
||||
</section>
|
||||
</ElConfigProvider>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 页内布局(非 Element 控件内部),间距对齐迁移规范:筛选条、面板分隔、分页右侧 */
|
||||
.admin-dept-filter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 12px 32px;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
.admin-dept-filter__search {
|
||||
width: 16rem;
|
||||
}
|
||||
.admin-dept-body {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
min-height: 24rem;
|
||||
}
|
||||
.admin-dept-tree {
|
||||
width: 320px;
|
||||
flex-shrink: 0;
|
||||
padding: 12px 8px 12px 32px;
|
||||
border-right: 1px solid var(--el-border-color-lighter);
|
||||
max-height: calc(100vh - 280px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
.admin-dept-tree__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 6px 4px;
|
||||
border-radius: var(--el-border-radius-base);
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
min-width: 0;
|
||||
}
|
||||
.admin-dept-tree__row:hover {
|
||||
background: var(--el-fill-color-light);
|
||||
}
|
||||
.admin-dept-tree__row--company {
|
||||
font-weight: 600;
|
||||
}
|
||||
.admin-dept-tree__row.is-selected {
|
||||
background: var(--el-color-primary-light-9);
|
||||
}
|
||||
.admin-dept-tree__row.is-selected .admin-dept-tree__name {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
.admin-dept-tree__chevron,
|
||||
.admin-dept-tree__toggle {
|
||||
flex-shrink: 0;
|
||||
width: 20px;
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
color: var(--el-text-color-secondary);
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
.admin-dept-tree__company-icon {
|
||||
flex-shrink: 0;
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
.admin-dept-tree__name {
|
||||
font-size: var(--el-font-size-base);
|
||||
color: var(--el-text-color-primary);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.admin-dept-tree__spacer {
|
||||
flex: 1;
|
||||
}
|
||||
.admin-dept-tree__actions {
|
||||
display: none;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.admin-dept-tree__row:hover .admin-dept-tree__actions {
|
||||
display: inline-flex;
|
||||
}
|
||||
.admin-dept-members {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.admin-dept-members__empty {
|
||||
margin: auto;
|
||||
}
|
||||
.admin-dept-members__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
padding: 16px 32px 8px;
|
||||
}
|
||||
.admin-dept-members__title {
|
||||
min-width: 0;
|
||||
}
|
||||
.admin-dept-members__title h3 {
|
||||
font-size: var(--el-font-size-large);
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-primary);
|
||||
margin: 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.admin-dept-members__title p {
|
||||
font-size: var(--el-font-size-small);
|
||||
color: var(--el-text-color-secondary);
|
||||
margin: 2px 0 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.admin-dept-members__toolbar {
|
||||
padding: 8px 32px 12px;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
.admin-dept-members__search {
|
||||
width: 16rem;
|
||||
}
|
||||
.admin-dept-members__table {
|
||||
flex: 1;
|
||||
}
|
||||
.admin-dept-members__footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
padding: 12px 32px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
.admin-dept-members__pages {
|
||||
font-size: var(--el-font-size-small);
|
||||
color: var(--el-text-color-secondary);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.admin-dept-member__name {
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
.admin-dept-member__sub {
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-top: 2px;
|
||||
}
|
||||
</style>
|
||||
+124
-102
@@ -1,15 +1,17 @@
|
||||
/**
|
||||
* features/admin/modules/departments/components/DepartmentFormModal.vue
|
||||
* 用途:部门创建/编辑居中弹窗(含上级部门选择、同级排序、隐藏标记)。
|
||||
* 依赖:DepartmentFormState、DeptParentOption、admin 通用 modal 样式。
|
||||
* 逻辑:DepartmentsPage 打开本组件;上级选项由父级传入(编辑时已排除自身及子孙);提交时 emit save。
|
||||
* 用途:部门创建/编辑对话框(上级部门选择、同级排序、隐藏标记)。
|
||||
* 依赖:element-plus 对话框和表单、DepartmentFormState、DeptParentOption。
|
||||
* 逻辑:DepartmentsPage 打开本组件。上级选项由父级传入(编辑时已排除自身及子孙,防成环);
|
||||
* 公司未填时由后端继承上级部门;提交时 emit save,由 useDepartmentsAdmin 调接口。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElButton, ElCol, ElDialog, ElForm, ElFormItem, ElInput, ElInputNumber, ElOption, ElRow, ElSelect, ElSwitch } from 'element-plus';
|
||||
import type { DepartmentFormState } from '@/features/admin/types/department.types';
|
||||
import type { DeptParentOption } from '../composables/useDepartmentsAdmin';
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
form: DepartmentFormState;
|
||||
parentOptions: DeptParentOption[];
|
||||
@@ -22,107 +24,127 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 上级部门下拉回写:ElSelect 不接受 null 类型,空值在此统一为 null(顶级部门)。
|
||||
* @param value - 下拉选中的值
|
||||
*/
|
||||
function onParentChange(value: unknown): void {
|
||||
props.form.parentId = (value ?? null) as number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对话框关闭时通知页面收起并重置表单。
|
||||
* @param open - Element 对话框的打开状态
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="admin-modal-overlay animate-fade-in items-center">
|
||||
<div class="admin-modal-panel max-w-lg max-h-[92vh] scale-100">
|
||||
<div class="px-5 sm:px-8 pt-5 sm:pt-7 pb-4 border-b border-subtle">
|
||||
<h3 class="section-title">
|
||||
{{ form.id ? t('admin.dept.edit') : t('admin.dept.add') }}
|
||||
</h3>
|
||||
</div>
|
||||
<div class="px-5 sm:px-8 py-5 space-y-4 overflow-y-auto">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.dept.fields.parent') }}</label>
|
||||
<select v-model="form.parentId" class="input-field text-sm">
|
||||
<option
|
||||
v-for="option in parentOptions"
|
||||
:key="String(option.id)"
|
||||
:value="option.id"
|
||||
:disabled="option.disabled"
|
||||
>
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.dept.fields.name') }}</label>
|
||||
<input
|
||||
v-model="form.name"
|
||||
type="text"
|
||||
class="input-field text-sm"
|
||||
:placeholder="t('admin.dept.fields.namePlaceholder')"
|
||||
<ElDialog
|
||||
:model-value="visible"
|
||||
:title="form.id ? t('admin.dept.edit') : t('admin.dept.add')"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!isSaving"
|
||||
:show-close="!isSaving"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<ElForm label-position="top" :model="form" @submit.prevent="emit('save')">
|
||||
<ElFormItem :label="t('admin.dept.fields.parent')">
|
||||
<!-- 运行时以 null 表示顶级部门(有对应选项),modelValue 的类型限制此处用 as any 放行 -->
|
||||
<ElSelect :model-value="(form.parentId ?? null) as any" filterable @update:model-value="onParentChange">
|
||||
<ElOption
|
||||
v-for="option in parentOptions"
|
||||
:key="String(option.id)"
|
||||
:label="option.label"
|
||||
:value="option.id as number"
|
||||
:disabled="option.disabled"
|
||||
/>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.dept.fields.code') }}</label>
|
||||
<input
|
||||
v-model="form.code"
|
||||
type="text"
|
||||
class="input-field text-sm"
|
||||
:placeholder="t('admin.dept.fields.codePlaceholder')"
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.dept.fields.name')" required>
|
||||
<ElInput v-model="form.name" :placeholder="t('admin.dept.fields.namePlaceholder')" />
|
||||
</ElFormItem>
|
||||
<ElRow>
|
||||
<ElCol :span="12" class="admin-dept-form__col">
|
||||
<ElFormItem :label="t('admin.dept.fields.code')">
|
||||
<ElInput v-model="form.code" :placeholder="t('admin.dept.fields.codePlaceholder')" />
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
<ElCol :span="12" class="admin-dept-form__col">
|
||||
<ElFormItem :label="t('admin.dept.fields.company')">
|
||||
<ElInput v-model="form.company" :placeholder="t('admin.dept.fields.companyPlaceholder')" />
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
<ElRow>
|
||||
<ElCol :span="12" class="admin-dept-form__col">
|
||||
<ElFormItem :label="t('admin.dept.fields.sort')">
|
||||
<ElInputNumber
|
||||
:model-value="form.sortOrder ?? 0"
|
||||
:min="0"
|
||||
class="admin-dept-form__number"
|
||||
@update:model-value="form.sortOrder = $event ?? 0"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.dept.fields.company') }}</label>
|
||||
<input
|
||||
v-model="form.company"
|
||||
type="text"
|
||||
class="input-field text-sm"
|
||||
:placeholder="t('admin.dept.fields.companyPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4 items-start">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.dept.fields.sort') }}</label>
|
||||
<input
|
||||
v-model.number="form.sortOrder"
|
||||
type="number"
|
||||
class="input-field text-sm"
|
||||
:placeholder="'0'"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.dept.fields.visibility') }}</label>
|
||||
<label class="flex items-center gap-2 text-sm text-muted cursor-pointer select-none py-2">
|
||||
<input v-model="form.isHidden" type="checkbox" class="accent-brand-600 w-4 h-4" />
|
||||
{{ t('admin.dept.fields.hidden') }}
|
||||
</label>
|
||||
<p class="text-xs text-muted">{{ t('admin.dept.fields.hiddenHint') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.dept.fields.description') }}</label>
|
||||
<textarea
|
||||
v-model="form.description"
|
||||
rows="3"
|
||||
class="input-field text-sm resize-y"
|
||||
:placeholder="t('admin.dept.fields.descriptionPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-modal-footer">
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">
|
||||
{{ t('admin.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary disabled:opacity-70"
|
||||
:disabled="isSaving"
|
||||
@click="emit('save')"
|
||||
>
|
||||
{{
|
||||
isSaving
|
||||
? t('admin.save') + '...'
|
||||
: form.id
|
||||
? t('admin.update')
|
||||
: t('admin.add')
|
||||
}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
<ElCol :span="12" class="admin-dept-form__col">
|
||||
<ElFormItem :label="t('admin.dept.fields.visibility')">
|
||||
<div class="admin-dept-form__switch">
|
||||
<ElSwitch v-model="form.isHidden" />
|
||||
<span class="admin-dept-form__switch-label">{{ t('admin.dept.fields.hidden') }}</span>
|
||||
</div>
|
||||
<p class="admin-dept-form__hint">{{ t('admin.dept.fields.hiddenHint') }}</p>
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
<ElFormItem :label="t('admin.dept.fields.description')">
|
||||
<ElInput
|
||||
v-model="form.description"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
:placeholder="t('admin.dept.fields.descriptionPlaceholder')"
|
||||
/>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
<template #footer>
|
||||
<ElButton :disabled="isSaving" @click="emit('close')">{{ t('admin.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="isSaving" @click="emit('save')">
|
||||
{{ form.id ? t('admin.update') : t('admin.add') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.admin-dept-form__col {
|
||||
padding-right: 16px;
|
||||
}
|
||||
.admin-dept-form__col:last-child {
|
||||
padding-right: 0;
|
||||
}
|
||||
.admin-dept-form__number {
|
||||
width: 100%;
|
||||
}
|
||||
.admin-dept-form__switch {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding-top: 4px;
|
||||
}
|
||||
.admin-dept-form__switch-label {
|
||||
font-size: var(--el-font-size-base);
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
.admin-dept-form__hint {
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
color: var(--el-text-color-secondary);
|
||||
margin: 4px 0 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
+22
-52
@@ -1,12 +1,13 @@
|
||||
/**
|
||||
* features/admin/modules/departments/composables/useDepartmentsAdmin.ts
|
||||
* 用途:部门树加载、公司虚拟分组、展开/收起、搜索过滤、创建/编辑/删除。
|
||||
* 依赖:admin.api、department.types、useMessage。
|
||||
* 依赖:admin.api、department.types、useMessage、element-plus 的确认框。
|
||||
* 逻辑:DepartmentsPage 调用本 composable;数据来自 /admin/departments/tree(children 已按同级排序号排好);
|
||||
* 公司层不入库,按顶级部门的 company 字段在前端虚拟分组。
|
||||
* 公司层不入库,按顶级部门的 company 字段在前端虚拟分组;删除用 ElMessageBox,不再使用 DeleteConfirmDialog。
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
import {
|
||||
createAdminDepartment,
|
||||
deleteAdminDepartment,
|
||||
@@ -58,10 +59,6 @@ export function useDepartmentsAdmin() {
|
||||
const isSaving = ref(false);
|
||||
const showFormModal = ref(false);
|
||||
|
||||
const showDeleteConfirmDialog = ref(false);
|
||||
const deleteConfirmMessage = ref('');
|
||||
let deleteConfirmAction: (() => Promise<void> | void) | null = null;
|
||||
|
||||
/** 展开状态:部门节点 id 集合 / 公司分组 key 集合 */
|
||||
const expandedIds = ref<Set<number>>(new Set());
|
||||
const expandedCompanies = ref<Set<string>>(new Set());
|
||||
@@ -353,36 +350,6 @@ export function useDepartmentsAdmin() {
|
||||
expandedCompanies.value = new Set();
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开删除确认对话框并绑定确认后的删除动作。
|
||||
* @param message - 确认文案
|
||||
* @param action - 用户确认后执行的异步删除逻辑
|
||||
*/
|
||||
const openDeleteConfirm = (message: string, action: () => Promise<void> | void): void => {
|
||||
deleteConfirmMessage.value = message;
|
||||
deleteConfirmAction = action;
|
||||
showDeleteConfirmDialog.value = true;
|
||||
};
|
||||
|
||||
/** 关闭删除确认对话框并清空待执行动作。 */
|
||||
const closeDeleteConfirm = (): void => {
|
||||
showDeleteConfirmDialog.value = false;
|
||||
deleteConfirmAction = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 执行删除确认对话框中绑定的删除动作。
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
const confirmDelete = async (): Promise<void> => {
|
||||
if (!deleteConfirmAction) return;
|
||||
try {
|
||||
await deleteConfirmAction();
|
||||
} finally {
|
||||
closeDeleteConfirm();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开「添加部门」弹窗。
|
||||
* @param parent - 上级部门节点(添加子部门时传入);空 = 顶级
|
||||
@@ -448,21 +415,28 @@ export function useDepartmentsAdmin() {
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除指定部门,删除前弹出确认框。
|
||||
* 删除指定部门:ElMessageBox 确认后调接口。
|
||||
* 有下级部门或名下仍有员工时后端返回 409(HAS_CHILDREN / HAS_MEMBERS),此处展示其文案。
|
||||
* @param id - 部门主键
|
||||
*/
|
||||
const deleteDepartment = (id: number): void => {
|
||||
openDeleteConfirm(t('admin.dept.confirmDelete'), async () => {
|
||||
try {
|
||||
await deleteAdminDepartment(id);
|
||||
await loadDepartments();
|
||||
syncMemberPanelAfterTreeReload(id);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
});
|
||||
const deleteDepartment = async (id: number): Promise<void> => {
|
||||
try {
|
||||
await ElMessageBox.confirm(t('admin.dept.confirmDelete'), t('common.deleteDialog.defaultTitle'), {
|
||||
type: 'warning',
|
||||
confirmButtonText: t('common.deleteDialog.confirm'),
|
||||
cancelButtonText: t('common.deleteDialog.cancel'),
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await deleteAdminDepartment(id);
|
||||
await loadDepartments();
|
||||
syncMemberPanelAfterTreeReload(id);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -474,8 +448,6 @@ export function useDepartmentsAdmin() {
|
||||
isLoading,
|
||||
isSaving,
|
||||
showFormModal,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
loadAll,
|
||||
toggleNode,
|
||||
toggleCompany,
|
||||
@@ -486,8 +458,6 @@ export function useDepartmentsAdmin() {
|
||||
closeFormModal,
|
||||
saveDepartment,
|
||||
deleteDepartment,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
// 成员面板(OA 口径:左树右成员列表)
|
||||
selectedDeptId,
|
||||
selectedDept,
|
||||
|
||||
Reference in new issue
Block a user