Commit 66787efa authored by zhangjianguo's avatar zhangjianguo

颜色判定

parent 7a614b1e
......@@ -97,6 +97,7 @@ export default {
goodprice: '',
goodamount: '',
mc: '',
fu:'',
secondary: '',
gc: 1,
bian: false,
......@@ -151,6 +152,7 @@ export default {
this.goodimage = this.g.cover_pic;
this.mc = this.$uiConfig.mainColor;
this.fu = this.$uiConfig.secondary;
this.secondary = this.$uiConfig.secondary;
this.skuObj = this.skued.id ? this.skued : null;
if (this.skuObj) {
......@@ -186,6 +188,7 @@ export default {
}
});
}
this.getfu()
this.formatDisableSku();
this.formatChosenTips();
}
......@@ -193,6 +196,42 @@ export default {
// this.g = this.good;
},
methods: {
getfu(){
let fucolor = this.colorRgb(this.fu) ;
var RgbValue = fucolor.replace("rgb(", "").replace(")", "");
var RgbValueArry = RgbValue.split(",");
var grayLevel = RgbValueArry[0] * 0.299 + RgbValueArry[1] * 0.587 + RgbValueArry[2] * 0.114;
console.log(grayLevel)
if(grayLevel>=192){
this.btn1.color = this.mc;
}else{
this.btn1.color = '#FFF';
}
},
colorRgb(color) {
var sColor = color.toLowerCase();
//十六进制颜色值的正则表达式
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
// 如果是16进制颜色
if (sColor && reg.test(sColor)) {
if (sColor.length === 4) {
var sColorNew = "#";
for (var i = 1; i < 4; i += 1) {
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
}
sColor = sColorNew;
}
//处理六位的颜色值
var sColorChange = [];
for (var i = 1; i < 7; i += 2) {
sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
}
return sColorChange.join(",");
}
return sColor;
},
joinCar() {
if (this.skuObj && this.skuObj.id) {
this.request2(
......
......@@ -64,12 +64,48 @@ export default {
this.bian = this.$utils.is_biang;
this.btn1.background = this.fu;
this.btn2.background = this.mc;
this.getfu()
let t = getCurrentPages();
this.path = '/' + t[t.length - 1].route;
//console.log(t[t.length - 1]);
this.favorStatus = this.favorite;
},
methods: {
getfu(){
let fucolor = this.colorRgb(this.fu) ;
var RgbValue = fucolor.replace("rgb(", "").replace(")", "");
var RgbValueArry = RgbValue.split(",");
var grayLevel = RgbValueArry[0] * 0.299 + RgbValueArry[1] * 0.587 + RgbValueArry[2] * 0.114;
console.log(grayLevel)
if(grayLevel>=192){
this.btn1.color = this.mc;
}else{
this.btn1.color = '#FFF';
}
},
colorRgb(color) {
var sColor = color.toLowerCase();
//十六进制颜色值的正则表达式
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
// 如果是16进制颜色
if (sColor && reg.test(sColor)) {
if (sColor.length === 4) {
var sColorNew = "#";
for (var i = 1; i < 4; i += 1) {
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
}
sColor = sColorNew;
}
//处理六位的颜色值
var sColorChange = [];
for (var i = 1; i < 7; i += 2) {
sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
}
return sColorChange.join(",");
}
return sColor;
},
goCart() {
uni.redirectTo({
url: '/pages/cart/cart'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment