prodImage.js
1.25 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
/**
* Created by TaoHuang on 2017/5/12.
*/
import _ from 'lodash';
function sknImage({skn, sku, size}) {
let baseUrl = '/Api/platform/getRemoteImageUrlBySku';
let params = [];
if (skn) {
params.push(`skn_id=${skn}`);
}
if (sku) {
params.push(`sku_id=${sku}`);
}
params.push(size ? `size=${size}` : 'size=80x80');
params.push(`t=${new Date().getTime()}`);
return `${baseUrl}?${params.join('&')}`;
}
export default {
bind(el, binding) {
// v-prod-img.skn="{ val: 'fdsa', size: '121X123'}" skn
// v-prod-img.sku="{ val: 'fdsa', size: '121X123'}" sku
// v-prod-img.sku="row.productSkn" sku
// v-prod-img.skn="row.productSkn" skn
// v-prod-img="row.productSkn" skn
let data = null;
let key = null;
if (!_.isEmpty(binding.modifiers)) {
key = _.first(_.keys(binding.modifiers));
} else {
key = 'skn';
}
if (_.isPlainObject(binding.value)) {
data = {
[key]: binding.value.val,
size: binding.value.size
};
} else {
data = {
[key]: binding.value
};
}
el.src = sknImage(data);
}
};