-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathharmony.js
More file actions
63 lines (57 loc) · 1.21 KB
/
harmony.js
File metadata and controls
63 lines (57 loc) · 1.21 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
59
60
61
62
63
Component({
properties: {
// alipay | user | setup
name: {
type: String,
},
// string | string[]
color: {
type: null,
observer: function(color) {
this.setData({
colors: this.fixColor(),
isStr: typeof color === 'string',
});
}
},
size: {
type: Number,
value: 20,
observer: function(size) {
this.setData({
svgSize: size,
});
},
},
},
data: {
colors: '',
svgSize: 20,
quot: '"',
isStr: true,
},
methods: {
fixColor: function() {
var color = this.data.color;
var hex2rgb = this.hex2rgb;
if (typeof color === 'string') {
return color.indexOf('#') === 0 ? hex2rgb(color) : color;
}
return color.map(function (item) {
return item.indexOf('#') === 0 ? hex2rgb(item) : item;
});
},
hex2rgb: function(hex) {
var rgb = [];
hex = hex.substr(1);
if (hex.length === 3) {
hex = hex.replace(/(.)/g, '$1$1');
}
hex.replace(/../g, function(color) {
rgb.push(parseInt(color, 0x10));
return color;
});
return 'rgb(' + rgb.join(',') + ')';
}
}
});