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
+52 -14
View File
@@ -79,17 +79,25 @@
</t-cell>
</t-cell-group>
<card-container v-entrance-transition>
<media-selector
class="media-selector"
:model-value="photoList"
:photo-items="photoItemList"
:show-viewer-actions="canUpdateCustomer"
:show-add="false"
:show-remove="false"
:submit="submitPhotoItems"
show-type-label
<attachment-selector
:readonly="true"
class="attachment-selector"
:items="photoItemList"
title="照片列表"
/>
>
<template #item-label="{ item }">
<span v-text="getAttachmentTypeText(item.attachType)" />
</template>
<template #viewer-actions="{ item, index, close }">
<attachment-viewer-actions
v-if="canUpdateCustomer"
:attach-type="item.attachType"
:busy="isPhotoSaving"
@change-type="changePhotoType(index, $event, close)"
@remove="removePhoto(index, close)"
/>
</template>
</attachment-selector>
</card-container>
<customer-tag-card
v-if="canReadTag"
@@ -191,7 +199,8 @@ import TagAPI from "@/api/TagAPI";
import BodyAreaSelector from "@/components/BodyAreaSelector.vue";
import CustomerRemoveDialog from "@/pages/customer/component/CustomerRemoveDialog.vue";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentViewerActions from "@/components/attachmentSelector/AttachmentViewerActions.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import TagSelector from "@/components/TagSelector.vue";
import CustomerTagCard from "@/pages/customer/component/CustomerTagCard.vue";
import type { PointAccount } from "@/types/Point";
@@ -199,7 +208,7 @@ import type { PhotoItem } from "@/types/Photo";
import type { GaoSalesOrderType } from "@/types/SalesOrder";
import type { Tag } from "@/types/Tag";
import { bodyAreaLabelMap } from "@/utils/bodyArea";
import { getAttachmentReadURL } from "@/utils/attachment";
import { getAttachmentReadURL, getAttachmentTypeText } from "@/utils/attachment";
import { normalizeBodyAreaValue } from "@/utils/customer";
import { corePermissionCodes, permissionCodes } from "@/utils/permission";
import { LunarCalendar } from "@/utils/LunarCalendar";
@@ -275,7 +284,7 @@ const photoItemList = computed(() => (customer.value?.attachmentList || [])
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 90)
})));
const photoList = computed(() => photoItemList.value.map(item => item.url));
const isPhotoSaving = ref(false);
async function submitPhotoItems(photoItems: PhotoItem[]): Promise<void> {
const currentCustomer = customer.value;
@@ -297,6 +306,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 {
Message.error("媒体修改失败");
} finally {
isPhotoSaving.value = false;
}
}
async function changePhotoType(index: number, attachType: string, close: () => void): Promise<void> {
if (!photoItemList.value[index] || photoItemList.value[index].attachType === attachType) {
return;
}
await applyPhotoItems(photoItemList.value.map((item, itemIndex) => itemIndex === index ? { ...item, attachType } : item), close);
}
async function removePhoto(index: number, close: () => void): Promise<void> {
if (!photoItemList.value[index]) {
return;
}
await applyPhotoItems(photoItemList.value.filter((_, itemIndex) => itemIndex !== index), close);
}
function buildPhotoAttachmentList(photoItems: PhotoItem[]): Attachment[] {
return photoItems.flatMap(item => {
if (item.attachment) {
@@ -621,7 +659,7 @@ onUnmounted(() => clearPageNavBarRight());
}
}
:deep(.media-selector) {
:deep(.attachment-selector) {
padding: 1rem;
}