feat(i18n): 将前端用户可见中文硬编码改为四语言
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
dce915ea30
commit
ac7b53a523
105 files changed
+2928
-647
No files matched your search
@@ -2,10 +2,11 @@
|
||||
/**
|
||||
* features/maintenance/components/MaintenanceRecordPanel.vue
|
||||
* 用途:设备维保助手右侧固定面板中的“新增维修记录”页面。
|
||||
* 依赖:maintenanceRecord.api、maintenanceLedger.api、MaintenanceDeviceSnapshotCard、useMessage。
|
||||
* 依赖:maintenanceRecord.api、maintenanceLedger.api、MaintenanceDeviceSnapshotCard、useMessage、vue-i18n。
|
||||
* 逻辑:管理员通过按钮进入固定面板后填写维修记录;设备编号失焦时查询台账快照,保存后刷新最近记录用于确认。
|
||||
*/
|
||||
import { computed, onMounted, reactive, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import MaintenanceDeviceSnapshotCard from '@/features/maintenance/components/MaintenanceDeviceSnapshotCard.vue';
|
||||
import { listMaintenanceDevices } from '@/features/maintenance/api/maintenanceLedger.api';
|
||||
@@ -19,8 +20,10 @@ import type {
|
||||
MaintenanceRecordPayload,
|
||||
MaintenanceRepairStatus,
|
||||
} from '@/features/maintenance/types/record.types';
|
||||
import { repairStatusLabelKey } from '@/features/maintenance/utils/repair-status-display.utils';
|
||||
|
||||
const msg = useMessage();
|
||||
const { t } = useI18n();
|
||||
const saving = ref(false);
|
||||
const deviceLoading = ref(false);
|
||||
const recentLoading = ref(false);
|
||||
@@ -49,24 +52,28 @@ const form = reactive<MaintenanceRecordPayload>({
|
||||
});
|
||||
|
||||
const statusOptions: Array<{ value: MaintenanceRepairStatus | ''; label: string }> = [
|
||||
{ value: '', label: '全部状态' },
|
||||
{ value: 'pending', label: '待维修' },
|
||||
{ value: 'processing', label: '维修中' },
|
||||
{ value: 'done', label: '已完成' },
|
||||
{ value: 'cancelled', label: '已取消' },
|
||||
{ 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 selectedStatusLabel = computed(() => {
|
||||
return statusOptions.find((item) => item.value === form.repairStatus)?.label || form.repairStatus;
|
||||
const key = repairStatusLabelKey(form.repairStatus);
|
||||
return key ? t(key) : form.repairStatus;
|
||||
});
|
||||
|
||||
/**
|
||||
* 将状态值转换为中文展示。
|
||||
* 将状态值转换为当前语言展示文案。
|
||||
* @param value - 后端状态枚举。
|
||||
* @returns 页面展示文案。
|
||||
*/
|
||||
const formatStatus = (value: string): string => {
|
||||
return statusOptions.find((item) => item.value === value)?.label || value || '-';
|
||||
const key = repairStatusLabelKey(value);
|
||||
if (key) return t(key);
|
||||
const option = statusOptions.find((item) => item.value === value);
|
||||
return option ? t(option.label) : value || '-';
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -103,7 +110,7 @@ const loadDeviceSnapshot = async (): Promise<void> => {
|
||||
const result = await listMaintenanceDevices({ keyword: code, page: 1, pageSize: 5 });
|
||||
matchedDevice.value = result.items.find((item) => item.deviceCode === code) || null;
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || '查询设备台账失败');
|
||||
msg.error(error?.message || t('maintenance.record.messages.deviceLoadFailed'));
|
||||
} finally {
|
||||
deviceLoading.value = false;
|
||||
}
|
||||
@@ -121,12 +128,12 @@ const ensureDeviceExists = async (): Promise<boolean> => {
|
||||
const result = await listMaintenanceDevices({ keyword: code, page: 1, pageSize: 5 });
|
||||
matchedDevice.value = result.items.find((item) => item.deviceCode === code) || null;
|
||||
if (!matchedDevice.value) {
|
||||
msg.warning('设备不存在,不能新增维修记录');
|
||||
msg.warning(t('maintenance.record.messages.deviceNotFound'));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || '鏌ヨ璁惧鍙拌处澶辫触');
|
||||
msg.error(error?.message || t('maintenance.record.messages.deviceLoadFailed'));
|
||||
return false;
|
||||
} finally {
|
||||
deviceLoading.value = false;
|
||||
@@ -147,7 +154,7 @@ const loadRecentRecords = async (): Promise<void> => {
|
||||
});
|
||||
recentRecords.value = result.items;
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || '查询维修记录失败');
|
||||
msg.error(error?.message || t('maintenance.record.messages.loadFailed'));
|
||||
} finally {
|
||||
recentLoading.value = false;
|
||||
}
|
||||
@@ -182,7 +189,7 @@ const resetForm = (): void => {
|
||||
const saveRecord = async (): Promise<void> => {
|
||||
const payload = buildPayload();
|
||||
if (!payload.deviceCode || !payload.reportDate || !payload.faultDescription) {
|
||||
msg.warning('设备编号、报修日期和故障描述不能为空');
|
||||
msg.warning(t('maintenance.record.messages.required'));
|
||||
return;
|
||||
}
|
||||
if (!await ensureDeviceExists()) {
|
||||
@@ -191,12 +198,12 @@ const saveRecord = async (): Promise<void> => {
|
||||
saving.value = true;
|
||||
try {
|
||||
await createMaintenanceRecord(payload);
|
||||
msg.success('维修记录已保存');
|
||||
msg.success(t('maintenance.record.messages.saved'));
|
||||
recordKeyword.value = payload.deviceCode;
|
||||
resetForm();
|
||||
await loadRecentRecords();
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || '保存维修记录失败');
|
||||
msg.error(error?.message || t('maintenance.record.messages.saveFailed'));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
@@ -209,22 +216,22 @@ onMounted(loadRecentRecords);
|
||||
<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">
|
||||
维修记录为管理员配置入口,查询类问题仍建议通过会话直接提问。
|
||||
{{ t('maintenance.record.notice') }}
|
||||
</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="如 EQ-2026-001"
|
||||
: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>
|
||||
</div>
|
||||
@@ -239,94 +246,122 @@ onMounted(loadRecentRecords);
|
||||
|
||||
<div class="mt-4 grid gap-4 md:grid-cols-2">
|
||||
<label class="grid gap-1 text-sm text-secondary">
|
||||
维修类别
|
||||
<input v-model="form.repairCategory" class="admin-table-filter-input" placeholder="日常维修 / 保养 / 点检" />
|
||||
{{ 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">待维修</option>
|
||||
<option value="processing">维修中</option>
|
||||
<option value="done">已完成</option>
|
||||
<option value="cancelled">已取消</option>
|
||||
<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-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.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.sourceOrderNo') }}
|
||||
<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" />
|
||||
{{ 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">
|
||||
维修工时
|
||||
<input v-model="form.repairHours" class="admin-table-filter-input" placeholder="如 3.5h" />
|
||||
{{ 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="resetForm">清空</button>
|
||||
<button type="button" class="admin-report-page-btn" @click="resetForm">
|
||||
{{ t('maintenance.record.actions.clear') }}
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
class="admin-report-page-btn admin-report-page-btn--active"
|
||||
:disabled="saving"
|
||||
>
|
||||
{{ saving ? '保存中...' : `保存为${selectedStatusLabel}` }}
|
||||
{{
|
||||
saving
|
||||
? t('maintenance.record.actions.saving')
|
||||
: t('maintenance.record.actions.saveAs', { status: 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>
|
||||
<h3 class="text-sm font-semibold text-primary">{{ t('maintenance.record.recentTitle') }}</h3>
|
||||
<button type="button" class="admin-report-page-btn" @click="loadRecentRecords">
|
||||
{{ t('common.refresh') }}
|
||||
</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="筛选设备编号、故障、维修人" />
|
||||
<input
|
||||
v-model="recordKeyword"
|
||||
class="admin-table-filter-input"
|
||||
:placeholder="t('maintenance.record.filters.recentKeywordPlaceholder')"
|
||||
/>
|
||||
<select v-model="recordStatus" class="admin-table-filter-input">
|
||||
<option v-for="item in statusOptions" :key="item.value || 'all'" :value="item.value">
|
||||
{{ item.label }}
|
||||
{{ t(item.label) }}
|
||||
</option>
|
||||
</select>
|
||||
<button type="button" class="admin-report-page-btn admin-report-page-btn--active" @click="loadRecentRecords">
|
||||
查询
|
||||
{{ t('maintenance.record.actions.search') }}
|
||||
</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-if="recentLoading" class="px-3 py-6 text-center text-sm text-secondary">
|
||||
{{ t('maintenance.record.table.loading') }}
|
||||
</div>
|
||||
<div v-else-if="!recentRecords.length" class="px-3 py-6 text-center text-sm text-secondary">
|
||||
{{ t('maintenance.record.table.empty') }}
|
||||
</div>
|
||||
<div
|
||||
v-for="record in recentRecords"
|
||||
v-else
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* features/maintenance/utils/repair-status-display.utils.ts
|
||||
* 用途:维修记录状态在列表、卡片中的标签配色映射。
|
||||
* 用途:维修记录状态在列表、卡片中的标签配色与 i18n key 映射。
|
||||
* 依赖:MaintenanceRepairStatus 类型。
|
||||
* 逻辑:MaintenanceRecordManagerPanel、MaintenanceDeviceResultCard 等组件统一引用,保证状态色一致。
|
||||
* 逻辑:MaintenanceRecordManagerPanel、MaintenanceRecordPanel、MaintenanceDeviceResultCard 等组件统一引用,保证状态色与文案一致。
|
||||
*/
|
||||
import type { MaintenanceRepairStatus } from '@/features/maintenance/types/record.types';
|
||||
|
||||
@@ -18,3 +18,16 @@ export function repairStatusBadgeClass(value: MaintenanceRepairStatus | string):
|
||||
if (value === 'cancelled') return 'border-slate-200 bg-slate-100 text-slate-600';
|
||||
return 'border-slate-200 bg-slate-50 text-slate-600';
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回维修状态对应的 i18n 文案 key,供组件内 t() 翻译。
|
||||
* @param value - 维修状态枚举值。
|
||||
* @returns maintenance.record.status.* 的 key 路径;未知状态返回空字符串。
|
||||
*/
|
||||
export function repairStatusLabelKey(value: MaintenanceRepairStatus | string): string {
|
||||
if (value === 'pending') return 'maintenance.record.status.pending';
|
||||
if (value === 'processing') return 'maintenance.record.status.processing';
|
||||
if (value === 'done') return 'maintenance.record.status.done';
|
||||
if (value === 'cancelled') return 'maintenance.record.status.cancelled';
|
||||
return '';
|
||||
}
|
||||
Reference in new issue
Block a user