change type in PhotoScroller

This commit is contained in:
Timi
2026-08-24 17:53:21 +08:00
parent 9b843fc921
commit f42e865430
9 changed files with 316 additions and 35 deletions
+49 -7
View File
@@ -23,8 +23,10 @@
class="photo-panel"
:model-value="recordPhotoList"
:photo-items="recordPhotoItemList"
:show-viewer-actions="canUpdateRecord"
:show-add="false"
:show-remove="false"
:submit="submitPhotoItems"
title="登记照片"
/>
<t-empty v-else :description="isLoading ? '正在加载登记事件记录' : '登记事件记录不存在'" />
@@ -32,13 +34,14 @@
</template>
<script setup lang="ts">
import { Text, Time, useUserStore } from "timi-web";
import { Text, Time, useUserStore, type Attachment } from "timi-web";
import EventRecordAPI from "@/api/EventRecordAPI";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import PhotoScroller from "@/components/PhotoScroller.vue";
import { useNavBarStore } from "@/store/navBarStore";
import type { EventRecord } from "@/types/EventRecord";
import { getEventRecordPhotoURL } from "@/utils/eventRecord";
import type { PhotoItem } from "@/types/Photo";
import { getAttachmentReadURL } from "@/utils/attachment";
import { formatEventNumberValue } from "@/utils/eventValue";
import { permissionCodes } from "@/utils/permission";
@@ -57,13 +60,52 @@ const record = ref<EventRecord>();
const isLoading = ref(false);
const canUpdateRecord = computed(() => userStore.hasPermissions(permissionCodes.eventRecord.update));
const recordPhotoItemList = computed(() => {
const url = getEventRecordPhotoURL(record.value);
const thumbnailURL = getEventRecordPhotoURL(record.value, 64);
return thumbnailURL ? [{ url: thumbnailURL, previewUrl: url }] : [];
});
const recordPhotoItemList = computed(() => (record.value?.attachmentList || [])
.filter(item => !!item.id)
.map(item => ({
attachment: item,
attachType: item.attachType || "PHOTO",
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) {
throw new Error("登记记录不存在");
}
const attachmentList = buildPhotoAttachmentList(photoItems);
await EventRecordAPI.update({
id: currentRecord.id,
remark: currentRecord.remark || "",
attachmentList
});
record.value = {
...currentRecord,
attachmentList
};
}
function buildPhotoAttachmentList(photoItems: PhotoItem[]): Attachment[] {
return photoItems.flatMap(item => {
if (item.attachment) {
return [{
...item.attachment,
attachType: item.attachType || item.attachment.attachType || "PHOTO"
}];
}
if (item.tempFileId) {
return [{
attachType: item.attachType || "PHOTO",
tempFileId: item.tempFileId
}];
}
return [];
});
}
function getNumberValueText(value: EventRecord): string {
return formatEventNumberValue(value.event, value.numberValue);
}