Merge branch 'dev' into hugo-auto-transfer
This commit is contained in:
commit
fc42bb14c9
76 files changed
+6065
-1759
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);
|
||||
}
|
||||
@@ -4,9 +4,9 @@
|
||||
* 依赖:统一 requestJson;后端 /api/equipment-acceptance。
|
||||
* 逻辑:Chat 作业面调用。同步只读 E10。配置只保存天数和系统用户,不保存发送时刻。
|
||||
* 保存配置自行声明 Content-Type: application/json,供 Flask get_json 解析。
|
||||
* 发送记录只读已落库的行,扫描尚未写入时列表为空。
|
||||
* 发送记录只读已落库的行。每位收件人的 Excel 可再下载。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { requestBlob, requestJson } from '@/shared/api/client';
|
||||
|
||||
export interface EquipmentAcceptanceNode {
|
||||
node_id?: string | null;
|
||||
@@ -150,6 +150,7 @@ export interface EquipmentAcceptanceSendRecord {
|
||||
sent_at?: string | null;
|
||||
error_message?: string | null;
|
||||
created_at?: string | null;
|
||||
files?: Array<{ id: number; excel_file_name?: string | null }>;
|
||||
}
|
||||
|
||||
export interface EquipmentAcceptanceSendListResponse {
|
||||
@@ -166,6 +167,33 @@ export interface EquipmentAcceptanceSendListResponse {
|
||||
* @param params.pageSize - 每页条数
|
||||
* @returns 当前页记录和总数
|
||||
*/
|
||||
export interface EquipmentAcceptanceSendFile {
|
||||
id: number;
|
||||
recipient_name?: string | null;
|
||||
excel_file_name?: string | null;
|
||||
excel_file_size?: number | null;
|
||||
status: string;
|
||||
sent_at?: string | null;
|
||||
created_at?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出最近按收件人归档的 Excel。不含文件内容。
|
||||
* @returns 文件摘要
|
||||
*/
|
||||
export function listEquipmentAcceptanceSendFiles() {
|
||||
return requestJson<{ items: EquipmentAcceptanceSendFile[] }>('/api/equipment-acceptance/send-files');
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载一份当时发给收件人的 Excel。
|
||||
* @param fileId - 归档文件主键
|
||||
* @returns 文件字节和文件名
|
||||
*/
|
||||
export function downloadEquipmentAcceptanceSendFile(fileId: number) {
|
||||
return requestBlob(`/api/equipment-acceptance/send-files/${fileId}/excel`);
|
||||
}
|
||||
|
||||
export function listEquipmentAcceptanceSends(params?: { page?: number; pageSize?: number }) {
|
||||
const search = new URLSearchParams();
|
||||
if (params?.page) search.set('page', String(params.page));
|
||||
@@ -185,6 +213,7 @@ export interface EquipmentAcceptanceConfigUser {
|
||||
|
||||
export interface EquipmentAcceptanceConfig {
|
||||
days: number[];
|
||||
round_4_enabled?: boolean;
|
||||
buyer_manager_user_id?: number | null;
|
||||
coo_user_id?: number | null;
|
||||
executive_user_id?: number | null;
|
||||
@@ -202,9 +231,10 @@ export function getEquipmentAcceptanceConfig() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存四档天数和三个岗位的系统用户。仅平台管理员。
|
||||
* 核心逻辑:岗位传用户主键或 null,不传姓名。
|
||||
* 保存四档天数、第 4 轮开关和三个岗位的系统用户。仅平台管理员。
|
||||
* 核心逻辑:岗位传用户主键或 null,不传姓名。第 4 轮关闭时不通知总经理。
|
||||
* @param payload.days - 四个逐档增大的天数
|
||||
* @param payload.round4Enabled - 是否启用第 4 轮
|
||||
* @param payload.buyerManagerUserId - 采购经副理
|
||||
* @param payload.cooUserId - COO
|
||||
* @param payload.executiveUserId - 总经理对应岗位
|
||||
@@ -212,6 +242,7 @@ export function getEquipmentAcceptanceConfig() {
|
||||
*/
|
||||
export function saveEquipmentAcceptanceConfig(payload: {
|
||||
days: number[];
|
||||
round4Enabled: boolean;
|
||||
buyerManagerUserId: number | null;
|
||||
cooUserId: number | null;
|
||||
executiveUserId: number | null;
|
||||
@@ -221,6 +252,7 @@ export function saveEquipmentAcceptanceConfig(payload: {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
days: payload.days,
|
||||
round_4_enabled: payload.round4Enabled,
|
||||
buyer_manager_user_id: payload.buyerManagerUserId,
|
||||
coo_user_id: payload.cooUserId,
|
||||
executive_user_id: payload.executiveUserId,
|
||||
|
||||
+166
-107
@@ -1,8 +1,8 @@
|
||||
<!--
|
||||
features/equipment-acceptance/views/EquipmentAcceptanceConfigPage.vue
|
||||
用途:设备验收预警配置页。编辑四档天数,并为三个固定岗位选择系统用户。
|
||||
用途:设备验收预警配置页。按升级轮次编辑天数、第 4 轮开关和三个固定岗位。
|
||||
依赖:equipment-acceptance.api、UserPickerDialog、userPicker.utils、vue-i18n。
|
||||
逻辑:由 Chat 作业面的「预警配置」Tab 嵌入。姓名只用于展示。
|
||||
逻辑:由 Chat 作业面的「预警配置」Tab 嵌入。同一岗位在多个轮次里共用一个人。
|
||||
发送时刻不在本页,由排程 Cron 配置。非管理员只能查看。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
@@ -23,15 +23,47 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
type RoleKey = 'buyer_manager' | 'coo' | 'executive';
|
||||
type RoundLine =
|
||||
| { kind: 'plain'; tag: 'ruleTo' | 'ruleCc'; text: string; note?: string }
|
||||
| { kind: 'roles'; tag: 'ruleTo' | 'ruleCc'; roles: RoleKey[] };
|
||||
|
||||
const ROLE_FIELDS: RoleKey[] = ['buyer_manager', 'coo', 'executive'];
|
||||
const TIER_WHO = ['tierWho1', 'tierWho2', 'tierWho3', 'tierWho4'] as const;
|
||||
const ROUNDS: Array<{ index: number; lines: RoundLine[] }> = [
|
||||
{
|
||||
index: 0,
|
||||
lines: [
|
||||
{ kind: 'plain', tag: 'ruleTo', text: 'ruleTo1' },
|
||||
{ kind: 'plain', tag: 'ruleCc', text: 'ruleCc1', note: 'roundFixedNote' },
|
||||
],
|
||||
},
|
||||
{
|
||||
index: 1,
|
||||
lines: [
|
||||
{ kind: 'plain', tag: 'ruleTo', text: 'ruleTo2' },
|
||||
{ kind: 'roles', tag: 'ruleCc', roles: ['coo', 'buyer_manager'] },
|
||||
],
|
||||
},
|
||||
{
|
||||
index: 2,
|
||||
lines: [
|
||||
{ kind: 'roles', tag: 'ruleTo', roles: ['coo'] },
|
||||
{ kind: 'roles', tag: 'ruleCc', roles: ['buyer_manager'] },
|
||||
],
|
||||
},
|
||||
{
|
||||
index: 3,
|
||||
lines: [
|
||||
{ kind: 'roles', tag: 'ruleTo', roles: ['executive'] },
|
||||
{ kind: 'roles', tag: 'ruleCc', roles: ['coo', 'buyer_manager'] },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const days = ref<number[]>([30, 37, 44, 51]);
|
||||
const round4Enabled = ref(false);
|
||||
const roleIds = ref<Record<RoleKey, number | null>>({
|
||||
buyer_manager: null,
|
||||
coo: null,
|
||||
@@ -54,13 +86,6 @@ const pickerSelectedIds = computed(() => {
|
||||
return id ? [id] : [];
|
||||
});
|
||||
|
||||
const ruleRows = computed(() => ([
|
||||
{ to: 'ruleTo1', cc: 'ruleCc1' },
|
||||
{ to: 'ruleTo2', cc: 'ruleCc2' },
|
||||
{ to: 'ruleTo3', cc: 'ruleCc3' },
|
||||
{ to: 'ruleTo4', cc: 'ruleCc4' },
|
||||
]));
|
||||
|
||||
/**
|
||||
* 读取当前配置。管理员响应里包含候选人。
|
||||
* 核心逻辑:失败时保留页面上的默认天数,并用统一错误提示。
|
||||
@@ -70,6 +95,7 @@ async function load(): Promise<void> {
|
||||
try {
|
||||
const result = await getEquipmentAcceptanceConfig();
|
||||
days.value = result.days?.length === 4 ? [...result.days] : [30, 37, 44, 51];
|
||||
round4Enabled.value = result.round_4_enabled === true;
|
||||
roleIds.value = {
|
||||
buyer_manager: result.buyer_manager_user_id ?? null,
|
||||
coo: result.coo_user_id ?? null,
|
||||
@@ -114,7 +140,7 @@ function clearRole(role: RoleKey): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存天数和三个岗位。天数须逐档增大。
|
||||
* 保存天数、第 4 轮开关和三个岗位。天数须逐档增大。
|
||||
* 核心逻辑:先在页面拦住空值和倒序,服务端再校验用户是否存在。
|
||||
*/
|
||||
async function save(): Promise<void> {
|
||||
@@ -131,11 +157,13 @@ async function save(): Promise<void> {
|
||||
try {
|
||||
const result = await saveEquipmentAcceptanceConfig({
|
||||
days: nextDays,
|
||||
round4Enabled: round4Enabled.value,
|
||||
buyerManagerUserId: roleIds.value.buyer_manager,
|
||||
cooUserId: roleIds.value.coo,
|
||||
executiveUserId: roleIds.value.executive,
|
||||
});
|
||||
days.value = [...result.days];
|
||||
round4Enabled.value = result.round_4_enabled === true;
|
||||
knownUsers.value = result.selected_users || [];
|
||||
candidates.value = result.users || [];
|
||||
msg.success(t('admin.equipmentAcceptance.configSaved'));
|
||||
@@ -147,14 +175,47 @@ async function save(): Promise<void> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 岗位上已选用户的展示名。没有选择时返回空串,模板改显示未选择。
|
||||
* @param role - 岗位键
|
||||
* @returns 姓名,有工号时附在后面
|
||||
* 取出某个岗位已选的人。没有选择时为空。
|
||||
* @param role - buyer_manager、coo、executive
|
||||
* @returns 选人组件里的用户,或空
|
||||
*/
|
||||
function roleLabel(role: RoleKey): string {
|
||||
function rolePerson(role: RoleKey): UserPickerPerson | undefined {
|
||||
const id = roleIds.value[role];
|
||||
if (!id) return '';
|
||||
return userPickerLabel(people.value.get(id), id);
|
||||
if (!id) return undefined;
|
||||
return people.value.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 芯片上的姓名。没有选择时返回空串。
|
||||
* @param role - 岗位键
|
||||
* @returns 展示名
|
||||
*/
|
||||
function roleName(role: RoleKey): string {
|
||||
const person = rolePerson(role);
|
||||
if (!person) return '';
|
||||
return userPickerLabel(person).replace(/([^)]*)$/, '') || userPickerLabel(person);
|
||||
}
|
||||
|
||||
/**
|
||||
* 姓名首字,画在圆形头像里。
|
||||
* @param role - 岗位键
|
||||
* @returns 一个字符
|
||||
*/
|
||||
function roleInitial(role: RoleKey): string {
|
||||
const name = roleName(role).trim();
|
||||
return name.slice(0, 1) || '?';
|
||||
}
|
||||
|
||||
/**
|
||||
* 芯片第二行:工号和岗位名。
|
||||
* @param role - 岗位键
|
||||
* @returns 例如 26030025 · COO
|
||||
*/
|
||||
function roleMeta(role: RoleKey): string {
|
||||
const person = rolePerson(role);
|
||||
const roleText = t(`admin.equipmentAcceptance.role.${role}`);
|
||||
const employeeId = String(person?.employee_id || person?.username || '').trim();
|
||||
return employeeId ? `${employeeId} · ${roleText}` : roleText;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@@ -167,97 +228,95 @@ onMounted(() => {
|
||||
<p class="mb-3 text-sm text-[#64748b]">{{ t('admin.equipmentAcceptance.configLead') }}</p>
|
||||
<p v-if="loading" class="text-sm text-[#64748b]">{{ t('admin.equipmentAcceptance.loading') }}</p>
|
||||
<template v-else>
|
||||
<div class="grid grid-cols-4 gap-3">
|
||||
<label
|
||||
v-for="(who, index) in TIER_WHO"
|
||||
:key="who"
|
||||
class="rounded-xl border border-[#dce4ef] border-t-[3px] bg-white px-3 py-3"
|
||||
:class="index === 0 ? 'border-t-[#93c5fd]' : index === 1 ? 'border-t-[#2563eb]' : index === 2 ? 'border-t-[#d97706]' : 'border-t-[#dc2626]'"
|
||||
>
|
||||
<span class="block text-xs font-bold text-[#64748b]">{{ t(`admin.equipmentAcceptance.tier${index + 1}`) }}</span>
|
||||
<span class="mt-2 flex items-center gap-2">
|
||||
<input
|
||||
v-model.number="days[index]"
|
||||
class="h-11 w-16 rounded-lg border border-[#d7dee8] bg-[#f8fafc] text-center text-xl font-bold text-[#142033] disabled:opacity-70"
|
||||
type="number"
|
||||
min="1"
|
||||
:disabled="!editable"
|
||||
/>
|
||||
<span class="text-sm font-semibold text-[#94a3b8]">{{ t('admin.equipmentAcceptance.dayUnit') }}</span>
|
||||
</span>
|
||||
<span class="mt-2 block text-xs font-bold text-[#334155]">{{ t(`admin.equipmentAcceptance.${who}`) }}</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 grid gap-3 lg:grid-cols-2">
|
||||
<article class="rounded-xl border border-[#dce4ef] bg-white">
|
||||
<h2 class="px-4 pt-4 text-sm font-bold text-[#142033]">{{ t('admin.equipmentAcceptance.fixedRoles') }}</h2>
|
||||
<div class="px-4 pb-2">
|
||||
<div
|
||||
v-for="role in ROLE_FIELDS"
|
||||
:key="role"
|
||||
class="grid grid-cols-[108px_minmax(0,1fr)] items-center gap-3 border-b border-[#dce4ef] py-3 last:border-b-0"
|
||||
>
|
||||
<span class="text-sm font-bold text-[#334155]">{{ t(`admin.equipmentAcceptance.role.${role}`) }}</span>
|
||||
<div class="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<span v-if="roleLabel(role)" class="truncate text-sm text-[#142033]">{{ roleLabel(role) }}</span>
|
||||
<span v-else class="text-sm text-[#94a3b8]">{{ t('admin.equipmentAcceptance.roleEmpty') }}</span>
|
||||
<button
|
||||
v-if="editable"
|
||||
class="ml-auto rounded-lg border border-[#bfdbfe] bg-[#eaf2ff] px-2.5 py-1 text-xs font-bold text-[#1d4ed8]"
|
||||
type="button"
|
||||
@click="openPicker(role)"
|
||||
>
|
||||
{{ t('admin.equipmentAcceptance.selectUser') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="editable && roleIds[role]"
|
||||
class="text-xs font-bold text-[#64748b]"
|
||||
type="button"
|
||||
@click="clearRole(role)"
|
||||
>
|
||||
{{ t('admin.equipmentAcceptance.clearUser') }}
|
||||
</button>
|
||||
<section class="overflow-hidden rounded-2xl border border-[#dce4ef] bg-white">
|
||||
<div class="px-5 pb-2 pt-4">
|
||||
<h2 class="text-sm font-bold text-[#142033]">{{ t('admin.equipmentAcceptance.configSheetTitle') }}</h2>
|
||||
<p class="mt-1 text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.configSheetLead') }}</p>
|
||||
</div>
|
||||
<div class="px-3 pb-2">
|
||||
<article
|
||||
v-for="round in ROUNDS"
|
||||
:key="round.index"
|
||||
class="relative ml-4 grid grid-cols-1 gap-3 border-l-2 border-[#c9d4e3] py-4 pl-7 sm:grid-cols-[168px_minmax(0,1fr)] sm:gap-x-5"
|
||||
:class="round.index === ROUNDS.length - 1 ? 'border-transparent' : ''"
|
||||
>
|
||||
<span class="absolute -left-[7px] top-6 h-3 w-3 rounded-full border-2 border-white bg-[#1d4e89] shadow-[0_0_0_1px_#c9d4e3]"></span>
|
||||
<div class="flex flex-col gap-2">
|
||||
<b class="text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.roundName', { n: round.index + 1 }) }}</b>
|
||||
<label class="flex items-center gap-2 text-[13px] text-[#64748b]">
|
||||
{{ t('admin.equipmentAcceptance.overPrefix') }}
|
||||
<input
|
||||
v-model.number="days[round.index]"
|
||||
class="h-10 w-[72px] rounded-lg border border-[#d5dee8] bg-[#f8fafc] text-center text-[22px] font-semibold text-[#142033] disabled:opacity-70"
|
||||
type="number"
|
||||
min="1"
|
||||
:disabled="!editable"
|
||||
/>
|
||||
{{ t('admin.equipmentAcceptance.dayUnit') }}
|
||||
</label>
|
||||
<template v-if="round.index === 3">
|
||||
<label class="flex items-center gap-1.5 text-[13px] font-bold text-[#142033]">
|
||||
<input v-model="round4Enabled" class="h-4 w-4 accent-[#1d4e89]" type="checkbox" :disabled="!editable" />
|
||||
{{ t('admin.equipmentAcceptance.round4Enabled') }}
|
||||
</label>
|
||||
<small class="text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.round4ShortHint') }}</small>
|
||||
</template>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2" :class="round.index === 3 && !round4Enabled ? 'opacity-45' : ''">
|
||||
<div v-for="(line, lineIndex) in round.lines" :key="`${round.index}-${lineIndex}`" class="flex items-start gap-2.5">
|
||||
<span class="mt-1.5 w-9 shrink-0 text-xs font-bold text-[#64748b]">{{ t(`admin.equipmentAcceptance.${line.tag}`) }}</span>
|
||||
<div class="min-w-0">
|
||||
<template v-if="line.kind === 'plain'">
|
||||
<p class="mt-1 text-sm font-semibold text-[#142033]">{{ t(`admin.equipmentAcceptance.${line.text}`) }}</p>
|
||||
<p v-if="line.note" class="mt-1 text-xs text-[#94a3b8]">{{ t(`admin.equipmentAcceptance.${line.note}`) }}</p>
|
||||
</template>
|
||||
<div v-else class="flex flex-wrap gap-2">
|
||||
<div
|
||||
v-for="role in line.roles"
|
||||
:key="role"
|
||||
class="flex min-h-8 items-center gap-2 rounded-full bg-[#eef3f8] py-1 pl-1 pr-2"
|
||||
>
|
||||
<span class="grid h-6 w-6 place-items-center rounded-full bg-[#d7e4f2] text-xs font-bold text-[#1d4e89]">{{ roleInitial(role) }}</span>
|
||||
<span class="flex flex-col leading-tight">
|
||||
<strong class="text-[13px] text-[#142033]">{{ roleName(role) || t('admin.equipmentAcceptance.roleEmpty') }}</strong>
|
||||
<span class="text-[11px] text-[#64748b]">{{ roleMeta(role) }}</span>
|
||||
</span>
|
||||
<button
|
||||
v-if="editable"
|
||||
class="text-xs font-bold text-[#1d4e89]"
|
||||
type="button"
|
||||
@click="openPicker(role)"
|
||||
>
|
||||
{{ roleIds[role] ? t('admin.equipmentAcceptance.replaceUser') : t('admin.equipmentAcceptance.selectUser') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="editable && roleIds[role]"
|
||||
class="text-xs text-[#64748b]"
|
||||
type="button"
|
||||
@click="clearRole(role)"
|
||||
>
|
||||
{{ t('admin.equipmentAcceptance.clearUser') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between gap-3 border-t border-[#dce4ef] bg-[#fafbfd] px-4 py-3">
|
||||
<span class="text-xs text-[#64748b]">{{ editable ? t('admin.equipmentAcceptance.configSaveHint') : t('admin.equipmentAcceptance.configReadOnly') }}</span>
|
||||
<button
|
||||
v-if="editable"
|
||||
class="rounded-lg bg-[#2563eb] px-3 py-1.5 text-xs font-bold text-white disabled:opacity-50"
|
||||
type="button"
|
||||
:disabled="saving"
|
||||
@click="save"
|
||||
>
|
||||
{{ t('admin.equipmentAcceptance.saveConfig') }}
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="overflow-hidden rounded-xl border border-[#dce4ef] bg-white">
|
||||
<div class="px-4 pt-4">
|
||||
<h2 class="text-sm font-bold text-[#142033]">{{ t('admin.equipmentAcceptance.rulesTitle') }}</h2>
|
||||
<p class="mt-1 text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.rulesLead') }}</p>
|
||||
</div>
|
||||
<table class="mt-3 w-full border-collapse text-left text-xs">
|
||||
<thead class="bg-[#f8fbff] text-[#64748b]">
|
||||
<tr>
|
||||
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.ruleTier') }}</th>
|
||||
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.ruleTo') }}</th>
|
||||
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.ruleCc') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(row, index) in ruleRows" :key="row.to" class="border-t border-[#dce4ef]">
|
||||
<td class="px-3 py-2.5 font-bold text-[#142033]">{{ t('admin.equipmentAcceptance.ruleOver', { days: days[index] || '—' }) }}</td>
|
||||
<td class="px-3 py-2.5">{{ t(`admin.equipmentAcceptance.${row.to}`) }}</td>
|
||||
<td class="px-3 py-2.5">{{ t(`admin.equipmentAcceptance.${row.cc}`) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</article>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<div class="flex items-center justify-between gap-4 border-t border-[#dce4ef] bg-[#fafbfd] px-5 py-3.5">
|
||||
<span class="text-xs text-[#64748b]">{{ editable ? t('admin.equipmentAcceptance.configSaveHint') : t('admin.equipmentAcceptance.configReadOnly') }}</span>
|
||||
<button
|
||||
v-if="editable"
|
||||
class="h-9 rounded-lg bg-[#1d4e89] px-4 text-[13px] font-bold text-white disabled:opacity-50"
|
||||
type="button"
|
||||
:disabled="saving"
|
||||
@click="save"
|
||||
>
|
||||
{{ t('admin.equipmentAcceptance.saveConfig') }}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<UserPickerDialog
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
<!--
|
||||
features/equipment-acceptance/views/EquipmentAcceptanceSendsPage.vue
|
||||
用途:设备验收预警发送记录页,列出每张验收单某一档的主送、抄送和结果。
|
||||
依赖:equipment-acceptance.api、PaginationBar、统一消息提示、vue-i18n。
|
||||
逻辑:由 Chat 作业面的「发送记录」Tab 嵌入。只读已落库记录。扫描尚未写入时显示空状态。
|
||||
用途:设备验收预警发送记录页,列出每张验收单某一档的主送、抄送、Excel 附件和结果。
|
||||
依赖:equipment-acceptance.api、PaginationBar、统一消息提示、vue-i18n、lucide 图标。
|
||||
逻辑:由 Chat 作业面的「发送记录」Tab 嵌入。Excel 附件列点击文件名下载。发送失败时悬停图标看原因。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { CircleAlert, Download } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { formatLocalDateTime } from '@/shared/utils/dateTime';
|
||||
import {
|
||||
downloadEquipmentAcceptanceSendFile,
|
||||
listEquipmentAcceptanceSends,
|
||||
type EquipmentAcceptanceSendRecord,
|
||||
} from '../api/equipment-acceptance.api';
|
||||
@@ -19,11 +21,13 @@ import {
|
||||
const { t, te } = useI18n();
|
||||
const msg = useMessage();
|
||||
const records = ref<EquipmentAcceptanceSendRecord[]>([]);
|
||||
const downloadingId = ref<number | null>(null);
|
||||
const loading = ref(false);
|
||||
const page = ref(1);
|
||||
const pageSize = ref(20);
|
||||
const total = ref(0);
|
||||
const pages = ref(1);
|
||||
const failureTip = ref<{ text: string; left: number; top: number } | null>(null);
|
||||
|
||||
/**
|
||||
* 拉取当前页发送记录。
|
||||
@@ -76,6 +80,55 @@ function sentText(value?: string | null): string {
|
||||
return text === '-' ? '—' : text;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在失败图标下方显示原因。用固定定位,避免被表格滚动容器裁掉。
|
||||
* @param event - 悬停或聚焦事件
|
||||
* @param message - 发送失败原因
|
||||
*/
|
||||
function openFailureTip(event: Event, message: string): void {
|
||||
const target = event.currentTarget;
|
||||
if (!(target instanceof HTMLElement)) return;
|
||||
const rect = target.getBoundingClientRect();
|
||||
const width = 280;
|
||||
failureTip.value = {
|
||||
text: message || t('admin.equipmentAcceptance.failureReasonEmpty'),
|
||||
left: Math.max(8, Math.min(rect.left, window.innerWidth - width - 8)),
|
||||
top: rect.bottom + 6,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 鼠标离开或失焦时关掉失败原因提示。
|
||||
*/
|
||||
function closeFailureTip(): void {
|
||||
failureTip.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载一份已归档的收件人 Excel。
|
||||
* 核心逻辑:接口返回当时发出的字节,由浏览器保存。
|
||||
* @param file - 这一行上的 Excel 摘要
|
||||
*/
|
||||
async function downloadFile(file: { id: number; excel_file_name?: string | null }): Promise<void> {
|
||||
if (downloadingId.value === file.id) return;
|
||||
downloadingId.value = file.id;
|
||||
try {
|
||||
const { blob, filename } = await downloadEquipmentAcceptanceSendFile(file.id);
|
||||
const objectUrl = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = objectUrl;
|
||||
anchor.download = filename || file.excel_file_name || `equipment-acceptance-alert-${file.id}.xlsx`;
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
document.body.removeChild(anchor);
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
} catch (error) {
|
||||
msg.error(error instanceof BusinessError ? error.message : t('admin.equipmentAcceptance.excelDownloadFailed'));
|
||||
} finally {
|
||||
downloadingId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void load();
|
||||
});
|
||||
@@ -97,6 +150,7 @@ defineExpose({ reload: load });
|
||||
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.ruleTo') }}</th>
|
||||
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.ruleCc') }}</th>
|
||||
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.sendResult') }}</th>
|
||||
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.excelColumn') }}</th>
|
||||
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.sentAt') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -108,15 +162,43 @@ defineExpose({ reload: load });
|
||||
<td class="px-3 py-2.5">{{ item.to_text || '—' }}</td>
|
||||
<td class="px-3 py-2.5">{{ item.cc_text || '—' }}</td>
|
||||
<td class="px-3 py-2.5">
|
||||
{{ statusText(item.status) }}
|
||||
<span v-if="item.error_message" class="mt-1 block text-[#b42318]">
|
||||
{{ item.error_message }}
|
||||
<span class="inline-flex items-center gap-1" :class="item.status === 'failed' ? 'font-bold text-[#b42318]' : ''">
|
||||
{{ statusText(item.status) }}
|
||||
<button
|
||||
v-if="item.status === 'failed'"
|
||||
class="inline-flex h-[22px] w-[22px] items-center justify-center rounded-full text-[#b42318] hover:bg-[#fff1f2]"
|
||||
type="button"
|
||||
:aria-label="t('admin.equipmentAcceptance.failureReasonAria')"
|
||||
@mouseenter="openFailureTip($event, item.error_message || '')"
|
||||
@mouseleave="closeFailureTip"
|
||||
@focus="openFailureTip($event, item.error_message || '')"
|
||||
@blur="closeFailureTip"
|
||||
>
|
||||
<CircleAlert class="h-4 w-4" />
|
||||
</button>
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-3 py-2.5">
|
||||
<div v-if="item.files?.length" class="flex max-w-[280px] flex-col gap-1">
|
||||
<button
|
||||
v-for="file in item.files"
|
||||
:key="file.id"
|
||||
class="inline-flex min-w-0 items-center gap-1 font-semibold text-[#2563eb] disabled:opacity-50"
|
||||
type="button"
|
||||
:disabled="downloadingId === file.id"
|
||||
:title="t('admin.equipmentAcceptance.excelColumn')"
|
||||
@click="downloadFile(file)"
|
||||
>
|
||||
<Download class="h-3.5 w-3.5 shrink-0" />
|
||||
<span class="truncate">{{ file.excel_file_name }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<span v-else>—</span>
|
||||
</td>
|
||||
<td class="px-3 py-2.5">{{ sentText(item.sent_at) }}</td>
|
||||
</tr>
|
||||
<tr v-if="!loading && !records.length">
|
||||
<td colspan="7" class="px-3 py-10 text-center text-[#64748b]">
|
||||
<td colspan="8" class="px-3 py-10 text-center text-[#64748b]">
|
||||
{{ t('admin.equipmentAcceptance.sendsEmpty') }}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -133,5 +215,15 @@ defineExpose({ reload: load });
|
||||
@update:page="() => load()"
|
||||
@update:page-size="() => load()"
|
||||
/>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="failureTip"
|
||||
class="pointer-events-none fixed z-[80] max-w-[280px] whitespace-normal break-words rounded-lg bg-slate-900 px-2.5 py-1.5 text-xs leading-relaxed text-white shadow-lg"
|
||||
role="tooltip"
|
||||
:style="{ left: `${failureTip.left}px`, top: `${failureTip.top}px` }"
|
||||
>
|
||||
{{ failureTip.text }}
|
||||
</div>
|
||||
</Teleport>
|
||||
</section>
|
||||
</template>
|
||||
@@ -1,16 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/kb/components/DifyHealthDialog.vue
|
||||
* 知识库 Dify 健康检查弹窗。
|
||||
* 用途:展示知识库 Dify 连通性和本地同步计数。
|
||||
* 依赖:Element Plus、kb.api 的健康检查接口。
|
||||
* 逻辑:KbAdminPanel 打开本弹窗后拉取健康数据,失败时把文案交给父组件。结果用 Element 描述列表展示,不再套统计卡片。
|
||||
*/
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ElAlert, ElButton, ElDescriptions, ElDescriptionsItem, ElDialog, ElLoading, ElTag } from 'element-plus';
|
||||
import { getKbDifyHealth, type KbDifyHealth } from '../api/kb.api';
|
||||
|
||||
const props = defineProps<{ open: boolean }>();
|
||||
const emit = defineEmits<{ close: []; error: [message: string] }>();
|
||||
const { t } = useI18n();
|
||||
const vLoading = ElLoading.directive;
|
||||
|
||||
const loading = ref(false);
|
||||
const payload = ref<KbDifyHealth | null>(null);
|
||||
@@ -30,54 +34,90 @@ watch(() => props.open, (open) => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="open" class="dialog-overlay" @click="close">
|
||||
<div class="dialog-panel max-w-4xl p-6" @click.stop>
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="section-title text-xl">{{ t('kbDifyHealth.title') }}</h3>
|
||||
<p class="section-desc mt-1">{{ t('kbDifyHealth.subtitle') }}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<button type="button" class="btn-secondary btn-sm" @click="loadHealth">
|
||||
{{ t('common.refresh') }}
|
||||
</button>
|
||||
<button type="button" class="btn-secondary btn-sm" @click="close">
|
||||
{{ t('common.close') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="py-16 text-center text-sm text-muted">{{ t('kbDifyHealth.loading') }}</div>
|
||||
<div v-else-if="payload" class="mt-6 grid gap-4 md:grid-cols-2 xl:grid-cols-3">
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">Dify API</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.api.reachable ? t('kbDifyHealth.reachable') : t('kbDifyHealth.unreachable') }}</div>
|
||||
<div class="mt-2 break-all text-xs text-muted">{{ payload.dify_base_url || t('kbDifyHealth.notConfigured') }}</div>
|
||||
</div>
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">{{ t('kbDifyHealth.datasetCount') }}</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.api.dataset_count ?? '--' }}</div>
|
||||
<div class="mt-2 text-xs text-muted">{{ t('kbDifyHealth.configured') }}{{ payload.dify_api_configured ? t('common.yes') : t('common.no') }}</div>
|
||||
</div>
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">{{ t('kbDifyHealth.boundGroups') }}</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.local_sync_health.dataset_bound_groups }}</div>
|
||||
<div class="mt-2 text-xs text-muted">{{ t('kbDifyHealth.localSyncRecords') }}{{ payload.local_sync_health.sync_records }}</div>
|
||||
</div>
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">{{ t('kbDifyHealth.syncingVersions') }}</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.local_sync_health.syncing_versions }}</div>
|
||||
</div>
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">{{ t('kbDifyHealth.syncedVersions') }}</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.local_sync_health.synced_versions }}</div>
|
||||
</div>
|
||||
<div class="dialog-stat-card">
|
||||
<div class="label-field">{{ t('kbDifyHealth.pendingSyncJobs') }}</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-primary">{{ payload.local_sync_health.pending_sync_jobs }}</div>
|
||||
<div v-if="payload.api.error" class="mt-2 text-xs text-rose-500">{{ payload.api.error }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<ElDialog
|
||||
:model-value="open"
|
||||
:title="t('kbDifyHealth.title')"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="(value) => { if (!value) close(); }"
|
||||
>
|
||||
<p class="section-desc">{{ t('kbDifyHealth.subtitle') }}</p>
|
||||
<div v-loading="loading" class="dify-health-body">
|
||||
<template v-if="payload">
|
||||
<ElAlert
|
||||
v-if="payload.api.error"
|
||||
class="dify-health-alert"
|
||||
:title="payload.api.error"
|
||||
type="error"
|
||||
show-icon
|
||||
:closable="false"
|
||||
/>
|
||||
<ElDescriptions :column="1" border label-width="148px">
|
||||
<ElDescriptionsItem label="Dify API">
|
||||
<div class="dify-health-status">
|
||||
<ElTag :type="payload.api.reachable ? 'success' : 'danger'" effect="light">
|
||||
{{ payload.api.reachable ? t('kbDifyHealth.reachable') : t('kbDifyHealth.unreachable') }}
|
||||
</ElTag>
|
||||
<span class="hx-element-hint dify-health-url">{{ payload.dify_base_url || t('kbDifyHealth.notConfigured') }}</span>
|
||||
</div>
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.datasetCount')">
|
||||
{{ payload.api.dataset_count ?? '--' }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.configured')">
|
||||
{{ payload.dify_api_configured ? t('common.yes') : t('common.no') }}
|
||||
</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
<ElDescriptions class="dify-health-sync" :column="2" border label-width="148px">
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.boundGroups')">
|
||||
{{ payload.local_sync_health.dataset_bound_groups }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.localSyncRecords')">
|
||||
{{ payload.local_sync_health.sync_records }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.syncingVersions')">
|
||||
{{ payload.local_sync_health.syncing_versions }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.syncedVersions')">
|
||||
{{ payload.local_sync_health.synced_versions }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="t('kbDifyHealth.pendingSyncJobs')" :span="2">
|
||||
{{ payload.local_sync_health.pending_sync_jobs }}
|
||||
</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<ElButton :loading="loading" @click="loadHealth">{{ t('common.refresh') }}</ElButton>
|
||||
<ElButton type="primary" @click="close">{{ t('common.close') }}</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.dify-health-body {
|
||||
min-height: 8rem;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.dify-health-alert {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.dify-health-status {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px 12px;
|
||||
}
|
||||
|
||||
.dify-health-url {
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.dify-health-sync {
|
||||
margin-top: 16px;
|
||||
}
|
||||
</style>
|
||||
@@ -2,17 +2,34 @@
|
||||
/**
|
||||
* features/kb/components/DifySettingsDialog.vue
|
||||
* 用途:提供知识库 Dify 连接及默认同步参数的查看、编辑和保存界面。
|
||||
* 依赖:Vue 响应式 API、Vue I18n、kb.api 的 Dify 设置读写接口。
|
||||
* 逻辑:KbAdminPanel 控制弹窗开关;本组件加载或保存设置后通过事件把结果反馈给父组件。
|
||||
* 依赖:Vue 响应式 API、Element Plus、Vue I18n、kb.api 的 Dify 设置读写接口。
|
||||
* 逻辑:KbAdminPanel 控制弹窗开关;本组件加载或保存设置后通过事件把结果反馈给父组件。表单按连接、检索、分段三块排,密钥默认遮挡;开关行按左标题、开关、右标题、数字四列对齐。
|
||||
*/
|
||||
|
||||
import { reactive, ref, watch } from 'vue';
|
||||
import { reactive, ref, useId, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
ElButton,
|
||||
ElDialog,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElInput,
|
||||
ElInputNumber,
|
||||
ElLoading,
|
||||
ElOption,
|
||||
ElSelect,
|
||||
ElSwitch,
|
||||
} from 'element-plus';
|
||||
import { getKbDifySettings, updateKbDifySettings } from '../api/kb.api';
|
||||
|
||||
const props = defineProps<{ open: boolean }>();
|
||||
const emit = defineEmits<{ close: []; saved: [message: string]; error: [message: string] }>();
|
||||
const { t } = useI18n();
|
||||
const vLoading = ElLoading.directive;
|
||||
const rerankLabelId = useId();
|
||||
const topKLabelId = useId();
|
||||
const scoreSwitchLabelId = useId();
|
||||
const scoreValueLabelId = useId();
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
@@ -108,94 +125,243 @@ watch(() => props.open, (open) => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="open" class="dialog-overlay" @click="close">
|
||||
<div class="dialog-panel max-w-3xl max-h-[92vh] overflow-y-auto" @click.stop>
|
||||
<div class="px-5 sm:px-8 pt-5 sm:pt-7 pb-4 border-b border-subtle flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="section-title">{{ t('kbDifySettings.title') }}</h3>
|
||||
<p class="section-desc mt-1">{{ t('kbDifySettings.subtitle') }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary btn-sm" @click="close">
|
||||
{{ t('common.close') }}
|
||||
</button>
|
||||
<ElDialog
|
||||
:model-value="open"
|
||||
width="680px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="(value) => { if (!value) close(); }"
|
||||
>
|
||||
<template #header="{ titleId, titleClass }">
|
||||
<div class="dify-settings-heading">
|
||||
<span :id="titleId" :class="titleClass">{{ t('kbDifySettings.title') }}</span>
|
||||
<p class="dify-settings-subtitle">{{ t('kbDifySettings.subtitle') }}</p>
|
||||
</div>
|
||||
</template>
|
||||
<div v-loading="loading" class="dify-settings-body">
|
||||
<ElForm v-if="!loading" class="dify-settings-form" label-position="top" :model="form">
|
||||
<section class="dify-settings-section">
|
||||
<p class="dify-settings-section-title">{{ t('kbDifySettings.sections.connection') }}</p>
|
||||
<div class="dify-settings-panel dify-settings-stack">
|
||||
<ElFormItem :label="t('kbDifySettings.fields.baseUrl')">
|
||||
<ElInput v-model="form.DIFY_API_BASE" placeholder="https://api.dify.ai/v1" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.apiKey')">
|
||||
<ElInput v-model="form.DIFY_API_KEY" type="password" show-password autocomplete="off" placeholder="app-..." />
|
||||
</ElFormItem>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div v-if="loading" class="px-5 sm:px-8 py-16 text-center text-sm text-muted">{{ t('kbDifySettings.loading') }}</div>
|
||||
<div v-else class="px-5 sm:px-8 py-5 grid gap-4 md:grid-cols-2">
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.baseUrl') }}</span>
|
||||
<input v-model="form.DIFY_API_BASE" class="input-field text-sm" placeholder="https://api.dify.ai/v1" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.apiKey') }}</span>
|
||||
<input v-model="form.DIFY_API_KEY" class="input-field text-sm" placeholder="app-..." />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.permission') }}</span>
|
||||
<select v-model="form.KB_DIFY_PERMISSION" class="input-field text-sm">
|
||||
<option value="only_me">{{ t('kbDifySettings.options.permission.onlyMe') }}</option>
|
||||
<option value="all_team_members">{{ t('kbDifySettings.options.permission.allTeamMembers') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.indexingTechnique') }}</span>
|
||||
<select v-model="form.KB_DIFY_INDEXING_TECHNIQUE" class="input-field text-sm">
|
||||
<option value="high_quality">{{ t('kbDifySettings.options.indexingTechnique.highQuality') }}</option>
|
||||
<option value="economy">{{ t('kbDifySettings.options.indexingTechnique.economy') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.searchMethod') }}</span>
|
||||
<select v-model="form.KB_DIFY_SEARCH_METHOD" class="input-field text-sm">
|
||||
<option value="semantic_search">{{ t('kbDifySettings.options.searchMethod.semanticSearch') }}</option>
|
||||
<option value="hybrid_search">{{ t('kbDifySettings.options.searchMethod.hybridSearch') }}</option>
|
||||
<option value="full_text_search">{{ t('kbDifySettings.options.searchMethod.fullTextSearch') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.documentForm') }}</span>
|
||||
<select v-model="form.KB_DIFY_DOC_FORM" class="input-field text-sm">
|
||||
<option value="text_model">{{ t('kbDifySettings.options.documentForm.textModel') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="flex items-center gap-2 space-y-0">
|
||||
<input v-model="form.KB_DIFY_RERANKING_ENABLE" type="checkbox" class="h-4 w-4" />
|
||||
<span class="label-field">{{ t('kbDifySettings.fields.rerankingEnable') }}</span>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.topK') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_TOP_K" type="number" min="1" max="10" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
<label class="flex items-center gap-2 space-y-0">
|
||||
<input v-model="form.KB_DIFY_SCORE_THRESHOLD_ENABLED" type="checkbox" class="h-4 w-4" />
|
||||
<span class="label-field">{{ t('kbDifySettings.fields.scoreThresholdEnabled') }}</span>
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.scoreThreshold') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SCORE_THRESHOLD" type="number" min="0" max="1" step="0.01" class="input-field text-sm" :disabled="!form.KB_DIFY_SCORE_THRESHOLD_ENABLED" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.segmentMaxTokens') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SEGMENT_MAX_TOKENS" type="number" min="1" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.segmentMaxTokensExcel') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SEGMENT_MAX_TOKENS_EXCEL" type="number" min="1" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
<label class="space-y-1.5">
|
||||
<span class="label-field block">{{ t('kbDifySettings.fields.segmentChunkOverlap') }}</span>
|
||||
<input v-model.number="form.KB_DIFY_SEGMENT_CHUNK_OVERLAP" type="number" min="0" step="1" class="input-field text-sm" />
|
||||
</label>
|
||||
</div>
|
||||
<section class="dify-settings-section">
|
||||
<p class="dify-settings-section-title">{{ t('kbDifySettings.sections.retrieval') }}</p>
|
||||
<div class="dify-settings-panel">
|
||||
<div class="dify-settings-grid">
|
||||
<ElFormItem :label="t('kbDifySettings.fields.permission')">
|
||||
<ElSelect v-model="form.KB_DIFY_PERMISSION">
|
||||
<ElOption value="only_me" :label="t('kbDifySettings.options.permission.onlyMe')" />
|
||||
<ElOption value="all_team_members" :label="t('kbDifySettings.options.permission.allTeamMembers')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.indexingTechnique')">
|
||||
<ElSelect v-model="form.KB_DIFY_INDEXING_TECHNIQUE">
|
||||
<ElOption value="high_quality" :label="t('kbDifySettings.options.indexingTechnique.highQuality')" />
|
||||
<ElOption value="economy" :label="t('kbDifySettings.options.indexingTechnique.economy')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.searchMethod')">
|
||||
<ElSelect v-model="form.KB_DIFY_SEARCH_METHOD">
|
||||
<ElOption value="semantic_search" :label="t('kbDifySettings.options.searchMethod.semanticSearch')" />
|
||||
<ElOption value="hybrid_search" :label="t('kbDifySettings.options.searchMethod.hybridSearch')" />
|
||||
<ElOption value="full_text_search" :label="t('kbDifySettings.options.searchMethod.fullTextSearch')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.documentForm')">
|
||||
<ElSelect v-model="form.KB_DIFY_DOC_FORM">
|
||||
<ElOption value="text_model" :label="t('kbDifySettings.options.documentForm.textModel')" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
|
||||
<div class="admin-modal-footer">
|
||||
<button type="button" class="btn-ghost" @click="close">
|
||||
{{ t('common.cancel') }}
|
||||
</button>
|
||||
<button type="button" class="btn-primary" :disabled="saving" @click="save">
|
||||
{{ saving ? t('kbDifySettings.saving') : t('kbDifySettings.save') }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="dify-settings-switch-grid">
|
||||
<div class="dify-settings-switch-row">
|
||||
<span :id="rerankLabelId">{{ t('kbDifySettings.fields.rerankingEnable') }}</span>
|
||||
<ElSwitch v-model="form.KB_DIFY_RERANKING_ENABLE" :aria-labelledby="rerankLabelId" />
|
||||
<span :id="topKLabelId">{{ t('kbDifySettings.fields.topK') }}</span>
|
||||
<ElInputNumber
|
||||
v-model="form.KB_DIFY_TOP_K"
|
||||
:min="1"
|
||||
:max="10"
|
||||
:step="1"
|
||||
controls-position="right"
|
||||
:aria-labelledby="topKLabelId"
|
||||
/>
|
||||
</div>
|
||||
<div class="dify-settings-switch-row">
|
||||
<span :id="scoreSwitchLabelId">{{ t('kbDifySettings.fields.scoreThresholdEnabled') }}</span>
|
||||
<ElSwitch v-model="form.KB_DIFY_SCORE_THRESHOLD_ENABLED" :aria-labelledby="scoreSwitchLabelId" />
|
||||
<span :id="scoreValueLabelId">{{ t('kbDifySettings.fields.scoreThreshold') }}</span>
|
||||
<ElInputNumber
|
||||
v-model="form.KB_DIFY_SCORE_THRESHOLD"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.01"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
:disabled="!form.KB_DIFY_SCORE_THRESHOLD_ENABLED"
|
||||
:aria-labelledby="scoreValueLabelId"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="dify-settings-section">
|
||||
<p class="dify-settings-section-title">{{ t('kbDifySettings.sections.chunking') }}</p>
|
||||
<div class="dify-settings-panel dify-settings-segments">
|
||||
<ElFormItem :label="t('kbDifySettings.fields.segmentMaxTokens')">
|
||||
<ElInputNumber v-model="form.KB_DIFY_SEGMENT_MAX_TOKENS" :min="1" :step="1" controls-position="right" />
|
||||
<p class="dify-settings-hint">{{ t('kbDifySettings.hints.maxTokens') }}</p>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.segmentMaxTokensExcel')">
|
||||
<ElInputNumber v-model="form.KB_DIFY_SEGMENT_MAX_TOKENS_EXCEL" :min="1" :step="1" controls-position="right" />
|
||||
<p class="dify-settings-hint">{{ t('kbDifySettings.hints.maxTokens') }}</p>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbDifySettings.fields.segmentChunkOverlap')">
|
||||
<ElInputNumber v-model="form.KB_DIFY_SEGMENT_CHUNK_OVERLAP" :min="0" :step="1" controls-position="right" />
|
||||
<p class="dify-settings-hint">{{ t('kbDifySettings.hints.tokens') }}</p>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
</section>
|
||||
</ElForm>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<ElButton @click="close">{{ t('common.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :loading="saving" @click="save">{{ t('kbDifySettings.save') }}</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.dify-settings-heading {
|
||||
padding-right: 24px;
|
||||
}
|
||||
|
||||
.dify-settings-subtitle {
|
||||
margin: 4px 0 0;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.dify-settings-body {
|
||||
min-height: 8rem;
|
||||
}
|
||||
|
||||
.dify-settings-section + .dify-settings-section {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.dify-settings-section-title {
|
||||
margin: 0 0 8px;
|
||||
color: var(--el-text-color-primary);
|
||||
font-size: var(--el-font-size-base);
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-panel {
|
||||
padding: 16px;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: var(--el-border-radius-base);
|
||||
}
|
||||
|
||||
.dify-settings-stack,
|
||||
.dify-settings-grid,
|
||||
.dify-settings-segments {
|
||||
display: grid;
|
||||
gap: 12px 16px;
|
||||
}
|
||||
|
||||
.dify-settings-grid,
|
||||
.dify-settings-segments {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
|
||||
.dify-settings-segments {
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-form-item) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-form-item__label) {
|
||||
margin-bottom: 4px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-select),
|
||||
.dify-settings-stack :deep(.el-input),
|
||||
.dify-settings-segments :deep(.el-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dify-settings-segments :deep(.el-form-item__content) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.dify-settings-hint {
|
||||
margin: 4px 0 0;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: var(--el-font-size-extra-small);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-switch-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto max-content 8.5rem;
|
||||
column-gap: 16px;
|
||||
}
|
||||
|
||||
.dify-settings-switch-row {
|
||||
display: grid;
|
||||
grid-template-columns: subgrid;
|
||||
grid-column: 1 / -1;
|
||||
align-items: center;
|
||||
margin-top: 12px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
color: var(--el-text-color-regular);
|
||||
font-size: var(--el-font-size-base);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.dify-settings-form :deep(.el-input-number .el-input__inner) {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.dify-settings-switch-row :deep(.el-input-number) {
|
||||
width: 8.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.dify-settings-grid,
|
||||
.dify-settings-segments {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.dify-settings-switch-grid,
|
||||
.dify-settings-switch-row {
|
||||
grid-template-columns: 1fr;
|
||||
row-gap: 8px;
|
||||
}
|
||||
|
||||
.dify-settings-switch-row :deep(.el-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -2,28 +2,33 @@
|
||||
/**
|
||||
* features/kb/components/KbAdminPanel.vue
|
||||
* 知识库配置面板(治理面:分组、Dify)。
|
||||
* 依赖:kb.api、DifySettingsDialog、DifyHealthDialog、DeleteConfirmDialog、Vue I18n。
|
||||
* 逻辑:管理控制台加载知识库分组;分组列表在主表格过滤排序,新增/编辑通过右侧抽屉提交。
|
||||
* 依赖:kb.api、Element Plus、DifySettingsDialog、DifyHealthDialog、Vue I18n。
|
||||
* 逻辑:管理控制台加载知识库分组;列表、表头排序、文档数筛选、分页和删除确认用 Element。排序和筛选都作用在全量数据上,再分页。新增/编辑走 KbGroupDrawer。
|
||||
*/
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { CircleCheck, Plus, Search, Setting, Tools } from '@element-plus/icons-vue';
|
||||
import {
|
||||
Activity,
|
||||
Pencil,
|
||||
Plus,
|
||||
RefreshCw,
|
||||
Search,
|
||||
Settings,
|
||||
Trash2,
|
||||
Wrench,
|
||||
} from 'lucide-vue-next';
|
||||
ElAlert,
|
||||
ElButton,
|
||||
ElConfigProvider,
|
||||
ElInput,
|
||||
ElLoading,
|
||||
ElMessageBox,
|
||||
ElPagination,
|
||||
ElSpace,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
} 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 KbGroupDrawer, { type KbGroupFormValue } from './KbGroupDrawer.vue';
|
||||
import DifyHealthDialog from './DifyHealthDialog.vue';
|
||||
import DifySettingsDialog from './DifySettingsDialog.vue';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import { WORKSPACE_PATHS } from '@/features/workspace/constants/routes';
|
||||
import {
|
||||
createKbGroup,
|
||||
@@ -35,35 +40,42 @@ import {
|
||||
import { formatDateTime } from '../utils/kb-display.utils';
|
||||
|
||||
type GroupFilterMode = 'all' | 'withDocs' | 'empty';
|
||||
type GroupSortMode = 'updatedDesc' | 'updatedAsc' | 'docsDesc' | 'docsAsc' | 'nameAsc';
|
||||
type GroupSortKey = 'name' | 'document_count' | 'updated_at';
|
||||
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
const { elementLocale } = useElementProvider();
|
||||
const vLoading = ElLoading.directive;
|
||||
|
||||
const groups = ref<KbGroup[]>([]);
|
||||
const isSubmitting = ref(false);
|
||||
const isDeleting = ref(false);
|
||||
const isRefreshing = ref(false);
|
||||
const isRefreshing = ref(true);
|
||||
const editingGroupId = ref<number | null>(null);
|
||||
const form = ref<KbGroupFormValue>({ name: '', description: '' });
|
||||
const feedback = ref('');
|
||||
const feedbackType = ref<'success' | 'error' | ''>('');
|
||||
const settingsDialogOpen = ref(false);
|
||||
const healthDialogOpen = ref(false);
|
||||
const deleteDialogOpen = ref(false);
|
||||
const drawerOpen = ref(false);
|
||||
const deletingGroup = ref<KbGroup | null>(null);
|
||||
const searchKeyword = ref('');
|
||||
const filterMode = ref<GroupFilterMode>('all');
|
||||
const sortMode = ref<GroupSortMode>('updatedDesc');
|
||||
const sortKey = ref<GroupSortKey | ''>('updated_at');
|
||||
const sortDir = ref<'asc' | 'desc' | ''>('desc');
|
||||
const currentPage = ref(1);
|
||||
const pageSize = ref(20);
|
||||
|
||||
const filterOptions: GroupFilterMode[] = ['all', 'withDocs', 'empty'];
|
||||
const sortOptions: GroupSortMode[] = ['updatedDesc', 'updatedAsc', 'docsDesc', 'docsAsc', 'nameAsc'];
|
||||
const pageSizeOptions = [10, 20, 50, 100];
|
||||
|
||||
const totalDocuments = computed(() => groups.value.reduce((total, group) => total + (group.document_count ?? 0), 0));
|
||||
/**
|
||||
* 文档数表头筛选项。
|
||||
* 核心逻辑:不放「全部」;Element 筛选面板的重置会清空条件,等同于全部。
|
||||
*/
|
||||
const documentFilters = computed(() => [
|
||||
{ text: t('kbAdmin.filters.withDocs'), value: 'withDocs' },
|
||||
{ text: t('kbAdmin.filters.empty'), value: 'empty' },
|
||||
]);
|
||||
|
||||
const filteredGroups = computed(() => {
|
||||
const keyword = searchKeyword.value.trim().toLowerCase();
|
||||
const matched = groups.value.filter((group) => {
|
||||
@@ -77,16 +89,17 @@ const filteredGroups = computed(() => {
|
||||
return matchesKeyword && matchesFilter;
|
||||
});
|
||||
|
||||
if (!sortKey.value || !sortDir.value) return matched;
|
||||
return [...matched].sort((a, b) => {
|
||||
const docsA = a.document_count ?? 0;
|
||||
const docsB = b.document_count ?? 0;
|
||||
const updatedA = Date.parse(a.updated_at || '') || 0;
|
||||
const updatedB = Date.parse(b.updated_at || '') || 0;
|
||||
if (sortMode.value === 'updatedAsc') return updatedA - updatedB;
|
||||
if (sortMode.value === 'docsDesc') return docsB - docsA;
|
||||
if (sortMode.value === 'docsAsc') return docsA - docsB;
|
||||
if (sortMode.value === 'nameAsc') return a.name.localeCompare(b.name, undefined, { numeric: true });
|
||||
return updatedB - updatedA;
|
||||
let result = 0;
|
||||
if (sortKey.value === 'name') {
|
||||
result = a.name.localeCompare(b.name, undefined, { numeric: true });
|
||||
} else if (sortKey.value === 'document_count') {
|
||||
result = (a.document_count ?? 0) - (b.document_count ?? 0);
|
||||
} else {
|
||||
result = (Date.parse(a.updated_at || '') || 0) - (Date.parse(b.updated_at || '') || 0);
|
||||
}
|
||||
return sortDir.value === 'asc' ? result : -result;
|
||||
});
|
||||
});
|
||||
const pagedGroups = computed(() => {
|
||||
@@ -94,19 +107,33 @@ const pagedGroups = computed(() => {
|
||||
return filteredGroups.value.slice(start, start + pageSize.value);
|
||||
});
|
||||
|
||||
/**
|
||||
* 表格空状态文案。
|
||||
* 核心逻辑:一个分组都没有时提示去创建;有分组但筛选后为空时提示调整条件。
|
||||
*/
|
||||
const tableEmptyText = computed(() => (
|
||||
groups.value.length === 0 ? t('kbAdmin.groupsEmpty') : t('kbAdmin.filters.emptyResult')
|
||||
));
|
||||
|
||||
/** 格式化分组更新时间,避免管理台表格直接暴露后端 ISO 时间字符串。 */
|
||||
const formatGroupUpdatedAt = (value?: string | null) => formatDateTime(value);
|
||||
|
||||
/** 加载知识库治理页的分组数据,供页面初始渲染和操作后刷新复用。 */
|
||||
/**
|
||||
* 加载知识库治理页的分组数据,供页面初始渲染和操作后刷新复用。
|
||||
* 核心逻辑:只等分组列表;失败写入页面提示,并用 finally 关掉表格加载态。
|
||||
*/
|
||||
const loadData = async () => {
|
||||
isRefreshing.value = true;
|
||||
const groupsResult = await getKbGroupsSafe();
|
||||
if (groupsResult.ok) groups.value = groupsResult.data;
|
||||
else {
|
||||
feedback.value = groupsResult.error || t('kbAdmin.msg.loadGroupsFailed');
|
||||
feedbackType.value = 'error';
|
||||
try {
|
||||
const groupsResult = await getKbGroupsSafe();
|
||||
if (groupsResult.ok) groups.value = groupsResult.data;
|
||||
else {
|
||||
feedback.value = groupsResult.error || t('kbAdmin.msg.loadGroupsFailed');
|
||||
feedbackType.value = 'error';
|
||||
}
|
||||
} finally {
|
||||
isRefreshing.value = false;
|
||||
}
|
||||
isRefreshing.value = false;
|
||||
};
|
||||
|
||||
/** 重置分组表单到新建状态,关闭抽屉或切换新建时清空当前编辑对象。 */
|
||||
@@ -162,17 +189,27 @@ const handleSubmitGroup = async () => {
|
||||
await loadData();
|
||||
};
|
||||
|
||||
/** 打开分组删除确认弹窗,确认前不直接调用删除接口。 */
|
||||
const handleDeleteGroup = (group: KbGroup) => {
|
||||
deletingGroup.value = group;
|
||||
deleteDialogOpen.value = true;
|
||||
};
|
||||
|
||||
/** 确认删除当前选中的分组,并在成功后同步刷新列表与编辑表单状态。 */
|
||||
const handleDeleteGroupConfirm = async () => {
|
||||
if (!deletingGroup.value) return;
|
||||
/**
|
||||
* 确认后删除分组,并刷新列表。
|
||||
* 核心逻辑:Element 确认框取消会 reject,这里直接返回,不调用删除接口。
|
||||
* @param group - 待删除的分组
|
||||
*/
|
||||
const handleDeleteGroup = async (group: KbGroup) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
t('kbAdmin.deleteDialog.message', { name: group.name }),
|
||||
t('kbAdmin.deleteDialog.title'),
|
||||
{
|
||||
type: 'warning',
|
||||
confirmButtonText: t('common.deleteDialog.confirm'),
|
||||
cancelButtonText: t('common.deleteDialog.cancel'),
|
||||
},
|
||||
);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
isDeleting.value = true;
|
||||
const result = await deleteKbGroup(deletingGroup.value.id);
|
||||
const result = await deleteKbGroup(group.id);
|
||||
isDeleting.value = false;
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || t('kbAdmin.msg.deleteFailed');
|
||||
@@ -180,15 +217,46 @@ const handleDeleteGroupConfirm = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (editingGroupId.value === deletingGroup.value.id) closeDrawer();
|
||||
if (editingGroupId.value === group.id) closeDrawer();
|
||||
feedback.value = t('kbAdmin.msg.deleted');
|
||||
feedbackType.value = 'success';
|
||||
deleteDialogOpen.value = false;
|
||||
deletingGroup.value = null;
|
||||
await loadData();
|
||||
};
|
||||
|
||||
watch([searchKeyword, filterMode, sortMode, pageSize], () => {
|
||||
/**
|
||||
* 按文档数表头筛选全部分组,并回到第一页。
|
||||
* 核心逻辑:筛选发生在分页之前。未选或重置时显示全部;单选时只留有文档或空分组。
|
||||
* @param filters - Element 按 column-key 给出的已选值
|
||||
*/
|
||||
function onFilterChange(filters: Record<string, string[]>): void {
|
||||
const selected = filters.document_count ?? [];
|
||||
if (selected.length === 1 && (selected[0] === 'withDocs' || selected[0] === 'empty')) {
|
||||
filterMode.value = selected[0];
|
||||
} else {
|
||||
filterMode.value = 'all';
|
||||
}
|
||||
currentPage.value = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按表头把筛选后的全部分组重排,并回到第一页。
|
||||
* 核心逻辑:排序发生在分页之前,所以翻页后顺序不变。第三次点击表头时 Element 清空排序,列表回到接口原顺序。
|
||||
* @param payload.prop - 列字段
|
||||
* @param payload.order - ascending、descending 或空
|
||||
*/
|
||||
function onSortChange(payload: { prop: string | null; order: string | null }): void {
|
||||
const field = payload.prop;
|
||||
if ((field === 'name' || field === 'document_count' || field === 'updated_at') && payload.order) {
|
||||
sortKey.value = field;
|
||||
sortDir.value = payload.order === 'ascending' ? 'asc' : 'desc';
|
||||
} else {
|
||||
sortKey.value = '';
|
||||
sortDir.value = '';
|
||||
}
|
||||
currentPage.value = 1;
|
||||
}
|
||||
|
||||
watch([searchKeyword, pageSize], () => {
|
||||
currentPage.value = 1;
|
||||
});
|
||||
|
||||
@@ -200,142 +268,98 @@ defineExpose({ loadData });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="animate-fade-in-up">
|
||||
<div class="kb-admin-header">
|
||||
<ElConfigProvider :locale="elementLocale">
|
||||
<section class="admin-table-section">
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div class="min-w-0 flex-1">
|
||||
<h2 class="text-xl font-bold text-primary">{{ t('kbAdmin.groupsTitle') }}</h2>
|
||||
<h2 class="section-title">{{ t('kbAdmin.groupsTitle') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('kbAdmin.groupManageSubtitle') }}</p>
|
||||
</div>
|
||||
<div class="flex w-full shrink-0 flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:justify-end">
|
||||
<div class="kb-admin-toolbar" role="toolbar" :aria-label="t('kbAdmin.toolbar')">
|
||||
<button type="button" class="kb-admin-toolbar-btn" @click="settingsDialogOpen = true" :title="t('kbAdmin.difySettings')">
|
||||
<Settings class="h-4 w-4 shrink-0" />
|
||||
<span class="whitespace-nowrap">{{ t('kbAdmin.difySettings') }}</span>
|
||||
</button>
|
||||
<button type="button" class="kb-admin-toolbar-btn" @click="healthDialogOpen = true" :title="t('kbAdmin.healthCheck')">
|
||||
<Activity class="h-4 w-4 shrink-0" />
|
||||
<span class="whitespace-nowrap">{{ t('kbAdmin.healthCheck') }}</span>
|
||||
</button>
|
||||
<button type="button" class="kb-admin-toolbar-btn" @click="loadData" :title="t('common.refresh')">
|
||||
<RefreshCw class="h-4 w-4 shrink-0" :class="{ 'animate-spin': isRefreshing }" />
|
||||
<span class="whitespace-nowrap">{{ t('common.refresh') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary inline-flex w-full items-center justify-center gap-2 px-4 py-2.5 text-sm sm:w-auto" @click="router.push(WORKSPACE_PATHS.knowledgeBase)">
|
||||
<Wrench class="h-4 w-4 shrink-0" />
|
||||
<span class="whitespace-nowrap">{{ t('kbAdmin.goWorkspace') }}</span>
|
||||
</button>
|
||||
<button type="button" class="btn-primary inline-flex w-full items-center justify-center gap-2 px-4 py-2.5 text-sm sm:w-auto" @click="openCreateDrawer">
|
||||
<Plus class="h-4 w-4 shrink-0" />
|
||||
<span class="whitespace-nowrap">{{ t('kbAdmin.form.create') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<ElSpace wrap>
|
||||
<ElButton :icon="Setting" @click="settingsDialogOpen = true">{{ t('kbAdmin.difySettings') }}</ElButton>
|
||||
<ElButton :icon="CircleCheck" @click="healthDialogOpen = true">{{ t('kbAdmin.healthCheck') }}</ElButton>
|
||||
<ElButton :icon="Tools" @click="router.push(WORKSPACE_PATHS.knowledgeBase)">{{ t('kbAdmin.goWorkspace') }}</ElButton>
|
||||
<ElButton type="primary" :icon="Plus" @click="openCreateDrawer">{{ t('kbAdmin.form.create') }}</ElButton>
|
||||
</ElSpace>
|
||||
</div>
|
||||
|
||||
<div class="kb-admin-body">
|
||||
<section class="admin-table-section">
|
||||
<div class="admin-table-filters flex flex-col gap-4">
|
||||
<div class="grid grid-cols-1 gap-3 lg:grid-cols-[minmax(16rem,1fr)_auto_minmax(11rem,14rem)] lg:items-center">
|
||||
<label class="relative min-w-0">
|
||||
<Search class="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted" />
|
||||
<input v-model="searchKeyword" class="input-field w-full pl-9" :placeholder="t('kbAdmin.filters.searchPlaceholder')" />
|
||||
</label>
|
||||
<div class="inline-flex w-full overflow-hidden rounded-xl border border-default bg-surface lg:w-auto">
|
||||
<button
|
||||
v-for="option in filterOptions"
|
||||
:key="option"
|
||||
type="button"
|
||||
class="min-w-0 flex-1 whitespace-nowrap px-4 py-2.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft hover:text-primary lg:flex-none"
|
||||
:class="{ 'bg-brand-50 text-brand-700': filterMode === option }"
|
||||
@click="filterMode = option"
|
||||
>
|
||||
{{ t(`kbAdmin.filters.${option}`) }}
|
||||
</button>
|
||||
</div>
|
||||
<select v-model="sortMode" class="select-field w-full">
|
||||
<option v-for="option in sortOptions" :key="option" :value="option">
|
||||
{{ t(`kbAdmin.sort.${option}`) }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 text-xs text-muted">
|
||||
<span>{{ t('kbAdmin.stats.groups', { count: groups.length }) }}</span>
|
||||
<span>{{ t('kbAdmin.stats.documents', { count: totalDocuments }) }}</span>
|
||||
<span>{{ t('kbAdmin.stats.visible', { count: filteredGroups.length }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="feedback" class="mx-6 mt-4 rounded-xl border px-4 py-3 text-sm" :class="feedbackType === 'error' ? 'border-rose-200 bg-rose-50 text-rose-600' : 'border-emerald-200 bg-emerald-50 text-emerald-700'">
|
||||
{{ feedback }}
|
||||
</p>
|
||||
|
||||
<div v-if="groups.length === 0" class="admin-table-empty">{{ t('kbAdmin.groupsEmpty') }}</div>
|
||||
<div v-else-if="filteredGroups.length === 0" class="admin-table-empty">{{ t('kbAdmin.filters.emptyResult') }}</div>
|
||||
<div v-else>
|
||||
<div class="admin-table-wrap hidden md:block">
|
||||
<table class="admin-table table-fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="w-[20%] px-6 py-3 text-xs">{{ t('kbAdmin.table.name') }}</th>
|
||||
<th class="w-[30%] px-6 py-3 text-xs">{{ t('kbAdmin.table.description') }}</th>
|
||||
<th class="w-[12%] px-6 py-3 text-xs">{{ t('kbAdmin.table.documents') }}</th>
|
||||
<th class="w-[26%] px-6 py-3 text-xs">{{ t('kbAdmin.table.updatedAt') }}</th>
|
||||
<th class="w-[12%] px-6 py-3 text-right text-xs">{{ t('kbAdmin.table.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="group in pagedGroups" :key="group.id">
|
||||
<td class="px-6 py-4 align-middle"><div class="truncate font-semibold text-primary" :title="group.name">{{ group.name }}</div></td>
|
||||
<td class="px-6 py-4 align-middle text-sm text-muted">
|
||||
<div class="truncate" :title="group.description || t('kbAdmin.noDescription')">
|
||||
{{ group.description || t('kbAdmin.noDescription') }}
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 align-middle"><span class="kb-admin-badge whitespace-nowrap">{{ group.document_count ?? 0 }}</span></td>
|
||||
<td class="px-6 py-4 align-middle text-sm text-muted"><div class="truncate" :title="formatGroupUpdatedAt(group.updated_at)">{{ formatGroupUpdatedAt(group.updated_at) }}</div></td>
|
||||
<td class="px-6 py-4 align-middle">
|
||||
<div class="flex justify-end gap-1.5">
|
||||
<button type="button" class="btn-icon-ds border border-default" @click="openEditDrawer(group)" :title="t('common.edit')"><Pencil class="h-4 w-4" /></button>
|
||||
<button type="button" class="btn-icon-ds border border-rose-200 text-rose-600 hover:bg-rose-50" @click="handleDeleteGroup(group)" :disabled="isDeleting" :title="t('common.delete')"><Trash2 class="h-4 w-4" /></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3 p-4 md:hidden">
|
||||
<article v-for="group in pagedGroups" :key="group.id" class="kb-admin-card">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<h3 class="font-semibold text-primary">{{ group.name }}</h3>
|
||||
<p class="mt-1 line-clamp-2 text-sm text-muted" :title="group.description || t('kbAdmin.noDescription')">{{ group.description || t('kbAdmin.noDescription') }}</p>
|
||||
</div>
|
||||
<span class="kb-admin-badge">{{ group.document_count ?? 0 }}</span>
|
||||
</div>
|
||||
<div class="mt-3 flex items-center justify-between gap-3">
|
||||
<span class="text-xs text-muted">{{ formatGroupUpdatedAt(group.updated_at) }}</span>
|
||||
<div class="flex gap-1.5">
|
||||
<button type="button" class="btn-icon-ds border border-default" @click="openEditDrawer(group)" :title="t('common.edit')"><Pencil class="h-4 w-4" /></button>
|
||||
<button type="button" class="btn-icon-ds border border-rose-200 text-rose-600" @click="handleDeleteGroup(group)" :title="t('common.delete')"><Trash2 class="h-4 w-4" /></button>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<div class="border-t border-default px-6 py-4">
|
||||
<PaginationBar
|
||||
v-model:page="currentPage"
|
||||
v-model:page-size="pageSize"
|
||||
:total="filteredGroups.length"
|
||||
:page-size-options="pageSizeOptions"
|
||||
<div class="kb-admin-filters">
|
||||
<div class="kb-element-filters">
|
||||
<ElInput
|
||||
v-model="searchKeyword"
|
||||
clearable
|
||||
:prefix-icon="Search"
|
||||
:placeholder="t('kbAdmin.filters.searchPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<ElAlert
|
||||
v-if="feedback"
|
||||
class="kb-admin-alert"
|
||||
:title="feedback"
|
||||
:type="feedbackType === 'error' ? 'error' : 'success'"
|
||||
show-icon
|
||||
closable
|
||||
@close="feedback = ''"
|
||||
/>
|
||||
|
||||
<ElTable
|
||||
v-loading="isRefreshing"
|
||||
class="hx-admin-table"
|
||||
:data="pagedGroups"
|
||||
row-key="id"
|
||||
:default-sort="{ prop: 'updated_at', order: 'descending' }"
|
||||
:empty-text="tableEmptyText"
|
||||
@sort-change="onSortChange"
|
||||
@filter-change="onFilterChange"
|
||||
>
|
||||
<ElTableColumn prop="name" :label="t('kbAdmin.table.name')" min-width="160" sortable="custom">
|
||||
<template #default="{ row }">
|
||||
<div class="truncate" :title="(row as KbGroup).name">{{ (row as KbGroup).name }}</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('kbAdmin.table.description')" min-width="220">
|
||||
<template #default="{ row }">
|
||||
<div class="truncate hx-element-hint" :title="(row as KbGroup).description || t('kbAdmin.noDescription')">
|
||||
{{ (row as KbGroup).description || t('kbAdmin.noDescription') }}
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn
|
||||
prop="document_count"
|
||||
column-key="document_count"
|
||||
:label="t('kbAdmin.table.documents')"
|
||||
width="160"
|
||||
sortable="custom"
|
||||
:filters="documentFilters"
|
||||
:filter-multiple="false"
|
||||
>
|
||||
<template #default="{ row }">{{ (row as KbGroup).document_count ?? 0 }}</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn prop="updated_at" :label="t('kbAdmin.table.updatedAt')" min-width="180" sortable="custom">
|
||||
<template #default="{ row }">{{ formatGroupUpdatedAt((row as KbGroup).updated_at) }}</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn :label="t('kbAdmin.table.actions')" width="160" align="right">
|
||||
<template #default="{ row }">
|
||||
<ElButton link type="primary" @click="openEditDrawer(row as KbGroup)">{{ t('common.edit') }}</ElButton>
|
||||
<ElButton link type="danger" :disabled="isDeleting" @click="handleDeleteGroup(row as KbGroup)">
|
||||
{{ t('common.delete') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
|
||||
<div v-if="filteredGroups.length > 0" class="hx-admin-pager">
|
||||
<ElPagination
|
||||
v-model:current-page="currentPage"
|
||||
v-model:page-size="pageSize"
|
||||
:total="filteredGroups.length"
|
||||
:page-sizes="pageSizeOptions"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
background
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<KbGroupDrawer
|
||||
v-model:form="form"
|
||||
@@ -348,5 +372,32 @@ defineExpose({ loadData });
|
||||
|
||||
<DifySettingsDialog :open="settingsDialogOpen" @close="settingsDialogOpen = false" @saved="(message) => { feedback = message; feedbackType = 'success'; void loadData(); }" @error="(message) => { feedback = message; feedbackType = 'error'; }" />
|
||||
<DifyHealthDialog :open="healthDialogOpen" @close="healthDialogOpen = false" @error="(message) => { feedback = message; feedbackType = 'error'; }" />
|
||||
<DeleteConfirmDialog v-model="deleteDialogOpen" :title="t('kbAdmin.deleteDialog.title')" :message="t('kbAdmin.deleteDialog.message', { name: deletingGroup?.name || '' })" :confirm-loading="isDeleting" @confirm="handleDeleteGroupConfirm" @cancel="() => { deleteDialogOpen = false; deletingGroup = null; }" />
|
||||
</ElConfigProvider>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.kb-admin-filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12px 24px;
|
||||
padding: 16px 32px;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
.kb-admin-alert {
|
||||
margin: 16px 32px 0;
|
||||
}
|
||||
|
||||
.kb-element-filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.kb-element-filters :deep(.el-input) {
|
||||
width: 16rem;
|
||||
flex: none;
|
||||
}
|
||||
</style>
|
||||
@@ -1,14 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/kb/components/KbGroupDrawer.vue
|
||||
* 知识库分组新建/编辑抽屉表单。
|
||||
* 依赖:Vue I18n、lucide-vue-next、父级 KbAdminPanel 传入的表单状态。
|
||||
* 逻辑:只负责抽屉展示、表单双向同步和提交/关闭事件;接口调用与列表刷新由父组件处理。
|
||||
* 知识库分组新建/编辑弹窗。
|
||||
* 依赖:Element Plus 对话框与表单、Vue I18n、父级 KbAdminPanel 传入的表单状态。
|
||||
* 逻辑:只负责弹窗展示、表单双向同步和提交/关闭事件;接口调用与列表刷新由父组件处理。
|
||||
* 字段只有名称和描述,用随内容增高的对话框,避免整屏抽屉留下大块空白。
|
||||
*/
|
||||
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { FolderPlus, X } from 'lucide-vue-next';
|
||||
import { FolderAdd } from '@element-plus/icons-vue';
|
||||
import { ElButton, ElDialog, ElForm, ElFormItem, ElInput } from 'element-plus';
|
||||
|
||||
export interface KbGroupFormValue {
|
||||
name: string;
|
||||
@@ -37,7 +39,11 @@ const submitText = computed(() => {
|
||||
return props.mode === 'edit' ? t('kbAdmin.form.saveChanges') : t('kbAdmin.form.create');
|
||||
});
|
||||
|
||||
/** 更新指定表单字段,并将完整表单值同步回父组件。 */
|
||||
/**
|
||||
* 更新指定表单字段,并将完整表单值同步回父组件。
|
||||
* @param field - 要改的字段,只能是名称或描述
|
||||
* @param value - 输入框当前文本
|
||||
*/
|
||||
const updateField = (field: keyof KbGroupFormValue, value: string) => {
|
||||
emit('update:form', {
|
||||
...props.form,
|
||||
@@ -47,81 +53,53 @@ const updateField = (field: keyof KbGroupFormValue, value: string) => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<Transition name="kb-admin-drawer">
|
||||
<div v-if="open" class="fixed inset-0 z-[100] bg-overlay backdrop-blur-sm" @click.self="emit('close')">
|
||||
<aside class="ml-auto flex h-full w-full max-w-[440px] flex-col border-l border-default bg-surface shadow-elevated">
|
||||
<header class="flex items-start justify-between gap-4 border-b border-default px-6 py-5">
|
||||
<div class="min-w-0">
|
||||
<h3 class="text-lg font-semibold text-primary">{{ formTitle }}</h3>
|
||||
<p class="section-desc mt-1">{{ formDescription }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds shrink-0" @click="emit('close')" :title="t('common.close')">
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div class="flex-1 space-y-5 overflow-y-auto px-6 py-5">
|
||||
<div>
|
||||
<label class="label-field mb-2 block">{{ t('kbAdmin.form.groupName') }}</label>
|
||||
<input
|
||||
:value="form.name"
|
||||
class="input-field"
|
||||
:placeholder="t('kbAdmin.form.groupNamePlaceholder')"
|
||||
@input="updateField('name', ($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label-field mb-2 block">{{ t('kbAdmin.form.groupDesc') }}</label>
|
||||
<textarea
|
||||
:value="form.description"
|
||||
rows="8"
|
||||
class="input-field"
|
||||
:placeholder="t('kbAdmin.form.groupDescPlaceholder')"
|
||||
@input="updateField('description', ($event.target as HTMLTextAreaElement).value)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="flex justify-end gap-2 border-t border-default px-6 py-4">
|
||||
<button type="button" class="btn-secondary inline-flex items-center gap-1.5 px-4 py-2 text-sm" @click="emit('close')">
|
||||
<X class="h-4 w-4 shrink-0" />
|
||||
{{ t('common.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary inline-flex items-center gap-1.5 px-5 py-2 text-sm disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="submitting"
|
||||
@click="emit('submit')"
|
||||
>
|
||||
<FolderPlus v-if="!submitting" class="h-4 w-4 shrink-0" />
|
||||
{{ submitText }}
|
||||
</button>
|
||||
</footer>
|
||||
</aside>
|
||||
<ElDialog
|
||||
:model-value="open"
|
||||
width="480px"
|
||||
align-center
|
||||
append-to-body
|
||||
:close-on-click-modal="!submitting"
|
||||
:close-on-press-escape="!submitting"
|
||||
:show-close="!submitting"
|
||||
@close="emit('close')"
|
||||
>
|
||||
<template #header>
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-primary">{{ formTitle }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">{{ formDescription }}</p>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<ElForm class="kb-group-form" label-position="top" @submit.prevent="emit('submit')">
|
||||
<ElFormItem :label="t('kbAdmin.form.groupName')">
|
||||
<ElInput
|
||||
:model-value="form.name"
|
||||
:placeholder="t('kbAdmin.form.groupNamePlaceholder')"
|
||||
@update:model-value="updateField('name', String($event))"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('kbAdmin.form.groupDesc')">
|
||||
<ElInput
|
||||
:model-value="form.description"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
:placeholder="t('kbAdmin.form.groupDescPlaceholder')"
|
||||
@update:model-value="updateField('description', String($event))"
|
||||
/>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
|
||||
<template #footer>
|
||||
<ElButton :disabled="submitting" @click="emit('close')">{{ t('common.cancel') }}</ElButton>
|
||||
<ElButton type="primary" :icon="FolderAdd" :loading="submitting" @click="emit('submit')">
|
||||
{{ submitText }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.kb-admin-drawer-enter-active,
|
||||
.kb-admin-drawer-leave-active {
|
||||
transition: opacity 0.18s ease;
|
||||
}
|
||||
|
||||
.kb-admin-drawer-enter-active aside,
|
||||
.kb-admin-drawer-leave-active aside {
|
||||
transition: transform 0.18s ease;
|
||||
}
|
||||
|
||||
.kb-admin-drawer-enter-from,
|
||||
.kb-admin-drawer-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.kb-admin-drawer-enter-from aside,
|
||||
.kb-admin-drawer-leave-to aside {
|
||||
transform: translateX(100%);
|
||||
.kb-group-form :deep(.el-form-item:last-child) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -3,9 +3,11 @@
|
||||
* 依赖:统一 requestJson(失败抛 BusinessError);后端 /api/order-delivery-reply。
|
||||
* 逻辑:列表筛选分页、保存批次(单行/联合)、单行与批量通知、手动同步与最近同步状态。
|
||||
* 带 JSON 正文的写请求在本文件声明 Content-Type: application/json,供 Flask get_json 解析。
|
||||
* 按当前筛选导出 Excel(后端生成 xlsx,blob 触发下载)。
|
||||
*/
|
||||
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
|
||||
/**
|
||||
* 组装带 JSON 正文的写请求。
|
||||
@@ -157,3 +159,41 @@ export const runOrderDeliverySync = () =>
|
||||
/** 最近一次同步运行记录;从未同步过返回 null。 */
|
||||
export const getLatestOrderDeliverySync = () =>
|
||||
requestJson<OrderDeliverySyncRun | null>('/api/order-delivery-reply/sync/latest');
|
||||
|
||||
/** 导出 Excel 查询参数(与列表筛选一致;导出全部命中行,不分页)。 */
|
||||
export interface OrderDeliveryExportParams {
|
||||
keyword?: string;
|
||||
order_date?: string;
|
||||
status?: '' | 'replied' | 'not_fully_replied';
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出当前筛选下的全部订单行 Excel。
|
||||
* 触发时机:工具栏「导出 Excel」按钮。后端生成 xlsx 文件流,此处 blob 触发浏览器下载,
|
||||
* 文件名「订单交期回复_YYYY-MM-DD.xlsx」(日期取本地当天);失败抛 Error(HTTP 状态码)。
|
||||
*/
|
||||
export async function exportOrderDeliveryLines(params: OrderDeliveryExportParams): Promise<void> {
|
||||
const query = new URLSearchParams();
|
||||
if (params.keyword) query.set('keyword', params.keyword);
|
||||
if (params.order_date) query.set('order_date', params.order_date);
|
||||
if (params.status) query.set('status', params.status);
|
||||
const response = await fetch(`/api/order-delivery-reply/lines/export?${query.toString()}`, {
|
||||
method: 'GET',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Export failed: HTTP ${response.status}`);
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
// 文件名日期取浏览器本地时区(toISOString 为 UTC,北京时间 0-8 点导出会差一天)
|
||||
const now = new Date();
|
||||
const localDate = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
|
||||
link.download = `订单交期回复_${localDate}.xlsx`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* features/order-delivery-reply/views/OrderDeliveryReplyPage.chipEdit.spec.ts
|
||||
* 用途:锁定「批次条就地编辑」核心契约(回归用)。
|
||||
* 依赖:vitest、@vue/test-utils、vue-i18n、vue-router memory history。
|
||||
* 逻辑:完整挂载工作台页(mock API/权限/消息):
|
||||
* 1) 未回复行点击空批次条进入编辑态,填写日期+数量失焦 → 调用单行保存接口(整行批次);
|
||||
* 2) 只填数量不填日期失焦 → 不保存且行内红字提示(batchMissingDate);
|
||||
* 3) 多批次行改其中一条数量致合计≠订单数量 → 不保存且红字提示(qtyTotalMismatchLine)。
|
||||
*/
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
||||
import { flushPromises, mount } from '@vue/test-utils';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import { createRouter, createMemoryHistory } from 'vue-router';
|
||||
import OrderDeliveryReplyPage from './OrderDeliveryReplyPage.vue';
|
||||
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
listMock: vi.fn(),
|
||||
saveMock: vi.fn(),
|
||||
batchMock: vi.fn(),
|
||||
notifyMock: vi.fn(),
|
||||
syncMock: vi.fn(),
|
||||
latestSyncMock: vi.fn(),
|
||||
requestJsonMock: vi.fn(),
|
||||
messageMocks: { info: vi.fn(), success: vi.fn(), warning: vi.fn(), error: vi.fn() },
|
||||
}));
|
||||
|
||||
vi.mock('@/features/order-delivery-reply/api/orderDeliveryReply.api', () => ({
|
||||
listOrderDeliveryLines: hoisted.listMock,
|
||||
saveOrderDeliveryBatches: hoisted.saveMock,
|
||||
batchReplyOrderDelivery: hoisted.batchMock,
|
||||
notifyOrderDeliveryBatch: hoisted.notifyMock,
|
||||
runOrderDeliverySync: hoisted.syncMock,
|
||||
getLatestOrderDeliverySync: hoisted.latestSyncMock,
|
||||
}));
|
||||
|
||||
vi.mock('@/shared/api/client', () => ({
|
||||
requestJson: hoisted.requestJsonMock,
|
||||
}));
|
||||
|
||||
vi.mock('@/shared/composables/useMessage', () => ({
|
||||
useMessage: () => hoisted.messageMocks,
|
||||
}));
|
||||
|
||||
vi.mock('@/features/auth/stores/auth.store', () => ({
|
||||
useAuthStore: () => ({ hasFeaturePermission: () => true }),
|
||||
}));
|
||||
|
||||
/** 两行样例:A 未回复(空批次,订单数量 1);B 部分回复(3 批次 30/50/20,订单数量 100)。 */
|
||||
const sampleLines = [
|
||||
{
|
||||
id: 1,
|
||||
order_no: '8301-T1',
|
||||
line_no: 4,
|
||||
qty: '1',
|
||||
unit: 'SET',
|
||||
status: 'not_replied' as const,
|
||||
locked: false,
|
||||
batches: [] as { seq?: number; planned_date: string; qty: string; remark?: string | null }[],
|
||||
undelivered_qty: '1',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
order_no: '8301-T2',
|
||||
line_no: 1,
|
||||
qty: '100',
|
||||
unit: 'PCS',
|
||||
status: 'partial_replied' as const,
|
||||
locked: false,
|
||||
batches: [
|
||||
{ seq: 1, planned_date: '2026-09-04', qty: '30', remark: null },
|
||||
{ seq: 2, planned_date: '2026-09-11', qty: '50', remark: null },
|
||||
{ seq: 3, planned_date: '2026-09-23', qty: '20', remark: null },
|
||||
],
|
||||
undelivered_qty: '0',
|
||||
},
|
||||
];
|
||||
|
||||
const mountPage = async () => {
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [{ path: '/:pathMatch(.*)*', component: { template: '<div />' } }],
|
||||
});
|
||||
router.push('/chat/39');
|
||||
await router.isReady();
|
||||
const i18n = createI18n({ legacy: false, locale: 'zh-CN', messages: { 'zh-CN': {} } });
|
||||
const wrapper = mount(OrderDeliveryReplyPage, {
|
||||
global: {
|
||||
plugins: [router, i18n],
|
||||
stubs: { PaginationBar: true, DeleteConfirmDialog: true },
|
||||
},
|
||||
});
|
||||
await flushPromises();
|
||||
return wrapper;
|
||||
};
|
||||
|
||||
describe('OrderDeliveryReplyPage 批次条就地编辑', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
hoisted.listMock.mockResolvedValue({ items: sampleLines, page: 1, page_size: 50, total: 2 });
|
||||
hoisted.latestSyncMock.mockResolvedValue(null);
|
||||
hoisted.saveMock.mockResolvedValue({ order_no: '8301-T1', line_no: 4, batches: [], total_qty: '1' });
|
||||
hoisted.requestJsonMock.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
it('未回复行:点击空批次条进入编辑,填写日期+数量失焦后调用单行保存', async () => {
|
||||
const wrapper = await mountPage();
|
||||
|
||||
// 未回复行(8301-T1:4)的可编辑空批次条:title 为 replyAction 键(i18n 缺失时回退键名)
|
||||
const emptyChip = wrapper.find('div[title="workspace.orderDeliveryReply.replyAction"]');
|
||||
expect(emptyChip.exists()).toBe(true);
|
||||
await emptyChip.trigger('click');
|
||||
await flushPromises();
|
||||
|
||||
// 编辑态输入条出现(data-chip-edit),自动聚焦日期框
|
||||
const editor = wrapper.find('[data-chip-edit]');
|
||||
expect(editor.exists()).toBe(true);
|
||||
const dateInput = editor.find('[data-chip-date]');
|
||||
expect((dateInput.element as HTMLInputElement).value).toBe('');
|
||||
|
||||
// 填写日期 + 数量后失焦提交
|
||||
await dateInput.setValue('2026-10-20');
|
||||
await editor.find('input[type="number"]').setValue('1');
|
||||
await editor.trigger('focusout');
|
||||
await flushPromises();
|
||||
|
||||
expect(hoisted.saveMock).toHaveBeenCalledTimes(1);
|
||||
expect(hoisted.saveMock).toHaveBeenCalledWith('8301-T1', 4, [
|
||||
{ planned_date: '2026-10-20', qty: '1', remark: null },
|
||||
]);
|
||||
});
|
||||
|
||||
it('未回复行:只填数量不填日期失焦 → 不保存且红字提示缺交期', async () => {
|
||||
const wrapper = await mountPage();
|
||||
const emptyChip = wrapper.find('div[title="workspace.orderDeliveryReply.replyAction"]');
|
||||
await emptyChip.trigger('click');
|
||||
await flushPromises();
|
||||
|
||||
const editor = wrapper.find('[data-chip-edit]');
|
||||
await editor.find('input[type="number"]').setValue('1');
|
||||
await editor.trigger('focusout');
|
||||
await flushPromises();
|
||||
|
||||
expect(hoisted.saveMock).not.toHaveBeenCalled();
|
||||
const hint = wrapper.find('p.text-status-error');
|
||||
expect(hint.exists()).toBe(true);
|
||||
expect(hint.text()).toContain('batchMissingDate');
|
||||
});
|
||||
|
||||
it('多批次行:改第 2 条数量致合计≠订单数量失焦 → 不保存且红字提示', async () => {
|
||||
const wrapper = await mountPage();
|
||||
|
||||
// B 行(8301-T2:1)首条批次条:title 为 editReplyAction 键
|
||||
const chips = wrapper.findAll('div[title="workspace.orderDeliveryReply.editReplyAction"]');
|
||||
expect(chips.length).toBeGreaterThanOrEqual(1);
|
||||
await chips[0].trigger('click');
|
||||
await flushPromises();
|
||||
|
||||
const editor = wrapper.find('[data-chip-edit]');
|
||||
// 预填首条批次当前值
|
||||
expect((editor.find('[data-chip-date]').element as HTMLInputElement).value).toBe('2026-09-04');
|
||||
// 只改数量为 60 → 30→60 后合计 130 ≠ 100
|
||||
await editor.find('input[type="number"]').setValue('60');
|
||||
await editor.trigger('focusout');
|
||||
await flushPromises();
|
||||
|
||||
expect(hoisted.saveMock).not.toHaveBeenCalled();
|
||||
const hint = wrapper.find('p.text-status-error');
|
||||
expect(hint.exists()).toBe(true);
|
||||
expect(hint.text()).toContain('qtyTotalMismatchLine');
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* features/order-delivery-reply/views/OrderDeliveryReplyPage.vue
|
||||
* 用途:订单交期回复工作台操作页——筛选分页、单行/联合回复批次、单行/批量通知、手动同步。
|
||||
* 依赖:api/orderDeliveryReply.api(统一 requestJson)、useMessage、auth store(manage/access 权限)。
|
||||
* 依赖:api/orderDeliveryReply.api(统一 requestJson)、useMessage、auth store(manage/access 权限)、
|
||||
* shared DeleteConfirmDialog(批量通知二次确认)、PaginationBar。
|
||||
* 逻辑:所有数据只读本地快照;保存与通知是两步(联合回复只保存,批量通知才发送并锁定);
|
||||
* 保存/通知成功后即时刷新列表(需求 §9);仅 access 用户隐藏全部写操作。
|
||||
* 回复弹窗数量守恒(2026-09-23 由「超额仅提醒」修订):每行各批次合计必须等于订单数量
|
||||
@@ -10,10 +11,30 @@
|
||||
* wecom_trace 上报打开回执——保证「点卡片 → 登录 → 直达该 Agent 对应内容与位置」。
|
||||
* 列顺序:客户编号(简称副文案) → 订单日期 → 订单单号:项次 → 产品编号(品名副文案) →
|
||||
* 客户产品编号 → 数量 → 约定交货日 → 交期回复状态 → 交期回复 → 交期回复人员 →
|
||||
* 业务员(部门副文案) → 客户订单 → 规格 → 单位;独立的部门列/品名列已并入合并展示。
|
||||
* 业务员(部门副文案) → 客户订单 → 规格 → 单位 → 通知时间(2026-10-09 自交期回复人员列拆出);
|
||||
* 独立的部门列/品名列已并入合并展示。
|
||||
* 浏览体验:页面高度收敛至视口(滚动全部发生在表格容器内 → 列头 sticky 固定、横向滚动条
|
||||
* 常驻表格底缘);左侧冻结前四列标识区(勾选/客户编号/订单日期/订单单号:项次,
|
||||
* 冻结单元格用实色背景防透出);筛选区与工具栏字号与表格统一(text-sm 14px)并压缩高度。
|
||||
* 冻结单元格用 utilities.css 的 frozen-cell 实色基底防透出,并随行悬停/选中/直达高亮联动);
|
||||
* 筛选区无外置字段标签(提示字占位已取消,含义由 placeholder/选项承担,aria-label 保留无障碍语义),
|
||||
* 输入框/按钮显式 text-sm + h-9(36px),与合同付款预警 .contract-filter-input/.contract-filter-submit
|
||||
* (14px/600/36px/圆角8px)渲染规格逐项一致。
|
||||
* 交期回复列批次交互(2026-10-09):动作入口统一为批次条前的加号(lucide Plus,title/aria 复用
|
||||
* replyAction/editReplyAction 键)——未回复=空批次条(不显示时间/数量)+ 加号回复;
|
||||
* 已回复/部分回复=加号修改回复(仅未锁定可管理);「交期已锁定」徽标已取消(锁定状态由
|
||||
* 无加号与交期回复人员列「已通知」体现)。全表批次条左缘对齐:所有行首条批次前保留
|
||||
* w-6 加号占位,展开行其余批次条加 pl-7 缩进;>1 批时首条批次后保留展开/收起小箭头
|
||||
* (▼ 全部 / ▲ 收起只留第一批)。
|
||||
* 批次条就地编辑(2026-10-09):未锁定可管理行点击批次条原地变「日期+数量」输入(预填当前值;
|
||||
* 未回复行空批次条点击=新增第一条批次),输入条渲染后自动聚焦日期框;回车/失焦自动保存单行
|
||||
* 接口(整行批次提交,与弹窗保存同口径校验);校验失败红字持续显示并重聚焦日期框,直至修正
|
||||
* 保存或 Esc 取消;双清空=放弃编辑;批次条不显示备注内容;多批次/备注仍走加号弹窗。
|
||||
* 表格对齐(2026-10-09):除交期回复列(批次条按既定左对齐布局)外,全列内容水平居中、
|
||||
* 行内容垂直居中,列头文字全部居中;交期回复状态徽标统一等宽(min-w-68px)。
|
||||
* 设计系统(docs/ui/DESIGN_SYSTEM.md):根节点挂 page-shell;区块容器用 surface-panel;
|
||||
* 弹窗用 dialog-overlay/panel/header/body/footer;输入用 input-field/select-field;
|
||||
* 状态与交互色一律走 --status-* 令牌(badge-*/bg-row-*/frozen-cell-*),品牌强调用 brand-*。
|
||||
* 批量通知确认使用共享 DeleteConfirmDialog(confirmTone=primary),不再用原生 window.confirm。
|
||||
*/
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -24,11 +45,14 @@ import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import { ChevronDown, ChevronUp, Download, Plus } from 'lucide-vue-next';
|
||||
import {
|
||||
ORDER_DELIVERY_REPLY_MANAGE_PERMISSION,
|
||||
} from '@/features/order-delivery-reply/constants';
|
||||
import {
|
||||
batchReplyOrderDelivery,
|
||||
exportOrderDeliveryLines,
|
||||
getLatestOrderDeliverySync,
|
||||
listOrderDeliveryLines,
|
||||
notifyOrderDeliveryBatch,
|
||||
@@ -158,15 +182,13 @@ function toggleExpand(key: string) {
|
||||
}
|
||||
|
||||
/* ============ 派生展示 ============ */
|
||||
const repliedQty = (line: OrderDeliveryLine) =>
|
||||
line.batches.reduce((sum, batch) => sum + Number(batch.qty || 0), 0);
|
||||
const undelivered = (line: OrderDeliveryLine) => Number(line.undelivered_qty || 0);
|
||||
type LineStatus = OrderDeliveryLine['status'];
|
||||
/** 状态徽章:颜色走 badge-success/warning/error(--status-* 令牌,亮暗自适应)。 */
|
||||
const statusMeta = (status: LineStatus) => {
|
||||
const map: Record<LineStatus, { label: string; cls: string }> = {
|
||||
not_replied: { label: t('workspace.orderDeliveryReply.statusNotReplied'), cls: 'bg-rose-50 text-rose-600' },
|
||||
partial_replied: { label: t('workspace.orderDeliveryReply.statusPartial'), cls: 'bg-orange-50 text-orange-600' },
|
||||
replied: { label: t('workspace.orderDeliveryReply.statusReplied'), cls: 'bg-emerald-50 text-emerald-600' },
|
||||
not_replied: { label: t('workspace.orderDeliveryReply.statusNotReplied'), cls: 'badge-error' },
|
||||
partial_replied: { label: t('workspace.orderDeliveryReply.statusPartial'), cls: 'badge-warning' },
|
||||
replied: { label: t('workspace.orderDeliveryReply.statusReplied'), cls: 'badge-success' },
|
||||
};
|
||||
return map[status];
|
||||
};
|
||||
@@ -184,6 +206,7 @@ const quickDate = ref('');
|
||||
const saving = ref(false);
|
||||
|
||||
function openReplyModal(lines: OrderDeliveryLine[], title: string, mode: 'single' | 'batch') {
|
||||
cancelChipEdit(); // 打开弹窗前退出批次条就地编辑,避免弹窗与行内编辑态叠加
|
||||
modalLines.value = lines.map((line) => ({
|
||||
line,
|
||||
batches: line.batches.map((batch) => ({
|
||||
@@ -203,10 +226,12 @@ function openReplyModal(lines: OrderDeliveryLine[], title: string, mode: 'single
|
||||
}
|
||||
|
||||
function openSingleReply(line: OrderDeliveryLine) {
|
||||
if (chipSaving.value) return; // 保存进行中禁止开弹窗:弹窗按旧批次数据提交会覆盖刚保存的编辑
|
||||
openReplyModal([line], t('workspace.orderDeliveryReply.modalTitleSingle', { order: line.order_no, item: line.line_no }), 'single');
|
||||
}
|
||||
|
||||
function openBatchReply() {
|
||||
if (chipSaving.value) return;
|
||||
const lines = selectedLines.value.filter((line) => !line.locked);
|
||||
if (!lines.length) return;
|
||||
openReplyModal(lines, t('workspace.orderDeliveryReply.modalTitleBatch', { count: lines.length }), 'batch');
|
||||
@@ -316,15 +341,153 @@ async function saveReplies() {
|
||||
}
|
||||
}
|
||||
|
||||
/* ============ 批次条就地编辑(2026-10-09) ============ */
|
||||
// 未锁定且可管理的行:点击批次条原地变「日期+数量」输入,回车/失焦自动保存单行接口;
|
||||
// 校验与弹窗同口径(lineIssueText:缺交期/缺数量、同单交期重复、合计≠订单数量),红字阻断保存;
|
||||
// 双清空=放弃编辑(行内不提供删除,结构调整/备注/多批次走加号弹窗)。
|
||||
const editingChip = ref<{ key: string; idx: number } | null>(null);
|
||||
const chipDraft = reactive({ planned_date: '', qty: '' });
|
||||
const chipIssue = ref('');
|
||||
// 单行保存进行中标志:整行提交语义下,禁止并发(再点其他批次条/开弹窗),
|
||||
// 否则两个 in-flight 保存或「弹窗基于旧批次数据」会互相覆盖丢编辑
|
||||
const chipSaving = ref(false);
|
||||
|
||||
const isChipEditable = (line: OrderDeliveryLine) => canManage.value && !line.locked;
|
||||
const isChipEditing = (line: OrderDeliveryLine, idx: number) =>
|
||||
editingChip.value?.key === lineKey(line) && editingChip.value?.idx === idx;
|
||||
|
||||
function startChipEdit(line: OrderDeliveryLine, idx: number) {
|
||||
if (!isChipEditable(line) || chipSaving.value) return;
|
||||
// 未回复行批次列表为空:idx=0 表示「新增第一条批次」,同样可进入编辑
|
||||
if (line.batches.length > 0 && idx >= line.batches.length) return;
|
||||
const batch = line.batches[idx];
|
||||
editingChip.value = { key: lineKey(line), idx };
|
||||
chipDraft.planned_date = batch?.planned_date ?? '';
|
||||
chipDraft.qty = batch ? String(Number(batch.qty)) : '';
|
||||
chipIssue.value = '';
|
||||
// 输入条渲染后自动聚焦日期框,点击即可填
|
||||
void nextTick(() => {
|
||||
document.querySelector<HTMLInputElement>('[data-chip-edit] [data-chip-date]')?.focus();
|
||||
});
|
||||
}
|
||||
|
||||
function cancelChipEdit() {
|
||||
editingChip.value = null;
|
||||
chipIssue.value = '';
|
||||
}
|
||||
|
||||
/** 失焦提交:relatedTarget 仍在输入条内(日期↔数量切换)时不提交。 */
|
||||
function onChipFocusout(event: FocusEvent, line: OrderDeliveryLine, idx: number) {
|
||||
const next = event.relatedTarget as Node | null;
|
||||
if (next && (event.currentTarget as HTMLElement).contains(next)) return;
|
||||
chipCommit(line, idx);
|
||||
}
|
||||
|
||||
function chipCommit(line: OrderDeliveryLine, idx: number) {
|
||||
if (!isChipEditing(line, idx) || chipSaving.value) return;
|
||||
// 注意:v-model 在 type="number" 输入框上会自动把值转成 number,
|
||||
// 这里必须统一 String() 容错,否则 qty.trim() 抛 TypeError 中断整个失焦提交
|
||||
const date = String(chipDraft.planned_date ?? '').trim();
|
||||
const qty = String(chipDraft.qty ?? '').trim();
|
||||
// 双清空=放弃编辑;只填其一致「缺交期/缺数量」红字,保持编辑态
|
||||
if (!date && !(qty !== '' && Number(qty) > 0)) {
|
||||
cancelChipEdit();
|
||||
return;
|
||||
}
|
||||
// 整行批次合并提交,与弹窗保存完全同口径:
|
||||
// 编辑已有批次=仅替换该条;未回复行空批次条=新增第一条(line.batches 为空数组)
|
||||
const source = line.batches[idx];
|
||||
const edited: EditableBatch = { planned_date: date, qty, remark: source?.remark || '' };
|
||||
const merged: EditableBatch[] =
|
||||
idx < line.batches.length
|
||||
? line.batches.map((b, i) =>
|
||||
i === idx ? edited : { planned_date: b.planned_date, qty: String(Number(b.qty)), remark: b.remark || '' },
|
||||
)
|
||||
: [edited];
|
||||
const issue = lineIssueText({ line, batches: merged });
|
||||
if (issue) {
|
||||
chipIssue.value = issue;
|
||||
// 校验失败:保持编辑态并重新聚焦日期框,红字提示持续可见,直至修正保存或 Esc 取消
|
||||
void nextTick(() => {
|
||||
document.querySelector<HTMLInputElement>('[data-chip-edit] [data-chip-date]')?.focus();
|
||||
});
|
||||
return;
|
||||
}
|
||||
const cleaned = merged
|
||||
.filter((b) => b.planned_date && Number(b.qty) > 0)
|
||||
.map((b) => ({ planned_date: b.planned_date, qty: b.qty, remark: b.remark.trim() || null }));
|
||||
if (!cleaned.length) {
|
||||
cancelChipEdit();
|
||||
return;
|
||||
}
|
||||
void saveChipEdit(line, idx, cleaned);
|
||||
}
|
||||
|
||||
async function saveChipEdit(
|
||||
line: OrderDeliveryLine,
|
||||
idx: number,
|
||||
cleaned: { planned_date: string; qty: string; remark: string | null }[],
|
||||
) {
|
||||
const target = { key: lineKey(line), idx };
|
||||
chipSaving.value = true;
|
||||
try {
|
||||
await saveOrderDeliveryBatches(line.order_no, line.line_no, cleaned);
|
||||
msg.success(t('workspace.orderDeliveryReply.saveSingleDone'));
|
||||
// 仅当用户未切去编辑其他批次条时才退出编辑态
|
||||
if (editingChip.value?.key === target.key && editingChip.value?.idx === target.idx) {
|
||||
cancelChipEdit();
|
||||
}
|
||||
await loadLines();
|
||||
// loadLines 重建行 DOM:若用户已切去编辑其他批次条,重聚焦其日期框,
|
||||
// 否则焦点丢失后后续「失焦提交」永远不会触发(表现为填了不保存)
|
||||
if (editingChip.value) {
|
||||
void nextTick(() => {
|
||||
document.querySelector<HTMLInputElement>('[data-chip-edit] [data-chip-date]')?.focus();
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
msg.error(error instanceof Error ? error.message : t('workspace.orderDeliveryReply.saveFailedTitle'));
|
||||
const message = error instanceof Error ? error.message : '';
|
||||
if (message.includes('LINE_NOT_FOUND') || message.includes('不在同步范围') || message.includes('not found')) {
|
||||
editingChip.value = null;
|
||||
chipIssue.value = '';
|
||||
await loadLines();
|
||||
}
|
||||
} finally {
|
||||
chipSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* ============ 导出 Excel(2026-10-09) ============ */
|
||||
const exporting = ref(false);
|
||||
|
||||
/** 按当前筛选(appliedFilters)导出全部命中行;后端生成 xlsx,前端 blob 触发下载。 */
|
||||
async function doExportExcel() {
|
||||
exporting.value = true;
|
||||
try {
|
||||
await exportOrderDeliveryLines({ ...appliedFilters });
|
||||
msg.success(t('workspace.orderDeliveryReply.exportDone'));
|
||||
} catch (error) {
|
||||
msg.error(error instanceof Error ? error.message : t('workspace.orderDeliveryReply.exportFailed'));
|
||||
} finally {
|
||||
exporting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* ============ 通知 ============ */
|
||||
const notifying = ref(false);
|
||||
const notifyConfirmVisible = ref(false);
|
||||
|
||||
/** 批量通知入口:先弹共享 DeleteConfirmDialog(primary 语气)二次确认,确认后执行 doNotifyBatch。 */
|
||||
function requestNotifyBatch() {
|
||||
if (!notifiableSelected.value.length) return;
|
||||
notifyConfirmVisible.value = true;
|
||||
}
|
||||
|
||||
/** 批量通知:部分成功 warning 汇总,全部失败 error;提示后刷新列表让锁定即时生效。 */
|
||||
async function doNotifyBatch() {
|
||||
const lines = notifiableSelected.value;
|
||||
if (!lines.length) return;
|
||||
const ok = window.confirm(t('workspace.orderDeliveryReply.notifyBatchConfirm', { count: lines.length }));
|
||||
if (!ok) return;
|
||||
notifying.value = true;
|
||||
try {
|
||||
const summary = await notifyOrderDeliveryBatch(lines.map((line) => ({ order_no: line.order_no, line_no: line.line_no })));
|
||||
@@ -373,15 +536,16 @@ function clearHighlight() {
|
||||
}
|
||||
|
||||
const isLineHighlighted = (line: OrderDeliveryLine) => highlightKey.value === lineKey(line);
|
||||
const rowCls = (line: OrderDeliveryLine) =>
|
||||
isLineHighlighted(line) ? 'bg-amber-50' : selected.value.includes(lineKey(line)) ? 'bg-blue-50/60' : '';
|
||||
/** 冻结单元格必须实色背景(防透出滚动内容),且与整行高亮/勾选色联动;高亮优先于勾选。 */
|
||||
const frozenCellCls = (line: OrderDeliveryLine) =>
|
||||
isLineHighlighted(line)
|
||||
? 'bg-amber-100 group-hover:bg-amber-200'
|
||||
: selected.value.includes(lineKey(line))
|
||||
? 'bg-blue-100 group-hover:bg-blue-200'
|
||||
: 'bg-white group-hover:bg-slate-100';
|
||||
/** 行交互态:直达高亮(warning)优先于勾选选中(info),均走状态令牌(亮暗自适应)。 */
|
||||
const rowCls = (line: OrderDeliveryLine) => {
|
||||
if (isLineHighlighted(line)) return 'bg-row-highlight';
|
||||
return selected.value.includes(lineKey(line)) ? 'bg-row-selected' : '';
|
||||
};
|
||||
/** 冻结单元格用 utilities.css 的 frozen-cell(实色基底防透出滚动内容),状态与整行联动;高亮优先于勾选。 */
|
||||
const frozenCellCls = (line: OrderDeliveryLine) => {
|
||||
if (isLineHighlighted(line)) return 'frozen-cell frozen-cell--highlight';
|
||||
return selected.value.includes(lineKey(line)) ? 'frozen-cell frozen-cell--selected' : 'frozen-cell';
|
||||
};
|
||||
|
||||
/** 列表就绪后定位目标行:滚动到视口中央 + 高亮 8 秒;行不在当前筛选结果中时静默跳过。 */
|
||||
async function focusTargetLine(orderNo: string, lineNo: number) {
|
||||
@@ -430,15 +594,17 @@ onMounted(async () => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 全页统一字号:与表头一致(text-sm 14px),根容器设定基准,子元素不再覆写;
|
||||
唯一例外:交期回复状态/交期已锁定徽标保持 text-xs(12px)加粗 -->
|
||||
<!-- 高度收敛至视口(h-screen + overflow-hidden):页面自身不滚动,滚动全部在表格容器内,
|
||||
列头 sticky 固定、横向滚动条常驻表格底缘;聊天壳 iframe 与独立路由均适用 -->
|
||||
<div class="flex h-screen flex-col gap-4 overflow-hidden p-6 text-sm">
|
||||
<!-- 全页基准字号:text-sm 14px(表头/筛选区/工具栏/表格统一),子元素按需覆写;
|
||||
例外:页头标题 text-lg→md:text-xl(18/20px,与合同付款预警页头对齐)、徽章类 badge 基类自带 text-xs(12px)
|
||||
高度收敛至视口(h-screen + overflow-hidden):页面自身不滚动,滚动全部在表格容器内,
|
||||
列头 sticky 固定、横向滚动条常驻表格底缘;聊天壳 iframe 与独立路由均适用。
|
||||
page-shell:iframe 嵌入路由无外层布局壳,由本页根节点补齐 L1 页面底色与前景色 -->
|
||||
<div class="page-shell flex h-screen flex-col gap-4 overflow-hidden p-6 text-sm">
|
||||
<!-- 页头:标题 + 最近同步 + 手动刷新 -->
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<h1 class="font-bold text-primary">{{ t('workspace.nav.orderDeliveryReply') }}</h1>
|
||||
<span class="rounded-full px-3 py-1" :class="latestSyncFailed ? 'bg-rose-50 text-rose-600' : 'bg-blue-50 text-blue-600'">
|
||||
<!-- 页头标题字号与合同付款预警页头一致:小屏 text-lg 18px、≥768px md:text-xl 20px -->
|
||||
<h1 class="text-lg font-bold text-primary md:text-xl">{{ t('workspace.nav.orderDeliveryReply') }}</h1>
|
||||
<span class="badge whitespace-nowrap" :class="latestSyncFailed ? 'badge-error' : 'badge-info'">
|
||||
{{ latestSyncText }}
|
||||
</span>
|
||||
<div class="flex-1" />
|
||||
@@ -447,72 +613,70 @@ onMounted(async () => {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 搜索区:合并关键词搜索(订单/产品/客户命中任一字段),字号与表格统一(text-sm),shrink-0 防压缩 -->
|
||||
<div class="flex shrink-0 flex-wrap items-end gap-3 rounded-2xl border border-default bg-surface px-4 py-2.5">
|
||||
<label class="flex flex-col gap-1 text-muted">
|
||||
{{ t('workspace.orderDeliveryReply.filterKeyword') }}
|
||||
<input v-model="filters.keyword" class="h-8 min-w-[340px] rounded-lg border border-default px-3 text-primary outline-none focus:border-blue-500" :placeholder="t('workspace.orderDeliveryReply.filterKeywordPh')" @keyup.enter="doSearch" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1 text-muted">
|
||||
{{ t('workspace.orderDeliveryReply.filterOrderDate') }}
|
||||
<input v-model="filters.order_date" type="date" class="h-8 rounded-lg border border-default px-3 text-primary outline-none focus:border-blue-500" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1 text-muted">
|
||||
{{ t('workspace.orderDeliveryReply.filterStatus') }}
|
||||
<!-- 状态筛选选择即生效(无需再点查询);其余条件仍由「查询」统一提交 -->
|
||||
<select v-model="filters.status" class="min-w-[140px] rounded-lg border border-default bg-white px-3 py-[5px] text-sm leading-5 text-primary outline-none focus:border-blue-500" @change="doSearch">
|
||||
<option value="">{{ t('workspace.orderDeliveryReply.statusAll') }}</option>
|
||||
<option value="replied">{{ t('workspace.orderDeliveryReply.statusReplied') }}</option>
|
||||
<option value="not_fully_replied">{{ t('workspace.orderDeliveryReply.statusNotFully') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<button type="button" class="btn-primary h-8" @click="doSearch">{{ t('workspace.orderDeliveryReply.search') }}</button>
|
||||
<button type="button" class="btn-ghost h-8" @click="doReset">{{ t('workspace.orderDeliveryReply.reset') }}</button>
|
||||
<div class="flex-1" />
|
||||
<span class="text-muted">{{ t('workspace.orderDeliveryReply.totalCount', { count: total }) }}</span>
|
||||
<!-- 搜索区:合并关键词搜索(订单/产品/客户命中任一字段),shrink-0 防压缩;surface-panel 为设计系统 L2 区块容器(无 hover 阴影)。
|
||||
外置字段标签已取消(2026-10-09:去掉提示字及其占位,单行紧凑布局与合同付款预警筛选一致):
|
||||
字段含义由输入框 placeholder / 选项承担,无障碍语义用 aria-label 保留(复用 filterKeyword 等 i18n 键)。
|
||||
输入控件显式 text-sm(14px)+h-9(36px):与 .contract-filter-input(14px/36px/圆角8px)渲染规格逐项一致 -->
|
||||
<div class="surface-panel flex shrink-0 flex-wrap items-center gap-3 px-4 py-2.5">
|
||||
<input v-model="filters.keyword" class="input-field h-9 w-auto min-w-[340px] rounded-lg px-3 py-1 text-sm" :placeholder="t('workspace.orderDeliveryReply.filterKeywordPh')" :aria-label="t('workspace.orderDeliveryReply.filterKeyword')" @keyup.enter="doSearch" />
|
||||
<input v-model="filters.order_date" type="date" class="input-field h-9 w-auto rounded-lg px-3 py-1 text-sm" :aria-label="t('workspace.orderDeliveryReply.filterOrderDate')" />
|
||||
<!-- 状态筛选选择即生效(无需再点查询);其余条件仍由「查询」统一提交 -->
|
||||
<select v-model="filters.status" class="select-field h-9 w-auto min-w-[140px] rounded-lg px-3 py-1 text-sm" :aria-label="t('workspace.orderDeliveryReply.filterStatus')" @change="doSearch">
|
||||
<option value="">{{ t('workspace.orderDeliveryReply.statusAll') }}</option>
|
||||
<option value="replied">{{ t('workspace.orderDeliveryReply.statusReplied') }}</option>
|
||||
<option value="not_fully_replied">{{ t('workspace.orderDeliveryReply.statusNotFully') }}</option>
|
||||
</select>
|
||||
<!-- 查询/重置:text-sm(14px)+font-semibold(600)+h-9(36px),与合同付款预警 .contract-filter-submit 完全一致 -->
|
||||
<button type="button" class="btn-primary h-9 text-sm font-semibold" @click="doSearch">{{ t('workspace.orderDeliveryReply.search') }}</button>
|
||||
<button type="button" class="btn-ghost h-9 text-sm font-semibold" @click="doReset">{{ t('workspace.orderDeliveryReply.reset') }}</button>
|
||||
</div>
|
||||
|
||||
<!-- 工具栏:全选 + 联合回复 + 批量通知(shrink-0 防压缩,py-2 紧凑高度) -->
|
||||
<div class="flex shrink-0 flex-wrap items-center gap-3 rounded-2xl border border-default bg-surface px-4 py-2">
|
||||
<div class="surface-panel flex shrink-0 flex-wrap items-center gap-3 px-4 py-2">
|
||||
<label class="flex items-center gap-2 text-primary">
|
||||
<input type="checkbox" class="h-4 w-4 rounded border-default text-blue-600" :checked="allChecked" :indeterminate.prop="someChecked" @change="togglePageAll(($event.target as HTMLInputElement).checked)" />
|
||||
<input type="checkbox" class="admin-checkbox" :checked="allChecked" :indeterminate.prop="someChecked" @change="togglePageAll(($event.target as HTMLInputElement).checked)" />
|
||||
{{ t('workspace.orderDeliveryReply.selectAll') }}
|
||||
</label>
|
||||
<span class="text-muted">{{ t('workspace.orderDeliveryReply.selectedCount', { count: selectedLines.length }) }}</span>
|
||||
<template v-if="canManage">
|
||||
<button type="button" class="btn-primary h-8" :disabled="selectedLines.length === 0" @click="openBatchReply">
|
||||
<button type="button" class="btn-primary h-9 text-sm font-semibold" :disabled="selectedLines.length === 0" @click="openBatchReply">
|
||||
{{ t('workspace.orderDeliveryReply.batchReply') }}
|
||||
</button>
|
||||
<button type="button" class="btn-primary h-8" :disabled="notifiableSelected.length === 0 || notifying" @click="doNotifyBatch">
|
||||
<button type="button" class="btn-primary h-9 text-sm font-semibold" :disabled="notifiableSelected.length === 0 || notifying" @click="requestNotifyBatch">
|
||||
{{ t('workspace.orderDeliveryReply.batchNotify') }}
|
||||
</button>
|
||||
</template>
|
||||
<div class="flex-1" />
|
||||
<span class="whitespace-nowrap rounded-full bg-slate-100 px-3 py-1 text-muted">{{ t('workspace.orderDeliveryReply.toolbarHint') }}</span>
|
||||
<!-- 导出 Excel(2026-10-09 增补,原提示文字胶囊取消):按当前筛选导出全部行 -->
|
||||
<button type="button" class="btn-primary h-9 text-sm font-semibold" :disabled="exporting" @click="doExportExcel">
|
||||
<Download class="h-4 w-4" aria-hidden="true" />
|
||||
{{ t('workspace.orderDeliveryReply.exportExcel') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 列表 -->
|
||||
<div class="min-h-0 flex-1 overflow-auto rounded-2xl border border-default bg-surface">
|
||||
<table class="w-full border-collapse">
|
||||
<div class="surface-panel min-h-0 flex-1 overflow-auto">
|
||||
<table class="w-full border-collapse text-center">
|
||||
<!-- z-30 高于表体冻结单元格(z-20):纵向滚动时冻结列不会盖住表头 -->
|
||||
<thead class="sticky top-0 z-30 bg-slate-50 text-muted [&_th]:whitespace-nowrap">
|
||||
<thead class="sticky top-0 z-30 bg-surface-soft text-muted [&_th]:whitespace-nowrap">
|
||||
<tr>
|
||||
<!-- 左侧冻结标识区(前四列):勾选/客户编号/订单日期/订单单号:项次,宽度固定保证偏移对齐 -->
|
||||
<th class="sticky left-0 z-30 w-8 bg-slate-50 px-2 py-2" />
|
||||
<th class="sticky left-8 z-30 w-32 min-w-[8rem] bg-slate-50 px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colCustomer') }}</th>
|
||||
<th class="sticky left-[10rem] z-30 w-24 bg-slate-50 px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colOrderDate') }}</th>
|
||||
<th class="sticky left-[16rem] z-30 w-40 min-w-[10rem] border-r border-default bg-slate-50 px-2 py-2 text-left shadow-[2px_0_6px_-2px_rgba(15,23,42,0.12)]">{{ t('workspace.orderDeliveryReply.colOrderLine') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colPartNo') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colCustomerPartNo') }}</th>
|
||||
<th class="px-2 py-2 text-right">{{ t('workspace.orderDeliveryReply.colQty') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colAgreedDate') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colStatus') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colReply') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colReplyPerson') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colSalesperson') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colCustomerPo') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colSpec') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colUnit') }}</th>
|
||||
<th class="sticky left-0 z-30 w-8 bg-surface-soft px-2 py-2" />
|
||||
<th class="sticky left-8 z-30 w-32 min-w-[8rem] bg-surface-soft px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colCustomer') }}</th>
|
||||
<th class="sticky left-[10rem] z-30 w-24 bg-surface-soft px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colOrderDate') }}</th>
|
||||
<th class="sticky left-[16rem] z-30 w-40 min-w-[10rem] border-r border-default bg-surface-soft px-2 py-2 text-center shadow-sticky-col">{{ t('workspace.orderDeliveryReply.colOrderLine') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colPartNo') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colCustomerPartNo') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colQty') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colAgreedDate') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colStatus') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colReply') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colReplyPerson') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colSalesperson') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colCustomerPo') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colSpec') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colUnit') }}</th>
|
||||
<th class="px-2 py-2 text-center">{{ t('workspace.orderDeliveryReply.colNotifiedTime') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -520,15 +684,15 @@ onMounted(async () => {
|
||||
v-for="line in items"
|
||||
:key="lineKey(line)"
|
||||
:data-line-key="lineKey(line)"
|
||||
class="group border-t border-default hover:bg-slate-50"
|
||||
class="hover-row border-t border-default"
|
||||
:class="rowCls(line)"
|
||||
>
|
||||
<!-- 冻结单元格必须实色背景(半透明会透出滚动内容),并用 group-hover 与整行悬停/选中/直达高亮联动 -->
|
||||
<!-- 冻结单元格:frozen-cell 实色基底(半透明会透出滚动内容),悬停/选中/直达高亮由 CSS 联动 -->
|
||||
<td
|
||||
class="sticky left-0 z-20 px-2 py-1.5"
|
||||
:class="frozenCellCls(line)"
|
||||
>
|
||||
<input type="checkbox" class="h-4 w-4 rounded border-default text-blue-600" :checked="selected.includes(lineKey(line))" @change="toggleLine(line, ($event.target as HTMLInputElement).checked)" />
|
||||
<input type="checkbox" class="admin-checkbox" :checked="selected.includes(lineKey(line))" @change="toggleLine(line, ($event.target as HTMLInputElement).checked)" />
|
||||
</td>
|
||||
<td
|
||||
class="sticky left-8 z-20 w-32 min-w-[8rem] max-w-[8rem] px-2 py-1.5"
|
||||
@@ -543,70 +707,132 @@ onMounted(async () => {
|
||||
:class="frozenCellCls(line)"
|
||||
>{{ line.order_date || '—' }}</td>
|
||||
<td
|
||||
class="sticky left-[16rem] z-20 w-40 min-w-[10rem] max-w-[10rem] overflow-hidden whitespace-nowrap border-r border-default px-2 py-1.5 font-mono shadow-[2px_0_6px_-2px_rgba(15,23,42,0.12)]"
|
||||
class="sticky left-[16rem] z-20 w-40 min-w-[10rem] max-w-[10rem] overflow-hidden whitespace-nowrap border-r border-default px-2 py-1.5 font-mono text-left shadow-sticky-col"
|
||||
:class="frozenCellCls(line)"
|
||||
>{{ line.order_no }}:{{ line.line_no }}</td>
|
||||
<td class="px-2 py-1.5" :title="line.part_name || ''">
|
||||
<div class="max-w-[10rem] truncate font-mono">{{ line.part_no || '—' }}</div>
|
||||
<div class="max-w-[14rem] truncate text-muted">{{ line.part_name || '' }}</div>
|
||||
<!-- 截断盒 mx-auto:限宽盒在列内居中(继承 text-center),截断能力保留 -->
|
||||
<div class="mx-auto max-w-[10rem] truncate font-mono">{{ line.part_no || '—' }}</div>
|
||||
<div class="mx-auto max-w-[14rem] truncate text-muted">{{ line.part_name || '' }}</div>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-2 py-1.5 font-mono">{{ line.customer_part_no || '—' }}</td>
|
||||
<td class="px-2 py-2 text-right tabular-nums">{{ line.qty ?? '—' }}</td>
|
||||
<td class="px-2 py-2 text-center tabular-nums">{{ line.qty ?? '—' }}</td>
|
||||
<td class="whitespace-nowrap px-2 py-1.5">{{ line.agreed_date || '—' }}</td>
|
||||
<td class="px-2 py-1.5">
|
||||
<span class="whitespace-nowrap rounded-full px-2.5 py-0.5 text-xs font-semibold" :class="statusMeta(line.status).cls">
|
||||
<span class="badge inline-block min-w-[68px] whitespace-nowrap text-center font-semibold" :class="statusMeta(line.status).cls">
|
||||
{{ statusMeta(line.status).label }}
|
||||
</span>
|
||||
</td>
|
||||
<!-- 交期回复:无批次=回复交期;有批次可展开;锁定=已锁定 -->
|
||||
<td class="px-2 py-1.5 align-top">
|
||||
<!-- 交期回复:动作入口为批次条前的加号(lucide Plus);未回复=空批次条(不显示时间/数量);
|
||||
所有行首条批次条前保留等宽加号占位(无动作时为透明占位)、展开行其余批次条加 pl-7 缩进,
|
||||
保证全表批次条左缘对齐;「交期已锁定」徽标已取消(锁定状态由无加号与交期回复人员列「已通知」体现);
|
||||
>1 批时首条批次后有展开/收起小箭头 -->
|
||||
<td class="px-2 py-1.5">
|
||||
<template v-if="line.batches.length === 0">
|
||||
<span class="text-muted">{{ t('workspace.orderDeliveryReply.statusNotReplied') }}</span>
|
||||
<div v-if="canManage" class="mt-0.5">
|
||||
<button type="button" class="rounded-md border border-blue-200 bg-blue-50 px-2 py-0.5 text-blue-600" @click="openSingleReply(line)">
|
||||
{{ t('workspace.orderDeliveryReply.replyAction') }}
|
||||
<div class="flex items-center gap-1">
|
||||
<button
|
||||
v-if="canManage"
|
||||
type="button"
|
||||
class="btn-ghost h-6 w-6 shrink-0 rounded-md p-0"
|
||||
:disabled="chipSaving"
|
||||
:title="t('workspace.orderDeliveryReply.replyAction')"
|
||||
:aria-label="t('workspace.orderDeliveryReply.replyAction')"
|
||||
@click="openSingleReply(line)"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
</button>
|
||||
<span v-else class="w-6 shrink-0" aria-hidden="true" />
|
||||
<!-- 未回复空批次条:可管理时可点击就地填写交期+数量(回车/失焦自动保存单行接口);不显示占位文字 -->
|
||||
<div
|
||||
v-if="isChipEditing(line, 0)"
|
||||
data-chip-edit
|
||||
class="flex items-center gap-1 rounded border-l-[3px] border-brand-500 bg-surface-soft px-1.5 py-0.5"
|
||||
:class="chipSaving ? 'opacity-60' : ''"
|
||||
@focusout="onChipFocusout($event, line, 0)"
|
||||
@keydown.enter.prevent="chipCommit(line, 0)"
|
||||
@keydown.esc.prevent="cancelChipEdit"
|
||||
>
|
||||
<input v-model="chipDraft.planned_date" data-chip-date type="date" class="h-6 w-[125px] rounded border border-default bg-surface px-1 text-sm text-primary outline-none focus:border-brand-500" :aria-label="t('workspace.orderDeliveryReply.filterOrderDate')" />
|
||||
<input v-model="chipDraft.qty" type="number" min="0" class="h-6 w-16 rounded border border-default bg-surface px-1 text-sm text-primary outline-none focus:border-brand-500" :aria-label="t('workspace.orderDeliveryReply.colQty')" @focus="($event.target as HTMLInputElement).select()" />
|
||||
<span v-if="line.unit" class="text-muted">{{ line.unit }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="isChipEditable(line)"
|
||||
class="h-6 w-24 cursor-pointer rounded border-l-[3px] border-brand-500 bg-surface-soft transition-colors hover-surface-strong"
|
||||
:title="t('workspace.orderDeliveryReply.replyAction')"
|
||||
@click="startChipEdit(line, 0)"
|
||||
/>
|
||||
<div v-else class="h-6 w-24 rounded border-l-[3px] border-brand-500 bg-surface-soft" />
|
||||
</div>
|
||||
<p v-if="isChipEditing(line, 0) && chipIssue" class="mt-0.5 text-xs text-status-error">{{ chipIssue }}</p>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="whitespace-nowrap rounded-full border border-default bg-slate-50 px-2 py-0.5 text-muted">
|
||||
{{ t('workspace.orderDeliveryReply.batchCount', { count: line.batches.length }) }} ·
|
||||
{{ t('workspace.orderDeliveryReply.repliedOf', { replied: repliedQty(line), remain: undelivered(line) }) }}
|
||||
<span v-if="repliedQty(line) > undelivered(line)" class="ml-1 font-semibold text-orange-500">{{ t('workspace.orderDeliveryReply.overTag') }}</span>
|
||||
</span>
|
||||
<button v-if="line.batches.length > 1" type="button" class="rounded-full border border-default px-2 py-0.5 text-blue-600" @click="toggleExpand(lineKey(line))">
|
||||
{{ expanded.includes(lineKey(line)) ? t('workspace.orderDeliveryReply.collapse') : t('workspace.orderDeliveryReply.expand', { count: line.batches.length - 1 }) }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="mt-0.5 flex flex-col gap-0.5">
|
||||
<div class="flex flex-col gap-0.5">
|
||||
<div
|
||||
v-for="(batch, idx) in line.batches"
|
||||
:key="batch.seq ?? idx"
|
||||
v-show="expanded.includes(lineKey(line)) || idx === 0"
|
||||
class="max-w-[230px] truncate rounded border-l-[3px] border-blue-500 bg-blue-50/50 px-2 py-0.5 text-secondary"
|
||||
v-show="idx === 0 || expanded.includes(lineKey(line))"
|
||||
class="flex items-center gap-1"
|
||||
:class="idx > 0 ? 'pl-7' : ''"
|
||||
>
|
||||
{{ batch.planned_date }} · <b class="text-blue-600">{{ batch.qty }}</b> {{ line.unit }}
|
||||
<i v-if="batch.remark" class="ml-1 not-italic text-muted">{{ batch.remark }}</i>
|
||||
<template v-if="idx === 0">
|
||||
<button
|
||||
v-if="canManage && !line.locked"
|
||||
type="button"
|
||||
class="btn-ghost h-6 w-6 shrink-0 rounded-md p-0"
|
||||
:disabled="chipSaving"
|
||||
:title="t('workspace.orderDeliveryReply.editReplyAction')"
|
||||
:aria-label="t('workspace.orderDeliveryReply.editReplyAction')"
|
||||
@click="openSingleReply(line)"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
</button>
|
||||
<span v-else class="w-6 shrink-0" aria-hidden="true" />
|
||||
</template>
|
||||
<!-- 批次条:未锁定可管理行点击原地编辑(日期+数量,回车/失焦自动保存) -->
|
||||
<div
|
||||
v-if="isChipEditing(line, idx)"
|
||||
data-chip-edit
|
||||
class="flex items-center gap-1 rounded border-l-[3px] border-brand-500 bg-surface-soft px-1.5 py-0.5"
|
||||
:class="chipSaving ? 'opacity-60' : ''"
|
||||
@focusout="onChipFocusout($event, line, idx)"
|
||||
@keydown.enter.prevent="chipCommit(line, idx)"
|
||||
@keydown.esc.prevent="cancelChipEdit"
|
||||
>
|
||||
<input v-model="chipDraft.planned_date" data-chip-date type="date" class="h-6 w-[125px] rounded border border-default bg-surface px-1 text-sm text-primary outline-none focus:border-brand-500" :aria-label="t('workspace.orderDeliveryReply.filterOrderDate')" />
|
||||
<input v-model="chipDraft.qty" type="number" min="0" class="h-6 w-16 rounded border border-default bg-surface px-1 text-sm text-primary outline-none focus:border-brand-500" :aria-label="t('workspace.orderDeliveryReply.colQty')" @focus="($event.target as HTMLInputElement).select()" />
|
||||
<span v-if="line.unit" class="text-muted">{{ line.unit }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="max-w-[230px] truncate rounded border-l-[3px] border-brand-500 bg-surface-soft px-2 py-0.5 text-secondary"
|
||||
:class="isChipEditable(line) ? 'cursor-pointer transition-colors hover-surface-strong' : ''"
|
||||
:title="isChipEditable(line) ? t('workspace.orderDeliveryReply.editReplyAction') : undefined"
|
||||
@click="startChipEdit(line, idx)"
|
||||
>
|
||||
{{ batch.planned_date }} · <b class="text-brand-600">{{ batch.qty }}</b> {{ line.unit }}
|
||||
</div>
|
||||
<button
|
||||
v-if="idx === 0 && line.batches.length > 1"
|
||||
type="button"
|
||||
class="btn-ghost h-6 w-6 shrink-0 rounded-md p-0"
|
||||
:title="expanded.includes(lineKey(line)) ? t('workspace.orderDeliveryReply.collapse') : t('workspace.orderDeliveryReply.expand', { count: line.batches.length - 1 })"
|
||||
:aria-label="expanded.includes(lineKey(line)) ? t('workspace.orderDeliveryReply.collapse') : t('workspace.orderDeliveryReply.expand', { count: line.batches.length - 1 })"
|
||||
@click="toggleExpand(lineKey(line))"
|
||||
>
|
||||
<ChevronUp v-if="expanded.includes(lineKey(line))" class="h-4 w-4" />
|
||||
<ChevronDown v-else class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-0.5">
|
||||
<span v-if="line.locked" class="rounded-full bg-emerald-50 px-2.5 py-0.5 text-xs font-semibold text-emerald-600">{{ t('workspace.orderDeliveryReply.lockedTag') }}</span>
|
||||
<button v-else-if="canManage" type="button" class="rounded-md border border-blue-200 bg-blue-50 px-2 py-0.5 text-blue-600" @click="openSingleReply(line)">
|
||||
{{ t('workspace.orderDeliveryReply.editReplyAction') }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="editingChip && editingChip.key === lineKey(line) && chipIssue" class="mt-0.5 text-xs text-status-error">{{ chipIssue }}</p>
|
||||
</template>
|
||||
</td>
|
||||
<!-- 交期回复人员:锁定行附带已通知对象与时间(原「通知业务部门」列已取消,信息并入此处) -->
|
||||
<!-- 交期回复人员:通知时间已拆至独立「通知时间」列(2026-10-09),本列仅工号/姓名/待通知提示 -->
|
||||
<td class="px-2 py-1.5">
|
||||
<template v-if="line.notified_employee_id || line.notified_user_name">
|
||||
<div class="font-mono">{{ line.notified_employee_id || '' }}</div>
|
||||
<div class="text-muted">{{ line.notified_user_name || '' }}</div>
|
||||
<div v-if="line.locked" class="text-emerald-600">
|
||||
{{ t('workspace.orderDeliveryReply.notifiedTag', { name: line.salesperson_name || line.salesperson_code || '' }) }}
|
||||
<span class="text-muted">{{ line.notified_at || '' }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<span v-else class="text-muted">{{ t('workspace.orderDeliveryReply.pendingNotify') }}</span>
|
||||
</td>
|
||||
@@ -615,20 +841,21 @@ onMounted(async () => {
|
||||
<div class="whitespace-nowrap">{{ line.salesperson_name || line.salesperson_code || '—' }}</div>
|
||||
<div class="text-muted">{{ line.dept_name || line.dept_code || '' }}</div>
|
||||
</td>
|
||||
<td class="px-2 py-1.5 font-mono" :title="line.customer_po || ''"><span class="block max-w-[10rem] truncate">{{ line.customer_po || '—' }}</span></td>
|
||||
<td class="px-2 py-1.5" :title="line.spec || ''"><span class="block max-w-[10rem] truncate">{{ line.spec || '—' }}</span></td>
|
||||
<td class="px-2 py-1.5 font-mono" :title="line.customer_po || ''"><span class="mx-auto block max-w-[10rem] truncate">{{ line.customer_po || '—' }}</span></td>
|
||||
<td class="px-2 py-1.5" :title="line.spec || ''"><span class="mx-auto block max-w-[10rem] truncate">{{ line.spec || '—' }}</span></td>
|
||||
<td class="px-2 py-1.5">{{ line.unit || '—' }}</td>
|
||||
<!-- 通知时间(2026-10-09 自「交期回复人员」列拆出独立列):锁定行展示通知时间戳,单行不折行 -->
|
||||
<td class="whitespace-nowrap px-2 py-1.5" :class="line.locked ? 'text-status-success' : 'text-muted'">{{ line.locked ? (line.notified_at || '—') : '—' }}</td>
|
||||
</tr>
|
||||
<tr v-if="!loading && items.length === 0">
|
||||
<td colspan="15" class="px-4 py-16 text-center text-muted">{{ t('workspace.orderDeliveryReply.empty') }}</td>
|
||||
<td colspan="16" class="px-4 py-16 text-center text-muted">{{ t('workspace.orderDeliveryReply.empty') }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 分页:复用管理控制台-数据报表的 PaginationBar(摘要 + 每页条数 + 页码按钮) -->
|
||||
<!-- 分页:复用管理控制台-数据报表的 PaginationBar(摘要 + 每页条数 + 页码按钮),组件自带字号不再强改 -->
|
||||
<PaginationBar
|
||||
class="[&_*]:!text-sm"
|
||||
:page="page"
|
||||
:page-size="pageSize"
|
||||
:total="total"
|
||||
@@ -637,30 +864,29 @@ onMounted(async () => {
|
||||
@update:page-size="changePageSize"
|
||||
/>
|
||||
|
||||
<!-- 回复弹窗 -->
|
||||
<div v-if="modalVisible" class="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/40" @click.self="modalVisible = false">
|
||||
<div class="flex max-h-[88vh] w-[min(960px,94vw)] flex-col overflow-hidden rounded-2xl bg-white shadow-2xl">
|
||||
<div class="flex items-center gap-3 border-b border-default px-5 py-4">
|
||||
<!-- 回复弹窗:dialog-overlay/panel/header/body/footer 设计系统 L2 结构 -->
|
||||
<div v-if="modalVisible" class="dialog-overlay items-center" @click.self="modalVisible = false">
|
||||
<div class="dialog-panel max-h-[88vh] w-[min(960px,94vw)]">
|
||||
<div class="dialog-header">
|
||||
<h3 class="font-bold text-primary">{{ modalTitle }}</h3>
|
||||
<div class="flex-1" />
|
||||
<button type="button" class="text-muted" @click="modalVisible = false">×</button>
|
||||
<button type="button" class="btn-ghost h-8 w-8 px-0 text-lg leading-none" @click="modalVisible = false">×</button>
|
||||
</div>
|
||||
<div class="flex-1 overflow-auto px-5 py-4">
|
||||
<div class="dialog-body">
|
||||
<!-- 快速统一交期:仅联合回复弹窗显示;单行回复/修改回复弹窗已取消该区(2026-10-07),直接逐批次填写 -->
|
||||
<div v-if="modalMode === 'batch'" class="mb-4 flex flex-wrap items-end gap-3 rounded-xl border border-default bg-blue-50/40 px-4 py-3">
|
||||
<div v-if="modalMode === 'batch'" class="flex flex-wrap items-end gap-3 rounded-xl border border-default bg-surface-soft px-4 py-3">
|
||||
<label class="flex flex-col gap-1 text-muted">
|
||||
{{ t('workspace.orderDeliveryReply.quickDate') }}
|
||||
<input v-model="quickDate" type="date" class="h-9 rounded-lg border border-default px-3 text-primary" />
|
||||
<input v-model="quickDate" type="date" class="input-field h-9 w-auto rounded-lg px-3 py-1.5" />
|
||||
</label>
|
||||
<button type="button" class="h-9 rounded-lg border border-default px-3 text-primary" @click="applyQuickDate">
|
||||
<button type="button" class="btn-secondary btn-sm h-9" @click="applyQuickDate">
|
||||
{{ t('workspace.orderDeliveryReply.applyQuickDate') }}
|
||||
</button>
|
||||
<span class="text-muted">{{ t('workspace.orderDeliveryReply.modalHint') }}</span>
|
||||
</div>
|
||||
<!-- 每行批次编辑器 -->
|
||||
<div v-for="entry in modalLines" :key="lineKey(entry.line)" class="mb-4 overflow-hidden rounded-xl border border-default">
|
||||
<div class="flex flex-wrap items-center gap-2 bg-slate-50 px-3 py-2">
|
||||
<span class="rounded bg-indigo-50 px-2 py-0.5 font-semibold text-indigo-600">{{ entry.line.order_no }}</span>
|
||||
<div v-for="entry in modalLines" :key="lineKey(entry.line)" class="overflow-hidden rounded-xl border border-default">
|
||||
<div class="flex flex-wrap items-center gap-2 bg-surface-soft px-3 py-2">
|
||||
<span class="rounded bg-surface-strong px-2 py-0.5 font-semibold text-primary">{{ entry.line.order_no }}</span>
|
||||
<span>{{ t('workspace.orderDeliveryReply.itemLabel', { item: entry.line.line_no }) }}</span>
|
||||
<span class="text-muted">{{ entry.line.customer_no }} · {{ entry.line.customer_short_name }}</span>
|
||||
<span class="text-muted">{{ entry.line.part_no }} · {{ entry.line.part_name }}</span>
|
||||
@@ -669,27 +895,36 @@ onMounted(async () => {
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2 px-3 py-3">
|
||||
<div v-for="(batch, idx) in entry.batches" :key="idx" class="grid grid-cols-[170px_120px_1fr_36px] items-center gap-2">
|
||||
<input v-model="batch.planned_date" type="date" class="h-9 rounded-lg border border-default px-2 text-primary" />
|
||||
<input v-model="batch.qty" type="number" min="0" :placeholder="t('workspace.orderDeliveryReply.qtyPh')" class="h-9 rounded-lg border border-default px-2 text-primary" />
|
||||
<input v-model="batch.remark" :placeholder="t('workspace.orderDeliveryReply.remarkPh')" class="h-9 rounded-lg border border-default px-2 text-primary" />
|
||||
<button type="button" class="h-9 rounded-lg bg-rose-50 text-rose-600" :title="t('workspace.orderDeliveryReply.removeBatch')" @click="entry.batches.splice(idx, 1)">✕</button>
|
||||
<div v-for="(batch, idx) in entry.batches" :key="idx" class="grid grid-cols-[170px_120px_1fr_40px] items-center gap-2">
|
||||
<input v-model="batch.planned_date" type="date" class="input-field h-9 rounded-lg px-2 py-1.5" />
|
||||
<input v-model="batch.qty" type="number" min="0" :placeholder="t('workspace.orderDeliveryReply.qtyPh')" class="input-field h-9 rounded-lg px-2 py-1.5" />
|
||||
<input v-model="batch.remark" :placeholder="t('workspace.orderDeliveryReply.remarkPh')" class="input-field h-9 rounded-lg px-2 py-1.5" />
|
||||
<button type="button" class="btn-danger btn-sm" :title="t('workspace.orderDeliveryReply.removeBatch')" @click="entry.batches.splice(idx, 1)">✕</button>
|
||||
</div>
|
||||
<button type="button" class="w-full rounded-lg border border-dashed border-slate-300 py-2 text-blue-600" @click="entry.batches.push({ planned_date: '', qty: '', remark: '' })">
|
||||
<button type="button" class="w-full rounded-lg border border-dashed border-default py-2 text-brand-600 transition-colors hover-surface-soft" @click="entry.batches.push({ planned_date: '', qty: '', remark: '' })">
|
||||
{{ t('workspace.orderDeliveryReply.addBatch') }}
|
||||
</button>
|
||||
<!-- 行级实时校验提示:缺交期/缺数量按批次序号指出,合计不等给出已填/应填;随填写实时切换 -->
|
||||
<p v-if="lineIssueText(entry)" class="text-rose-500">{{ lineIssueText(entry) }}</p>
|
||||
<p v-if="lineIssueText(entry)" class="text-status-error">{{ lineIssueText(entry) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-end gap-3 border-t border-default bg-slate-50 px-5 py-3">
|
||||
<button type="button" class="btn-ghost" @click="modalVisible = false">{{ t('common.cancel') }}</button>
|
||||
<div class="dialog-footer">
|
||||
<button type="button" class="btn-secondary" @click="modalVisible = false">{{ t('common.cancel') }}</button>
|
||||
<button type="button" class="btn-primary" :disabled="saving" @click="saveReplies">
|
||||
{{ saving ? t('workspace.orderDeliveryReply.saving') : t('workspace.orderDeliveryReply.saveReply') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 批量通知二次确认:共享 DeleteConfirmDialog(primary 语气,非删除;确认/取消文案用组件默认 i18n) -->
|
||||
<DeleteConfirmDialog
|
||||
v-model="notifyConfirmVisible"
|
||||
:title="t('workspace.orderDeliveryReply.batchNotify')"
|
||||
:message="t('workspace.orderDeliveryReply.notifyBatchConfirm', { count: notifiableSelected.length })"
|
||||
confirm-tone="primary"
|
||||
@confirm="doNotifyBatch"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user