Commit 24d145d2 by zhuzhequan

fix:修复md5图片不显示问题

parent d2b3b13e
......@@ -5,12 +5,13 @@
@mouseover="(ev) => mouseoverImg(ev, src)"
@mouseleave="mouseleaveImg"
>
<img :src="src" :style="imageStyle" />
<img :src="formatUrl" :style="imageStyle" />
</div>
</template>
<script setup lang="ts">
import useImagePreview from '@/utils/hooks/useImagePreview.'
import { computed, defineProps } from 'vue'
import { formatImgUrl } from '@/utils/hooks/commonUtil.ts'
const props = defineProps({
src: {
type: String,
......@@ -31,6 +32,12 @@ const imageStyle = computed(() => {
height: props.height,
}
})
const formatUrl = computed(() => {
const w = Number(props.width.replace('px',''))
const h = Number(props.height.replace('px',''))
return formatImgUrl({url:props.src,w,h})
})
const { mouseoverImg, mouseleaveImg } = useImagePreview()
</script>
<style lang="scss" scoped>
......
import {md5} from 'js-md5'
export type AnyObject = {
[propName: string]: string | number | boolean | undefined | unknown
}
......@@ -145,3 +146,65 @@ export function checkUpdateParams(
}
return params
}
/**
* 图片下载地址
* w=width&h=height&g=isgray&x=position_x&y=position_y&r=rotate&q=quality&f=format
* @param {*} url
* @param {Object} options
* @param {Number} options.w -width
* @param {Number} options.w -height
* @param {0 | 1} options.g -isgray 灰色
* @param {Number} options.x -position_x
* @param {Number} options.y -position_y
* @param {Number} options.r -rotate 旋转
* @param {Number} options.f - 格式
* @param {Number} options.q -quality 质量
* @param {'jpeg' | 'png' | 'gif' | 'jeg'} options.f -format
* @returns String
*/
interface formatOption{
url:string
w?:number
h?:number
others?:never
options?:never
}
// 图片地址格式化
export function formatImgUrl(option:formatOption): string {
const {url,w,h,others} = option
let imagePath = ''
let query = ''
if (w) {
query += query ? '&w=' : 'w=' + Math.floor(w);
}
if (h) {
query += query ? '&h=' : 'h=' + Math.floor(h);
}
if(others){
Object.keys(others).forEach(key => {
query += `${query ? '&' : ''}${key}=${others[key]}`;
});
}
const zImgPath = `${location.origin}${
location.host.indexOf('test') !== -1 || location.protocol == 'http:'
? '/erpimg/'
: ''
}`
if(url.startsWith('http')) {
return url
}else if(url.startsWith('/')) {
return window.location + url
} else {
if ('42f2b26039d7fd526b8a1d50bb329cbc' === md5(location.host)) {
imagePath = zImgPath + '/erpimg/'+ url
} else if (zImgPath.indexOf('/erpimg') !== -1) {
imagePath = zImgPath +url
} else {
imagePath = 'https://image.jomalls.com/'+ url + (query ? '?' : '') + query
}
return imagePath
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment