upper attachment-selector to lib

This commit is contained in:
Timi
2026-10-21 16:24:00 +08:00
parent e40c912dd9
commit c870bcdd39
43 changed files with 678 additions and 1663 deletions
+46 -11
View File
@@ -110,15 +110,21 @@
核销登记记录
</t-button>
<div v-if="record" class="photo-wrapper" v-entrance-transition>
<media-selector
:model-value="recordPhotoList"
:photo-items="recordPhotoItemList"
:show-viewer-actions="canUpdateRecord"
:show-add="false"
:show-remove="false"
:submit="submitPhotoItems"
<attachment-selector
:readonly="true"
:items="recordPhotoItemList"
title="登记照片"
/>
>
<template #viewer-actions="{ item, index, close }">
<attachment-viewer-actions
v-if="canUpdateRecord"
:attach-type="item.attachType"
:busy="isPhotoSaving"
@change-type="changePhotoType(index, $event, close)"
@remove="removePhoto(index, close)"
/>
</template>
</attachment-selector>
</div>
<t-button
v-if="record && canDeleteRecord"
@@ -149,7 +155,8 @@ import EventRecordAPI from "@/api/EventRecordAPI";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import EventOptionSelector from "@/components/EventOptionSelector.vue";
import EventRecordVerifyDialog from "@/components/EventRecordVerifyDialog.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentViewerActions from "@/components/attachmentSelector/AttachmentViewerActions.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { PhotoItem } from "@/types/Photo";
import type { PointLedgerChangeType } from "@/types/Point";
import { getAttachmentReadURL } from "@/utils/attachment";
@@ -207,6 +214,7 @@ const record = ref<EventRecord>();
const isLoading = ref(false);
const isVerifying = ref(false);
const isDeleting = ref(false);
const isPhotoSaving = ref(false);
const verifyDialogVisible = ref(false);
const isRetiredRecord = computed(() => isRetiredEvent(record.value?.event));
@@ -222,8 +230,6 @@ const recordPhotoItemList = computed(() => (record.value?.attachmentList || [])
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 64)
})));
const recordPhotoList = computed(() => recordPhotoItemList.value.map(item => item.url));
async function submitPhotoItems(photoItems: PhotoItem[]): Promise<void> {
const currentRecord = record.value;
if (!currentRecord?.id || isRetiredRecord.value) {
@@ -242,6 +248,35 @@ async function submitPhotoItems(photoItems: PhotoItem[]): Promise<void> {
};
}
async function applyPhotoItems(photoItems: PhotoItem[], close: () => void): Promise<void> {
if (isPhotoSaving.value) {
return;
}
isPhotoSaving.value = true;
try {
await submitPhotoItems(photoItems);
close();
} catch (error) {
Message.error(getErrorMessage(error, "登记照片修改失败"));
} finally {
isPhotoSaving.value = false;
}
}
async function changePhotoType(index: number, attachType: string, close: () => void): Promise<void> {
if (!recordPhotoItemList.value[index] || recordPhotoItemList.value[index].attachType === attachType) {
return;
}
await applyPhotoItems(recordPhotoItemList.value.map((item, itemIndex) => itemIndex === index ? { ...item, attachType } : item), close);
}
async function removePhoto(index: number, close: () => void): Promise<void> {
if (!recordPhotoItemList.value[index]) {
return;
}
await applyPhotoItems(recordPhotoItemList.value.filter((_, itemIndex) => itemIndex !== index), close);
}
function buildPhotoAttachmentList(photoItems: PhotoItem[]): Attachment[] {
return photoItems.flatMap(item => {
if (item.attachment) {