|
|
@ -43,34 +43,36 @@ |
|
|
|
let bgcolor = item.bgcolor; |
|
|
|
let bgcolor = item.bgcolor; |
|
|
|
// 颜色不存在 |
|
|
|
// 颜色不存在 |
|
|
|
if (bgcolor === '') { |
|
|
|
if (bgcolor === '') { |
|
|
|
let ctx = uni.createCanvasContext('colorThief', that); |
|
|
|
// let ctx = uni.createCanvasContext('colorThief', that); |
|
|
|
if (0 === that.webviewId || ctx.webviewId === that.webviewId) { |
|
|
|
// if (0 === that.webviewId || ctx.webviewId === that.webviewId) { |
|
|
|
that.webviewId = ctx.webviewId; |
|
|
|
// that.webviewId = ctx.webviewId; |
|
|
|
uni.getImageInfo({ |
|
|
|
// uni.getImageInfo({ |
|
|
|
src: item.pic, |
|
|
|
// src: item.pic, |
|
|
|
success: function (image) { |
|
|
|
// success: function (image) { |
|
|
|
ctx.drawImage(image.path, 0, 0, image.width, image.height); |
|
|
|
// ctx.drawImage(image.path, 0, 0, image.width, image.height); |
|
|
|
ctx.draw(true, function (e) { |
|
|
|
// ctx.draw(true, function (e) { |
|
|
|
uni.canvasGetImageData({ |
|
|
|
// uni.canvasGetImageData({ |
|
|
|
canvasId: 'colorThief', |
|
|
|
// canvasId: 'colorThief', |
|
|
|
x: 0, |
|
|
|
// x: 0, |
|
|
|
y: 0, |
|
|
|
// y: 0, |
|
|
|
width: parseInt(image.width), |
|
|
|
// width: parseInt(image.width), |
|
|
|
height: parseInt(image.height), |
|
|
|
// height: parseInt(image.height), |
|
|
|
success(res) { |
|
|
|
// success(res) { |
|
|
|
let bgcolor = colorThief(res.data) |
|
|
|
// let bgcolor = colorThief(res.data) |
|
|
|
.color() |
|
|
|
// .color() |
|
|
|
.getHex(); |
|
|
|
// .getHex(); |
|
|
|
that.$set(item, 'bgcolor', bgcolor); |
|
|
|
// that.$set(item, 'bgcolor', bgcolor); |
|
|
|
that.$emit('getbgcolor', bgcolor); |
|
|
|
// that.$emit('getbgcolor', bgcolor); |
|
|
|
} |
|
|
|
// } |
|
|
|
}, |
|
|
|
// }, |
|
|
|
that |
|
|
|
// that |
|
|
|
); |
|
|
|
// ); |
|
|
|
}); |
|
|
|
// }); |
|
|
|
} |
|
|
|
// } |
|
|
|
}); |
|
|
|
// }); |
|
|
|
} |
|
|
|
// } |
|
|
|
|
|
|
|
that.$set(item, 'bgcolor', '#c40414'); |
|
|
|
|
|
|
|
that.$emit('getbgcolor', '#c40414'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
that.$set(item, 'bgcolor', bgcolor); |
|
|
|
that.$set(item, 'bgcolor', bgcolor); |
|
|
|
that.$emit('getbgcolor', bgcolor); |
|
|
|
that.$emit('getbgcolor', bgcolor); |
|
|
|