update image thumb
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { AttachmentAPI } from "timi-web";
|
||||
|
||||
/**
|
||||
* 获取附件读取地址。
|
||||
*
|
||||
* @param id 附件 ID
|
||||
* @param thumbnailSize 缩略图尺寸,不传时返回原图地址
|
||||
*/
|
||||
export function getAttachmentReadURL(id: string, thumbnailSize?: number): string {
|
||||
const url = AttachmentAPI.getReadURL(id);
|
||||
if (thumbnailSize === undefined) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const params = new URLSearchParams({
|
||||
thumbWidth: String(thumbnailSize),
|
||||
thumbHeight: String(thumbnailSize)
|
||||
});
|
||||
const separator = url.includes("?") ? "&" : "?";
|
||||
return `${url}${separator}${params.toString()}`;
|
||||
}
|
||||
+2
-11
@@ -1,5 +1,5 @@
|
||||
import { AttachmentAPI } from "timi-web";
|
||||
import type { BodyAreaValue, Customer } from "@/types/Customer";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
|
||||
export function getCustomerPhotoURL(customer?: Customer, thumbnailSize?: number): string {
|
||||
return getCustomerAttachmentURL(customer, "PHOTO", thumbnailSize);
|
||||
@@ -14,16 +14,7 @@ function getCustomerAttachmentURL(customer: Customer | undefined, attachType: st
|
||||
if (!attachment?.id) {
|
||||
return "";
|
||||
}
|
||||
const url = AttachmentAPI.getReadURL(attachment.id);
|
||||
if (thumbnailSize === undefined) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const params = new URLSearchParams({
|
||||
thumbWidth: String(thumbnailSize),
|
||||
thumbHeight: String(thumbnailSize)
|
||||
});
|
||||
return `${url}?${params.toString()}`;
|
||||
return getAttachmentReadURL(attachment.id, thumbnailSize);
|
||||
}
|
||||
|
||||
export function normalizeBodyAreaValue(value: unknown): BodyAreaValue {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { AttachmentAPI } from "timi-web";
|
||||
import type { EventRecord } from "@/types/EventRecord";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
|
||||
export function getEventRecordPhotoURL(record?: EventRecord): string {
|
||||
export function getEventRecordPhotoURL(record?: EventRecord, thumbnailSize?: number): string {
|
||||
const attachment = record?.attachmentList?.find(item => item.attachType === "PHOTO") || record?.attachmentList?.[0];
|
||||
if (!attachment?.id) {
|
||||
return "";
|
||||
}
|
||||
return AttachmentAPI.getReadURL(attachment.id);
|
||||
return getAttachmentReadURL(attachment.id, thumbnailSize);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user