diff --git a/resources/assets/js/functions/web.js b/resources/assets/js/functions/web.js index b91e95f99..3c6f3b6e5 100755 --- a/resources/assets/js/functions/web.js +++ b/resources/assets/js/functions/web.js @@ -529,7 +529,7 @@ import {MarkdownPreview} from "../store/markdown"; /** * 图片尺寸比例超出 - * @param params {{src: *, width: (number|*), height: (number|*), crops: {percentage: string, ratio: number}, scaleSize: (number)}} + * @param params {{src: *, width: (number|*), height: (number|*), crops: {ratio?: number, size?: string, percentage?: string, cover?: string, contain?: string}, scaleSize: (number)}} * src, // 原图地址 * width, // 原图宽度 * height, // 原图高度 @@ -537,24 +537,22 @@ import {MarkdownPreview} from "../store/markdown"; * scaleSize, // 返回尺寸缩放最高尺寸 */ imageRatioHandle(params) { - if (!/\.(png|jpg|jpeg)$/.test(params.src)) { - return params - } - if (!$A.isJson(params.crops)) { return params } - params.src = $A.thumbRestore(params.src) + "/crop/" + Object.keys(params.crops).map(key => { - return `${key}:${params.crops[key]}` - }).join(",") + if ($A.imageRatioJudge(params.src)) { + params.src = $A.thumbRestore(params.src) + "/crop/" + Object.keys(params.crops).map(key => { + return `${key}:${params.crops[key]}` + }).join(",") - const ratio = $A.imageRatioExceed(params.width, params.height, params.crops.ratio) - if (ratio > 0) { - if (params.width > params.height) { - params.width = params.height * ratio; - } else { - params.height = params.width * ratio; + const ratio = $A.imageRatioExceed(params.width, params.height, params.crops.ratio) + if (ratio > 0) { + if (params.width > params.height) { + params.width = params.height * ratio; + } else { + params.height = params.width * ratio; + } } } @@ -567,6 +565,18 @@ import {MarkdownPreview} from "../store/markdown"; return params; }, + /** + * 判断图片地址是否满足比例缩放 + * @param url + * @returns {boolean} + */ + imageRatioJudge(url) { + if (!/\.(png|jpg|jpeg)$/.test(url)) { + return false + } + return $A.getDomain(url) == $A.getDomain($A.mainUrl()); + }, + /** * 图片尺寸比例超出 * @param width diff --git a/resources/assets/js/pages/manage/components/DialogView/file.vue b/resources/assets/js/pages/manage/components/DialogView/file.vue index 1a9d0e72b..169278867 100644 --- a/resources/assets/js/pages/manage/components/DialogView/file.vue +++ b/resources/assets/js/pages/manage/components/DialogView/file.vue @@ -52,7 +52,7 @@ export default { imageStyle({width, height, thumb}, type = 'style') { if (width && height) { const ratioExceed = $A.imageRatioExceed(width, height, 3) - if (/\.(png|jpg|jpeg)$/.test(thumb) && ratioExceed > 0) { + if ($A.imageRatioJudge(thumb) && ratioExceed > 0) { if (width > height) { width = height * ratioExceed; } else { @@ -91,7 +91,7 @@ export default { imageSrc({width, height, thumb}) { const ratioExceed = $A.imageRatioExceed(width, height, 3) - if (/\.(png|jpg|jpeg)$/.test(thumb) && ratioExceed > 0) { + if ($A.imageRatioJudge(thumb) && ratioExceed > 0) { thumb = $A.thumbRestore(thumb) + `/crop/ratio:${ratioExceed},percentage:320x0`; } return thumb;