GlsxImage.vue
1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<template>
<image
:src="imagePath"
:mode="mode"
/>
</template>
<script>
import {
systemApi
} from '../api/index'
import { IMG_URL } from '../utils/cache/constantData'
export default {
props: {
mode: {
type: String,
default: 'scaleToFill'
},
src: {
type: null,
default: ''
},
},
name: 'GlsxImage',
data () {
return {
isWebp: false,
imagePath: ''
}
},
watch: {
src (n) {
if (n) this.init(n)
}
},
async mounted () {
if (this.src) this.init(this.src)
},
methods: {
async init (url) {
this.isWebp = url.includes('webp')
let checkList = ['https://', 'http://'],
isFullAdd = checkList.map(item => url.includes(item)).some(item => item),
isBASE64 = url.includes('data:image'),
v = await systemApi.getImageVersion()
this.imagePath = `${isFullAdd || isBASE64 ? '' : IMG_URL}${url}` + (isBASE64 ? '' : `?v=${v}`)
}
}
}
</script>
<style scoped lang='scss'>
image{
width: 100%;
height: 100%;
vertical-align: top;
}
</style>