refactor event

This commit is contained in:
Timi
2026-08-06 20:53:22 +08:00
parent 1243068fc3
commit 9df6dfaf59
37 changed files with 1584 additions and 2316 deletions
+14 -19
View File
@@ -3,7 +3,7 @@
<customer-profile-card v-if="record?.customer" class="customer-profile" :customer="record.customer" />
<t-cell-group v-if="record" title="登记信息" theme="card">
<t-cell title="登记事件" :note="record.event?.name || '未知事件'" />
<t-cell title="登记时间" :note="formatTime(record.registeredAt)" />
<t-cell title="登记时间" :note="record.registeredAt ? Time.toPassedDateTime(record.registeredAt) : '-'" />
<t-cell title="登记人" :note="Text.display(record.operator?.nick || record.operator?.name)" />
<t-cell title="客户编码" :note="Text.display(record.customer?.code)" />
<t-cell title="备注" :note="Text.display(record.remark)" />
@@ -16,7 +16,7 @@
title="登记照片"
/>
</section>
<t-empty v-else :description="loading ? '正在加载登记事件记录' : '登记事件记录不存在'" />
<t-empty v-else :description="isLoading ? '正在加载登记事件记录' : '登记事件记录不存在'" />
</div>
</template>
@@ -38,8 +38,11 @@ const route = useRoute();
const router = useRouter();
const navBarStore = useNavBarStore();
const userStore = useUserStore();
// ---------- 记录数据 ----------
const record = ref<EventRecord>();
const loading = ref(false);
const isLoading = ref(false);
const canUpdateRecord = computed(() => userStore.hasPermissions(permissionCodes.eventRecord.update));
const recordPhotoList = computed(() => {
@@ -47,6 +50,8 @@ const recordPhotoList = computed(() => {
return url ? [url] : [];
});
// ---------- 页面数据 ----------
async function loadRecord(): Promise<void> {
const recordId = String(route.params.id || "");
if (!recordId) {
@@ -54,18 +59,20 @@ async function loadRecord(): Promise<void> {
return;
}
loading.value = true;
isLoading.value = true;
try {
record.value = await EventRecordAPI.detail(recordId);
} catch (err) {
record.value = undefined;
console.warn("登记事件记录加载失败", err);
} finally {
loading.value = false;
isLoading.value = false;
}
}
async function goEdit(): Promise<void> {
// ---------- 导航 ----------
async function toEdit(): Promise<void> {
const recordId = String(route.params.id || "");
if (!recordId) {
return;
@@ -73,18 +80,6 @@ async function goEdit(): Promise<void> {
await router.push(`/management/registration-event-records/${recordId}/edit`);
}
function formatTime(value?: number): string {
if (!value) {
return "-";
}
const date = Time.toDateObject(value);
if (!date) {
return "-";
}
return Time.formatDateTime(date);
}
watch(() => route.params.id, async () => {
await loadRecord();
}, { immediate: true });
@@ -92,7 +87,7 @@ watch(() => route.params.id, async () => {
onMounted(() => {
navBarStore.clearRight();
if (canUpdateRecord.value) {
navBarStore.setRightText("编辑", "var(--td-brand-color)", goEdit);
navBarStore.setRightText("编辑", "var(--td-brand-color)", toEdit);
}
});