feat(equipment-maintenance): 设备维保助手相关功能
This commit is contained in:
1 parent
599475d4e2
commit
0f3f40e735
39 files changed
+6554
-6
No files matched your search
@@ -39,6 +39,7 @@ const props = defineProps<{
|
||||
isUploadingAttachments: boolean;
|
||||
canSendMessage: boolean;
|
||||
isShippingNoticeAgent: boolean;
|
||||
isMaintenanceAgent?: boolean;
|
||||
shippingSuggestedPrompt: string;
|
||||
shippingFocusTaskNo?: string;
|
||||
shippingFocusReason?: string;
|
||||
@@ -56,6 +57,8 @@ const emit = defineEmits<{
|
||||
'add-remote-url': [url: string];
|
||||
'shipping-inventory-selected': [event: Event];
|
||||
'use-shipping-suggested-prompt': [];
|
||||
'maintenance-ledger-config': [];
|
||||
'maintenance-create-record': [];
|
||||
'clear-shipping-focus': [];
|
||||
}>();
|
||||
|
||||
@@ -253,6 +256,27 @@ watch(
|
||||
<span>点发送开始处理</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="isMaintenanceAgent"
|
||||
class="flex flex-wrap items-center gap-2 px-3 pb-1 text-xs text-muted"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-full border border-default bg-surface-soft px-3 py-1 font-medium text-secondary transition-colors hover:bg-surface-soft/70"
|
||||
@click="emit('maintenance-create-record')"
|
||||
>
|
||||
{{ $t('maintenance.panel.recordTitle') }}
|
||||
</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-ledger-config')"
|
||||
>
|
||||
▦ {{ $t('maintenance.panel.ledgerTitle') }}
|
||||
</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
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Loader2 } from 'lucide-vue-next';
|
||||
import { Maximize2, Minimize2, Loader2 } from 'lucide-vue-next';
|
||||
import ChatShell from '@/shared/layouts/ChatShell.vue';
|
||||
import ChatSidebar from '@/features/chat/components/ChatSidebar.vue';
|
||||
import ChatInputBar from '@/features/chat/components/ChatInputBar.vue';
|
||||
@@ -16,17 +16,63 @@ import ChatBrowserPanel from '@/features/chat/components/ChatBrowserPanel.vue';
|
||||
import ShippingBatchProgressPanel from '@/features/chat/components/ShippingBatchProgressPanel.vue';
|
||||
import ShippingBatchWorkspaceDrawer from '@/features/chat/components/ShippingBatchWorkspaceDrawer.vue';
|
||||
import TrainingWorkspacePanel from '@/features/chat/components/TrainingWorkspacePanel.vue';
|
||||
import LedgerConfigPanel from '@/features/maintenance/components/LedgerConfigPanel.vue';
|
||||
import MaintenanceRecordManagerPanel from '@/features/maintenance/components/MaintenanceRecordManagerPanel.vue';
|
||||
import { useChatPageContext } from '@/features/chat/composables/chat.context';
|
||||
import { matchesTrainingAgent } from '@/features/chat/composables/useTrainingWorkspace';
|
||||
|
||||
const page = useChatPageContext();
|
||||
const isTrainingAgentPage = computed(() => matchesTrainingAgent(page.currentAgent));
|
||||
const isMaintenanceAgentPage = computed(() => {
|
||||
const name = String(page.currentAgent?.name || '').trim();
|
||||
return name === '设备维保助手' || (name.includes('设备维保') && name.includes('助手'));
|
||||
});
|
||||
const hideWelcomePanel = computed(() => isTrainingAgentPage.value);
|
||||
const isTrainingWorkspaceExpanded = ref(false);
|
||||
const maintenancePanel = ref<'ledger' | 'record' | null>(null);
|
||||
const maintenancePanelWidth = ref(560);
|
||||
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',
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* 开始拖拽设备维保右侧面板左边缘,允许管理员按表格内容临时调宽。
|
||||
* @param event - 鼠标按下事件。
|
||||
*/
|
||||
const startMaintenancePanelResize = (event: MouseEvent): void => {
|
||||
if (isMaintenancePanelFullscreen.value) return;
|
||||
event.preventDefault();
|
||||
isMaintenancePanelResizing.value = true;
|
||||
const startX = event.clientX;
|
||||
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));
|
||||
};
|
||||
const stopResize = () => {
|
||||
isMaintenancePanelResizing.value = false;
|
||||
window.removeEventListener('mousemove', handleMove);
|
||||
window.removeEventListener('mouseup', stopResize);
|
||||
};
|
||||
window.addEventListener('mousemove', handleMove);
|
||||
window.addEventListener('mouseup', stopResize);
|
||||
};
|
||||
|
||||
// 切换 Agent 时,重置工作区展开状态,确保每次进入都是收起状态(聊天优先)
|
||||
watch(() => page.currentAgentId, () => {
|
||||
isTrainingWorkspaceExpanded.value = false;
|
||||
maintenancePanel.value = null;
|
||||
isMaintenancePanelFullscreen.value = false;
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -170,6 +216,7 @@ watch(() => page.currentAgentId, () => {
|
||||
:is-uploading-attachments="page.isUploadingAttachments"
|
||||
:can-send-message="page.canSendMessage"
|
||||
:is-shipping-notice-agent="page.isShippingNoticeAgent"
|
||||
:is-maintenance-agent="isMaintenanceAgentPage"
|
||||
:shipping-suggested-prompt="page.shippingSuggestedPrompt"
|
||||
:shipping-focus-task-no="page.focusedShippingTaskNo"
|
||||
:shipping-focus-reason="page.shippingFocusReason"
|
||||
@@ -183,10 +230,63 @@ watch(() => page.currentAgentId, () => {
|
||||
@add-remote-url="page.addRemoteUrlAttachment"
|
||||
@shipping-inventory-selected="page.handleShippingInventorySelected"
|
||||
@use-shipping-suggested-prompt="page.useShippingSuggestedPrompt"
|
||||
@maintenance-ledger-config="maintenancePanel = 'ledger'"
|
||||
@maintenance-create-record="maintenancePanel = 'record'"
|
||||
@clear-shipping-focus="page.clearShippingFocus"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<aside
|
||||
v-if="isMaintenanceAgentPage && maintenancePanel"
|
||||
class="relative flex flex-col border-l border-default bg-surface shadow-[-8px_0_24px_rgba(15,23,42,0.06)]"
|
||||
:class="[
|
||||
isMaintenancePanelFullscreen ? 'absolute inset-y-0 right-0 z-30' : '',
|
||||
isMaintenancePanelResizing ? 'select-none' : '',
|
||||
]"
|
||||
:style="maintenancePanelStyle"
|
||||
>
|
||||
<button
|
||||
v-if="!isMaintenancePanelFullscreen"
|
||||
type="button"
|
||||
class="absolute inset-y-0 left-[-4px] z-10 w-2 cursor-col-resize bg-transparent hover:bg-brand-200/60"
|
||||
:title="$t('maintenance.panel.resizeTitle')"
|
||||
@mousedown="startMaintenancePanelResize"
|
||||
/>
|
||||
<div class="flex items-start justify-between gap-3 border-b border-default px-4 py-3">
|
||||
<div>
|
||||
<h2 class="text-base font-semibold text-primary">
|
||||
{{ maintenancePanel === 'ledger' ? $t('maintenance.panel.ledgerTitle') : $t('maintenance.panel.recordTitle') }}
|
||||
</h2>
|
||||
<p class="mt-1 text-xs text-secondary">
|
||||
{{ maintenancePanel === 'ledger' ? $t('maintenance.panel.ledgerSubtitle') : $t('maintenance.panel.recordSubtitle') }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-8 w-8 items-center justify-center rounded-lg border border-default text-secondary hover:bg-surface-soft"
|
||||
:title="isMaintenancePanelFullscreen ? $t('maintenance.panel.exitFullscreen') : $t('maintenance.panel.fullscreen')"
|
||||
@click="isMaintenancePanelFullscreen = !isMaintenancePanelFullscreen"
|
||||
>
|
||||
<Minimize2 v-if="isMaintenancePanelFullscreen" class="h-4 w-4" />
|
||||
<Maximize2 v-else class="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-8 w-8 items-center justify-center rounded-lg border border-default text-sm text-secondary hover:bg-surface-soft"
|
||||
:title="$t('maintenance.panel.close')"
|
||||
@click="maintenancePanel = null"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="min-h-0 flex-1 overflow-auto p-4">
|
||||
<LedgerConfigPanel v-if="maintenancePanel === 'ledger'" />
|
||||
<MaintenanceRecordManagerPanel v-else />
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<ChatBrowserPanel
|
||||
v-model:open="page.browserPanelOpen"
|
||||
v-model:draft-url="page.browserDraftUrl"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Check, Copy, Download, Edit2, Eye, LayoutGrid, MessageSquareText, RotateCw, X } from 'lucide-vue-next';
|
||||
import LeaveMessageBlock, { type LeaveMessageHandlers } from './LeaveMessageBlock.vue';
|
||||
import MaintenanceDeviceResultCard from './MaintenanceDeviceResultCard.vue';
|
||||
import ShippingInventoryMappingMessage, { type ShippingMappingHandlers } from './ShippingInventoryMappingMessage.vue';
|
||||
import ShippingMatchResultCard from './ShippingMatchResultCard.vue';
|
||||
import ShippingParseReviewMessage, { type ShippingParseReviewHandlers } from './ShippingParseReviewMessage.vue';
|
||||
@@ -514,6 +515,10 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
:action-button-class="handlers.shippingActionButtonClass"
|
||||
:on-action-click="(action) => handlers.onShippingActionClick(message, action)"
|
||||
/>
|
||||
<MaintenanceDeviceResultCard
|
||||
v-else-if="message.type === 'maintenance-device-result'"
|
||||
:message="message"
|
||||
/>
|
||||
<TrainingExamQuestionMessage
|
||||
v-else-if="isTrainingExamMessage && trainingHandlers.getQuestion()"
|
||||
:question="trainingHandlers.getQuestion()!"
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* features/chat/components/messages/MaintenanceDeviceResultCard.vue
|
||||
* 用途:设备维保助手会话中的设备台账查询结果卡片。
|
||||
* 依赖:chat.types、ledger/record 类型、vue-i18n。
|
||||
* 逻辑:后端返回 maintenance-device-result payload 后,本组件按原型展示设备基础信息、匹配状态和快捷操作。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
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';
|
||||
|
||||
interface MaintenanceDeviceResultPayload {
|
||||
matched?: boolean;
|
||||
device?: MaintenanceDevice;
|
||||
records?: MaintenanceRecord[];
|
||||
actions?: Array<{ id: string; label: string }>;
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
message: ChatMessage;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const payload = computed<MaintenanceDeviceResultPayload | null>(() => {
|
||||
const raw = props.message.payload;
|
||||
if (!raw || typeof raw !== 'object') return null;
|
||||
return raw as MaintenanceDeviceResultPayload;
|
||||
});
|
||||
|
||||
const device = computed(() => payload.value?.device || null);
|
||||
const records = computed(() => payload.value?.records || []);
|
||||
|
||||
const statusLabel = computed(() => {
|
||||
const status = device.value?.deviceStatus;
|
||||
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 item = device.value;
|
||||
if (!item) return [];
|
||||
return [
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.deviceCode'), value: item.deviceCode },
|
||||
{ label: t('maintenance.ledger.fields.deviceName'), value: item.deviceName },
|
||||
],
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.modelSpec'), value: item.modelSpec },
|
||||
{ label: t('maintenance.ledger.fields.department'), value: item.department },
|
||||
],
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.devicePosition'), value: item.installLocation },
|
||||
{ label: t('maintenance.ledger.fields.deviceStatus'), value: statusLabel.value },
|
||||
],
|
||||
[
|
||||
{ label: t('maintenance.ledger.fields.manufacturer'), value: item.manufacturer },
|
||||
{ label: t('maintenance.ledger.fields.startDate'), value: item.startDate },
|
||||
],
|
||||
];
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section v-if="device" 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">{{ t('maintenance.chat.deviceLedgerInfo') }}</h3>
|
||||
<span class="rounded-full bg-emerald-50 px-2.5 py-0.5 text-xs font-semibold text-emerald-700">
|
||||
{{ t('maintenance.chat.matched') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div 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 }) }}
|
||||
</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>
|
||||
</section>
|
||||
</template>
|
||||
@@ -21,7 +21,7 @@ export interface RetrieverResource {
|
||||
export interface ChatMessage {
|
||||
role: 'user' | 'assistant';
|
||||
content: string;
|
||||
type?: 'text' | 'leave-form' | 'leave-confirmation' | 'leave-result' | 'shipping-inventory-mapping' | 'shipping-parse-review' | 'shipping-match-result';
|
||||
type?: 'text' | 'leave-form' | 'leave-confirmation' | 'leave-result' | 'shipping-inventory-mapping' | 'shipping-parse-review' | 'shipping-match-result' | 'maintenance-device-result';
|
||||
retriever_resources?: RetrieverResource[];
|
||||
attribution_parts?: string[];
|
||||
chat_log_id?: number;
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* features/maintenance/api/maintenanceLedger.api.ts
|
||||
* 用途:设备维保台账配置 HTTP API 封装。
|
||||
* 依赖:shared/api/client、shared/utils/auth、ledger.types。
|
||||
* 逻辑:右侧固定面板通过本模块加载列表、保存设备、下载模板和导入 Excel。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import type {
|
||||
MaintenanceDevice,
|
||||
MaintenanceDeviceImportResult,
|
||||
MaintenanceDeviceListResult,
|
||||
MaintenanceDevicePayload,
|
||||
} from '@/features/maintenance/types/ledger.types';
|
||||
|
||||
const API_BASE = '/api/maintenance/ledger';
|
||||
|
||||
export interface ListMaintenanceDevicesParams {
|
||||
keyword?: string;
|
||||
status?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
const jsonHeaders = () => ({
|
||||
...getAuthHeaders(),
|
||||
'Content-Type': 'application/json',
|
||||
});
|
||||
|
||||
export const listMaintenanceDevices = (params: ListMaintenanceDevicesParams = {}) => {
|
||||
const sp = new URLSearchParams();
|
||||
if (params.keyword) sp.set('keyword', params.keyword);
|
||||
if (params.status) sp.set('status', params.status);
|
||||
if (params.page) sp.set('page', String(params.page));
|
||||
if (params.pageSize) sp.set('page_size', String(params.pageSize));
|
||||
const qs = sp.toString();
|
||||
return requestJson<MaintenanceDeviceListResult>(`${API_BASE}/devices${qs ? `?${qs}` : ''}`, {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
};
|
||||
|
||||
export const getMaintenanceDevice = (id: number) => {
|
||||
return requestJson<MaintenanceDevice>(`${API_BASE}/devices/${id}`, {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
};
|
||||
|
||||
export const createMaintenanceDevice = (payload: MaintenanceDevicePayload) => {
|
||||
return requestJson<MaintenanceDevice>(`${API_BASE}/devices`, {
|
||||
method: 'POST',
|
||||
headers: jsonHeaders(),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
};
|
||||
|
||||
export const updateMaintenanceDevice = (id: number, payload: MaintenanceDevicePayload) => {
|
||||
return requestJson<MaintenanceDevice>(`${API_BASE}/devices/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: jsonHeaders(),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
};
|
||||
|
||||
export const maintenanceLedgerImportTemplateUrl = `${API_BASE}/import-template`;
|
||||
|
||||
export const importMaintenanceDevices = (file: File) => {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
return requestJson<MaintenanceDeviceImportResult>(`${API_BASE}/import`, {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders(),
|
||||
body: form,
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* features/maintenance/api/maintenanceRecord.api.ts
|
||||
* 用途:设备维修记录 HTTP API 封装。
|
||||
* 依赖:shared/api/client、shared/utils/auth、record.types。
|
||||
* 逻辑:右侧固定面板通过本模块新增记录和查询最近记录;会话查询也可复用同一后端接口。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import type {
|
||||
MaintenanceRecord,
|
||||
MaintenanceRecordListResult,
|
||||
MaintenanceRecordPayload,
|
||||
} from '@/features/maintenance/types/record.types';
|
||||
|
||||
const API_BASE = '/api/maintenance/records';
|
||||
|
||||
export interface ListMaintenanceRecordsParams {
|
||||
keyword?: string;
|
||||
deviceCode?: string;
|
||||
status?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
const jsonHeaders = () => ({
|
||||
...getAuthHeaders(),
|
||||
'Content-Type': 'application/json',
|
||||
});
|
||||
|
||||
export const listMaintenanceRecords = (params: ListMaintenanceRecordsParams = {}) => {
|
||||
const sp = new URLSearchParams();
|
||||
if (params.keyword) sp.set('keyword', params.keyword);
|
||||
if (params.deviceCode) sp.set('deviceCode', params.deviceCode);
|
||||
if (params.status) sp.set('status', params.status);
|
||||
if (params.page) sp.set('page', String(params.page));
|
||||
if (params.pageSize) sp.set('page_size', String(params.pageSize));
|
||||
const qs = sp.toString();
|
||||
return requestJson<MaintenanceRecordListResult>(`${API_BASE}${qs ? `?${qs}` : ''}`, {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
};
|
||||
|
||||
export const getMaintenanceRecord = (id: number) => {
|
||||
return requestJson<MaintenanceRecord>(`${API_BASE}/${id}`, {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
};
|
||||
|
||||
export const createMaintenanceRecord = (payload: MaintenanceRecordPayload) => {
|
||||
return requestJson<MaintenanceRecord>(API_BASE, {
|
||||
method: 'POST',
|
||||
headers: jsonHeaders(),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
};
|
||||
|
||||
export const updateMaintenanceRecord = (id: number, payload: MaintenanceRecordPayload) => {
|
||||
return requestJson<MaintenanceRecord>(`${API_BASE}/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: jsonHeaders(),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteMaintenanceRecord = (id: number) => {
|
||||
return requestJson<{ deleted: boolean; id: number }>(`${API_BASE}/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
};
|
||||
|
||||
export const exportMaintenanceRecords = async (params: ListMaintenanceRecordsParams = {}) => {
|
||||
const sp = new URLSearchParams();
|
||||
if (params.keyword) sp.set('keyword', params.keyword);
|
||||
if (params.deviceCode) sp.set('deviceCode', params.deviceCode);
|
||||
if (params.status) sp.set('status', params.status);
|
||||
const qs = sp.toString();
|
||||
const response = await fetch(`${API_BASE}/export${qs ? `?${qs}` : ''}`, {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
return response.blob();
|
||||
};
|
||||
@@ -0,0 +1,459 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/maintenance/components/LedgerConfigPanel.vue
|
||||
* 用途:设备维保助手右侧固定面板中的“台账配置”页面,包含设备列表与设备配置两个 Tab。
|
||||
* 依赖:maintenanceLedger.api、PaginationBar、useMessage。
|
||||
* 逻辑:列表 Tab 负责查询/导入/选择设备;配置 Tab 负责新增或编辑设备台账,保存后刷新列表。
|
||||
*/
|
||||
import { computed, onMounted, reactive, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
createMaintenanceDevice,
|
||||
importMaintenanceDevices,
|
||||
listMaintenanceDevices,
|
||||
maintenanceLedgerImportTemplateUrl,
|
||||
updateMaintenanceDevice,
|
||||
} from '@/features/maintenance/api/maintenanceLedger.api';
|
||||
import type {
|
||||
MaintenanceDevice,
|
||||
MaintenanceDeviceImportResult,
|
||||
MaintenanceDevicePayload,
|
||||
MaintenanceDeviceStatus,
|
||||
} from '@/features/maintenance/types/ledger.types';
|
||||
|
||||
type TabName = 'list' | 'form';
|
||||
|
||||
const msg = useMessage();
|
||||
const { t } = useI18n();
|
||||
const activeTab = ref<TabName>('list');
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const importing = ref(false);
|
||||
const devices = ref<MaintenanceDevice[]>([]);
|
||||
const total = ref(0);
|
||||
const page = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const keyword = ref('');
|
||||
const status = ref('');
|
||||
const editingId = ref<number | null>(null);
|
||||
const importResult = ref<MaintenanceDeviceImportResult | null>(null);
|
||||
const MAX_IMPORT_FILE_SIZE = 10 * 1024 * 1024;
|
||||
const DEFAULT_ACCOUNT_SET = '和信';
|
||||
const accountSetOptions = ['和信', '科技', '电子', '和宏智'];
|
||||
|
||||
const form = reactive<MaintenanceDevicePayload>({
|
||||
deviceCode: '',
|
||||
deviceName: '',
|
||||
modelSpec: '',
|
||||
department: '',
|
||||
installLocation: '',
|
||||
deviceStatus: 'in_use',
|
||||
manufacturer: '',
|
||||
entryDate: '',
|
||||
productionDate: '',
|
||||
startDate: '',
|
||||
responsibleUser: '',
|
||||
maintenanceCycle: '',
|
||||
originalValue: '',
|
||||
residualValue: '',
|
||||
accountSet: DEFAULT_ACCOUNT_SET,
|
||||
remark: '',
|
||||
});
|
||||
|
||||
const statusOptions: Array<{ value: MaintenanceDeviceStatus | ''; label: string }> = [
|
||||
{ value: '', label: 'maintenance.ledger.status.all' },
|
||||
{ value: 'in_use', label: 'maintenance.ledger.status.inUse' },
|
||||
{ value: 'disabled', label: 'maintenance.ledger.status.disabled' },
|
||||
{ value: 'scrapped', label: 'maintenance.ledger.status.scrapped' },
|
||||
{ value: 'sold', label: 'maintenance.ledger.status.sold' },
|
||||
];
|
||||
|
||||
const formTitle = computed(() => t(editingId.value ? 'maintenance.ledger.formTitle.edit' : 'maintenance.ledger.formTitle.create'));
|
||||
|
||||
/**
|
||||
* 将后端状态值转换为中文展示。
|
||||
* @param value - 设备状态值。
|
||||
* @returns 中文状态。
|
||||
*/
|
||||
const formatStatus = (value: string): string => {
|
||||
const item = statusOptions.find((option) => option.value === value);
|
||||
return item?.label ? t(item.label) : value || '-';
|
||||
};
|
||||
|
||||
/**
|
||||
* 从表单状态生成 API payload,集中裁剪字符串。
|
||||
* @returns 设备保存入参。
|
||||
*/
|
||||
const buildPayload = (): MaintenanceDevicePayload => ({
|
||||
deviceCode: form.deviceCode.trim(),
|
||||
deviceName: form.deviceName.trim(),
|
||||
modelSpec: form.modelSpec?.trim(),
|
||||
department: form.department?.trim(),
|
||||
installLocation: form.installLocation?.trim(),
|
||||
deviceStatus: form.deviceStatus,
|
||||
manufacturer: form.manufacturer?.trim(),
|
||||
entryDate: form.entryDate || undefined,
|
||||
productionDate: form.productionDate || undefined,
|
||||
startDate: form.startDate || undefined,
|
||||
responsibleUser: form.responsibleUser?.trim(),
|
||||
maintenanceCycle: form.maintenanceCycle?.trim(),
|
||||
originalValue: form.originalValue?.trim(),
|
||||
residualValue: form.residualValue?.trim(),
|
||||
accountSet: form.accountSet?.trim(),
|
||||
remark: form.remark?.trim(),
|
||||
});
|
||||
|
||||
/**
|
||||
* 加载设备台账分页列表。
|
||||
* 核心逻辑:根据当前 keyword/status/page/pageSize 调用后端,刷新列表 Tab。
|
||||
*/
|
||||
const loadDevices = async (): Promise<void> => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const result = await listMaintenanceDevices({
|
||||
keyword: keyword.value.trim(),
|
||||
status: status.value,
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
});
|
||||
devices.value = result.items;
|
||||
total.value = result.total;
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || t('maintenance.ledger.messages.loadFailed'));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置表单并切换到新增模式。
|
||||
*/
|
||||
const startCreate = (): void => {
|
||||
editingId.value = null;
|
||||
Object.assign(form, {
|
||||
deviceCode: '',
|
||||
deviceName: '',
|
||||
modelSpec: '',
|
||||
department: '',
|
||||
installLocation: '',
|
||||
deviceStatus: 'in_use',
|
||||
manufacturer: '',
|
||||
entryDate: '',
|
||||
productionDate: '',
|
||||
startDate: '',
|
||||
responsibleUser: '',
|
||||
maintenanceCycle: '',
|
||||
originalValue: '',
|
||||
residualValue: '',
|
||||
accountSet: DEFAULT_ACCOUNT_SET,
|
||||
remark: '',
|
||||
});
|
||||
activeTab.value = 'form';
|
||||
};
|
||||
|
||||
/**
|
||||
* 将选中设备带入表单并切换到配置 Tab。
|
||||
* @param device - 列表中选中的设备。
|
||||
*/
|
||||
const startEdit = (device: MaintenanceDevice): void => {
|
||||
editingId.value = device.id;
|
||||
Object.assign(form, {
|
||||
deviceCode: device.deviceCode || '',
|
||||
deviceName: device.deviceName || '',
|
||||
modelSpec: device.modelSpec || '',
|
||||
department: device.department || '',
|
||||
installLocation: device.installLocation || '',
|
||||
deviceStatus: device.deviceStatus,
|
||||
manufacturer: device.manufacturer || '',
|
||||
entryDate: device.entryDate || '',
|
||||
productionDate: device.productionDate || '',
|
||||
startDate: device.startDate || '',
|
||||
responsibleUser: device.responsibleUser || '',
|
||||
maintenanceCycle: device.maintenanceCycle || '',
|
||||
originalValue: device.originalValue != null ? String(device.originalValue) : '',
|
||||
residualValue: device.residualValue != null ? String(device.residualValue) : '',
|
||||
accountSet: device.accountSet || '',
|
||||
remark: device.remark || '',
|
||||
});
|
||||
activeTab.value = 'form';
|
||||
};
|
||||
|
||||
/**
|
||||
* 保存设备台账配置。
|
||||
* 核心逻辑:新增/编辑共用同一表单;保存成功后刷新列表并回到设备列表 Tab。
|
||||
*/
|
||||
const saveDevice = async (): Promise<void> => {
|
||||
const payload = buildPayload();
|
||||
if (!payload.deviceCode || !payload.deviceName) {
|
||||
msg.warning(t('maintenance.ledger.messages.required'));
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
if (editingId.value) {
|
||||
await updateMaintenanceDevice(editingId.value, payload);
|
||||
} else {
|
||||
await createMaintenanceDevice(payload);
|
||||
}
|
||||
msg.success(t('maintenance.ledger.messages.saved'));
|
||||
activeTab.value = 'list';
|
||||
await loadDevices();
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || t('maintenance.ledger.messages.saveFailed'));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 校验设备台账导入文件,避免明显不符合要求的文件进入后端解析。
|
||||
* @param file - 用户选择的 Excel 文件。
|
||||
* @returns 校验是否通过。
|
||||
*/
|
||||
const validateImportFile = (file: File): boolean => {
|
||||
const fileName = file.name.toLowerCase();
|
||||
if (!fileName.endsWith('.xlsx')) {
|
||||
msg.warning(t('maintenance.ledger.messages.invalidFormat'));
|
||||
return false;
|
||||
}
|
||||
if (file.size > MAX_IMPORT_FILE_SIZE) {
|
||||
msg.warning(t('maintenance.ledger.messages.fileTooLarge'));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 上传 Excel 模板并导入设备台账。
|
||||
* @param event - 文件选择事件。
|
||||
*/
|
||||
const onImportFileChange = async (event: Event): Promise<void> => {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
input.value = '';
|
||||
if (!file) return;
|
||||
if (!validateImportFile(file)) return;
|
||||
importing.value = true;
|
||||
try {
|
||||
importResult.value = await importMaintenanceDevices(file);
|
||||
msg.success(t('maintenance.ledger.messages.importDone'));
|
||||
await loadDevices();
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || t('maintenance.ledger.messages.importFailed'));
|
||||
} finally {
|
||||
importing.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(loadDevices);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="flex h-full min-h-0 flex-col">
|
||||
<div class="mb-4 rounded-xl border border-sky-200 bg-sky-50 px-3 py-2 text-sm text-sky-800">
|
||||
{{ t('maintenance.ledger.notice') }}
|
||||
</div>
|
||||
|
||||
<div class="mb-4 flex rounded-xl border border-default bg-muted/30 p-1">
|
||||
<button
|
||||
type="button"
|
||||
class="relative flex-1 cursor-pointer rounded-lg border px-3 py-2 text-sm font-semibold transition-all hover:bg-surface hover:text-brand"
|
||||
:class="activeTab === 'list' ? 'border-brand-300 bg-surface text-brand shadow-sm after:absolute after:inset-x-6 after:bottom-0 after:h-0.5 after:rounded-full after:bg-brand' : 'border-transparent text-secondary'"
|
||||
:aria-selected="activeTab === 'list'"
|
||||
@click="activeTab = 'list'"
|
||||
>
|
||||
{{ t('maintenance.ledger.tabs.list') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="relative flex-1 cursor-pointer rounded-lg border px-3 py-2 text-sm font-semibold transition-all hover:bg-surface hover:text-brand"
|
||||
:class="activeTab === 'form' ? 'border-brand-300 bg-surface text-brand shadow-sm after:absolute after:inset-x-6 after:bottom-0 after:h-0.5 after:rounded-full after:bg-brand' : 'border-transparent text-secondary'"
|
||||
:aria-selected="activeTab === 'form'"
|
||||
@click="activeTab = 'form'"
|
||||
>
|
||||
{{ t('maintenance.ledger.tabs.form') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="activeTab === 'list'" class="flex min-h-0 flex-1 flex-col gap-4">
|
||||
<div class="flex flex-wrap gap-3">
|
||||
<input
|
||||
v-model="keyword"
|
||||
class="admin-table-filter-input w-full md:w-[360px] lg:w-[420px]"
|
||||
:placeholder="t('maintenance.ledger.filters.keywordPlaceholder')"
|
||||
@keyup.enter="page = 1; loadDevices()"
|
||||
/>
|
||||
<select v-model="status" class="admin-table-filter-input w-full md:w-[150px]" @change="page = 1; loadDevices()">
|
||||
<option v-for="item in statusOptions" :key="item.value || 'all'" :value="item.value">
|
||||
{{ t(item.label) }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button type="button" class="admin-report-page-btn admin-report-page-btn--active" @click="page = 1; loadDevices()">
|
||||
{{ t('maintenance.ledger.actions.search') }}
|
||||
</button>
|
||||
<button type="button" class="admin-report-page-btn" @click="startCreate">
|
||||
{{ t('maintenance.ledger.actions.create') }}
|
||||
</button>
|
||||
<a class="admin-report-page-btn" :href="maintenanceLedgerImportTemplateUrl" target="_blank">
|
||||
{{ t('maintenance.ledger.actions.downloadTemplate') }}
|
||||
</a>
|
||||
<label class="admin-report-page-btn cursor-pointer">
|
||||
{{ importing ? t('maintenance.ledger.actions.importing') : t('maintenance.ledger.actions.importExcel') }}
|
||||
<input type="file" class="hidden" accept=".xlsx" :disabled="importing" @change="onImportFileChange" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div v-if="importResult" class="rounded-xl border border-default bg-surface px-3 py-2 text-sm">
|
||||
{{ t('maintenance.ledger.importResult', importResult) }}
|
||||
<div v-if="importResult.errors.length" class="mt-2 text-danger">
|
||||
<div v-for="err in importResult.errors.slice(0, 5)" :key="`${err.row}-${err.message}`">
|
||||
{{ t('maintenance.ledger.importErrorRow', err) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="min-h-0 overflow-auto rounded-xl border border-default bg-surface">
|
||||
<table class="min-w-full text-left text-sm">
|
||||
<thead class="bg-muted/50 text-secondary">
|
||||
<tr>
|
||||
<th class="px-3 py-2">{{ t('maintenance.ledger.table.deviceCode') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.ledger.table.deviceName') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.ledger.table.modelSpec') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.ledger.table.manufacturer') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.ledger.table.status') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.ledger.table.operation') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="loading">
|
||||
<td colspan="6" class="px-3 py-8 text-center text-secondary">{{ t('maintenance.ledger.table.loading') }}</td>
|
||||
</tr>
|
||||
<tr v-else-if="!devices.length">
|
||||
<td colspan="6" class="px-3 py-8 text-center text-secondary">{{ t('maintenance.ledger.table.empty') }}</td>
|
||||
</tr>
|
||||
<tr v-for="device in devices" v-else :key="device.id" class="border-t border-default">
|
||||
<td class="px-3 py-2 font-semibold">{{ device.deviceCode }}</td>
|
||||
<td class="px-3 py-2">{{ device.deviceName }}</td>
|
||||
<td class="px-3 py-2">{{ device.modelSpec || '-' }}</td>
|
||||
<td class="px-3 py-2">{{ device.manufacturer || '-' }}</td>
|
||||
<td class="px-3 py-2">{{ formatStatus(device.deviceStatus) }}</td>
|
||||
<td class="px-3 py-2">
|
||||
<button type="button" class="admin-report-page-btn" @click="startEdit(device)">
|
||||
{{ t('maintenance.ledger.actions.edit') }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<PaginationBar
|
||||
v-model:page="page"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
@update:page="loadDevices"
|
||||
@update:page-size="loadDevices"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-else class="min-h-0 flex-1 overflow-auto">
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h3 class="text-base font-semibold text-primary">{{ formTitle }}</h3>
|
||||
<button type="button" class="admin-report-page-btn" @click="activeTab = 'list'">{{ t('maintenance.ledger.actions.backToList') }}</button>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.deviceCode') }} *
|
||||
<input v-model="form.deviceCode" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.deviceName') }} *
|
||||
<input v-model="form.deviceName" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.modelSpec') }}
|
||||
<input v-model="form.modelSpec" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.manufacturer') }}
|
||||
<input v-model="form.manufacturer" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.devicePosition') }}
|
||||
<input v-model="form.installLocation" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.deviceStatus') }}
|
||||
<select v-model="form.deviceStatus" class="admin-table-filter-input">
|
||||
<option value="in_use">{{ t('maintenance.ledger.status.inUse') }}</option>
|
||||
<option value="disabled">{{ t('maintenance.ledger.status.disabled') }}</option>
|
||||
<option value="scrapped">{{ t('maintenance.ledger.status.scrapped') }}</option>
|
||||
<option value="sold">{{ t('maintenance.ledger.status.sold') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.department') }}
|
||||
<input v-model="form.department" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.responsibleUser') }}
|
||||
<input v-model="form.responsibleUser" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.productionDate') }}
|
||||
<input v-model="form.productionDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.entryDate') }}
|
||||
<input v-model="form.entryDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.startDate') }}
|
||||
<input v-model="form.startDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.maintenanceCycle') }}
|
||||
<input v-model="form.maintenanceCycle" class="admin-table-filter-input" :placeholder="t('maintenance.ledger.placeholder.maintenanceCycle')" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.originalValue') }}
|
||||
<input v-model="form.originalValue" type="number" min="0" step="0.01" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.residualValue') }}
|
||||
<input v-model="form.residualValue" type="number" min="0" step="0.01" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.ledger.fields.accountSet') }}
|
||||
<select v-model="form.accountSet" class="admin-table-filter-input">
|
||||
<option v-for="item in accountSetOptions" :key="item" :value="item">
|
||||
{{ item }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary md:col-span-2">
|
||||
{{ t('maintenance.ledger.fields.remark') }}
|
||||
<textarea v-model="form.remark" class="admin-table-filter-input min-h-24" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="mt-5 flex justify-end gap-2">
|
||||
<button type="button" class="admin-report-page-btn" @click="activeTab = 'list'">{{ t('maintenance.ledger.actions.cancel') }}</button>
|
||||
<button
|
||||
type="button"
|
||||
class="admin-report-page-btn admin-report-page-btn--active"
|
||||
:disabled="saving"
|
||||
@click="saveDevice"
|
||||
>
|
||||
{{ saving ? t('maintenance.ledger.actions.saving') : t('maintenance.ledger.actions.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,484 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/maintenance/components/MaintenanceRecordManagerPanel.vue
|
||||
* 用途:设备维保助手右侧固定面板中的维修记录管理页,覆盖查询、新增、编辑和删除。
|
||||
* 依赖:maintenanceRecord.api、maintenanceLedger.api、PaginationBar、useMessage。
|
||||
* 逻辑:列表 Tab 按设备编号/名称和维修状态筛选;配置 Tab 复用同一表单新增或修改记录。
|
||||
*/
|
||||
import { computed, onMounted, reactive, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { listMaintenanceDevices } from '@/features/maintenance/api/maintenanceLedger.api';
|
||||
import {
|
||||
createMaintenanceRecord,
|
||||
deleteMaintenanceRecord,
|
||||
exportMaintenanceRecords,
|
||||
listMaintenanceRecords,
|
||||
updateMaintenanceRecord,
|
||||
} from '@/features/maintenance/api/maintenanceRecord.api';
|
||||
import type { MaintenanceDevice } from '@/features/maintenance/types/ledger.types';
|
||||
import type {
|
||||
MaintenanceRecord,
|
||||
MaintenanceRecordPayload,
|
||||
MaintenanceRepairStatus,
|
||||
} from '@/features/maintenance/types/record.types';
|
||||
|
||||
type TabName = 'list' | 'form';
|
||||
|
||||
const msg = useMessage();
|
||||
const { t } = useI18n();
|
||||
const activeTab = ref<TabName>('list');
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const deviceLoading = ref(false);
|
||||
const deletingId = ref<number | null>(null);
|
||||
const exporting = ref(false);
|
||||
const records = ref<MaintenanceRecord[]>([]);
|
||||
const matchedDevice = ref<MaintenanceDevice | null>(null);
|
||||
const total = ref(0);
|
||||
const page = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const keyword = ref('');
|
||||
const status = ref('');
|
||||
const editingId = ref<number | null>(null);
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
|
||||
const form = reactive<MaintenanceRecordPayload>({
|
||||
deviceCode: '',
|
||||
reportDate: today,
|
||||
repairCategory: '',
|
||||
faultDescription: '',
|
||||
reporter: '',
|
||||
approver: '',
|
||||
repairStatus: 'pending',
|
||||
repairDate: '',
|
||||
repairUnit: '',
|
||||
repairer: '',
|
||||
repairCost: '',
|
||||
repairHours: '',
|
||||
repairDescription: '',
|
||||
sourceOrderNo: '',
|
||||
});
|
||||
|
||||
const statusOptions: Array<{ value: MaintenanceRepairStatus | ''; label: string }> = [
|
||||
{ value: '', label: 'maintenance.record.status.all' },
|
||||
{ value: 'pending', label: 'maintenance.record.status.pending' },
|
||||
{ value: 'processing', label: 'maintenance.record.status.processing' },
|
||||
{ value: 'done', label: 'maintenance.record.status.done' },
|
||||
{ value: 'cancelled', label: 'maintenance.record.status.cancelled' },
|
||||
];
|
||||
|
||||
const formTitle = computed(() => t(editingId.value ? 'maintenance.record.formTitle.edit' : 'maintenance.record.formTitle.create'));
|
||||
|
||||
/**
|
||||
* 将维修状态枚举转为中文展示。
|
||||
* @param value - 后端状态枚举。
|
||||
* @returns 中文状态文案。
|
||||
*/
|
||||
const formatStatus = (value: string): string => {
|
||||
const option = statusOptions.find((item) => item.value === value);
|
||||
return option ? t(option.label) : value || '-';
|
||||
};
|
||||
|
||||
/**
|
||||
* 从表单生成保存 payload,统一裁剪字符串并保留可空日期。
|
||||
* @returns 保存维修记录入参。
|
||||
*/
|
||||
const buildPayload = (): MaintenanceRecordPayload => ({
|
||||
deviceCode: form.deviceCode.trim(),
|
||||
reportDate: form.reportDate,
|
||||
repairCategory: form.repairCategory?.trim(),
|
||||
faultDescription: form.faultDescription.trim(),
|
||||
reporter: form.reporter?.trim(),
|
||||
approver: form.approver?.trim(),
|
||||
repairStatus: form.repairStatus,
|
||||
repairDate: form.repairDate || undefined,
|
||||
repairUnit: form.repairUnit?.trim(),
|
||||
repairer: form.repairer?.trim(),
|
||||
repairCost: form.repairCost?.trim(),
|
||||
repairHours: form.repairHours?.trim(),
|
||||
repairDescription: form.repairDescription?.trim(),
|
||||
sourceOrderNo: form.sourceOrderNo?.trim(),
|
||||
});
|
||||
|
||||
/**
|
||||
* 查询维修记录列表,仅按设备编号/设备名称和状态筛选。
|
||||
*/
|
||||
const loadRecords = async (): Promise<void> => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const result = await listMaintenanceRecords({
|
||||
keyword: keyword.value.trim(),
|
||||
status: status.value,
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
});
|
||||
records.value = result.items;
|
||||
total.value = result.total;
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || t('maintenance.record.messages.loadFailed'));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 导出当前筛选条件下的维修记录 Excel。
|
||||
*/
|
||||
const exportRecords = async (): Promise<void> => {
|
||||
exporting.value = true;
|
||||
try {
|
||||
const blob = await exportMaintenanceRecords({
|
||||
keyword: keyword.value.trim(),
|
||||
status: status.value,
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `maintenance_records_${new Date().toISOString().slice(0, 10)}.xlsx`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
msg.success(t('maintenance.record.messages.exported'));
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || t('maintenance.record.messages.exportFailed'));
|
||||
} finally {
|
||||
exporting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询设备台账快照,帮助管理员确认维修记录归属。
|
||||
*/
|
||||
const loadDeviceSnapshot = async (): Promise<void> => {
|
||||
const code = form.deviceCode.trim();
|
||||
matchedDevice.value = null;
|
||||
if (!code) return;
|
||||
deviceLoading.value = true;
|
||||
try {
|
||||
const result = await listMaintenanceDevices({ keyword: code, page: 1, pageSize: 5 });
|
||||
matchedDevice.value = result.items.find((item) => item.deviceCode === code) || result.items[0] || null;
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || t('maintenance.record.messages.deviceLoadFailed'));
|
||||
} finally {
|
||||
deviceLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置表单并进入新增模式。
|
||||
*/
|
||||
const startCreate = (): void => {
|
||||
editingId.value = null;
|
||||
Object.assign(form, {
|
||||
deviceCode: '',
|
||||
reportDate: today,
|
||||
repairCategory: '',
|
||||
faultDescription: '',
|
||||
reporter: '',
|
||||
approver: '',
|
||||
repairStatus: 'pending',
|
||||
repairDate: '',
|
||||
repairUnit: '',
|
||||
repairer: '',
|
||||
repairCost: '',
|
||||
repairHours: '',
|
||||
repairDescription: '',
|
||||
sourceOrderNo: '',
|
||||
});
|
||||
matchedDevice.value = null;
|
||||
activeTab.value = 'form';
|
||||
};
|
||||
|
||||
/**
|
||||
* 将选中的维修记录带入表单并进入编辑模式。
|
||||
* @param record - 列表中选中的维修记录。
|
||||
*/
|
||||
const startEdit = (record: MaintenanceRecord): void => {
|
||||
editingId.value = record.id;
|
||||
Object.assign(form, {
|
||||
deviceCode: record.deviceCode || '',
|
||||
reportDate: record.reportDate || today,
|
||||
repairCategory: record.repairCategory || '',
|
||||
faultDescription: record.faultDescription || '',
|
||||
reporter: record.reporter || '',
|
||||
approver: record.approver || '',
|
||||
repairStatus: record.repairStatus,
|
||||
repairDate: record.repairDate || '',
|
||||
repairUnit: record.repairUnit || '',
|
||||
repairer: record.repairer || '',
|
||||
repairCost: record.repairCost || '',
|
||||
repairHours: record.repairHours || '',
|
||||
repairDescription: record.repairDescription || '',
|
||||
sourceOrderNo: record.sourceOrderNo || '',
|
||||
});
|
||||
matchedDevice.value = record.deviceCode
|
||||
? {
|
||||
id: record.deviceId || 0,
|
||||
deviceCode: record.deviceCode,
|
||||
deviceName: record.deviceName || '',
|
||||
modelSpec: record.modelSpec || '',
|
||||
installLocation: record.installLocation || '',
|
||||
deviceStatus: 'in_use',
|
||||
} as MaintenanceDevice
|
||||
: null;
|
||||
activeTab.value = 'form';
|
||||
};
|
||||
|
||||
/**
|
||||
* 新增或更新维修记录,并回到列表刷新结果。
|
||||
*/
|
||||
const saveRecord = async (): Promise<void> => {
|
||||
const payload = buildPayload();
|
||||
if (!payload.deviceCode || !payload.reportDate || !payload.faultDescription) {
|
||||
msg.warning(t('maintenance.record.messages.required'));
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
if (editingId.value) {
|
||||
await updateMaintenanceRecord(editingId.value, payload);
|
||||
msg.success(t('maintenance.record.messages.updated'));
|
||||
} else {
|
||||
await createMaintenanceRecord(payload);
|
||||
msg.success(t('maintenance.record.messages.created'));
|
||||
keyword.value = payload.deviceCode;
|
||||
}
|
||||
activeTab.value = 'list';
|
||||
await loadRecords();
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || t('maintenance.record.messages.saveFailed'));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除维修记录。
|
||||
* @param record - 待删除的维修记录。
|
||||
*/
|
||||
const removeRecord = async (record: MaintenanceRecord): Promise<void> => {
|
||||
if (!window.confirm(t('maintenance.record.messages.deleteConfirm', { deviceCode: record.deviceCode }))) return;
|
||||
deletingId.value = record.id;
|
||||
try {
|
||||
await deleteMaintenanceRecord(record.id);
|
||||
msg.success(t('maintenance.record.messages.deleted'));
|
||||
await loadRecords();
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || t('maintenance.record.messages.deleteFailed'));
|
||||
} finally {
|
||||
deletingId.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(loadRecords);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="flex h-full min-h-0 flex-col">
|
||||
<div class="mb-4 rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900">
|
||||
{{ t('maintenance.record.notice') }}
|
||||
</div>
|
||||
|
||||
<div class="mb-4 flex rounded-xl border border-default bg-muted/30 p-1">
|
||||
<button
|
||||
type="button"
|
||||
class="relative flex-1 cursor-pointer rounded-lg border px-3 py-2 text-sm font-semibold transition-all hover:bg-surface hover:text-brand"
|
||||
:class="activeTab === 'list' ? 'border-brand-300 bg-surface text-brand shadow-sm after:absolute after:inset-x-6 after:bottom-0 after:h-0.5 after:rounded-full after:bg-brand' : 'border-transparent text-secondary'"
|
||||
:aria-selected="activeTab === 'list'"
|
||||
@click="activeTab = 'list'"
|
||||
>
|
||||
{{ t('maintenance.record.tabs.list') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="relative flex-1 cursor-pointer rounded-lg border px-3 py-2 text-sm font-semibold transition-all hover:bg-surface hover:text-brand"
|
||||
:class="activeTab === 'form' ? 'border-brand-300 bg-surface text-brand shadow-sm after:absolute after:inset-x-6 after:bottom-0 after:h-0.5 after:rounded-full after:bg-brand' : 'border-transparent text-secondary'"
|
||||
:aria-selected="activeTab === 'form'"
|
||||
@click="activeTab = 'form'"
|
||||
>
|
||||
{{ t('maintenance.record.tabs.form') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="activeTab === 'list'" class="flex min-h-0 flex-1 flex-col gap-4">
|
||||
<div class="flex flex-wrap gap-3">
|
||||
<input
|
||||
v-model="keyword"
|
||||
class="admin-table-filter-input w-full md:w-[360px] lg:w-[420px]"
|
||||
:placeholder="t('maintenance.record.filters.keywordPlaceholder')"
|
||||
@keyup.enter="page = 1; loadRecords()"
|
||||
/>
|
||||
<select v-model="status" class="admin-table-filter-input w-full md:w-[150px]" @change="page = 1; loadRecords()">
|
||||
<option v-for="item in statusOptions" :key="item.value || 'all'" :value="item.value">
|
||||
{{ t(item.label) }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button type="button" class="admin-report-page-btn admin-report-page-btn--active" @click="page = 1; loadRecords()">
|
||||
{{ t('maintenance.record.actions.search') }}
|
||||
</button>
|
||||
<button type="button" class="admin-report-page-btn" @click="startCreate">
|
||||
{{ t('maintenance.record.actions.create') }}
|
||||
</button>
|
||||
<button type="button" class="admin-report-page-btn" :disabled="exporting" @click="exportRecords">
|
||||
{{ exporting ? t('maintenance.record.actions.exporting') : t('maintenance.record.actions.export') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="min-h-0 overflow-auto rounded-xl border border-default bg-surface">
|
||||
<table class="min-w-full text-left text-sm">
|
||||
<thead class="bg-muted/50 text-secondary">
|
||||
<tr>
|
||||
<th class="px-3 py-2">{{ t('maintenance.record.table.deviceCode') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.record.table.deviceName') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.record.table.modelSpec') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.record.table.faultDescription') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.record.table.status') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.record.table.repairer') }}</th>
|
||||
<th class="px-3 py-2">{{ t('maintenance.record.table.operation') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="loading">
|
||||
<td colspan="7" class="px-3 py-8 text-center text-secondary">{{ t('maintenance.record.table.loading') }}</td>
|
||||
</tr>
|
||||
<tr v-else-if="!records.length">
|
||||
<td colspan="7" class="px-3 py-8 text-center text-secondary">{{ t('maintenance.record.table.empty') }}</td>
|
||||
</tr>
|
||||
<tr v-for="record in records" v-else :key="record.id" class="border-t border-default">
|
||||
<td class="px-3 py-2 font-semibold">{{ record.deviceCode }}</td>
|
||||
<td class="px-3 py-2">{{ record.deviceName || '-' }}</td>
|
||||
<td class="px-3 py-2">{{ record.modelSpec || '-' }}</td>
|
||||
<td class="max-w-[260px] truncate px-3 py-2">{{ record.faultDescription }}</td>
|
||||
<td class="px-3 py-2">{{ formatStatus(record.repairStatus) }}</td>
|
||||
<td class="px-3 py-2">{{ record.repairer || '-' }}</td>
|
||||
<td class="px-3 py-2">
|
||||
<div class="flex gap-2">
|
||||
<button type="button" class="admin-report-page-btn" @click="startEdit(record)">{{ t('maintenance.record.actions.edit') }}</button>
|
||||
<button
|
||||
type="button"
|
||||
class="admin-report-page-btn"
|
||||
:disabled="deletingId === record.id"
|
||||
@click="removeRecord(record)"
|
||||
>
|
||||
{{ deletingId === record.id ? t('maintenance.record.actions.deleting') : t('maintenance.record.actions.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<PaginationBar
|
||||
v-model:page="page"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
@update:page="loadRecords"
|
||||
@update:page-size="loadRecords"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<form v-else class="min-h-0 flex-1 overflow-auto" @submit.prevent="saveRecord">
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h3 class="text-base font-semibold text-primary">{{ formTitle }}</h3>
|
||||
<button type="button" class="admin-report-page-btn" @click="activeTab = 'list'">{{ t('maintenance.record.actions.backToList') }}</button>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.deviceCode') }} *
|
||||
<input
|
||||
v-model="form.deviceCode"
|
||||
class="admin-table-filter-input"
|
||||
:placeholder="t('maintenance.record.placeholder.deviceCode')"
|
||||
@blur="loadDeviceSnapshot"
|
||||
@keyup.enter.prevent="loadDeviceSnapshot"
|
||||
/>
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.reportDate') }} *
|
||||
<input v-model="form.reportDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.repairCategory') }}
|
||||
<input v-model="form.repairCategory" class="admin-table-filter-input" :placeholder="t('maintenance.record.placeholder.repairCategory')" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.repairStatus') }}
|
||||
<select v-model="form.repairStatus" class="admin-table-filter-input">
|
||||
<option value="pending">{{ t('maintenance.record.status.pending') }}</option>
|
||||
<option value="processing">{{ t('maintenance.record.status.processing') }}</option>
|
||||
<option value="done">{{ t('maintenance.record.status.done') }}</option>
|
||||
<option value="cancelled">{{ t('maintenance.record.status.cancelled') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 rounded-xl border border-default bg-surface-soft px-3 py-2 text-sm">
|
||||
<div v-if="deviceLoading" class="text-secondary">{{ t('maintenance.record.deviceSnapshot.loading') }}</div>
|
||||
<div v-else-if="matchedDevice" class="grid gap-1 text-secondary">
|
||||
<div class="font-semibold text-primary">{{ matchedDevice.deviceName }}({{ matchedDevice.deviceCode }})</div>
|
||||
<div>{{ t('maintenance.record.deviceSnapshot.position') }}:{{ matchedDevice.installLocation || '-' }} | {{ t('maintenance.record.deviceSnapshot.department') }}:{{ matchedDevice.department || '-' }}</div>
|
||||
<div>{{ t('maintenance.record.deviceSnapshot.responsibleUser') }}:{{ matchedDevice.responsibleUser || '-' }} | {{ t('maintenance.record.deviceSnapshot.status') }}:{{ matchedDevice.deviceStatus }}</div>
|
||||
</div>
|
||||
<div v-else class="text-secondary">{{ t('maintenance.record.deviceSnapshot.empty') }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid gap-4 md:grid-cols-2">
|
||||
<label class="grid gap-1 text-sm text-secondary md:col-span-2">
|
||||
{{ t('maintenance.record.fields.faultDescription') }} *
|
||||
<textarea v-model="form.faultDescription" class="admin-table-filter-input min-h-24" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.reporter') }}
|
||||
<input v-model="form.reporter" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.approver') }}
|
||||
<input v-model="form.approver" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.repairDate') }}
|
||||
<input v-model="form.repairDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.sourceOrderNo') }}
|
||||
<input v-model="form.sourceOrderNo" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.repairUnit') }}
|
||||
<input v-model="form.repairUnit" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.repairer') }}
|
||||
<input v-model="form.repairer" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.repairCost') }}
|
||||
<input v-model="form.repairCost" class="admin-table-filter-input" :placeholder="t('maintenance.record.placeholder.repairCost')" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
{{ t('maintenance.record.fields.repairHours') }}
|
||||
<input v-model="form.repairHours" class="admin-table-filter-input" :placeholder="t('maintenance.record.placeholder.repairHours')" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary md:col-span-2">
|
||||
{{ t('maintenance.record.fields.repairDescription') }}
|
||||
<textarea v-model="form.repairDescription" class="admin-table-filter-input min-h-24" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="sticky bottom-0 mt-5 flex justify-end gap-2 border-t border-default bg-surface py-3">
|
||||
<button type="button" class="admin-report-page-btn" @click="activeTab = 'list'">{{ t('maintenance.record.actions.cancel') }}</button>
|
||||
<button type="submit" class="admin-report-page-btn admin-report-page-btn--active" :disabled="saving">
|
||||
{{ saving ? t('maintenance.record.actions.saving') : t('maintenance.record.actions.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,316 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/maintenance/components/MaintenanceRecordPanel.vue
|
||||
* 用途:设备维保助手右侧固定面板中的“新增维修记录”页面。
|
||||
* 依赖:maintenanceRecord.api、maintenanceLedger.api、useMessage。
|
||||
* 逻辑:管理员通过按钮进入固定面板后填写维修记录;设备编号失焦时查询台账快照,保存后刷新最近记录用于确认。
|
||||
*/
|
||||
import { computed, onMounted, reactive, ref } from 'vue';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { listMaintenanceDevices } from '@/features/maintenance/api/maintenanceLedger.api';
|
||||
import {
|
||||
createMaintenanceRecord,
|
||||
listMaintenanceRecords,
|
||||
} from '@/features/maintenance/api/maintenanceRecord.api';
|
||||
import type { MaintenanceDevice } from '@/features/maintenance/types/ledger.types';
|
||||
import type {
|
||||
MaintenanceRecord,
|
||||
MaintenanceRecordPayload,
|
||||
MaintenanceRepairStatus,
|
||||
} from '@/features/maintenance/types/record.types';
|
||||
|
||||
const msg = useMessage();
|
||||
const saving = ref(false);
|
||||
const deviceLoading = ref(false);
|
||||
const recentLoading = ref(false);
|
||||
const matchedDevice = ref<MaintenanceDevice | null>(null);
|
||||
const recentRecords = ref<MaintenanceRecord[]>([]);
|
||||
const recordKeyword = ref('');
|
||||
const recordStatus = ref('');
|
||||
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
|
||||
const form = reactive<MaintenanceRecordPayload>({
|
||||
deviceCode: '',
|
||||
reportDate: today,
|
||||
repairCategory: '',
|
||||
faultDescription: '',
|
||||
reporter: '',
|
||||
approver: '',
|
||||
repairStatus: 'pending',
|
||||
repairDate: '',
|
||||
repairUnit: '',
|
||||
repairer: '',
|
||||
repairCost: '',
|
||||
repairHours: '',
|
||||
repairDescription: '',
|
||||
sourceOrderNo: '',
|
||||
});
|
||||
|
||||
const statusOptions: Array<{ value: MaintenanceRepairStatus | ''; label: string }> = [
|
||||
{ value: '', label: '全部状态' },
|
||||
{ value: 'pending', label: '待维修' },
|
||||
{ value: 'processing', label: '维修中' },
|
||||
{ value: 'done', label: '已完成' },
|
||||
{ value: 'cancelled', label: '已取消' },
|
||||
];
|
||||
|
||||
const selectedStatusLabel = computed(() => {
|
||||
return statusOptions.find((item) => item.value === form.repairStatus)?.label || form.repairStatus;
|
||||
});
|
||||
|
||||
/**
|
||||
* 将状态值转换为中文展示。
|
||||
* @param value - 后端状态枚举。
|
||||
* @returns 页面展示文案。
|
||||
*/
|
||||
const formatStatus = (value: string): string => {
|
||||
return statusOptions.find((item) => item.value === value)?.label || value || '-';
|
||||
};
|
||||
|
||||
/**
|
||||
* 从表单状态生成新增维修记录 payload,统一处理空字符串。
|
||||
* @returns 新增维修记录入参。
|
||||
*/
|
||||
const buildPayload = (): MaintenanceRecordPayload => ({
|
||||
deviceCode: form.deviceCode.trim(),
|
||||
reportDate: form.reportDate,
|
||||
repairCategory: form.repairCategory?.trim(),
|
||||
faultDescription: form.faultDescription.trim(),
|
||||
reporter: form.reporter?.trim(),
|
||||
approver: form.approver?.trim(),
|
||||
repairStatus: form.repairStatus,
|
||||
repairDate: form.repairDate || undefined,
|
||||
repairUnit: form.repairUnit?.trim(),
|
||||
repairer: form.repairer?.trim(),
|
||||
repairCost: form.repairCost?.trim(),
|
||||
repairHours: form.repairHours?.trim(),
|
||||
repairDescription: form.repairDescription?.trim(),
|
||||
sourceOrderNo: form.sourceOrderNo?.trim(),
|
||||
});
|
||||
|
||||
/**
|
||||
* 按设备编号查询台账快照,帮助管理员确认记录归属。
|
||||
* AI 触发时机:当用户输入或修改设备编号后,需要自动带出台账信息时调用。
|
||||
*/
|
||||
const loadDeviceSnapshot = async (): Promise<void> => {
|
||||
const code = form.deviceCode.trim();
|
||||
matchedDevice.value = null;
|
||||
if (!code) return;
|
||||
deviceLoading.value = true;
|
||||
try {
|
||||
const result = await listMaintenanceDevices({ keyword: code, page: 1, pageSize: 5 });
|
||||
matchedDevice.value = result.items.find((item) => item.deviceCode === code) || result.items[0] || null;
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || '查询设备台账失败');
|
||||
} finally {
|
||||
deviceLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询最近维修记录,作为保存后的确认列表和轻量筛选入口。
|
||||
*/
|
||||
const loadRecentRecords = async (): Promise<void> => {
|
||||
recentLoading.value = true;
|
||||
try {
|
||||
const result = await listMaintenanceRecords({
|
||||
keyword: recordKeyword.value.trim(),
|
||||
status: recordStatus.value,
|
||||
page: 1,
|
||||
pageSize: 5,
|
||||
});
|
||||
recentRecords.value = result.items;
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || '查询维修记录失败');
|
||||
} finally {
|
||||
recentLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 清空维修记录表单,保留默认报修日期。
|
||||
*/
|
||||
const resetForm = (): void => {
|
||||
Object.assign(form, {
|
||||
deviceCode: '',
|
||||
reportDate: today,
|
||||
repairCategory: '',
|
||||
faultDescription: '',
|
||||
reporter: '',
|
||||
approver: '',
|
||||
repairStatus: 'pending',
|
||||
repairDate: '',
|
||||
repairUnit: '',
|
||||
repairer: '',
|
||||
repairCost: '',
|
||||
repairHours: '',
|
||||
repairDescription: '',
|
||||
sourceOrderNo: '',
|
||||
});
|
||||
matchedDevice.value = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 新增维修记录,并刷新最近记录列表。
|
||||
*/
|
||||
const saveRecord = async (): Promise<void> => {
|
||||
const payload = buildPayload();
|
||||
if (!payload.deviceCode || !payload.reportDate || !payload.faultDescription) {
|
||||
msg.warning('设备编号、报修日期和故障描述不能为空');
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
await createMaintenanceRecord(payload);
|
||||
msg.success('维修记录已保存');
|
||||
recordKeyword.value = payload.deviceCode;
|
||||
resetForm();
|
||||
await loadRecentRecords();
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || '保存维修记录失败');
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(loadRecentRecords);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="flex h-full min-h-0 flex-col gap-4">
|
||||
<form class="min-h-0 flex-1 overflow-auto" @submit.prevent="saveRecord">
|
||||
<div class="mb-4 rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900">
|
||||
维修记录为管理员配置入口,查询类问题仍建议通过会话直接提问。
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
设备编号 *
|
||||
<input
|
||||
v-model="form.deviceCode"
|
||||
class="admin-table-filter-input"
|
||||
placeholder="如 EQ-2026-001"
|
||||
@blur="loadDeviceSnapshot"
|
||||
@keyup.enter.prevent="loadDeviceSnapshot"
|
||||
/>
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
报修日期 *
|
||||
<input v-model="form.reportDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
维修类别
|
||||
<input v-model="form.repairCategory" class="admin-table-filter-input" placeholder="日常维修 / 保养 / 点检" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
维修状态
|
||||
<select v-model="form.repairStatus" class="admin-table-filter-input">
|
||||
<option value="pending">待维修</option>
|
||||
<option value="processing">维修中</option>
|
||||
<option value="done">已完成</option>
|
||||
<option value="cancelled">已取消</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 rounded-xl border border-default bg-surface-soft px-3 py-2 text-sm">
|
||||
<div v-if="deviceLoading" class="text-secondary">正在查询设备台账...</div>
|
||||
<div v-else-if="matchedDevice" class="grid gap-1 text-secondary">
|
||||
<div class="font-semibold text-primary">{{ matchedDevice.deviceName }}({{ matchedDevice.deviceCode }})</div>
|
||||
<div>位置:{{ matchedDevice.installLocation || '-' }} | 部门:{{ matchedDevice.department || '-' }}</div>
|
||||
<div>负责人:{{ matchedDevice.responsibleUser || '-' }} | 状态:{{ matchedDevice.deviceStatus }}</div>
|
||||
</div>
|
||||
<div v-else class="text-secondary">输入设备编号后可自动匹配设备台账快照。</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid gap-4 md:grid-cols-2">
|
||||
<label class="grid gap-1 text-sm text-secondary md:col-span-2">
|
||||
故障描述 *
|
||||
<textarea v-model="form.faultDescription" class="admin-table-filter-input min-h-24" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
报修人
|
||||
<input v-model="form.reporter" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
审批人
|
||||
<input v-model="form.approver" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
维修日期
|
||||
<input v-model="form.repairDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
维修单位
|
||||
<input v-model="form.repairUnit" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
维修人
|
||||
<input v-model="form.repairer" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
来源工单号
|
||||
<input v-model="form.sourceOrderNo" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
维修费用
|
||||
<input v-model="form.repairCost" class="admin-table-filter-input" placeholder="如 1200.00" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
维修工时
|
||||
<input v-model="form.repairHours" class="admin-table-filter-input" placeholder="如 3.5h" />
|
||||
</label>
|
||||
<label class="grid gap-1 text-sm text-secondary md:col-span-2">
|
||||
维修说明
|
||||
<textarea v-model="form.repairDescription" class="admin-table-filter-input min-h-24" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="sticky bottom-0 mt-5 flex justify-end gap-2 border-t border-default bg-surface py-3">
|
||||
<button type="button" class="admin-report-page-btn" @click="resetForm">清空</button>
|
||||
<button
|
||||
type="submit"
|
||||
class="admin-report-page-btn admin-report-page-btn--active"
|
||||
:disabled="saving"
|
||||
>
|
||||
{{ saving ? '保存中...' : `保存为${selectedStatusLabel}` }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="border-t border-default pt-4">
|
||||
<div class="mb-3 flex items-center justify-between gap-2">
|
||||
<h3 class="text-sm font-semibold text-primary">最近维修记录</h3>
|
||||
<button type="button" class="admin-report-page-btn" @click="loadRecentRecords">刷新</button>
|
||||
</div>
|
||||
<div class="mb-3 grid gap-2 md:grid-cols-[1fr_120px_72px]">
|
||||
<input v-model="recordKeyword" class="admin-table-filter-input" placeholder="筛选设备编号、故障、维修人" />
|
||||
<select v-model="recordStatus" class="admin-table-filter-input">
|
||||
<option v-for="item in statusOptions" :key="item.value || 'all'" :value="item.value">
|
||||
{{ item.label }}
|
||||
</option>
|
||||
</select>
|
||||
<button type="button" class="admin-report-page-btn admin-report-page-btn--active" @click="loadRecentRecords">
|
||||
查询
|
||||
</button>
|
||||
</div>
|
||||
<div class="max-h-56 overflow-auto rounded-xl border border-default bg-surface">
|
||||
<div v-if="recentLoading" class="px-3 py-6 text-center text-sm text-secondary">加载中...</div>
|
||||
<div v-else-if="!recentRecords.length" class="px-3 py-6 text-center text-sm text-secondary">暂无维修记录</div>
|
||||
<div
|
||||
v-for="record in recentRecords"
|
||||
v-else
|
||||
:key="record.id"
|
||||
class="border-t border-default px-3 py-2 text-sm first:border-t-0"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="font-semibold text-primary">{{ record.deviceCode }} {{ record.deviceName || '' }}</span>
|
||||
<span class="text-xs text-secondary">{{ formatStatus(record.repairStatus) }}</span>
|
||||
</div>
|
||||
<div class="mt-1 text-secondary">{{ record.reportDate }} | {{ record.faultDescription }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* features/maintenance/types/ledger.types.ts
|
||||
* 用途:设备维保台账配置的前端类型定义。
|
||||
* 依赖:无运行时依赖。
|
||||
* 逻辑:API 层、右侧固定面板和后续 Agent 结果卡片共享这些类型,保持字段一致。
|
||||
*/
|
||||
|
||||
export type MaintenanceDeviceStatus = 'in_use' | 'disabled' | 'scrapped' | 'sold';
|
||||
|
||||
export interface MaintenanceDevice {
|
||||
id: number;
|
||||
deviceCode: string;
|
||||
deviceName: string;
|
||||
modelSpec?: string | null;
|
||||
department?: string | null;
|
||||
installLocation?: string | null;
|
||||
deviceStatus: MaintenanceDeviceStatus;
|
||||
manufacturer?: string | null;
|
||||
entryDate?: string | null;
|
||||
productionDate?: string | null;
|
||||
startDate?: string | null;
|
||||
responsibleUser?: string | null;
|
||||
maintenanceCycle?: string | null;
|
||||
originalValue?: number | null;
|
||||
residualValue?: number | null;
|
||||
accountSet?: string | null;
|
||||
remark?: string | null;
|
||||
createdAt?: string | null;
|
||||
updatedAt?: string | null;
|
||||
}
|
||||
|
||||
export interface MaintenanceDevicePayload {
|
||||
deviceCode: string;
|
||||
deviceName: string;
|
||||
modelSpec?: string;
|
||||
department?: string;
|
||||
installLocation?: string;
|
||||
deviceStatus: MaintenanceDeviceStatus;
|
||||
manufacturer?: string;
|
||||
entryDate?: string;
|
||||
productionDate?: string;
|
||||
startDate?: string;
|
||||
responsibleUser?: string;
|
||||
maintenanceCycle?: string;
|
||||
originalValue?: string;
|
||||
residualValue?: string;
|
||||
accountSet?: string;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
export interface MaintenanceDeviceListResult {
|
||||
items: MaintenanceDevice[];
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
export interface MaintenanceDeviceImportResult {
|
||||
total: number;
|
||||
created: number;
|
||||
updated: number;
|
||||
failed: number;
|
||||
errors: Array<{ row: number; message: string }>;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* features/maintenance/types/record.types.ts
|
||||
* 用途:设备维保助手的维修记录前端类型定义。
|
||||
* 依赖:无运行时依赖。
|
||||
* 逻辑:API 层、右侧固定面板和后续 Agent 查询结果卡片共享这些字段,保持前后端命名一致。
|
||||
*/
|
||||
|
||||
export type MaintenanceRepairStatus = 'pending' | 'processing' | 'done' | 'cancelled';
|
||||
|
||||
export interface MaintenanceRecord {
|
||||
id: number;
|
||||
deviceId?: number | null;
|
||||
deviceCode: string;
|
||||
deviceName?: string | null;
|
||||
modelSpec?: string | null;
|
||||
installLocation?: string | null;
|
||||
reportDate: string;
|
||||
repairCategory?: string | null;
|
||||
faultDescription: string;
|
||||
reporter?: string | null;
|
||||
approver?: string | null;
|
||||
repairStatus: MaintenanceRepairStatus;
|
||||
repairDate?: string | null;
|
||||
repairUnit?: string | null;
|
||||
repairer?: string | null;
|
||||
repairCost?: string | null;
|
||||
repairHours?: string | null;
|
||||
repairDescription?: string | null;
|
||||
sourceOrderNo?: string | null;
|
||||
createdAt?: string | null;
|
||||
updatedAt?: string | null;
|
||||
}
|
||||
|
||||
export interface MaintenanceRecordPayload {
|
||||
deviceCode: string;
|
||||
reportDate: string;
|
||||
repairCategory?: string;
|
||||
faultDescription: string;
|
||||
reporter?: string;
|
||||
approver?: string;
|
||||
repairStatus: MaintenanceRepairStatus;
|
||||
repairDate?: string;
|
||||
repairUnit?: string;
|
||||
repairer?: string;
|
||||
repairCost?: string;
|
||||
repairHours?: string;
|
||||
repairDescription?: string;
|
||||
sourceOrderNo?: string;
|
||||
}
|
||||
|
||||
export interface MaintenanceRecordListResult {
|
||||
items: MaintenanceRecord[];
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
}
|
||||
Reference in new issue
Block a user