diff --git a/src/components/hover-image-preview/index.vue b/src/components/hover-image-preview/index.vue new file mode 100644 index 0000000..2366750 --- /dev/null +++ b/src/components/hover-image-preview/index.vue @@ -0,0 +1,93 @@ + + + + + + diff --git a/src/utils/tools.ts b/src/utils/tools.ts index 687c535..93676a4 100644 --- a/src/utils/tools.ts +++ b/src/utils/tools.ts @@ -298,3 +298,44 @@ export const generateFullUrl = (pathTemplate: string, params: Record { + if (!width || !height) return 'square'; + if (width > height) return 'landscape'; + if (height > width) return 'portrait'; + return 'square'; +}; + +/** + * 加载图片自然尺寸(跨域下需服务端允许匿名访问) + */ +export const getImageNaturalSize = (url: string): Promise<{ width: number; height: number }> => { + return new Promise((resolve) => { + const img = new Image(); + img.onload = () => { + resolve({ width: img.naturalWidth, height: img.naturalHeight }); + }; + img.onerror = () => { + resolve({ width: 0, height: 0 }); + }; + // 若是跨域资源并允许匿名访问,可尝试设置 + try { + img.crossOrigin = 'anonymous'; + } catch (_) {} + img.src = url; + }); +}; + +/** + * 基于图片 URL 判断图片横竖 + */ +export const getImageOrientationByUrl = async (url: string): Promise => { + const { width, height } = await getImageNaturalSize(url); + return getImageOrientationBySize(width, height); +}; diff --git a/src/views/creative-generation-workshop/manuscript/list/components/manuscript-table/index.vue b/src/views/creative-generation-workshop/manuscript/list/components/manuscript-table/index.vue index feb9347..57df651 100644 --- a/src/views/creative-generation-workshop/manuscript/list/components/manuscript-table/index.vue +++ b/src/views/creative-generation-workshop/manuscript/list/components/manuscript-table/index.vue @@ -71,11 +71,13 @@ {{ exactFormatTime(record[column.dataIndex]) }}