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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
<div :class="{'app-field-image-dynamic':true,[`${cssClass}`]:cssClass?true:false}">
<img :style="cssStyle" :src="imgUrl" />
</div>
</template>
<script lang = 'ts'>
import { Vue, Component, Prop, Watch, Provide } from 'vue-property-decorator';
import { ImgurlBase64 } from '@/utils';
import { Environment } from "@/environments/environment";
@Component({})
export default class AppFieldImageDynamic extends Vue {
/**
* 输入值
*
* @type {string}
* @memberof AppRawItemImage
*/
@Prop() public value: any;
/**
* 样式
*
* @type {string}
* @memberof AppRawItemImage
*/
@Prop() public cssStyle?: string;
/**
* 样式表类名
*
* @type {string}
* @memberof AppRawItemImage
*/
@Prop({default:''}) public cssClass?: string;
/**
* 动态图片路径
*
* @memberof AppPresetRawitem
*/
protected dynaImgUrl: string = '';
/**
* 下载文件路径
*
* @memberof AppPresetRawitem
*/
public downloadUrl = Environment.ExportFile;
/**
* 图片路径
*
* @memberof AppPresetRawitem
*/
get imgUrl(): string {
return this.dynaImgUrl;
}
created() {
this.handleDynaImg();
}
/**
* 处理动态图片
*
* @memberof AppPresetRawitem
*/
protected handleDynaImg() {
if (this.value && typeof this.value == "string") {
// 默认识别文件对象形式,识别失败则为全路径模式
try {
const _files = JSON.parse(this.value);
const file = _files instanceof Array ? _files[0] : null;
const url =
file && file.id ? `${this.downloadUrl}/${file.id}` : "";
ImgurlBase64.getInstance()
.getImgURLOfBase64(url)
.then((res: any) => {
this.dynaImgUrl = res;
});
} catch (error) {
this.dynaImgUrl = this.value;
}
}
}
}
</script>
<style lang = "less">
@import './app-field-image-dynamic.less';
</style>