-
Notifications
You must be signed in to change notification settings - Fork 552
Expand file tree
/
Copy pathicon.ts
More file actions
58 lines (56 loc) · 1.38 KB
/
icon.ts
File metadata and controls
58 lines (56 loc) · 1.38 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
import Base64 from './base64'
import iconData from './icondata'
const getFixedIconType = function (type: string): string {
// 兼容旧版本 typo
return type === 'field' ? 'filled' : type
}
Component({
options: {
addGlobalClass: true
},
properties: {
extClass: {
type: String,
value: ''
},
type: {
type: String,
value: 'outline',
observer: '_genSrcByType'
},
icon: {
type: String,
value: '',
observer: '_genSrcByIcon'
},
size: {
type: Number,
value: 20
},
color: {
type: String,
value: '#000000'
}
},
data: {
src: '',
height: 20,
width: 20
},
methods: {
_genSrcByIcon(v) {
this._genSrc(/<svg .*>.*<\/svg>/.test(v) ? v : iconData[v][getFixedIconType(this.data.type)])
},
_genSrcByType(v) {
const iconDataItem = iconData[this.data.icon]
if (iconDataItem) this._genSrc(iconDataItem[getFixedIconType(v)])
},
_genSrc(rawData) {
if (!rawData) return // type 不存在
const base64 = Base64.encode(rawData)
this.setData({
src: 'data:image/svg+xml;base64,' + base64
})
}
}
})