feat: element plus UI组件库
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
041bb73b9a
commit
5f6fbcd76f
30 files changed
+3621
-1327
No files matched your search
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* features/admin/composables/useElementProvider.ts
|
||||
* 用途:管理端 Element Plus 试点的界面语言。
|
||||
* 依赖:element-plus locale、vue-i18n。
|
||||
* 逻辑:UsersPage、AgentsPage、KbAdminPanel 把 elementLocale 传给 ElConfigProvider;亮暗靠 html.dark 与 Element 暗色变量,不在这里重复切换。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
||||
import zhTw from 'element-plus/es/locale/lang/zh-tw';
|
||||
import en from 'element-plus/es/locale/lang/en';
|
||||
import th from 'element-plus/es/locale/lang/th';
|
||||
|
||||
const ELEMENT_LOCALES = {
|
||||
'zh-CN': zhCn,
|
||||
'zh-TW': zhTw,
|
||||
en,
|
||||
th,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 取当前界面语言对应的 Element Plus 语言包。
|
||||
* 核心逻辑:未知语言回退简体中文。
|
||||
* @returns elementLocale,随 vue-i18n 语言变化
|
||||
*/
|
||||
export function useElementProvider() {
|
||||
const { locale } = useI18n();
|
||||
|
||||
const elementLocale = computed(() => {
|
||||
const key = locale.value as keyof typeof ELEMENT_LOCALES;
|
||||
return ELEMENT_LOCALES[key] ?? zhCn;
|
||||
});
|
||||
|
||||
return { elementLocale };
|
||||
}
|
||||
@@ -2,22 +2,35 @@
|
||||
* features/admin/modules/agents/AgentsPage.vue
|
||||
*
|
||||
* 用途:管理控制台的应用管理页,提供应用列表、创建/编辑弹窗、测试与授权入口。
|
||||
* 依赖:useAgentsAdmin 业务编排、AgentFormModal/AgentTestModal/AgentPermissionModal 弹窗。
|
||||
* 逻辑:页面加载后拉取应用/用户/排程数据;权限组启用后隐藏按人授权按钮。
|
||||
* 依赖:useAgentsAdmin 业务编排、Element Plus 表格与按钮、AgentFormModal/AgentTestModal/AgentPermissionModal 弹窗。
|
||||
* 逻辑:页面加载后先展示应用列表;目录、用户和排程在后台补齐。权限组启用后隐藏按人授权按钮。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, onMounted } from 'vue';
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Bot, Plus, SquarePen, Trash2, Users } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import { Plus } from '@element-plus/icons-vue';
|
||||
import {
|
||||
ElButton,
|
||||
ElConfigProvider,
|
||||
ElEmpty,
|
||||
ElLoading,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
ElTag,
|
||||
} from 'element-plus';
|
||||
import 'element-plus/dist/index.css';
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||
import '@/features/admin/styles/element-trial.css';
|
||||
import { useElementProvider } from '@/features/admin/composables/useElementProvider';
|
||||
import AgentFormModal from './components/AgentFormModal.vue';
|
||||
import AgentPermissionModal from './components/AgentPermissionModal.vue';
|
||||
import AgentTestModal from './components/AgentTestModal.vue';
|
||||
import { useAgentsAdmin } from './composables/useAgentsAdmin';
|
||||
import { useAgentsTableColumnResize } from './composables/useAgentsTableColumnResize';
|
||||
import type { AgentRow } from '@/features/admin/types/agent.types';
|
||||
|
||||
const { t } = useI18n();
|
||||
const { elementLocale } = useElementProvider();
|
||||
const vLoading = ElLoading.directive;
|
||||
|
||||
const {
|
||||
agents,
|
||||
@@ -44,8 +57,7 @@ const {
|
||||
permissionAgent,
|
||||
permissionUserIds,
|
||||
rolesConfigured,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
rolesChecked,
|
||||
loadAll,
|
||||
resetForm,
|
||||
selectAgent,
|
||||
@@ -63,23 +75,8 @@ const {
|
||||
openPermissionModal,
|
||||
togglePermissionUser,
|
||||
savePermissions,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
} = useAgentsAdmin();
|
||||
|
||||
const {
|
||||
columnWidths,
|
||||
tableMinWidth,
|
||||
startColumnResize,
|
||||
resetColumnWidths,
|
||||
} = useAgentsTableColumnResize();
|
||||
|
||||
const tableHeaderColumns = computed(() => [
|
||||
{ key: 'name', label: t('admin.agent.headers.name'), align: 'left' as const },
|
||||
{ key: 'status', label: t('admin.agent.headers.status'), align: 'left' as const },
|
||||
{ key: 'actions', label: t('admin.agent.headers.actions'), align: 'right' as const },
|
||||
]);
|
||||
|
||||
/* 列表仅展示名称、状态和操作;类型/聚合/配置仍由编辑弹窗维护。 */
|
||||
const formatAgentCode = (agent: AgentRow) => agent.agent_code || 'generic';
|
||||
|
||||
@@ -153,6 +150,23 @@ const openEditDialog = (agent: Parameters<typeof selectAgent>[0]): void => {
|
||||
showFormDialog.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 点击表格行时打开编辑弹窗。
|
||||
* 核心逻辑:Element 行对象按 id 找回完整应用,避免把表格行类型直接交给 selectAgent。
|
||||
*/
|
||||
const onRowClick = (row: { id?: number }): void => {
|
||||
const agent = agents.value.find((item) => item.id === row.id);
|
||||
if (agent) openEditDialog(agent);
|
||||
};
|
||||
|
||||
/**
|
||||
* 当前选中应用的行样式。
|
||||
* 核心逻辑:编辑弹窗打开前,用 selectedAgentId 给对应行加上浅底。
|
||||
*/
|
||||
const agentRowClass = ({ row }: { row: AgentRow }): string => (
|
||||
selectedAgentId.value === row.id ? 'agents-row-selected' : ''
|
||||
);
|
||||
|
||||
/**
|
||||
* 保存应用表单,成功后关闭弹窗。
|
||||
* 核心逻辑:submitAgent 会处理校验、接口调用和列表刷新;仅在返回 true 时收起弹窗。
|
||||
@@ -168,134 +182,73 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-table-section">
|
||||
<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" />
|
||||
<ElConfigProvider :locale="elementLocale">
|
||||
<section class="admin-table-section min-h-64">
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.agent.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.agent.subtitle') }}</p>
|
||||
</div>
|
||||
<ElButton type="primary" :icon="Plus" @click="openCreateDialog">
|
||||
{{ t('admin.agent.new') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.agent.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.agent.subtitle') }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-primary" @click="openCreateDialog">
|
||||
<Plus class="w-5 h-5" />
|
||||
<span class="font-medium">{{ t('admin.agent.new') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="admin-table-wrap">
|
||||
<div v-if="agents.length === 0" class="admin-table-empty">
|
||||
<Bot class="w-12 h-12 mx-auto text-muted mb-3" />
|
||||
<p class="text-lg text-secondary">{{ t('admin.agent.noAgents') }}</p>
|
||||
</div>
|
||||
<table
|
||||
v-else
|
||||
class="admin-table agent-list-table table-fixed w-full"
|
||||
:style="{ minWidth: `${tableMinWidth}px` }"
|
||||
>
|
||||
<colgroup>
|
||||
<col
|
||||
v-for="(width, index) in columnWidths"
|
||||
:key="`col-${index}`"
|
||||
:style="{ width: `${width}px` }"
|
||||
/>
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
v-for="(column, index) in tableHeaderColumns"
|
||||
:key="column.key"
|
||||
class="relative px-4 py-3 text-xs"
|
||||
:class="column.align === 'right' ? 'text-right' : 'text-left'"
|
||||
>
|
||||
<span class="truncate pr-2">{{ column.label }}</span>
|
||||
<button
|
||||
v-if="index < tableHeaderColumns.length - 1"
|
||||
type="button"
|
||||
class="agent-col-resize-handle"
|
||||
:title="t('admin.agent.resizeColumn')"
|
||||
@mousedown.prevent="startColumnResize(index, $event)"
|
||||
@dblclick.prevent="resetColumnWidths"
|
||||
/>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="agent in agents"
|
||||
:key="agent.id"
|
||||
class="group cursor-pointer"
|
||||
:class="{ 'bg-blue-50/50': selectedAgentId === agent.id }"
|
||||
@click="openEditDialog(agent)"
|
||||
<ElEmpty v-if="!isLoading && agents.length === 0" :description="t('admin.agent.noAgents')" />
|
||||
<ElTable
|
||||
v-else
|
||||
v-loading="isLoading"
|
||||
:data="agents"
|
||||
row-key="id"
|
||||
class="agents-element-table hx-admin-table"
|
||||
:row-class-name="agentRowClass"
|
||||
@row-click="onRowClick"
|
||||
>
|
||||
<ElTableColumn :label="t('admin.agent.headers.name')" min-width="280">
|
||||
<template #default="{ row }">
|
||||
<p class="truncate" :title="(row as AgentRow).name">
|
||||
{{ (row as AgentRow).name }}
|
||||
</p>
|
||||
<p
|
||||
v-if="(row as AgentRow).description"
|
||||
class="truncate hx-element-hint"
|
||||
:title="(row as AgentRow).description"
|
||||
>
|
||||
{{ (row as AgentRow).description }}
|
||||
</p>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('admin.agent.headers.status')" width="140">
|
||||
<template #default="{ row }">
|
||||
<ElTag :type="(row as AgentRow).is_active ? 'success' : 'info'" effect="light">
|
||||
{{ (row as AgentRow).is_active ? t('admin.status.active') : t('admin.status.disabled') }}
|
||||
</ElTag>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('admin.agent.headers.actions')" min-width="280" align="right">
|
||||
<template #default="{ row }">
|
||||
<div class="inline-flex items-center justify-end" @click.stop>
|
||||
<ElButton link type="primary" @click="openEditDialog(row as AgentRow)">
|
||||
{{ t('admin.edit') }}
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-if="rolesChecked && !rolesConfigured"
|
||||
link
|
||||
type="primary"
|
||||
@click="openPermissionModal(row as AgentRow)"
|
||||
>
|
||||
<td class="px-4 py-4 align-middle">
|
||||
<div class="agent-list-cell">
|
||||
<p class="truncate text-sm font-semibold text-primary" :title="agent.name">{{ agent.name }}</p>
|
||||
<p
|
||||
v-if="agent.description"
|
||||
class="truncate text-xs text-muted"
|
||||
:title="agent.description"
|
||||
>
|
||||
{{ agent.description }}
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-4 align-middle">
|
||||
<div class="agent-list-cell">
|
||||
<span
|
||||
class="inline-flex w-fit items-center gap-1.5 rounded-full border px-2.5 py-0.5 text-xs font-medium"
|
||||
:class="agent.is_active ? 'border-green-100 bg-green-50 text-green-700' : 'border-default bg-surface-soft text-secondary'"
|
||||
>
|
||||
<span class="h-1.5 w-1.5 shrink-0 rounded-full" :class="agent.is_active ? 'bg-green-500' : 'bg-surface-strong'" />
|
||||
{{ agent.is_active ? t('admin.status.active') : t('admin.status.disabled') }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-4 align-middle text-right">
|
||||
<div class="inline-flex items-center justify-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center gap-1.5 whitespace-nowrap rounded-lg bg-blue-50 px-3 py-2 text-sm font-medium text-blue-600 transition-all hover:bg-blue-100"
|
||||
:title="t('admin.edit')"
|
||||
@click.stop="openEditDialog(agent)"
|
||||
>
|
||||
<SquarePen class="w-4 h-4 shrink-0" />
|
||||
{{ t('admin.edit') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!rolesConfigured"
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center justify-center p-2 text-blue-600 bg-blue-50 hover:bg-blue-100 rounded-lg transition-all"
|
||||
:title="t('admin.agent.manageAccess')"
|
||||
@click.stop="openPermissionModal(agent)"
|
||||
>
|
||||
<Users class="w-5 h-5 shrink-0" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center whitespace-nowrap p-2 text-emerald-600 bg-emerald-50 hover:bg-emerald-100 rounded-lg transition-all"
|
||||
:title="t('admin.agent.test')"
|
||||
@click.stop="openTestModal(agent)"
|
||||
>
|
||||
{{ t('admin.agent.test') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center justify-center p-2 text-muted hover:text-red-600 hover:bg-red-50 rounded-lg transition-all"
|
||||
:title="t('admin.agent.delete')"
|
||||
@click.stop="deleteAgent(agent.id)"
|
||||
>
|
||||
<Trash2 class="w-5 h-5 shrink-0" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
{{ t('admin.agent.manageAccess') }}
|
||||
</ElButton>
|
||||
<ElButton link type="primary" @click="openTestModal(row as AgentRow)">
|
||||
{{ t('admin.agent.test') }}
|
||||
</ElButton>
|
||||
<ElButton link type="danger" @click="deleteAgent((row as AgentRow).id)">
|
||||
{{ t('admin.agent.delete') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
|
||||
<AgentTestModal
|
||||
:visible="showTestModal"
|
||||
@@ -342,45 +295,16 @@ onMounted(() => {
|
||||
@save="savePermissions"
|
||||
@toggle-user="togglePermissionUser"
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
@confirm="confirmDelete"
|
||||
@cancel="closeDeleteConfirm"
|
||||
/>
|
||||
</section>
|
||||
</ElConfigProvider>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.agent-list-table {
|
||||
table-layout: fixed;
|
||||
.agents-element-table :deep(.agents-row-selected) {
|
||||
--el-table-tr-bg-color: color-mix(in srgb, #0284c7 8%, transparent);
|
||||
}
|
||||
|
||||
.agent-list-cell {
|
||||
display: flex;
|
||||
min-height: 2.5rem;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 0.125rem;
|
||||
}
|
||||
|
||||
.agent-col-resize-handle {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
z-index: 1;
|
||||
width: 8px;
|
||||
height: 100%;
|
||||
cursor: col-resize;
|
||||
border: none;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.agent-col-resize-handle:hover,
|
||||
.agent-col-resize-handle:active {
|
||||
background-color: color-mix(in srgb, var(--border-default) 65%, transparent);
|
||||
.agents-element-table :deep(.el-table__row) {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
@@ -2,14 +2,15 @@
|
||||
* features/admin/modules/agents/components/AgentFormModal.vue
|
||||
*
|
||||
* 用途:应用管理新增/编辑弹窗,集中承载 Agent 基础信息(含启用状态)、Dify/Iframe 配置和常见问题表单。
|
||||
* 依赖:agent.types AgentFormState、schedule.types ScheduleTask、AgentToolRunProgressConfig、vue-i18n。
|
||||
* 逻辑:父组件控制 visible/isEditing/isSaving 与保存;本组件直接编辑传入的 form(含 is_active),并通过事件通知关闭、保存、增删常见问题。
|
||||
* 依赖:element-plus 对话框、agent.types AgentFormState、schedule.types ScheduleTask、AgentToolRunProgressConfig、vue-i18n。
|
||||
* 逻辑:父组件控制 visible/isEditing/isSaving 与保存;外壳是 680px 对话框。表单内部字段仍沿用原有输入控件。
|
||||
*/
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { ChevronDown, FileDown, FolderTree, Plus, Search, Trash2, X } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElButton, ElDialog } from 'element-plus';
|
||||
import type { AgentFormState, AgentGuideSummary, AgentRow } from '@/features/admin/types/agent.types';
|
||||
import type { ScheduleTask } from '@/shared/types/schedule.types';
|
||||
import type { AgentTypeCatalogEntry, IntentRouteOption } from '../composables/useAgentsAdminRegistry';
|
||||
@@ -252,22 +253,28 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
.map((_, optionIndex) => String.fromCharCode(97 + optionIndex));
|
||||
question.answer = validAnswerIds.includes(question.answer) ? question.answer : (validAnswerIds[0] || 'a');
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭应用编辑弹窗。
|
||||
* @param open - 对话框是否仍打开
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="fixed inset-0 z-50 flex items-center justify-center bg-black/40 px-4 py-6 backdrop-blur-sm">
|
||||
<div class="flex max-h-[92vh] w-full max-w-5xl flex-col overflow-hidden rounded-2xl border border-default bg-surface shadow-2xl">
|
||||
<div class="flex items-start justify-between gap-4 border-b border-default px-6 py-5">
|
||||
<div>
|
||||
<h3 class="section-title">{{ isEditing ? t('admin.agent.edit') : t('admin.agent.create') }}</h3>
|
||||
<p class="section-desc mt-1">{{ t('admin.agent.subtitle') }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds shrink-0" @click="emit('close')">
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="overflow-y-auto px-6 py-6">
|
||||
<ElDialog
|
||||
:model-value="visible"
|
||||
:title="isEditing ? t('admin.agent.edit') : t('admin.agent.create')"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<p class="section-desc">{{ t('admin.agent.subtitle') }}</p>
|
||||
<div class="agent-form-body">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.fields.name') }}</label>
|
||||
@@ -890,17 +897,20 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
:requires-schedule-task="requiresScheduleTask"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col-reverse gap-3 border-t border-default px-6 py-4 sm:flex-row sm:items-center sm:justify-end">
|
||||
<button type="button" class="btn-secondary" @click="emit('close')">
|
||||
{{ t('admin.cancel') }}
|
||||
</button>
|
||||
<button type="button" class="btn-primary btn-lg disabled:opacity-60" :disabled="isSaving" @click="emit('save')">
|
||||
<Plus v-if="!isEditing" class="w-5 h-5" />
|
||||
{{ isEditing ? t('admin.update') : t('admin.add') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<ElButton @click="emit('close')">{{ t('admin.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="isSaving" @click="emit('save')">
|
||||
{{ isEditing ? t('admin.update') : t('admin.add') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.agent-form-body {
|
||||
max-height: 65vh;
|
||||
margin-top: 12px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* features/admin/modules/agents/components/AgentPermissionModal.vue
|
||||
*
|
||||
* 为指定 Agent 批量勾选可访问用户的权限弹窗。
|
||||
* 用途:为指定应用勾选可访问用户。
|
||||
* 依赖:element-plus、admin.types、agent.types。
|
||||
* 逻辑:AgentsPage 传入用户和已选 id;勾选变化交给父组件 togglePermissionUser。
|
||||
*/
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElButton, ElCheckbox, ElDialog } from 'element-plus';
|
||||
import type { AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
import type { AgentRow } from '@/features/admin/types/agent.types';
|
||||
|
||||
@@ -24,71 +25,68 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 关闭弹窗。点遮罩或右上角关闭时 Element 会把打开状态写成 false。
|
||||
* @param open - 对话框是否仍打开
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible && agent" class="admin-modal-overlay items-center">
|
||||
<div class="admin-modal-panel max-w-2xl max-h-[90vh] animate-fade-in-up">
|
||||
<div class="px-8 py-6 border-b border-subtle flex justify-between items-center">
|
||||
<div>
|
||||
<h3 class="text-lg font-bold text-primary">{{ t('admin.perm.agentModal.title') }}</h3>
|
||||
<p class="text-sm text-muted">
|
||||
{{ t('admin.perm.agentModal.agent') }}
|
||||
<span class="font-medium text-blue-600">{{ agent.name }}</span>
|
||||
</p>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds rounded-full" @click="emit('close')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto p-8">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div
|
||||
v-for="user in users"
|
||||
:key="user.id"
|
||||
class="flex items-center gap-3 p-3 rounded-xl border transition-all cursor-pointer"
|
||||
:class="selectedUserIds.includes(user.id) ? 'border-blue-200 bg-blue-50/50' : 'border-default hover-surface-soft'"
|
||||
@click="emit('toggleUser', user.id)"
|
||||
>
|
||||
<div
|
||||
class="w-5 h-5 rounded border flex items-center justify-center transition-colors"
|
||||
:class="selectedUserIds.includes(user.id) ? 'bg-blue-600 border-blue-600' : 'bg-surface border-default'"
|
||||
>
|
||||
<svg
|
||||
v-if="selectedUserIds.includes(user.id)"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="h-3.5 w-3.5 text-white"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
>
|
||||
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<div class="font-medium text-primary text-sm">{{ user.username }}</div>
|
||||
<div class="text-xs text-muted">{{ user.real_name || user.email }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-modal-footer admin-modal-footer--muted px-8 py-6">
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">
|
||||
{{ t('admin.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="isSaving"
|
||||
class="btn-primary disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
@click="emit('save')"
|
||||
<ElDialog
|
||||
:model-value="visible && !!agent"
|
||||
:title="t('admin.perm.agentModal.title')"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<template v-if="agent">
|
||||
<p class="section-desc">{{ t('admin.perm.agentModal.agent') }}{{ agent.name }}</p>
|
||||
<div class="agent-perm-list">
|
||||
<ElCheckbox
|
||||
v-for="user in users"
|
||||
:key="user.id"
|
||||
:model-value="selectedUserIds.includes(user.id)"
|
||||
@change="emit('toggleUser', user.id)"
|
||||
>
|
||||
<div v-if="isSaving" class="animate-spin rounded-full h-4 w-4 border-2 border-white border-t-transparent" />
|
||||
{{ t('admin.perm.agentModal.save') }}
|
||||
</button>
|
||||
<span>{{ user.username }}</span>
|
||||
<span class="hx-element-hint">{{ user.real_name || user.email }}</span>
|
||||
</ElCheckbox>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #footer>
|
||||
<ElButton @click="emit('close')">{{ t('admin.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="isSaving" @click="emit('save')">
|
||||
{{ t('admin.perm.agentModal.save') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.agent-perm-list {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 8px 16px;
|
||||
max-height: 65vh;
|
||||
margin-top: 12px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.agent-perm-list :deep(.el-checkbox) {
|
||||
align-items: flex-start;
|
||||
height: auto;
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.agent-perm-list {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* features/admin/modules/agents/components/AgentTestModal.vue
|
||||
*
|
||||
* Agent 连通性测试弹窗:展示请求 URL、输出信息与分析结果。
|
||||
* 用途:应用连通性测试弹窗,展示请求地址、输出和分析结果。
|
||||
* 依赖:element-plus、agent.types。
|
||||
* 逻辑:AgentsPage 传入当前应用和测试结果;重新测试由父组件发起。
|
||||
*/
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElButton, ElDialog } from 'element-plus';
|
||||
import type { AgentRow, AgentTestResult } from '@/features/admin/types/agent.types';
|
||||
|
||||
defineProps<{
|
||||
@@ -21,62 +22,98 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 关闭弹窗。点遮罩或右上角关闭时 Element 会把打开状态写成 false。
|
||||
* @param open - 对话框是否仍打开
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible && agent" class="admin-modal-overlay items-center">
|
||||
<div class="admin-modal-panel max-w-3xl max-h-[90vh] animate-fade-in-up">
|
||||
<div class="px-8 py-6 border-b border-subtle flex justify-between items-start">
|
||||
<div>
|
||||
<h3 class="text-lg font-bold text-primary">{{ t('admin.agent.testModalTitle') }}</h3>
|
||||
<p class="section-desc mt-1">
|
||||
{{ t('admin.agent.testModalAgent') }}:
|
||||
<span class="font-medium text-blue-600">{{ agent.name }}</span>
|
||||
</p>
|
||||
<ElDialog
|
||||
:model-value="visible && !!agent"
|
||||
:title="t('admin.agent.testModalTitle')"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<template v-if="agent">
|
||||
<p class="section-desc">
|
||||
{{ t('admin.agent.testModalAgent') }}:{{ agent.name }}
|
||||
</p>
|
||||
<div class="agent-test-body">
|
||||
<div class="agent-test-toolbar">
|
||||
<span v-if="result?.tested_at" class="hx-element-hint">{{ t('admin.agent.testedAt') }}:{{ result.tested_at }}</span>
|
||||
<ElButton type="primary" :loading="isTesting" @click="emit('retest')">
|
||||
{{ t('admin.agent.retest') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds rounded-full" @click="emit('close')">✕</button>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto p-8 space-y-5">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="text-sm text-secondary">
|
||||
<span v-if="result?.tested_at">{{ t('admin.agent.testedAt') }}:{{ result.tested_at }}</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="isTesting"
|
||||
class="btn-primary btn-sm disabled:opacity-50"
|
||||
@click="emit('retest')"
|
||||
>
|
||||
{{ isTesting ? t('admin.agent.testing') : t('admin.agent.retest') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="isTesting" class="text-sm text-muted">{{ t('admin.agent.testingInProgress') }}</div>
|
||||
|
||||
<p v-if="isTesting" class="hx-element-hint">{{ t('admin.agent.testingInProgress') }}</p>
|
||||
<template v-if="result">
|
||||
<div>
|
||||
<div class="text-xs font-semibold text-muted uppercase tracking-wider mb-2">{{ t('admin.agent.requestUrl') }}</div>
|
||||
<div class="hx-element-hint">{{ t('admin.agent.requestUrl') }}</div>
|
||||
<div class="admin-code-block">{{ result.request_url || '-' }}</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="text-xs font-semibold text-muted uppercase tracking-wider mb-2">{{ t('admin.agent.outputInfo') }}</div>
|
||||
<pre class="admin-code-block max-h-64 overflow-y-auto whitespace-pre-wrap">{{ result.output_info || '-' }}</pre>
|
||||
<div class="hx-element-hint">{{ t('admin.agent.outputInfo') }}</div>
|
||||
<pre class="admin-code-block agent-test-output">{{ result.output_info || '-' }}</pre>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="text-xs font-semibold text-muted uppercase tracking-wider mb-2">{{ t('admin.agent.analysis') }}</div>
|
||||
<div
|
||||
class="p-3 rounded-lg border text-sm"
|
||||
:class="result.success ? 'bg-green-50 border-green-200 text-green-800' : 'bg-red-50 border-red-200 text-red-800'"
|
||||
>
|
||||
<div class="hx-element-hint">{{ t('admin.agent.analysis') }}</div>
|
||||
<div class="agent-test-analysis" :class="result.success ? 'is-ok' : 'is-fail'">
|
||||
{{ result.analysis }}
|
||||
<span v-if="result.http_status">(HTTP {{ result.http_status }})</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.agent-test-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
max-height: 65vh;
|
||||
margin-top: 12px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.agent-test-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.agent-test-output {
|
||||
max-height: 16rem;
|
||||
overflow-y: auto;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.agent-test-analysis {
|
||||
padding: 12px;
|
||||
border: 1px solid var(--el-border-color);
|
||||
border-radius: var(--el-border-radius-base);
|
||||
}
|
||||
|
||||
.agent-test-analysis.is-ok {
|
||||
color: var(--el-color-success);
|
||||
border-color: var(--el-color-success-light-5);
|
||||
background: var(--el-color-success-light-9);
|
||||
}
|
||||
|
||||
.agent-test-analysis.is-fail {
|
||||
color: var(--el-color-danger);
|
||||
border-color: var(--el-color-danger-light-5);
|
||||
background: var(--el-color-danger-light-9);
|
||||
}
|
||||
</style>
|
||||
@@ -4,10 +4,12 @@
|
||||
* Agent 管理模块的业务逻辑:列表 CRUD、连通性测试、权限分配。
|
||||
* 从原 AdminView.vue 的 agents 相关 script 抽取,供 AgentsPage 使用。
|
||||
* 权限组启用后拒绝打开按人授权弹窗,提示改到应用权限页的角色包。
|
||||
* 删除确认使用 Element MessageBox。
|
||||
*/
|
||||
|
||||
import { ref, computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
import {
|
||||
createAdminAgent,
|
||||
deleteAdminAgent,
|
||||
@@ -238,6 +240,7 @@ export function useAgentsAdmin() {
|
||||
const contentProfileOptions = ref<AdminContentProfileOption[]>([]);
|
||||
const users = ref<AdminUserRow[]>([]);
|
||||
const rolesConfigured = ref(false);
|
||||
const rolesChecked = ref(false);
|
||||
const scheduleTasks = ref<ScheduleTask[]>([]);
|
||||
const trainingExamPdfGuides = ref<AgentGuideSummary[]>([]);
|
||||
const isLoading = ref(true);
|
||||
@@ -256,9 +259,6 @@ export function useAgentsAdmin() {
|
||||
const permissionAgent = ref<AgentRow | null>(null);
|
||||
const permissionUserIds = ref<number[]>([]);
|
||||
|
||||
const showDeleteConfirmDialog = ref(false);
|
||||
const deleteConfirmMessage = ref('');
|
||||
let deleteConfirmAction: (() => Promise<void> | void) | null = null;
|
||||
|
||||
const activeUsers = () => users.value.filter((u) => u.status !== 'pending');
|
||||
|
||||
@@ -336,6 +336,8 @@ export function useAgentsAdmin() {
|
||||
} catch (e) {
|
||||
console.error('Error loading permission roles:', e);
|
||||
rolesConfigured.value = false;
|
||||
} finally {
|
||||
rolesChecked.value = true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -364,18 +366,25 @@ export function useAgentsAdmin() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 进入页面时先拉应用列表,再在后台补齐编辑弹窗要用的目录、用户和排程。
|
||||
* 核心逻辑:加载遮罩只等应用列表。权限组、用户、排程和目录在后台拉取,未返回时不盖住表格。
|
||||
*/
|
||||
const loadAll = async (): Promise<void> => {
|
||||
isLoading.value = true;
|
||||
await Promise.all([
|
||||
try {
|
||||
await loadAgents();
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
void Promise.all([
|
||||
loadRegistrySchema(),
|
||||
loadIntentRouteOptions(),
|
||||
loadContentProfileOptions(),
|
||||
loadAgents(),
|
||||
loadUsers(),
|
||||
loadRolesConfigured(),
|
||||
loadScheduleTasks(),
|
||||
]);
|
||||
isLoading.value = false;
|
||||
};
|
||||
|
||||
const resetForm = (): void => {
|
||||
@@ -405,27 +414,26 @@ export function useAgentsAdmin() {
|
||||
void loadTrainingExamPdfGuides(agent.id);
|
||||
};
|
||||
|
||||
const openDeleteConfirm = (
|
||||
/**
|
||||
* 用 Element 确认框询问后再执行删除。
|
||||
* 核心逻辑:取消时 MessageBox 会 reject,这里吞掉,不调用 action。
|
||||
* @param message - 确认文案
|
||||
* @param action - 用户点确定后执行的删除
|
||||
*/
|
||||
const openDeleteConfirm = async (
|
||||
message: string,
|
||||
action: () => Promise<void> | void,
|
||||
): void => {
|
||||
deleteConfirmMessage.value = message;
|
||||
deleteConfirmAction = action;
|
||||
showDeleteConfirmDialog.value = true;
|
||||
};
|
||||
|
||||
const closeDeleteConfirm = (): void => {
|
||||
showDeleteConfirmDialog.value = false;
|
||||
deleteConfirmAction = null;
|
||||
};
|
||||
|
||||
const confirmDelete = async (): Promise<void> => {
|
||||
if (!deleteConfirmAction) return;
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await deleteConfirmAction();
|
||||
} finally {
|
||||
closeDeleteConfirm();
|
||||
await ElMessageBox.confirm(message, t('common.deleteDialog.defaultTitle'), {
|
||||
type: 'warning',
|
||||
confirmButtonText: t('common.deleteDialog.confirm'),
|
||||
cancelButtonText: t('common.deleteDialog.cancel'),
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await action();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -613,7 +621,7 @@ export function useAgentsAdmin() {
|
||||
};
|
||||
|
||||
const deleteAgent = async (id: number): Promise<void> => {
|
||||
openDeleteConfirm(t('admin.agent.confirmDelete'), async () => {
|
||||
await openDeleteConfirm(t('admin.agent.confirmDelete'), async () => {
|
||||
try {
|
||||
await deleteAdminAgent(id);
|
||||
await loadAgents();
|
||||
@@ -723,6 +731,7 @@ export function useAgentsAdmin() {
|
||||
contentProfileOptions,
|
||||
users,
|
||||
rolesConfigured,
|
||||
rolesChecked,
|
||||
scheduleTasks,
|
||||
trainingExamPdfGuides,
|
||||
activeUsers,
|
||||
@@ -739,8 +748,6 @@ export function useAgentsAdmin() {
|
||||
showPermissionModal,
|
||||
permissionAgent,
|
||||
permissionUserIds,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
loadAll,
|
||||
resetForm,
|
||||
selectAgent,
|
||||
@@ -758,7 +765,5 @@ export function useAgentsAdmin() {
|
||||
openPermissionModal,
|
||||
togglePermissionUser,
|
||||
savePermissions,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
};
|
||||
}
|
||||
@@ -1,24 +1,43 @@
|
||||
/**
|
||||
* features/admin/modules/users/UsersPage.vue
|
||||
* 用途:用户管理独立页面(服务端筛选分页、用户/部门列排序、批量操作)。
|
||||
* 依赖:useUsersAdmin、SortableTableHeader、PaginationBar、用户相关 Modal、adminRoleLabel、getUserAvatarLabel。
|
||||
* 逻辑:路由 /admin/users;列表经 listAdminUsersPage 按页拉取;权限组启用后只选角色、关闭按人授权。
|
||||
* 依赖:useUsersAdmin、useElementProvider、element-plus、用户相关 Modal、adminRoleLabel、getUserAvatarLabel。
|
||||
* 逻辑:路由 /admin/users;本页是 Element Plus 试点,筛选、表格、分页、工具栏和三个业务弹窗走组件库。
|
||||
* 删除和改角色用 Element 确认框。列表经 listAdminUsersPage 按页拉取。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { computed, onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Edit, Plus, Trash2, Users } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import SortableTableHeader from '@/shared/components/SortableTableHeader.vue';
|
||||
import { Delete, Edit, Plus, User } from '@element-plus/icons-vue';
|
||||
import {
|
||||
ElButton,
|
||||
ElConfigProvider,
|
||||
ElInput,
|
||||
ElLoading,
|
||||
ElOption,
|
||||
ElPagination,
|
||||
ElSelect,
|
||||
ElSpace,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
ElTag,
|
||||
} from 'element-plus';
|
||||
import 'element-plus/dist/index.css';
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||
import '@/features/admin/styles/element-trial.css';
|
||||
import { adminRoleLabel } from '@/features/admin/utils/roleLabel';
|
||||
import { getUserAvatarLabel } from '@/shared/utils/user-avatar';
|
||||
import type { AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
import { useElementProvider } from '@/features/admin/composables/useElementProvider';
|
||||
import BatchEditUserModal from './components/BatchEditUserModal.vue';
|
||||
import BatchPermissionModal from './components/BatchPermissionModal.vue';
|
||||
import UserFormModal from './components/UserFormModal.vue';
|
||||
import { useUsersAdmin } from './composables/useUsersAdmin';
|
||||
|
||||
const vLoading = ElLoading.directive;
|
||||
|
||||
const { t } = useI18n();
|
||||
const { elementLocale } = useElementProvider();
|
||||
|
||||
const {
|
||||
agents,
|
||||
@@ -31,290 +50,273 @@ const {
|
||||
userFilters,
|
||||
sortKey,
|
||||
sortDir,
|
||||
// hideRejected,
|
||||
selectedUserIds,
|
||||
users,
|
||||
usersTotal,
|
||||
userPage,
|
||||
userPageSize,
|
||||
userPageSizeOptions,
|
||||
usersPages,
|
||||
allPaginatedUsersSelected,
|
||||
showUserModal,
|
||||
editingUser,
|
||||
showBatchEditModal,
|
||||
batchEditForm,
|
||||
showBatchPermissionModal,
|
||||
batchPermissionForm,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
showRoleConfirm,
|
||||
roleConfirmMessage,
|
||||
loadAll,
|
||||
toggleSort,
|
||||
applyServerSort,
|
||||
openCreateUserModal,
|
||||
openEditUserModal,
|
||||
saveUser,
|
||||
// cleanRejectedUsers,
|
||||
batchDeleteUsers,
|
||||
toggleUserSelection,
|
||||
toggleAllUsers,
|
||||
openBatchEditModal,
|
||||
openBatchPermissionModal,
|
||||
submitBatchEdit,
|
||||
submitBatchPermission,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
confirmRoleChange,
|
||||
closeRoleConfirm,
|
||||
} = useUsersAdmin();
|
||||
|
||||
const pageSizes = computed(() => [...userPageSizeOptions]);
|
||||
|
||||
const defaultSort = computed(() => ({
|
||||
prop: sortKey.value || 'username',
|
||||
order: sortDir.value === 'desc' ? 'descending' as const : 'ascending' as const,
|
||||
}));
|
||||
|
||||
/**
|
||||
* 把 Element 表格的勾选结果写回已选用户 id。
|
||||
* @param rows - 当前保留的选中行
|
||||
*/
|
||||
function onSelectionChange(rows: AdminUserRow[]): void {
|
||||
selectedUserIds.value = rows.map((row) => row.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门筛选。清空时写回空字符串,列表接口仍按「全部部门」查询。
|
||||
* @param value - 选中的部门名;清空为 undefined
|
||||
*/
|
||||
function onDepartmentChange(value: string | undefined): void {
|
||||
userFilters.value.department = value ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 把 Element 表头排序交给服务端查询。
|
||||
* 核心逻辑:取消排序时保持当前方向;有效排序走 applyServerSort 并回到第一页。
|
||||
* @param payload.prop - 列字段
|
||||
* @param payload.order - ascending、descending 或空
|
||||
*/
|
||||
function onSortChange(payload: { prop: string | null; order: string | null }): void {
|
||||
const field = payload.prop;
|
||||
if ((field === 'username' || field === 'department') && payload.order) {
|
||||
applyServerSort(field, payload.order === 'descending' ? 'desc' : 'asc');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开编辑弹窗。表格插槽行类型较宽,这里收成用户行。
|
||||
* @param row - 当前表格行
|
||||
*/
|
||||
function editUser(row: AdminUserRow): void {
|
||||
openEditUserModal(row);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadAll();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-table-section">
|
||||
<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">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.user.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.user.subtitle') }}</p>
|
||||
<ElConfigProvider :locale="elementLocale">
|
||||
<section v-loading="isLoading" class="admin-table-section min-h-64">
|
||||
<template v-if="!isLoading">
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.user.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.user.subtitle') }}</p>
|
||||
</div>
|
||||
<ElSpace wrap>
|
||||
<ElButton
|
||||
v-if="selectedUserIds.length > 0"
|
||||
type="danger"
|
||||
:icon="Delete"
|
||||
@click="batchDeleteUsers"
|
||||
>
|
||||
{{ t('admin.user.batchDelete') }} ({{ selectedUserIds.length }})
|
||||
</ElButton>
|
||||
<ElButton v-if="selectedUserIds.length > 0" :icon="Edit" @click="openBatchEditModal">
|
||||
{{ t('admin.user.batchEdit') }} ({{ selectedUserIds.length }})
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-if="selectedUserIds.length > 0 && !rolesConfigured"
|
||||
:icon="User"
|
||||
@click="openBatchPermissionModal"
|
||||
>
|
||||
{{ t('admin.user.batchPermission') }} ({{ selectedUserIds.length }})
|
||||
</ElButton>
|
||||
<ElButton type="primary" :icon="Plus" @click="openCreateUserModal">
|
||||
{{ t('admin.user.addUser') }}
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-3">
|
||||
<!-- 暂隐藏:清理已拒绝
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-red-50 text-red-600 rounded-xl hover:bg-red-100 transition-all border border-red-200 text-sm font-medium"
|
||||
@click="cleanRejectedUsers"
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
<span>{{ t('admin.user.cleanRejected') }}</span>
|
||||
</button>
|
||||
-->
|
||||
<button
|
||||
v-if="selectedUserIds.length > 0"
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-red-600 text-white rounded-xl hover:bg-red-700 transition-all shadow-lg shadow-red-200 active:scale-95 text-sm font-medium"
|
||||
@click="batchDeleteUsers"
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
<span>{{ t('admin.user.batchDelete') }} ({{ selectedUserIds.length }})</span>
|
||||
</button>
|
||||
<button
|
||||
v-if="selectedUserIds.length > 0"
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white rounded-xl hover:bg-indigo-700 transition-all shadow-lg shadow-indigo-200 active:scale-95 text-sm font-medium"
|
||||
@click="openBatchEditModal"
|
||||
>
|
||||
<Edit class="w-4 h-4" />
|
||||
<span>{{ t('admin.user.batchEdit') }} ({{ selectedUserIds.length }})</span>
|
||||
</button>
|
||||
<button
|
||||
v-if="selectedUserIds.length > 0 && !rolesConfigured"
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-purple-600 text-white rounded-xl hover:bg-purple-700 transition-all shadow-lg shadow-purple-200 active:scale-95 text-sm font-medium"
|
||||
@click="openBatchPermissionModal"
|
||||
>
|
||||
<Users class="w-4 h-4" />
|
||||
<span>{{ t('admin.user.batchPermission') }} ({{ selectedUserIds.length }})</span>
|
||||
</button>
|
||||
<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="openCreateUserModal"
|
||||
>
|
||||
<Plus class="w-4 h-4" />
|
||||
<span class="font-medium">{{ t('admin.user.addUser') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-table-filters--inline gap-3">
|
||||
<input v-model="userFilters.username" :placeholder="t('admin.user.filterUsername')" class="admin-table-filter-input w-40" />
|
||||
<input v-model="userFilters.real_name" :placeholder="t('admin.user.filterRealName')" class="admin-table-filter-input w-44" />
|
||||
<select v-model="userFilters.department" class="admin-table-filter-input w-40">
|
||||
<option value="">{{ t('admin.user.allDepts') }}</option>
|
||||
<option v-for="d in departments" :key="d.id" :value="d.name">{{ d.name }}</option>
|
||||
</select>
|
||||
<!-- 暂隐藏:隐藏已拒绝
|
||||
<div class="flex items-center gap-2">
|
||||
<input id="hideRejectedUsers" v-model="hideRejected" type="checkbox" class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500 border-default" />
|
||||
<label for="hideRejectedUsers" class="text-sm text-secondary select-none">{{ t('admin.user.hideRejected') }}</label>
|
||||
<div class="users-element-filters">
|
||||
<ElInput
|
||||
v-model="userFilters.username"
|
||||
clearable
|
||||
class="users-filter-username"
|
||||
:placeholder="t('admin.user.filterUsername')"
|
||||
/>
|
||||
<ElInput
|
||||
v-model="userFilters.real_name"
|
||||
clearable
|
||||
class="users-filter-name"
|
||||
:placeholder="t('admin.user.filterRealName')"
|
||||
/>
|
||||
<ElSelect
|
||||
:model-value="userFilters.department || undefined"
|
||||
class="users-filter-dept"
|
||||
clearable
|
||||
:placeholder="t('admin.user.allDepts')"
|
||||
@update:model-value="onDepartmentChange"
|
||||
>
|
||||
<ElOption v-for="department in departments" :key="department.id" :label="department.name" :value="department.name" />
|
||||
</ElSelect>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
|
||||
<div class="admin-table-wrap relative">
|
||||
<div
|
||||
v-if="isListLoading"
|
||||
class="absolute inset-0 z-10 flex items-center justify-center rounded-2xl bg-surface/60"
|
||||
<ElTable
|
||||
v-loading="isListLoading"
|
||||
class="hx-admin-table"
|
||||
:data="users"
|
||||
row-key="id"
|
||||
:default-sort="defaultSort"
|
||||
:empty-text="t('admin.user.noUsers')"
|
||||
@selection-change="onSelectionChange"
|
||||
@sort-change="onSortChange"
|
||||
>
|
||||
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-brand-600" />
|
||||
</div>
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-6 py-4 w-12 text-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500 cursor-pointer border-default"
|
||||
:checked="allPaginatedUsersSelected"
|
||||
@change="toggleAllUsers(users)"
|
||||
/>
|
||||
</th>
|
||||
<th class="px-6 py-4 text-left text-xs">
|
||||
<SortableTableHeader
|
||||
column-key="username"
|
||||
:label="t('admin.user.headers.user')"
|
||||
:active-key="sortKey"
|
||||
:direction="sortDir"
|
||||
@sort="toggleSort"
|
||||
/>
|
||||
</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.user.fields.realName') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">
|
||||
<SortableTableHeader
|
||||
column-key="department"
|
||||
:label="t('admin.user.headers.dept')"
|
||||
:active-key="sortKey"
|
||||
:direction="sortDir"
|
||||
@sort="toggleSort"
|
||||
/>
|
||||
</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.user.headers.role') }}</th>
|
||||
<th class="px-6 py-4 text-right text-xs">{{ t('admin.user.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="usersTotal === 0 && !isListLoading">
|
||||
<td colspan="6" class="px-6 admin-table-empty">{{ t('admin.user.noUsers') }}</td>
|
||||
</tr>
|
||||
<tr v-for="user in users" :key="user.id" class="group">
|
||||
<td class="px-6 py-4 text-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500 cursor-pointer border-default"
|
||||
:checked="selectedUserIds.includes(user.id)"
|
||||
@change="toggleUserSelection(user.id)"
|
||||
/>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex items-center">
|
||||
<div class="h-9 w-9 rounded-full bg-gradient-to-br from-brand-500 to-indigo-600 text-white flex items-center justify-center text-xs font-bold shadow-sm">
|
||||
{{ getUserAvatarLabel(user) }}
|
||||
</div>
|
||||
<div class="ml-3 text-sm font-medium text-primary">{{ user.username }}</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm text-primary">{{ user.real_name || '-' }}</td>
|
||||
<td class="px-6 py-4 text-sm text-muted">{{ user.department || '-' }}</td>
|
||||
<td class="px-6 py-4">
|
||||
<span
|
||||
class="px-2.5 py-0.5 rounded-full text-xs font-medium border"
|
||||
:class="user.is_platform_admin
|
||||
? 'bg-purple-50 text-purple-700 border-purple-100'
|
||||
: 'bg-blue-50 text-blue-700 border-blue-100'"
|
||||
>
|
||||
{{ adminRoleLabel(t, user.role, user.role_name) }}
|
||||
<ElTableColumn type="selection" width="64" reserve-selection />
|
||||
<ElTableColumn prop="username" :label="t('admin.user.headers.user')" sortable="custom" min-width="180">
|
||||
<template #default="{ row }">
|
||||
<span class="inline-flex items-center gap-3">
|
||||
<span class="users-avatar">
|
||||
{{ getUserAvatarLabel(row) }}
|
||||
</span>
|
||||
<div
|
||||
v-if="user.feature_permissions?.training_hr_manage || user.feature_permissions?.['maintenance.ledger_write']"
|
||||
class="mt-2 flex flex-wrap gap-1.5"
|
||||
>
|
||||
<span
|
||||
v-if="user.feature_permissions?.training_hr_manage"
|
||||
class="inline-flex rounded-full border border-brand-100 bg-brand-50 px-2.5 py-0.5 text-xs font-medium text-brand-700"
|
||||
>
|
||||
{{ t('admin.user.fields.trainingHrManage') }}
|
||||
</span>
|
||||
<span
|
||||
v-if="user.feature_permissions?.['maintenance.ledger_write']"
|
||||
class="inline-flex rounded-full border border-brand-100 bg-brand-50 px-2.5 py-0.5 text-xs font-medium text-brand-700"
|
||||
>
|
||||
{{ t('admin.permRoles.features.maintenance_ledger_write') }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<button
|
||||
type="button"
|
||||
class="text-brand-600 hover:text-brand-900 font-medium text-xs px-3 py-1.5 rounded-lg hover:bg-brand-50 transition-colors"
|
||||
@click="openEditUserModal(user)"
|
||||
>
|
||||
{{ t('admin.edit') }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<span>{{ row.username }}</span>
|
||||
</span>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn prop="real_name" :label="t('admin.user.fields.realName')" min-width="120">
|
||||
<template #default="{ row }">{{ row.real_name || '-' }}</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn prop="department" :label="t('admin.user.headers.dept')" sortable="custom" min-width="140">
|
||||
<template #default="{ row }">{{ row.department || '-' }}</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('admin.user.headers.role')" min-width="180">
|
||||
<template #default="{ row }">
|
||||
<ElTag :type="row.is_platform_admin ? 'warning' : 'primary'" effect="light">
|
||||
{{ adminRoleLabel(t, row.role, row.role_name) }}
|
||||
</ElTag>
|
||||
<div
|
||||
v-if="row.feature_permissions?.training_hr_manage || row.feature_permissions?.['maintenance.ledger_write']"
|
||||
class="mt-2 flex flex-wrap gap-1.5"
|
||||
>
|
||||
<ElTag v-if="row.feature_permissions?.training_hr_manage" size="small">
|
||||
{{ t('admin.user.fields.trainingHrManage') }}
|
||||
</ElTag>
|
||||
<ElTag v-if="row.feature_permissions?.['maintenance.ledger_write']" size="small">
|
||||
{{ t('admin.permRoles.features.maintenance_ledger_write') }}
|
||||
</ElTag>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('admin.user.headers.actions')" width="100" align="right">
|
||||
<template #default="{ row }">
|
||||
<ElButton link type="primary" @click="editUser(row as AdminUserRow)">{{ t('admin.edit') }}</ElButton>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
|
||||
<div class="px-4 pb-4 pt-2">
|
||||
<PaginationBar
|
||||
v-model:page="userPage"
|
||||
v-model:page-size="userPageSize"
|
||||
:total="usersTotal"
|
||||
:pages="usersPages"
|
||||
:page-size-options="[...userPageSizeOptions]"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<div class="hx-admin-pager">
|
||||
<ElPagination
|
||||
v-model:current-page="userPage"
|
||||
v-model:page-size="userPageSize"
|
||||
:total="usersTotal"
|
||||
:page-sizes="pageSizes"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
background
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<UserFormModal
|
||||
:visible="showUserModal"
|
||||
:form="editingUser"
|
||||
:agents="agents"
|
||||
:departments="departments"
|
||||
:roles="roles"
|
||||
:roles-configured="rolesConfigured"
|
||||
:is-saving="isSaving"
|
||||
@close="showUserModal = false"
|
||||
@save="saveUser"
|
||||
/>
|
||||
<UserFormModal
|
||||
:visible="showUserModal"
|
||||
:form="editingUser"
|
||||
:agents="agents"
|
||||
:departments="departments"
|
||||
:roles="roles"
|
||||
:roles-configured="rolesConfigured"
|
||||
:is-saving="isSaving"
|
||||
@close="showUserModal = false"
|
||||
@save="saveUser"
|
||||
/>
|
||||
|
||||
<BatchEditUserModal
|
||||
:visible="showBatchEditModal"
|
||||
:form="batchEditForm"
|
||||
:departments="departments"
|
||||
:roles="roles"
|
||||
:roles-configured="rolesConfigured"
|
||||
:selected-count="selectedUserIds.length"
|
||||
:is-saving="isSaving"
|
||||
@close="showBatchEditModal = false"
|
||||
@save="submitBatchEdit"
|
||||
/>
|
||||
<BatchEditUserModal
|
||||
:visible="showBatchEditModal"
|
||||
:form="batchEditForm"
|
||||
:departments="departments"
|
||||
:roles="roles"
|
||||
:roles-configured="rolesConfigured"
|
||||
:selected-count="selectedUserIds.length"
|
||||
:is-saving="isSaving"
|
||||
@close="showBatchEditModal = false"
|
||||
@save="submitBatchEdit"
|
||||
/>
|
||||
|
||||
<BatchPermissionModal
|
||||
:visible="showBatchPermissionModal"
|
||||
:form="batchPermissionForm"
|
||||
:agents="agents"
|
||||
:selected-count="selectedUserIds.length"
|
||||
:is-saving="isSaving"
|
||||
@close="showBatchPermissionModal = false"
|
||||
@save="submitBatchPermission"
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
@confirm="confirmDelete"
|
||||
@cancel="closeDeleteConfirm"
|
||||
/>
|
||||
<DeleteConfirmDialog
|
||||
v-model="showRoleConfirm"
|
||||
:title="t('admin.permRoles.userRoleConfirmTitle')"
|
||||
:message="roleConfirmMessage"
|
||||
:confirm-text="t('admin.save')"
|
||||
confirm-tone="primary"
|
||||
:confirm-loading="isSaving"
|
||||
@confirm="confirmRoleChange"
|
||||
@cancel="closeRoleConfirm"
|
||||
/>
|
||||
</section>
|
||||
<BatchPermissionModal
|
||||
:visible="showBatchPermissionModal"
|
||||
:form="batchPermissionForm"
|
||||
:agents="agents"
|
||||
:selected-count="selectedUserIds.length"
|
||||
:is-saving="isSaving"
|
||||
@close="showBatchPermissionModal = false"
|
||||
@save="submitBatchPermission"
|
||||
/>
|
||||
</section>
|
||||
</ElConfigProvider>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.users-element-filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 16px 32px;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
.users-element-filters :deep(.el-input),
|
||||
.users-element-filters :deep(.el-select) {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.users-element-filters :deep(.users-filter-username) {
|
||||
width: 10rem;
|
||||
}
|
||||
|
||||
.users-element-filters :deep(.users-filter-name),
|
||||
.users-element-filters :deep(.users-filter-dept) {
|
||||
width: 11rem;
|
||||
}
|
||||
|
||||
.users-avatar {
|
||||
display: flex;
|
||||
height: 2.25rem;
|
||||
width: 2.25rem;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 9999px;
|
||||
background-image: linear-gradient(to bottom right, #0ea5e9, #4f46e5);
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
@@ -1,17 +1,19 @@
|
||||
/**
|
||||
* features/admin/modules/users/components/BatchEditUserModal.vue
|
||||
* 用途:批量编辑用户部门/角色/状态弹窗。权限组启用后角色下拉读权限组列表。
|
||||
* 依赖:admin.types、permissionRole.types、user.types、roleLabel.LEGACY_ROLE_OPTIONS。
|
||||
* 逻辑:UsersPage 传入角色列表;未选字段表示保持不变。
|
||||
* 依赖:element-plus、admin.types、permissionRole.types、user.types、roleLabel.LEGACY_ROLE_OPTIONS。
|
||||
* 逻辑:UsersPage 传入角色列表;未选字段表示保持不变。本弹窗属于用户管理 Element Plus 试点。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElButton, ElDialog, ElForm, ElFormItem, ElOption, ElSelect } from 'element-plus';
|
||||
import type { AdminDepartmentRow } from '@/features/admin/types/admin.types';
|
||||
import type { PermissionRoleRow } from '@/features/admin/types/permissionRole.types';
|
||||
import type { BatchEditForm } from '@/features/admin/types/user.types';
|
||||
import { LEGACY_ROLE_OPTIONS } from '@/features/admin/utils/roleLabel';
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
form: BatchEditForm;
|
||||
departments: AdminDepartmentRow[];
|
||||
@@ -23,55 +25,61 @@ defineProps<{
|
||||
|
||||
const emit = defineEmits<{ close: []; save: [] }>();
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 角色下拉,首项为保持不变。
|
||||
*/
|
||||
const roleOptions = computed(() => {
|
||||
const keep = { value: '', label: t('admin.batchEdit.fields.keepUnchanged') };
|
||||
if (props.rolesConfigured) {
|
||||
return [keep, ...props.roles.map((role) => ({ value: role.code, label: role.name }))];
|
||||
}
|
||||
return [keep, ...LEGACY_ROLE_OPTIONS.map((option) => ({ value: option.code, label: t(option.i18nKey) }))];
|
||||
});
|
||||
|
||||
/**
|
||||
* 关闭弹窗并通知父页面收起。
|
||||
* @param open - Element 对话框的打开状态
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="admin-modal-overlay items-center">
|
||||
<div class="admin-modal-panel max-w-md animate-fade-in-up">
|
||||
<div class="px-8 py-6 border-b border-subtle">
|
||||
<h3 class="text-lg font-bold text-primary">{{ t('admin.batchEdit.title') }}</h3>
|
||||
<p class="text-sm text-muted">{{ t('admin.batchEdit.selected', { count: selectedCount }) }}</p>
|
||||
</div>
|
||||
<div class="p-8 space-y-4">
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.batchEdit.fields.dept') }}</label>
|
||||
<select v-model="form.department" class="input-field text-sm">
|
||||
<option value="">{{ t('admin.batchEdit.fields.keepUnchanged') }}</option>
|
||||
<option v-for="d in departments" :key="d.id" :value="d.name">{{ d.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.batchEdit.fields.role') }}</label>
|
||||
<select v-if="rolesConfigured" v-model="form.role" class="input-field text-sm">
|
||||
<option value="">{{ t('admin.batchEdit.fields.keepUnchanged') }}</option>
|
||||
<option v-for="role in roles" :key="role.code" :value="role.code">{{ role.name }}</option>
|
||||
</select>
|
||||
<select v-else v-model="form.role" class="input-field text-sm">
|
||||
<option value="">{{ t('admin.batchEdit.fields.keepUnchanged') }}</option>
|
||||
<option
|
||||
v-for="option in LEGACY_ROLE_OPTIONS"
|
||||
:key="option.code"
|
||||
:value="option.code"
|
||||
>
|
||||
{{ t(option.i18nKey) }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.batchEdit.fields.status') }}</label>
|
||||
<select v-model="form.status" class="input-field text-sm">
|
||||
<option value="">{{ t('admin.batchEdit.fields.keepUnchanged') }}</option>
|
||||
<option value="active">{{ t('admin.status.active') }}</option>
|
||||
<option value="disabled">{{ t('admin.status.disabled') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-modal-footer admin-modal-footer--muted px-8 py-6">
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">{{ t('admin.cancel') }}</button>
|
||||
<button type="button" class="btn-primary disabled:opacity-50" :disabled="isSaving" @click="emit('save')">
|
||||
{{ isSaving ? t('admin.save') + '...' : t('admin.batchEdit.update') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ElDialog
|
||||
:model-value="visible"
|
||||
:title="t('admin.batchEdit.title')"
|
||||
width="480px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<p class="hx-element-hint">{{ t('admin.batchEdit.selected', { count: selectedCount }) }}</p>
|
||||
<ElForm label-position="top" :model="form">
|
||||
<ElFormItem :label="t('admin.batchEdit.fields.dept')">
|
||||
<ElSelect v-model="form.department" class="w-full">
|
||||
<ElOption :label="t('admin.batchEdit.fields.keepUnchanged')" value="" />
|
||||
<ElOption v-for="department in departments" :key="department.id" :label="department.name" :value="department.name" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.batchEdit.fields.role')">
|
||||
<ElSelect v-model="form.role" class="w-full">
|
||||
<ElOption v-for="option in roleOptions" :key="option.value || 'keep'" :label="option.label" :value="option.value" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.batchEdit.fields.status')">
|
||||
<ElSelect v-model="form.status" class="w-full">
|
||||
<ElOption :label="t('admin.batchEdit.fields.keepUnchanged')" value="" />
|
||||
<ElOption :label="t('admin.status.active')" value="active" />
|
||||
<ElOption :label="t('admin.status.disabled')" value="disabled" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
<template #footer>
|
||||
<ElButton @click="emit('close')">{{ t('admin.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="isSaving" @click="emit('save')">{{ t('admin.batchEdit.update') }}</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
@@ -1,9 +1,21 @@
|
||||
/**
|
||||
* features/admin/modules/users/components/BatchPermissionModal.vue
|
||||
* 批量分配/移除用户 Agent 权限弹窗。
|
||||
* 用途:批量分配、移除或覆盖用户 Agent 权限。
|
||||
* 依赖:element-plus、admin.types、user.types。
|
||||
* 逻辑:UsersPage 传入已选人数与 Agent 列表;动作为 add / remove / set。本弹窗属于用户管理 Element Plus 试点。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
ElButton,
|
||||
ElCheckbox,
|
||||
ElCheckboxGroup,
|
||||
ElDialog,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElRadio,
|
||||
ElRadioGroup,
|
||||
} from 'element-plus';
|
||||
import type { AdminAgentOption } from '@/features/admin/types/admin.types';
|
||||
import type { BatchPermissionForm } from '@/features/admin/types/user.types';
|
||||
|
||||
@@ -17,54 +29,46 @@ defineProps<{
|
||||
|
||||
const emit = defineEmits<{ close: []; save: [] }>();
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 关闭弹窗并通知父页面收起。
|
||||
* @param open - Element 对话框的打开状态
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="admin-modal-overlay items-center">
|
||||
<div class="admin-modal-panel max-w-lg animate-fade-in-up">
|
||||
<div class="px-8 py-6 border-b border-subtle">
|
||||
<h3 class="text-lg font-bold text-primary">{{ t('admin.perm.batchModal.title') }}</h3>
|
||||
<p class="text-sm text-muted">{{ t('admin.perm.batchModal.selected', { count: selectedCount }) }}</p>
|
||||
</div>
|
||||
<div class="p-8 space-y-6">
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.perm.batchModal.action') }}</label>
|
||||
<div class="flex gap-4">
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input v-model="form.action" type="radio" value="add" class="text-blue-600 focus:ring-blue-500" />
|
||||
<span class="text-sm">{{ t('admin.perm.batchModal.add') }}</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input v-model="form.action" type="radio" value="remove" class="text-blue-600 focus:ring-blue-500" />
|
||||
<span class="text-sm">{{ t('admin.perm.batchModal.remove') }}</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input v-model="form.action" type="radio" value="set" class="text-blue-600 focus:ring-blue-500" />
|
||||
<span class="text-sm">{{ t('admin.perm.batchModal.set') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.perm.batchModal.selectAgents') }}</label>
|
||||
<div class="grid grid-cols-2 gap-3 max-h-60 overflow-y-auto p-1">
|
||||
<label
|
||||
v-for="agent in agents"
|
||||
:key="agent.id"
|
||||
class="flex items-center gap-2 p-3 border border-default rounded-lg cursor-pointer hover-surface-soft transition-colors"
|
||||
:class="form.agent_ids.includes(agent.id) ? 'border-blue-500 bg-blue-50' : ''"
|
||||
>
|
||||
<input v-model="form.agent_ids" type="checkbox" :value="agent.id" class="w-4 h-4 text-blue-600 rounded focus:ring-blue-500" />
|
||||
<span class="text-sm font-medium text-secondary">{{ agent.name }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-modal-footer admin-modal-footer--muted px-8 py-6">
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">{{ t('admin.cancel') }}</button>
|
||||
<button type="button" class="btn-primary disabled:opacity-50" :disabled="isSaving" @click="emit('save')">
|
||||
{{ isSaving ? t('admin.save') + '...' : t('admin.perm.batchModal.apply') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ElDialog
|
||||
:model-value="visible"
|
||||
:title="t('admin.perm.batchModal.title')"
|
||||
width="480px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<p class="hx-element-hint">{{ t('admin.perm.batchModal.selected', { count: selectedCount }) }}</p>
|
||||
<ElForm label-position="top" :model="form">
|
||||
<ElFormItem :label="t('admin.perm.batchModal.action')">
|
||||
<ElRadioGroup v-model="form.action">
|
||||
<ElRadio value="add">{{ t('admin.perm.batchModal.add') }}</ElRadio>
|
||||
<ElRadio value="remove">{{ t('admin.perm.batchModal.remove') }}</ElRadio>
|
||||
<ElRadio value="set">{{ t('admin.perm.batchModal.set') }}</ElRadio>
|
||||
</ElRadioGroup>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.perm.batchModal.selectAgents')">
|
||||
<ElCheckboxGroup v-model="form.agent_ids" class="grid max-h-60 grid-cols-2 gap-2 overflow-y-auto">
|
||||
<ElCheckbox v-for="agent in agents" :key="agent.id" :value="agent.id">
|
||||
{{ agent.name }}
|
||||
</ElCheckbox>
|
||||
</ElCheckboxGroup>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
<template #footer>
|
||||
<ElButton @click="emit('close')">{{ t('admin.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="isSaving" @click="emit('save')">{{ t('admin.perm.batchModal.apply') }}</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
@@ -1,17 +1,30 @@
|
||||
/**
|
||||
* features/admin/modules/users/components/UserFormModal.vue
|
||||
* 用途:创建/编辑用户弹窗。权限组启用后只选角色,不再按人勾应用或功能权限。
|
||||
* 依赖:admin.types、user.types、permissionRole.types、roleLabel.LEGACY_ROLE_OPTIONS。
|
||||
* 逻辑:UsersPage 传入角色列表;未种子权限组时保留历史 Agent / 培训 HR 勾选,角色下拉用旧枚举。
|
||||
* 依赖:element-plus、admin.types、user.types、permissionRole.types、roleLabel.LEGACY_ROLE_OPTIONS。
|
||||
* 逻辑:UsersPage 传入角色列表;未种子权限组时保留历史 Agent / 功能权限勾选,角色下拉用旧枚举。
|
||||
* 本弹窗属于用户管理 Element Plus 试点。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
ElButton,
|
||||
ElCheckbox,
|
||||
ElCheckboxGroup,
|
||||
ElDialog,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElInput,
|
||||
ElOption,
|
||||
ElSelect,
|
||||
} from 'element-plus';
|
||||
import type { AdminAgentOption, AdminDepartmentRow } from '@/features/admin/types/admin.types';
|
||||
import type { PermissionRoleRow } from '@/features/admin/types/permissionRole.types';
|
||||
import type { UserFormState } from '@/features/admin/types/user.types';
|
||||
import { LEGACY_ROLE_OPTIONS } from '@/features/admin/utils/roleLabel';
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
form: UserFormState;
|
||||
agents: AdminAgentOption[];
|
||||
@@ -24,150 +37,142 @@ defineProps<{
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
save: [];
|
||||
'update:form': [UserFormState];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
/**
|
||||
* 角色下拉。已配置权限组时用组名称,否则用历史角色枚举。
|
||||
*/
|
||||
const roleOptions = computed(() => {
|
||||
if (props.rolesConfigured) {
|
||||
return props.roles.map((role) => ({ value: role.code, label: role.name }));
|
||||
}
|
||||
return LEGACY_ROLE_OPTIONS.map((option) => ({ value: option.code, label: t(option.i18nKey) }));
|
||||
});
|
||||
|
||||
/**
|
||||
* 关闭弹窗并通知父页面收起。
|
||||
* @param open - Element 对话框的打开状态
|
||||
*/
|
||||
function onVisibleChange(open: boolean): void {
|
||||
if (!open) emit('close');
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门选择。清空时写回空字符串,表示不指定部门。
|
||||
* @param value - 选中的部门名;清空为 undefined
|
||||
*/
|
||||
function onDepartmentChange(value: string | undefined): void {
|
||||
props.form.department = value ?? '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="admin-modal-overlay animate-fade-in">
|
||||
<div class="admin-modal-panel max-w-2xl 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.user.editUser') : t('admin.user.createUser') }}</h3>
|
||||
</div>
|
||||
<div class="px-5 sm:px-8 py-5 space-y-5 overflow-y-auto">
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.realName') }}
|
||||
</label>
|
||||
<input v-model="form.real_name" type="text" class="w-full border-default rounded-xl px-4 py-3 text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.employeeId') }}
|
||||
</label>
|
||||
<input v-model="form.employee_id" type="text" class="w-full border-default rounded-xl px-4 py-3 text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.phone') }}
|
||||
</label>
|
||||
<input v-model="form.phone_number" type="text" class="w-full border-default rounded-xl px-4 py-3 text-sm" />
|
||||
</div>
|
||||
<div v-if="!rolesConfigured" class="space-y-1.5 col-span-1 md:col-span-2">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.user.fields.allowedAgents') }}</label>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3 mt-2">
|
||||
<label
|
||||
v-for="agent in agents"
|
||||
:key="agent.id"
|
||||
class="flex items-center gap-2 p-3 border border-default rounded-lg cursor-pointer hover-surface-soft transition-colors"
|
||||
:class="form.agent_ids.includes(agent.id) ? 'border-blue-500 bg-blue-50' : ''"
|
||||
>
|
||||
<input v-model="form.agent_ids" type="checkbox" :value="agent.id" class="w-4 h-4 text-blue-600 rounded focus:ring-blue-500" />
|
||||
<span class="text-sm font-medium text-secondary">{{ agent.name }}</span>
|
||||
</label>
|
||||
<ElDialog
|
||||
:model-value="visible"
|
||||
:title="form.id ? t('admin.user.editUser') : t('admin.user.createUser')"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="onVisibleChange"
|
||||
>
|
||||
<div class="max-h-[65vh] overflow-y-auto pr-1">
|
||||
<ElForm class="users-element-form" label-position="top" :model="form">
|
||||
<ElFormItem :label="t('admin.user.fields.realName')" :required="!form.id">
|
||||
<ElInput v-model="form.real_name" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.user.fields.employeeId')" :required="!form.id">
|
||||
<ElInput v-model="form.employee_id" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.user.fields.phone')" :required="!form.id">
|
||||
<ElInput v-model="form.phone_number" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.user.fields.username')" :required="!form.id">
|
||||
<ElInput v-model="form.username" :disabled="!!form.id" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.user.fields.email')" :required="!form.id">
|
||||
<ElInput v-model="form.email" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('admin.user.fields.department')">
|
||||
<ElSelect
|
||||
:model-value="form.department || undefined"
|
||||
class="w-full"
|
||||
clearable
|
||||
:placeholder="t('admin.user.allDepts')"
|
||||
@update:model-value="onDepartmentChange"
|
||||
>
|
||||
<ElOption v-for="department in departments" :key="department.id" :label="department.name" :value="department.name" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem v-if="!rolesConfigured" class="users-form-span" :label="t('admin.user.fields.allowedAgents')">
|
||||
<ElCheckboxGroup v-model="form.agent_ids">
|
||||
<div class="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
<ElCheckbox v-for="agent in agents" :key="agent.id" :value="agent.id">
|
||||
{{ agent.name }}
|
||||
</ElCheckbox>
|
||||
</div>
|
||||
</ElCheckboxGroup>
|
||||
<p v-if="agents.length === 0" class="hx-element-hint">{{ t('admin.user.fields.noAgents') }}</p>
|
||||
</ElFormItem>
|
||||
<ElFormItem class="users-form-span" :label="t('admin.user.fields.role')" required>
|
||||
<ElSelect v-model="form.role" class="w-full">
|
||||
<ElOption v-for="option in roleOptions" :key="option.value" :label="option.label" :value="option.value" />
|
||||
</ElSelect>
|
||||
<p v-if="rolesConfigured" class="hx-element-hint">{{ t('admin.permRoles.userFormHint') }}</p>
|
||||
</ElFormItem>
|
||||
<ElFormItem v-if="!rolesConfigured" class="users-form-span" :label="t('admin.user.fields.featurePermissions')">
|
||||
<div class="flex flex-col gap-3">
|
||||
<ElCheckbox v-model="form.feature_permissions.training_hr_manage">
|
||||
<span class="block">{{ t('admin.user.fields.trainingHrManage') }}</span>
|
||||
<span class="hx-element-hint">{{ t('admin.user.fields.trainingHrManageHint') }}</span>
|
||||
</ElCheckbox>
|
||||
<ElCheckbox v-model="form.feature_permissions['contract_payment.access']">
|
||||
<span class="block">{{ t('admin.user.fields.contractPaymentAccess') }}</span>
|
||||
<span class="hx-element-hint">{{ t('admin.user.fields.contractPaymentAccessHint') }}</span>
|
||||
</ElCheckbox>
|
||||
<ElCheckbox v-model="form.feature_permissions['order_delivery_reply.manage']">
|
||||
<span class="block">{{ t('admin.user.fields.orderDeliveryReplyManage') }}</span>
|
||||
<span class="hx-element-hint">{{ t('admin.user.fields.orderDeliveryReplyManageHint') }}</span>
|
||||
</ElCheckbox>
|
||||
<ElCheckbox v-model="form.feature_permissions['order_delivery_reply.access']">
|
||||
<span class="block">{{ t('admin.user.fields.orderDeliveryReplyAccess') }}</span>
|
||||
<span class="hx-element-hint">{{ t('admin.user.fields.orderDeliveryReplyAccessHint') }}</span>
|
||||
</ElCheckbox>
|
||||
</div>
|
||||
<p v-if="agents.length === 0" class="text-sm text-muted italic">{{ t('admin.user.fields.noAgents') }}</p>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.username') }}
|
||||
</label>
|
||||
<input v-model="form.username" type="text" class="w-full border-default rounded-xl px-4 py-3 text-sm" :disabled="!!form.id" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.email') }}
|
||||
</label>
|
||||
<input v-model="form.email" type="email" class="w-full border-default rounded-xl px-4 py-3 text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">{{ t('admin.user.fields.department') }}</label>
|
||||
<select v-model="form.department" class="w-full border-default rounded-xl px-4 py-3 text-sm">
|
||||
<option value="">{{ t('admin.user.allDepts') }}</option>
|
||||
<option v-for="d in departments" :key="d.id" :value="d.name">{{ d.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.role') }}
|
||||
</label>
|
||||
<select v-if="rolesConfigured" v-model="form.role" class="w-full border-default rounded-xl px-4 py-3 text-sm">
|
||||
<option v-for="role in roles" :key="role.code" :value="role.code">{{ role.name }}</option>
|
||||
</select>
|
||||
<select v-else v-model="form.role" class="w-full border-default rounded-xl px-4 py-3 text-sm">
|
||||
<option
|
||||
v-for="option in LEGACY_ROLE_OPTIONS"
|
||||
:key="option.code"
|
||||
:value="option.code"
|
||||
>
|
||||
{{ t(option.i18nKey) }}
|
||||
</option>
|
||||
</select>
|
||||
<p v-if="rolesConfigured" class="text-xs text-muted">{{ t('admin.permRoles.userFormHint') }}</p>
|
||||
</div>
|
||||
<div v-if="!rolesConfigured" class="space-y-2 rounded-2xl border border-default bg-surface px-4 py-4">
|
||||
<div class="text-xs font-semibold uppercase tracking-wider text-muted">{{ t('admin.user.fields.featurePermissions') }}</div>
|
||||
<label class="flex items-start gap-3 rounded-xl border border-default bg-white px-4 py-3">
|
||||
<input
|
||||
v-model="form.feature_permissions.training_hr_manage"
|
||||
type="checkbox"
|
||||
class="mt-0.5 h-4 w-4 rounded border-default text-brand-600 focus:ring-brand-500"
|
||||
/>
|
||||
<span class="space-y-1">
|
||||
<span class="block text-sm font-medium text-primary">{{ t('admin.user.fields.trainingHrManage') }}</span>
|
||||
<span class="block text-xs leading-5 text-muted">{{ t('admin.user.fields.trainingHrManageHint') }}</span>
|
||||
</span>
|
||||
</label>
|
||||
<label class="flex items-start gap-3 rounded-xl border border-default bg-white px-4 py-3">
|
||||
<input
|
||||
v-model="form.feature_permissions['contract_payment.access']"
|
||||
type="checkbox"
|
||||
class="mt-0.5 h-4 w-4 rounded border-default text-brand-600 focus:ring-brand-500"
|
||||
/>
|
||||
<span class="space-y-1">
|
||||
<span class="block text-sm font-medium text-primary">{{ t('admin.user.fields.contractPaymentAccess') }}</span>
|
||||
<span class="block text-xs leading-5 text-muted">{{ t('admin.user.fields.contractPaymentAccessHint') }}</span>
|
||||
</span>
|
||||
</label>
|
||||
<label class="flex items-start gap-3 rounded-xl border border-default bg-white px-4 py-3">
|
||||
<input
|
||||
v-model="form.feature_permissions['order_delivery_reply.manage']"
|
||||
type="checkbox"
|
||||
class="mt-0.5 h-4 w-4 rounded border-default text-brand-600 focus:ring-brand-500"
|
||||
/>
|
||||
<span class="space-y-1">
|
||||
<span class="block text-sm font-medium text-primary">{{ t('admin.user.fields.orderDeliveryReplyManage') }}</span>
|
||||
<span class="block text-xs leading-5 text-muted">{{ t('admin.user.fields.orderDeliveryReplyManageHint') }}</span>
|
||||
</span>
|
||||
</label>
|
||||
<label class="flex items-start gap-3 rounded-xl border border-default bg-white px-4 py-3">
|
||||
<input
|
||||
v-model="form.feature_permissions['order_delivery_reply.access']"
|
||||
type="checkbox"
|
||||
class="mt-0.5 h-4 w-4 rounded border-default text-brand-600 focus:ring-brand-500"
|
||||
/>
|
||||
<span class="space-y-1">
|
||||
<span class="block text-sm font-medium text-primary">{{ t('admin.user.fields.orderDeliveryReplyAccess') }}</span>
|
||||
<span class="block text-xs leading-5 text-muted">{{ t('admin.user.fields.orderDeliveryReplyAccessHint') }}</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-muted uppercase tracking-wider">
|
||||
<span v-if="!form.id" class="text-red-500 mr-0.5">*</span>{{ t('admin.user.fields.password') }}
|
||||
<span v-if="form.id" class="text-muted font-normal lowercase">{{ t('admin.user.fields.passwordHint') }}</span>
|
||||
</label>
|
||||
<input v-model="form.password" type="password" class="w-full border-default rounded-xl px-4 py-3 text-sm" />
|
||||
</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') + '...' : t('admin.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</ElFormItem>
|
||||
<ElFormItem class="users-form-span" :label="t('admin.user.fields.password')" :required="!form.id">
|
||||
<ElInput v-model="form.password" type="password" show-password />
|
||||
<p v-if="form.id" class="hx-element-hint">{{ t('admin.user.fields.passwordHint') }}</p>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<ElButton @click="emit('close')">{{ t('admin.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="isSaving" @click="emit('save')">{{ t('admin.save') }}</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.users-element-form {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
column-gap: 16px;
|
||||
}
|
||||
|
||||
.users-element-form :deep(.el-form-item) {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.users-element-form :deep(.users-form-span) {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.users-element-form {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -3,10 +3,12 @@
|
||||
* 用途:用户管理模块业务逻辑(CRUD、服务端筛选分页、用户/部门列排序、批量操作)。
|
||||
* 依赖:admin.api、useMessage、useTableSort、permissionRole.types。
|
||||
* 逻辑:UsersPage 调用本 composable;列表经 listAdminUsersPage 按页拉取,排序参数随请求下发。
|
||||
* 权限组启用后创建用户预填默认角色,改角色须确认;批量按人授权入口关闭。
|
||||
* 权限组启用后创建用户预填默认角色;删除和改角色用 Element 确认框。批量按人授权入口关闭。
|
||||
* Element Plus 表格通过 applyServerSort 写入列排序。
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
import {
|
||||
batchDeleteAdminUsers,
|
||||
batchUpdateAdminPermissions,
|
||||
@@ -68,10 +70,6 @@ export function useUsersAdmin() {
|
||||
const showUserModal = ref(false);
|
||||
const editingUser = ref<UserFormState>(createEmptyUserForm());
|
||||
const originalUserRole = ref('user');
|
||||
const showRoleConfirm = ref(false);
|
||||
const roleConfirmMessage = ref('');
|
||||
let pendingUserSave: (() => Promise<void>) | null = null;
|
||||
let pendingBatchSave: (() => Promise<void>) | null = null;
|
||||
|
||||
const showBatchEditModal = ref(false);
|
||||
const batchEditForm = ref<BatchEditForm>({ department: '', role: '', status: '' });
|
||||
@@ -79,9 +77,6 @@ export function useUsersAdmin() {
|
||||
const showBatchPermissionModal = ref(false);
|
||||
const batchPermissionForm = ref<BatchPermissionForm>({ agent_ids: [], action: 'add' });
|
||||
|
||||
const showDeleteConfirmDialog = ref(false);
|
||||
const deleteConfirmMessage = ref('');
|
||||
let deleteConfirmAction: (() => Promise<void> | void) | null = null;
|
||||
|
||||
/** 当前页是否已全部选中 */
|
||||
const allPaginatedUsersSelected = computed(
|
||||
@@ -194,25 +189,41 @@ export function useUsersAdmin() {
|
||||
}, 300);
|
||||
}, { deep: true });
|
||||
|
||||
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;
|
||||
/**
|
||||
* 用 Element 确认框询问后再执行删除。
|
||||
* 核心逻辑:取消时 MessageBox 会 reject,这里吞掉,不调用 action。
|
||||
* @param message - 确认文案
|
||||
* @param action - 用户点确定后执行的删除
|
||||
*/
|
||||
const openDeleteConfirm = async (message: string, action: () => Promise<void> | void): Promise<void> => {
|
||||
try {
|
||||
await ElMessageBox.confirm(message, t('common.deleteDialog.defaultTitle'), {
|
||||
type: 'warning',
|
||||
confirmButtonText: t('common.deleteDialog.confirm'),
|
||||
cancelButtonText: t('common.deleteDialog.cancel'),
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await action();
|
||||
};
|
||||
|
||||
/**
|
||||
* 执行待确认的删除操作。
|
||||
* 核心逻辑:先快照 action 并立即关闭弹窗,再 await 删除与刷新,避免异步完成前弹窗无法关闭。
|
||||
* 用 Element 确认框询问改角色,确定后执行保存。
|
||||
* 核心逻辑:与删除确认同一组件,避免一页两种确认框。取消则不保存。
|
||||
* @param message - 角色变更说明
|
||||
* @param action - 用户点确定后提交
|
||||
*/
|
||||
const confirmDelete = async (): Promise<void> => {
|
||||
const action = deleteConfirmAction;
|
||||
closeDeleteConfirm();
|
||||
if (!action) return;
|
||||
const confirmRoleThen = async (message: string, action: () => Promise<void>): Promise<void> => {
|
||||
try {
|
||||
await ElMessageBox.confirm(message, t('admin.permRoles.userRoleConfirmTitle'), {
|
||||
type: 'warning',
|
||||
confirmButtonText: t('admin.save'),
|
||||
cancelButtonText: t('admin.cancel'),
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await action();
|
||||
};
|
||||
|
||||
@@ -296,11 +307,10 @@ export function useUsersAdmin() {
|
||||
: nextRole !== originalUserRole.value;
|
||||
const touchesAdmin = isAdminRoleCode(nextRole) || isAdminRoleCode(originalUserRole.value);
|
||||
if (roleChanged) {
|
||||
roleConfirmMessage.value = touchesAdmin
|
||||
const message = touchesAdmin
|
||||
? t('admin.permRoles.userAdminConfirm')
|
||||
: t('admin.permRoles.userRoleConfirm', { role: nextRole });
|
||||
pendingUserSave = persistUser;
|
||||
showRoleConfirm.value = true;
|
||||
await confirmRoleThen(message, persistUser);
|
||||
return;
|
||||
}
|
||||
await persistUser();
|
||||
@@ -348,28 +358,6 @@ export function useUsersAdmin() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 确认改角色(含管理员)后再提交。
|
||||
*/
|
||||
const confirmRoleChange = async (): Promise<void> => {
|
||||
const userSave = pendingUserSave;
|
||||
const batchSave = pendingBatchSave;
|
||||
pendingUserSave = null;
|
||||
pendingBatchSave = null;
|
||||
showRoleConfirm.value = false;
|
||||
if (userSave) {
|
||||
await userSave();
|
||||
return;
|
||||
}
|
||||
if (batchSave) await batchSave();
|
||||
};
|
||||
|
||||
const closeRoleConfirm = (): void => {
|
||||
pendingUserSave = null;
|
||||
pendingBatchSave = null;
|
||||
showRoleConfirm.value = false;
|
||||
};
|
||||
|
||||
const cleanRejectedUsers = async (): Promise<void> => {
|
||||
openDeleteConfirm(t('admin.user.confirmClean'), async () => {
|
||||
try {
|
||||
@@ -446,11 +434,10 @@ export function useUsersAdmin() {
|
||||
return;
|
||||
}
|
||||
if (data.role) {
|
||||
roleConfirmMessage.value = isAdminRoleCode(data.role)
|
||||
const message = isAdminRoleCode(data.role)
|
||||
? t('admin.permRoles.userAdminConfirm')
|
||||
: t('admin.permRoles.batchRoleConfirm');
|
||||
pendingBatchSave = () => persistBatchEdit(data);
|
||||
showRoleConfirm.value = true;
|
||||
await confirmRoleThen(message, () => persistBatchEdit(data));
|
||||
return;
|
||||
}
|
||||
await persistBatchEdit(data);
|
||||
@@ -504,6 +491,19 @@ export function useUsersAdmin() {
|
||||
scheduleLoadUsers(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* 按指定列和方向重新查询第一页。
|
||||
* 核心逻辑:方向未变时不请求;变更后回到第一页再拉取。
|
||||
* @param key - username 或 department,与后端 sort_by 白名单一致
|
||||
* @param dir - asc 或 desc
|
||||
*/
|
||||
const applyServerSort = (key: UserSortKey, dir: 'asc' | 'desc'): void => {
|
||||
if (sortKey.value === key && sortDir.value === dir) return;
|
||||
sortKey.value = key;
|
||||
sortDir.value = dir;
|
||||
scheduleLoadUsers(true);
|
||||
};
|
||||
|
||||
return {
|
||||
users,
|
||||
agents,
|
||||
@@ -530,12 +530,9 @@ export function useUsersAdmin() {
|
||||
batchEditForm,
|
||||
showBatchPermissionModal,
|
||||
batchPermissionForm,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
showRoleConfirm,
|
||||
roleConfirmMessage,
|
||||
loadAll,
|
||||
toggleSort,
|
||||
applyServerSort,
|
||||
openCreateUserModal,
|
||||
openEditUserModal,
|
||||
saveUser,
|
||||
@@ -547,9 +544,5 @@ export function useUsersAdmin() {
|
||||
openBatchPermissionModal,
|
||||
submitBatchEdit,
|
||||
submitBatchPermission,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
confirmRoleChange,
|
||||
closeRoleConfirm,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* features/admin/styles/element-trial.css
|
||||
* 用途:管理端 Element Plus 的字体、字号、颜色、圆角、控件高度,以及和 Tailwind 共存的修正。
|
||||
* 依赖:tokens.css 的 --text-* / --bg-* / --border-*,element-plus 暗色变量,Tailwind preflight。
|
||||
* 逻辑:由 UsersPage、AgentsPage、KbAdminPanel 在暗色 CSS 之后引入,所以 html.dark 能盖过 Element 默认暗色。
|
||||
* 字号和颜色以本文变量为准。页面不要再用 text-sm / text-muted 改表格和按钮。
|
||||
*/
|
||||
|
||||
:root,
|
||||
html.dark {
|
||||
--el-color-primary: #0284c7;
|
||||
--el-color-primary-light-3: #4da3d6;
|
||||
--el-color-primary-light-5: #81c2e3;
|
||||
--el-color-primary-light-7: #b4daf0;
|
||||
--el-color-primary-light-8: #cde6f4;
|
||||
--el-color-primary-light-9: #e6f3fa;
|
||||
--el-color-primary-dark-2: #0269a0;
|
||||
--el-font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
|
||||
--el-font-size-extra-large: 20px;
|
||||
--el-font-size-large: 18px;
|
||||
--el-font-size-medium: 16px;
|
||||
--el-font-size-base: 14px;
|
||||
--el-font-size-small: 13px;
|
||||
--el-font-size-extra-small: 12px;
|
||||
--el-text-color-primary: var(--text-primary);
|
||||
--el-text-color-regular: var(--text-secondary);
|
||||
--el-text-color-secondary: var(--text-muted);
|
||||
--el-text-color-placeholder: var(--text-muted);
|
||||
--el-text-color-disabled: var(--text-muted);
|
||||
--el-border-color: var(--border-default);
|
||||
--el-border-color-light: var(--border-subtle);
|
||||
--el-border-color-lighter: var(--border-subtle);
|
||||
--el-bg-color: var(--bg-surface);
|
||||
--el-bg-color-overlay: var(--bg-surface);
|
||||
--el-fill-color-blank: var(--bg-surface);
|
||||
--el-fill-color-light: var(--bg-surface-soft);
|
||||
--el-border-radius-base: 8px;
|
||||
--el-component-size: 32px;
|
||||
}
|
||||
|
||||
.el-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.el-button .el-icon,
|
||||
.el-button svg {
|
||||
display: inline-flex;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
/* Tailwind forms 会给单行输入框内部的 input 加边框。聚焦时左右两边会多出两条蓝线。
|
||||
多行输入框的边框就画在 .el-textarea__inner 上,不能一起清掉。 */
|
||||
.el-input__inner,
|
||||
.el-select__input,
|
||||
.el-range-input,
|
||||
.el-input__inner:hover,
|
||||
.el-select__input:hover,
|
||||
.el-range-input:hover,
|
||||
.el-input__inner:focus,
|
||||
.el-select__input:focus,
|
||||
.el-range-input:focus {
|
||||
border: 0;
|
||||
outline: none;
|
||||
background-color: transparent;
|
||||
box-shadow: none;
|
||||
--tw-ring-shadow: 0 0 #0000;
|
||||
--tw-ring-offset-shadow: 0 0 #0000;
|
||||
}
|
||||
|
||||
.el-textarea__inner {
|
||||
background-color: var(--el-input-bg-color, var(--el-fill-color-blank));
|
||||
box-shadow: 0 0 0 1px var(--el-input-border-color, var(--el-border-color)) inset;
|
||||
}
|
||||
|
||||
.el-textarea__inner:hover {
|
||||
box-shadow: 0 0 0 1px var(--el-input-hover-border-color, var(--el-border-color-hover)) inset;
|
||||
}
|
||||
|
||||
.el-textarea__inner:focus {
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 1px var(--el-input-focus-border-color, var(--el-color-primary)) inset;
|
||||
--tw-ring-shadow: 0 0 #0000;
|
||||
--tw-ring-offset-shadow: 0 0 #0000;
|
||||
}
|
||||
|
||||
/* 列表首尾列与页头 32px 对齐;分页贴在表格下方 */
|
||||
.hx-admin-table .el-table__cell:first-child .cell {
|
||||
padding-left: 32px;
|
||||
}
|
||||
|
||||
.hx-admin-table .el-table__cell:last-child .cell {
|
||||
padding-right: 32px;
|
||||
}
|
||||
|
||||
.hx-admin-pager {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: 12px 32px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
/* 表单里的补充说明,字号和颜色走 Element 变量 */
|
||||
.hx-element-hint {
|
||||
margin-top: 4px;
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
line-height: 1.4;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
Reference in new issue
Block a user