Merge branch 'dev' into hugo-shipping-notice
# Conflicts: # backend/app/services/maintenance_chat_service.py # backend/tests/test_maintenance_chat_service.py # frontend/src/features/chat/components/ChatViewContent.vue
This commit is contained in:
commit
2ce1aca023
25 files changed
+1609
-304
No files matched your search
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* features/chat/components/ChatInputBar.vue
|
||||
* 聊天输入栏:文本框、附件、语音、知识库选择与发送按钮。
|
||||
* 逻辑:设备维保助手的管理入口(设备台账、登记维修)与语音按钮同侧排列,发送按钮独占右侧。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
@@ -259,27 +260,6 @@ watch(
|
||||
<span>点发送开始处理</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="isMaintenanceAgent && canManageMaintenance"
|
||||
class="flex flex-wrap items-center gap-2 px-3 pb-1 text-xs text-muted"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-full border border-brand-200 bg-brand-50 px-3 py-1 font-medium text-brand-700 transition-colors hover:bg-brand-100"
|
||||
@click="emit('maintenance-ledger-config')"
|
||||
>
|
||||
▦ {{ $t('maintenance.panel.ledgerTitle') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-full border border-brand-200 bg-brand-50 px-3 py-1 font-medium text-brand-700 transition-colors hover:bg-brand-100"
|
||||
@click="emit('maintenance-create-record')"
|
||||
>
|
||||
{{ $t('maintenance.panel.recordTitle') }}
|
||||
</button>
|
||||
<span>{{ $t('maintenance.panel.adminOnly') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="mt-1.5 flex items-center justify-between px-1.5 pb-0.5">
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
@@ -359,7 +339,7 @@ watch(
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ref="kbMenuRef" class="relative">
|
||||
<div v-if="!isMaintenanceAgent" ref="kbMenuRef" class="relative">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="kbDropdownDisabled"
|
||||
@@ -386,6 +366,27 @@ watch(
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="isMaintenanceAgent && canManageMaintenance"
|
||||
class="flex flex-wrap items-center gap-2"
|
||||
:title="$t('maintenance.panel.adminOnly')"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-brand-300 bg-brand-50 px-3 py-1.5 text-xs font-semibold text-brand-700 transition-colors hover:bg-brand-100"
|
||||
@click="emit('maintenance-ledger-config')"
|
||||
>
|
||||
{{ $t('maintenance.chat.manageLedger') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-brand-300 bg-brand-50 px-3 py-1.5 text-xs font-semibold text-brand-700 transition-colors hover:bg-brand-100"
|
||||
@click="emit('maintenance-create-record')"
|
||||
>
|
||||
{{ $t('maintenance.chat.logRepair') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
@@ -402,7 +403,7 @@ watch(
|
||||
v-else
|
||||
type="button"
|
||||
:disabled="!canSendMessage"
|
||||
class="flex h-10 w-10 items-center justify-center rounded-full border shadow-sm transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full border shadow-sm transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:class="!canSendMessage
|
||||
? 'border-default bg-slate-100 text-muted'
|
||||
: 'border-brand-500 bg-brand-500 text-white shadow-[0_0_0_4px_rgba(59,130,246,0.18)] hover:scale-105 hover:bg-brand-600 hover:shadow-[0_0_0_6px_rgba(59,130,246,0.24)] active:scale-95'"
|
||||
|
||||
@@ -13,6 +13,8 @@ import type { ShippingMappingHandlers } from './messages/ShippingInventoryMappin
|
||||
import type { TrainingHandlers } from './messages/TrainingExamQuestionMessage.vue';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { ToolRunProgress } from '../api/toolRunProgress.api';
|
||||
import type { MaintenanceDevice } from '@/features/maintenance/types/ledger.types';
|
||||
import type { MaintenanceRecord } from '@/features/maintenance/types/record.types';
|
||||
|
||||
const {
|
||||
messages,
|
||||
@@ -55,6 +57,9 @@ const emit = defineEmits<{
|
||||
'open-feedback': [index: number];
|
||||
'select-question': [question: string];
|
||||
'scroll-to-bottom': [];
|
||||
'maintenance-edit-record': [record: MaintenanceRecord];
|
||||
'maintenance-view-record-history': [device: MaintenanceDevice];
|
||||
'maintenance-create-record-for-device': [device: MaintenanceDevice];
|
||||
}>();
|
||||
|
||||
const bindScrollContainer = (node: unknown) => {
|
||||
@@ -122,6 +127,9 @@ const isLatestAssistantMessage = (items: ChatMessage[], index: number) => {
|
||||
@resend="emit('resend', $event)"
|
||||
@regenerate="emit('regenerate')"
|
||||
@open-feedback="emit('open-feedback', index)"
|
||||
@maintenance-edit-record="emit('maintenance-edit-record', $event)"
|
||||
@maintenance-view-record-history="emit('maintenance-view-record-history', $event)"
|
||||
@maintenance-create-record-for-device="emit('maintenance-create-record-for-device', $event)"
|
||||
/>
|
||||
<ToolRunProgressCard
|
||||
v-if="shouldRenderMessage(msg) && shouldShowToolRunProgressAfterMessage(msg, index)"
|
||||
|
||||
@@ -21,6 +21,19 @@ import MaintenanceRecordManagerPanel from '@/features/maintenance/components/Mai
|
||||
import { useChatPageContext } from '@/features/chat/composables/chat.context';
|
||||
import { matchesTrainingAgent } from '@/features/chat/training/trainingWorkspace.utils';
|
||||
import { agentHasIntentUiProfile } from '@/shared/utils/agent-registry.utils';
|
||||
import type { MaintenanceDevice } from '@/features/maintenance/types/ledger.types';
|
||||
import type { MaintenanceRecord } from '@/features/maintenance/types/record.types';
|
||||
import {
|
||||
MAINTENANCE_PANEL_DEFAULT_WIDTH,
|
||||
buildMaintenancePanelWidthStyle,
|
||||
clampMaintenancePanelWidth,
|
||||
} from '@/features/maintenance/utils/maintenance-panel-layout.utils';
|
||||
|
||||
type MaintenanceRecordPanelCommand = {
|
||||
mode: 'list' | 'create';
|
||||
device: MaintenanceDevice;
|
||||
nonce: number;
|
||||
};
|
||||
|
||||
const page = useChatPageContext();
|
||||
const isTrainingAgentPage = computed(() => matchesTrainingAgent(page.currentAgent));
|
||||
@@ -35,18 +48,16 @@ const canManageMaintenance = computed(() => ['admin', 'maintenance_manager'].inc
|
||||
const hideWelcomePanel = computed(() => isTrainingAgentPage.value);
|
||||
const isTrainingWorkspaceExpanded = ref(false);
|
||||
const maintenancePanel = ref<'ledger' | 'record' | null>(null);
|
||||
const maintenancePanelWidth = ref(560);
|
||||
const maintenanceEditRecord = ref<MaintenanceRecord | null>(null);
|
||||
const maintenanceRecordPanelCommand = ref<MaintenanceRecordPanelCommand | null>(null);
|
||||
const maintenancePanelWidth = ref(MAINTENANCE_PANEL_DEFAULT_WIDTH);
|
||||
const isMaintenancePanelFullscreen = ref(false);
|
||||
const isMaintenancePanelResizing = ref(false);
|
||||
const maintenancePanelStyle = computed(() => {
|
||||
if (isMaintenancePanelFullscreen.value) {
|
||||
return { width: '100%', minWidth: '100%', maxWidth: '100%' };
|
||||
}
|
||||
return {
|
||||
width: `${maintenancePanelWidth.value}px`,
|
||||
minWidth: '420px',
|
||||
maxWidth: '82vw',
|
||||
};
|
||||
return buildMaintenancePanelWidthStyle(maintenancePanelWidth.value);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -61,8 +72,7 @@ const startMaintenancePanelResize = (event: MouseEvent): void => {
|
||||
const startWidth = maintenancePanelWidth.value;
|
||||
const handleMove = (moveEvent: MouseEvent) => {
|
||||
const nextWidth = startWidth + (startX - moveEvent.clientX);
|
||||
const maxWidth = Math.max(420, Math.floor(window.innerWidth * 0.82));
|
||||
maintenancePanelWidth.value = Math.min(maxWidth, Math.max(420, nextWidth));
|
||||
maintenancePanelWidth.value = clampMaintenancePanelWidth(nextWidth, window.innerWidth);
|
||||
};
|
||||
const stopResize = () => {
|
||||
isMaintenancePanelResizing.value = false;
|
||||
@@ -73,6 +83,42 @@ const startMaintenancePanelResize = (event: MouseEvent): void => {
|
||||
window.addEventListener('mouseup', stopResize);
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开右侧维修记录面板并进入指定记录的编辑表单。
|
||||
* @param record - 会话结果表格中选中的维修记录。
|
||||
*/
|
||||
const openMaintenanceRecordEdit = (record: MaintenanceRecord): void => {
|
||||
maintenanceEditRecord.value = record;
|
||||
maintenanceRecordPanelCommand.value = null;
|
||||
maintenancePanel.value = 'record';
|
||||
};
|
||||
|
||||
/**
|
||||
* 鎵撳紑鍙充晶缁翠慨璁板綍鍒楄〃锛屽苟鎸夊綋鍓嶈澶囩紪鍙风瓫閫夊巻鍙茶褰曘€?
|
||||
* @param device - 浼氳瘽缁撴灉涓懡涓殑璁惧銆?
|
||||
*/
|
||||
const openMaintenanceRecordHistory = (device: MaintenanceDevice): void => {
|
||||
maintenanceEditRecord.value = null;
|
||||
maintenanceRecordPanelCommand.value = { mode: 'list', device, nonce: Date.now() };
|
||||
maintenancePanel.value = 'record';
|
||||
};
|
||||
|
||||
/**
|
||||
* 鎵撳紑鍙充晶缁翠慨璁板綍鏂板琛ㄥ崟锛屽苟棰勫~褰撳墠璁惧缂栧彿銆?
|
||||
* @param device - 浼氳瘽缁撴灉涓懡涓殑璁惧銆?
|
||||
*/
|
||||
const openMaintenanceRecordCreate = (device: MaintenanceDevice): void => {
|
||||
maintenanceEditRecord.value = null;
|
||||
maintenanceRecordPanelCommand.value = { mode: 'create', device, nonce: Date.now() };
|
||||
maintenancePanel.value = 'record';
|
||||
};
|
||||
|
||||
const openBlankMaintenanceRecordCreate = (): void => {
|
||||
maintenanceEditRecord.value = null;
|
||||
maintenanceRecordPanelCommand.value = null;
|
||||
maintenancePanel.value = 'record';
|
||||
};
|
||||
|
||||
// 切换 Agent 时,重置工作区展开状态,确保每次进入都是收起状态(聊天优先)
|
||||
watch(() => page.currentAgentId, () => {
|
||||
isTrainingWorkspaceExpanded.value = false;
|
||||
@@ -207,6 +253,9 @@ watch(() => page.currentAgentId, () => {
|
||||
@open-feedback="page.handleOpenFeedback($event)"
|
||||
@select-question="page.handleSend"
|
||||
@scroll-to-bottom="page.scrollToBottom"
|
||||
@maintenance-edit-record="openMaintenanceRecordEdit"
|
||||
@maintenance-view-record-history="openMaintenanceRecordHistory"
|
||||
@maintenance-create-record-for-device="openMaintenanceRecordCreate"
|
||||
/>
|
||||
|
||||
<ChatInputBar
|
||||
@@ -241,7 +290,7 @@ watch(() => page.currentAgentId, () => {
|
||||
@shipping-inventory-selected="page.handleShippingInventorySelected"
|
||||
@use-shipping-suggested-prompt="page.useShippingSuggestedPrompt"
|
||||
@maintenance-ledger-config="maintenancePanel = 'ledger'"
|
||||
@maintenance-create-record="maintenancePanel = 'record'"
|
||||
@maintenance-create-record="openBlankMaintenanceRecordCreate"
|
||||
@clear-shipping-focus="page.clearShippingFocus"
|
||||
/>
|
||||
</div>
|
||||
@@ -293,7 +342,11 @@ watch(() => page.currentAgentId, () => {
|
||||
</div>
|
||||
<div class="min-h-0 flex-1 overflow-auto p-4">
|
||||
<LedgerConfigPanel v-if="maintenancePanel === 'ledger'" />
|
||||
<MaintenanceRecordManagerPanel v-else />
|
||||
<MaintenanceRecordManagerPanel
|
||||
v-else
|
||||
:edit-record="maintenanceEditRecord"
|
||||
:command="maintenanceRecordPanelCommand"
|
||||
/>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ import TrainingSummaryMessage from './TrainingSummaryMessage.vue';
|
||||
import TrainingResultCard from './TrainingResultCard.vue';
|
||||
import type { ChatMessage, InlineDownloadFile, SourceFileLink } from '../../types/chat.types';
|
||||
import type { ShippingInventoryMappingFormPayload, ShippingMatchResultPayload } from '../../types/shipping.types';
|
||||
import type { MaintenanceDevice } from '@/features/maintenance/types/ledger.types';
|
||||
import type { MaintenanceRecord } from '@/features/maintenance/types/record.types';
|
||||
|
||||
export interface ChatMessageBubbleHandlers {
|
||||
renderMarkdown: (text: string) => string;
|
||||
@@ -76,6 +78,9 @@ const emit = defineEmits<{
|
||||
resend: [content: string];
|
||||
regenerate: [];
|
||||
'open-feedback': [];
|
||||
'maintenance-edit-record': [record: MaintenanceRecord];
|
||||
'maintenance-view-record-history': [device: MaintenanceDevice];
|
||||
'maintenance-create-record-for-device': [device: MaintenanceDevice];
|
||||
}>();
|
||||
|
||||
const authStore = useAuthStore();
|
||||
@@ -693,6 +698,9 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
<MaintenanceDeviceResultCard
|
||||
v-else-if="message.type === 'maintenance-device-result'"
|
||||
:message="message"
|
||||
@edit-record="emit('maintenance-edit-record', $event)"
|
||||
@view-record-history="emit('maintenance-view-record-history', $event)"
|
||||
@create-record="emit('maintenance-create-record-for-device', $event)"
|
||||
/>
|
||||
<TrainingExamQuestionMessage
|
||||
v-else-if="isTrainingExamMessage && trainingHandlers.getQuestion()"
|
||||
|
||||
@@ -1,31 +1,51 @@
|
||||
/**
|
||||
* features/chat/components/messages/MaintenanceDeviceResultCard.vue
|
||||
* 用途:设备维保助手会话中的设备台账查询结果卡片。
|
||||
* 依赖:chat.types、ledger/record 类型、vue-i18n。
|
||||
* 逻辑:后端返回 maintenance-device-result payload 后,本组件按原型展示设备基础信息、匹配状态和快捷操作。
|
||||
* 用途:设备维保助手会话中的设备信息与维修记录结果卡片。
|
||||
* 依赖:auth.store、chat.types、maintenance ledger/record 类型、repair-status-display.utils、maintenance-panel-layout.utils、vue-i18n。
|
||||
* 逻辑:后端返回 queryMode=device 时按台账配置表单同序展示设备信息;queryMode=records 时按维修记录配置字段展示记录列表。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import type { ChatMessage } from '../../types/chat.types';
|
||||
import type { MaintenanceDevice } from '@/features/maintenance/types/ledger.types';
|
||||
import type { MaintenanceRecord } from '@/features/maintenance/types/record.types';
|
||||
import { repairStatusBadgeClass } from '@/features/maintenance/utils/repair-status-display.utils';
|
||||
import { buildMaintenancePanelWidthStyle } from '@/features/maintenance/utils/maintenance-panel-layout.utils';
|
||||
|
||||
interface MaintenanceDeviceResultPayload {
|
||||
matched?: boolean;
|
||||
queryMode?: 'device' | 'records';
|
||||
keyword?: string;
|
||||
device?: MaintenanceDevice;
|
||||
records?: MaintenanceRecord[];
|
||||
summary?: {
|
||||
recentRecordCount?: number;
|
||||
statusCounts?: Record<string, number>;
|
||||
ledgerMatched?: boolean;
|
||||
};
|
||||
actions?: Array<{ id: string; label: string }>;
|
||||
}
|
||||
|
||||
type DisplayCell = {
|
||||
label: string;
|
||||
value: string | number | null | undefined;
|
||||
};
|
||||
|
||||
const props = defineProps<{
|
||||
message: ChatMessage;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
'edit-record': [record: MaintenanceRecord];
|
||||
'view-record-history': [device: MaintenanceDevice];
|
||||
'create-record': [device: MaintenanceDevice];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const authStore = useAuthStore();
|
||||
|
||||
const recordDetailPanelStyle = buildMaintenancePanelWidthStyle();
|
||||
|
||||
const payload = computed<MaintenanceDeviceResultPayload | null>(() => {
|
||||
const raw = props.message.payload;
|
||||
@@ -35,21 +55,39 @@ const payload = computed<MaintenanceDeviceResultPayload | null>(() => {
|
||||
|
||||
const device = computed(() => payload.value?.device || null);
|
||||
const records = computed(() => payload.value?.records || []);
|
||||
const queryMode = computed(() => payload.value?.queryMode === 'records' ? 'records' : 'device');
|
||||
const hasResult = computed(() => Boolean(device.value || records.value.length));
|
||||
const ledgerMatched = computed(() => payload.value?.summary?.ledgerMatched !== false);
|
||||
const canManageMaintenance = computed(() => ['admin', 'maintenance_manager'].includes(String(authStore.user?.role || '')));
|
||||
const selectedRecord = ref<MaintenanceRecord | null>(null);
|
||||
|
||||
const statusLabel = computed(() => {
|
||||
const status = device.value?.deviceStatus;
|
||||
const deviceStatusLabel = (status?: string | null) => {
|
||||
if (status === 'in_use') return t('maintenance.ledger.status.inUse');
|
||||
if (status === 'disabled') return t('maintenance.ledger.status.disabled');
|
||||
if (status === 'scrapped') return t('maintenance.ledger.status.scrapped');
|
||||
if (status === 'sold') return t('maintenance.ledger.status.sold');
|
||||
return status || '-';
|
||||
});
|
||||
};
|
||||
|
||||
const rows = computed(() => {
|
||||
const recordStatusLabel = (status?: string | null) => {
|
||||
if (status === 'pending') return t('maintenance.record.status.pending');
|
||||
if (status === 'processing') return t('maintenance.record.status.processing');
|
||||
if (status === 'done') return t('maintenance.record.status.done');
|
||||
if (status === 'cancelled') return t('maintenance.record.status.cancelled');
|
||||
return status || '-';
|
||||
};
|
||||
|
||||
const displayValue = (value: DisplayCell['value']) => {
|
||||
if (value === null || value === undefined || value === '') return '-';
|
||||
return String(value);
|
||||
};
|
||||
|
||||
const firstCell = (row: DisplayCell[]): DisplayCell => row[0] || { label: '', value: '' };
|
||||
|
||||
const deviceRows = computed<DisplayCell[][]>(() => {
|
||||
const item = device.value;
|
||||
if (!item) return [];
|
||||
// 字段顺序与 LedgerConfigPanel 设备配置表单保持一致(左列优先、逐行两列)。
|
||||
return [
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.deviceCode'), value: item.deviceCode },
|
||||
@@ -57,76 +95,244 @@ const rows = computed(() => {
|
||||
],
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.modelSpec'), value: item.modelSpec },
|
||||
{ label: t('maintenance.ledger.fields.department'), value: item.department },
|
||||
{ label: t('maintenance.ledger.fields.manufacturer'), value: item.manufacturer },
|
||||
],
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.devicePosition'), value: item.installLocation },
|
||||
{ label: t('maintenance.ledger.fields.deviceStatus'), value: statusLabel.value },
|
||||
{ label: t('maintenance.ledger.fields.deviceStatus'), value: deviceStatusLabel(item.deviceStatus) },
|
||||
],
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.manufacturer'), value: item.manufacturer },
|
||||
{ label: t('maintenance.ledger.fields.startDate'), value: item.startDate },
|
||||
{ label: t('maintenance.ledger.fields.department'), value: item.department },
|
||||
{ label: t('maintenance.ledger.fields.responsibleUser'), value: item.responsibleUser },
|
||||
],
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.productionDate'), value: item.productionDate },
|
||||
{ label: t('maintenance.ledger.fields.entryDate'), value: item.entryDate },
|
||||
],
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.originalValue'), value: item.originalValue },
|
||||
{ label: t('maintenance.ledger.fields.residualValue'), value: item.residualValue },
|
||||
],
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.accountSet'), value: item.accountSet },
|
||||
],
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.remark'), value: item.remark },
|
||||
],
|
||||
];
|
||||
});
|
||||
|
||||
const latestRepairDate = computed(() => records.value[0]?.reportDate || '-');
|
||||
const totalCost = computed(() => records.value.reduce((sum, item) => {
|
||||
const value = Number(String(item.repairCost || '').replace(/[^\d.-]/g, ''));
|
||||
return Number.isFinite(value) ? sum + value : sum;
|
||||
}, 0));
|
||||
const summaryCards = computed(() => [
|
||||
{ label: t('maintenance.record.fields.deviceCode'), value: device.value?.deviceCode || payload.value?.keyword || '-' },
|
||||
{ label: t('maintenance.chat.latestRepair'), value: latestRepairDate.value },
|
||||
{ label: t('maintenance.chat.totalCount'), value: String(records.value.length) },
|
||||
{ label: t('maintenance.chat.totalCost'), value: totalCost.value ? String(totalCost.value) : '-' },
|
||||
]);
|
||||
|
||||
const recordDetailRows = (record: MaintenanceRecord): DisplayCell[] => [
|
||||
{ label: t('maintenance.record.fields.deviceCode'), value: record.deviceCode },
|
||||
{ label: t('maintenance.ledger.fields.deviceName'), value: record.deviceName },
|
||||
{ label: t('maintenance.record.fields.reportDate'), value: record.reportDate },
|
||||
{ label: t('maintenance.record.fields.repairCategory'), value: record.repairCategory },
|
||||
{ label: t('maintenance.record.fields.repairStatus'), value: recordStatusLabel(record.repairStatus) },
|
||||
{ label: t('maintenance.record.fields.faultDescription'), value: record.faultDescription },
|
||||
{ label: t('maintenance.record.fields.repairDescription'), value: record.repairDescription },
|
||||
{ label: t('maintenance.record.fields.reporter'), value: record.reporter },
|
||||
{ label: t('maintenance.record.fields.repairDate'), value: record.repairDate },
|
||||
{ label: t('maintenance.record.fields.repairUnit'), value: record.repairUnit },
|
||||
{ label: t('maintenance.record.fields.repairer'), value: record.repairer },
|
||||
{ label: t('maintenance.record.fields.approver'), value: record.approver },
|
||||
{ label: t('maintenance.record.fields.repairCost'), value: record.repairCost },
|
||||
{ label: t('maintenance.record.fields.repairHours'), value: record.repairHours },
|
||||
{ label: t('maintenance.record.fields.sourceOrderNo'), value: record.sourceOrderNo },
|
||||
{ label: t('maintenance.ledger.fields.devicePosition'), value: record.installLocation },
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section v-if="hasResult" class="mt-3 rounded-xl border border-slate-300 bg-white p-3 text-sm text-slate-800 shadow-sm">
|
||||
<div class="flex items-center justify-between gap-3 rounded-t-lg border border-slate-200 bg-slate-50 px-3 py-2">
|
||||
<h3 class="font-semibold">
|
||||
{{ device ? t('maintenance.chat.deviceLedgerInfo') : t('maintenance.chat.recordInfo') }}
|
||||
<section
|
||||
v-if="hasResult"
|
||||
class="mt-3 w-full max-w-[760px] overflow-hidden rounded-lg border border-slate-300 bg-white text-sm text-slate-800 shadow-sm"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-3 border-b border-slate-200 bg-slate-50 px-3 py-2.5">
|
||||
<h3 class="font-semibold text-slate-900">
|
||||
{{ queryMode === 'records' ? t('maintenance.chat.recordQueryResult') : t('maintenance.chat.deviceLedgerInfo') }}
|
||||
</h3>
|
||||
<span
|
||||
class="rounded-full px-2.5 py-0.5 text-xs font-semibold"
|
||||
class="shrink-0 rounded-full px-2.5 py-0.5 text-xs font-semibold"
|
||||
:class="ledgerMatched ? 'bg-emerald-50 text-emerald-700' : 'bg-amber-50 text-amber-700'"
|
||||
>
|
||||
{{ ledgerMatched ? t('maintenance.chat.matched') : t('maintenance.chat.recordMatched') }}
|
||||
{{ queryMode === 'records' ? t('maintenance.chat.returnedRecords', { count: records.length }) : t('maintenance.chat.matched') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div v-if="device" class="overflow-hidden border-x border-b border-slate-200">
|
||||
<table class="w-full table-fixed text-sm">
|
||||
<tbody>
|
||||
<tr v-for="(row, rowIndex) in rows" :key="rowIndex" class="border-t border-slate-200 first:border-t-0">
|
||||
<template v-for="cell in row" :key="cell.label">
|
||||
<th class="w-[16%] bg-slate-100 px-3 py-2 text-left font-semibold text-slate-700">{{ cell.label }}</th>
|
||||
<td class="w-[34%] px-3 py-2 text-slate-800">{{ cell.value || '-' }}</td>
|
||||
</template>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div v-if="records.length" class="mt-3 overflow-hidden rounded-lg border border-slate-200">
|
||||
<div class="bg-slate-50 px-3 py-2 text-xs font-semibold text-slate-600">
|
||||
{{ t('maintenance.chat.recentRecords', { count: records.length }) }}
|
||||
<template v-if="queryMode === 'device'">
|
||||
<div v-if="device" class="overflow-x-auto p-3">
|
||||
<table class="w-full min-w-[680px] border-collapse text-sm">
|
||||
<tbody>
|
||||
<tr v-for="(row, rowIndex) in deviceRows" :key="rowIndex">
|
||||
<template v-if="row.length === 1">
|
||||
<th class="w-[16%] border border-slate-200 bg-slate-100 px-3 py-2 text-left font-semibold text-slate-700">
|
||||
{{ firstCell(row).label }}
|
||||
</th>
|
||||
<td colspan="3" class="border border-slate-200 px-3 py-2 text-slate-900">
|
||||
{{ displayValue(firstCell(row).value) }}
|
||||
</td>
|
||||
</template>
|
||||
<template v-else>
|
||||
<template v-for="cell in row" :key="cell.label">
|
||||
<th class="w-[16%] border border-slate-200 bg-slate-100 px-3 py-2 text-left font-semibold text-slate-700">
|
||||
{{ cell.label }}
|
||||
</th>
|
||||
<td class="w-[34%] border border-slate-200 px-3 py-2 text-slate-900">
|
||||
{{ displayValue(cell.value) }}
|
||||
</td>
|
||||
</template>
|
||||
</template>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<table class="w-full text-left text-xs">
|
||||
<thead class="bg-slate-50 text-slate-500">
|
||||
<tr>
|
||||
<th class="px-3 py-2">{{ t('maintenance.record.fields.reportDate') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.record.fields.faultDescription') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.record.fields.repairer') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="record in records.slice(0, 3)" :key="record.id" class="border-t border-slate-200">
|
||||
<td class="px-3 py-2">{{ record.reportDate || '-' }}</td>
|
||||
<td class="max-w-[260px] truncate px-3 py-2">{{ record.faultDescription || '-' }}</td>
|
||||
<td class="px-3 py-2">{{ record.repairer || '-' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 flex flex-wrap gap-2">
|
||||
<button type="button" class="rounded-lg bg-brand-600 px-3 py-2 text-xs font-semibold text-white">
|
||||
{{ t('maintenance.chat.viewRepairHistory') }}
|
||||
</button>
|
||||
<button type="button" class="rounded-lg border border-slate-300 bg-white px-3 py-2 text-xs font-semibold text-slate-700">
|
||||
{{ t('maintenance.chat.addRepairRecord') }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="canManageMaintenance" class="flex flex-wrap gap-2 px-3 pb-3">
|
||||
<button
|
||||
v-if="device"
|
||||
type="button"
|
||||
class="rounded-lg bg-brand-600 px-3 py-2 text-xs font-semibold text-white transition-colors hover:bg-brand-700"
|
||||
@click="emit('view-record-history', device)"
|
||||
>
|
||||
{{ t('maintenance.chat.viewRepairHistory') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="device"
|
||||
type="button"
|
||||
class="rounded-lg border border-slate-300 bg-white px-3 py-2 text-xs font-semibold text-slate-700 transition-colors hover:bg-slate-50"
|
||||
@click="emit('create-record', device)"
|
||||
>
|
||||
{{ t('maintenance.chat.addRepairRecord') }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-else class="px-3 pb-3 text-xs text-slate-500">
|
||||
{{ t('maintenance.chat.adminActionsHidden') }}
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="grid gap-2 p-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||
<div v-for="card in summaryCards" :key="card.label" class="rounded-lg border border-dashed border-slate-300 bg-white px-3 py-2">
|
||||
<div class="text-xs text-slate-500">{{ card.label }}</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-900">{{ card.value }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="px-3 pb-3">
|
||||
<div class="overflow-hidden border border-slate-200">
|
||||
<table class="w-full table-fixed border-collapse text-left text-xs">
|
||||
<thead class="bg-slate-100 text-slate-700">
|
||||
<tr>
|
||||
<th class="w-[13%] border border-slate-200 px-2 py-2 font-semibold">{{ t('maintenance.record.fields.reportDate') }}</th>
|
||||
<th class="w-[29%] border border-slate-200 px-2 py-2 font-semibold">{{ t('maintenance.record.fields.faultDescription') }}</th>
|
||||
<th class="w-[29%] border border-slate-200 px-2 py-2 font-semibold">{{ t('maintenance.record.fields.repairDescription') }}</th>
|
||||
<th class="w-[11%] border border-slate-200 px-2 py-2 font-semibold">{{ t('maintenance.record.fields.repairStatus') }}</th>
|
||||
<th class="w-[18%] border border-slate-200 px-2 py-2 font-semibold">{{ t('maintenance.chat.operation') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="record in records" :key="record.id" class="bg-white">
|
||||
<td class="whitespace-nowrap border border-slate-200 px-2 py-2">{{ displayValue(record.reportDate) }}</td>
|
||||
<td class="border border-slate-200 px-2 py-2 align-top" :title="displayValue(record.faultDescription)">
|
||||
<span class="line-clamp-2 break-words leading-relaxed">{{ displayValue(record.faultDescription) }}</span>
|
||||
</td>
|
||||
<td class="border border-slate-200 px-2 py-2 align-top" :title="displayValue(record.repairDescription)">
|
||||
<span class="line-clamp-2 break-words leading-relaxed">{{ displayValue(record.repairDescription) }}</span>
|
||||
</td>
|
||||
<td class="border border-slate-200 px-2 py-2">
|
||||
<span
|
||||
class="inline-flex whitespace-nowrap rounded-full border px-2 py-0.5 text-xs font-semibold"
|
||||
:class="repairStatusBadgeClass(record.repairStatus)"
|
||||
>
|
||||
{{ recordStatusLabel(record.repairStatus) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="border border-slate-200 px-2 py-2">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center justify-center whitespace-nowrap rounded-md border border-brand-200 bg-brand-50 px-2 py-1 text-xs font-semibold leading-none text-brand-700 transition-colors hover:bg-brand-100"
|
||||
@click="selectedRecord = record"
|
||||
>
|
||||
{{ t('maintenance.chat.viewRecordDetail') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="canManageMaintenance"
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center justify-center whitespace-nowrap rounded-md border border-brand-200 bg-brand-50 px-2 py-1 text-xs font-semibold leading-none text-brand-700 transition-colors hover:bg-brand-100"
|
||||
@click="emit('edit-record', record)"
|
||||
>
|
||||
{{ t('maintenance.record.actions.edit') }}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="selectedRecord"
|
||||
class="fixed inset-y-0 right-0 z-50 flex flex-col border-l border-slate-200 bg-white shadow-2xl"
|
||||
:style="recordDetailPanelStyle"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3 border-b border-slate-200 px-5 py-4">
|
||||
<div>
|
||||
<h3 class="text-base font-semibold text-slate-900">{{ t('maintenance.chat.recordDetailTitle') }}</h3>
|
||||
<p class="mt-1 text-xs text-slate-500">{{ t('maintenance.chat.recordDetailHint') }}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-8 w-8 items-center justify-center rounded-lg border border-slate-200 text-slate-500 transition-colors hover:bg-slate-50 hover:text-slate-700"
|
||||
@click="selectedRecord = null"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto px-4 py-4">
|
||||
<div class="mb-4 rounded-lg border border-dashed border-brand-300 bg-brand-50 px-3 py-2 text-xs text-brand-700">
|
||||
{{ t('maintenance.chat.recordDetailPermissionHint') }}
|
||||
</div>
|
||||
<dl class="overflow-hidden border border-slate-200 text-sm">
|
||||
<div
|
||||
v-for="detail in recordDetailRows(selectedRecord)"
|
||||
:key="detail.label"
|
||||
class="grid grid-cols-[118px_minmax(0,1fr)] border-b border-slate-200 last:border-b-0"
|
||||
>
|
||||
<dt class="bg-slate-100 px-3 py-2 font-semibold text-slate-700">{{ detail.label }}</dt>
|
||||
<dd class="min-w-0 break-words px-3 py-2 text-slate-900">{{ displayValue(detail.value) }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="canManageMaintenance" class="flex flex-wrap gap-2 px-3 pb-3">
|
||||
<button
|
||||
v-if="device"
|
||||
type="button"
|
||||
class="rounded-lg border border-slate-300 bg-white px-3 py-2 text-xs font-semibold text-slate-700 transition-colors hover:bg-slate-50"
|
||||
@click="emit('create-record', device)"
|
||||
>
|
||||
{{ t('maintenance.chat.addRepairRecord') }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-else class="px-3 pb-3 text-xs text-slate-500">
|
||||
{{ t('maintenance.chat.adminActionsHidden') }}
|
||||
</p>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
Reference in new issue
Block a user