Component({
properties: {
initColor: {
type: String,
value:'rgb(255,0,0)'
},
maskClosable: {
type: Boolean,
value: true
},
mask: {
type: Boolean,
value: true
},
show: {
type: Boolean,
value: false
},
},
data: {
},
lifetimes: {
attached() {
let { initColor} = this.data;
this.setData({
hueColor: this.hsv2rgb((this.rgb2hsv(initColor)).h,100,100)
})
},
ready() {
const $ = this.createSelectorQuery()
const target = $.select('.target')
target.boundingClientRect()
$.exec((res) => {
const rect = res[0]
if (rect) {
this.SV = {
W: rect.width - 28, // block-size=28
H: rect.height - 28,
Step: (rect.width - 28) / 100
}
let { h, s, v } = this.rgb2hsv(this.data.initColor)
// 初始化定位
this.setData({
hsv:{
h,s,v
},
x: Math.round(s * this.SV.Step),
y: Math.round((100 - v) * this.SV.Step)
})
}
})
}
},
methods: {
areaTap(res) {
const $ = this.createSelectorQuery()
const target = $.select('.target')
target.boundingClientRect()
$.exec((r) => {
const rect = r[0]
if (rect) {
// 修正浮标位置, 魔法数字`-14`:去除半个浮标的宽度
this.setData({
x: res.detail.x - rect.left - 14,
y: res.detail.y - rect.top - 14
})
this.changeSV({
detail: {
x: this.data.x,
y: this.data.y
}
})
this.onEnd()
}
})
},
onEnd() {
this.triggerEvent('changeColor', {
color: this.data.colorRes
})
},
changeHue: function (e) {
let hue = e.detail.value;
this.setData({
"hsv.h":hue,
hueColor: this.hsv2rgb(hue, 100, 100),
colorRes: this.hsv2rgb(hue, this.data.hsv.s, this.data.hsv.v)
})
},
changeSV: function (e) {
let {
x,
y
} = e.detail;
x = Math.round(x / this.SV.Step);
y = 100 - Math.round(y / this.SV.Step);
this.setData({
"hsv.s":x,
"hsv.v": y,
colorRes: this.hsv2rgb(this.data.hsv.h, x, y)
})
},
close: function close(e) {
if (this.data.maskClosable) {
this.setData({
show: false
});
this.triggerEvent('close');
}
},
preventdefault:function() {
},
hsv2rgb: function (h, s, v) {
let hsv_h = (h / 360).toFixed(2);
let hsv_s = (s / 100).toFixed(2);
let hsv_v = (v / 100).toFixed(2);
var i = Math.floor(hsv_h * 6);
var f = hsv_h * 6 - i;
var p = hsv_v * (1 - hsv_s);
var q = hsv_v * (1 - f * hsv_s);
var t = hsv_v * (1 - (1 - f) * hsv_s);
var rgb_r = 0,
rgb_g = 0,
rgb_b = 0;
switch (i % 6) {
case 0:
rgb_r = hsv_v;
rgb_g = t;
rgb_b = p;
break;
case 1:
rgb_r = q;
rgb_g = hsv_v;
rgb_b = p;
break;
case 2:
rgb_r = p;
rgb_g = hsv_v;
rgb_b = t;
break;
case 3:
rgb_r = p;
rgb_g = q;
rgb_b = hsv_v;
break;
case 4:
rgb_r = t;
rgb_g = p;
rgb_b = hsv_v;
break;
case 5:
rgb_r = hsv_v, rgb_g = p, rgb_b = q;
break;
}
return 'rgb(' + (Math.floor(rgb_r * 255) + "," + Math.floor(rgb_g * 255) + "," + Math.floor(rgb_b * 255)) + ')';
},
rgb2hsv: function (color) {
let rgb = color.split(',');
let R = parseInt(rgb[0].split('(')[1]);
let G = parseInt(rgb[1]);
let B = parseInt(rgb[2].split(')')[0]);
let hsv_red = R / 255, hsv_green = G / 255, hsv_blue = B / 255;
let hsv_max = Math.max(hsv_red, hsv_green, hsv_blue),
hsv_min = Math.min(hsv_red, hsv_green, hsv_blue);
let hsv_h, hsv_s, hsv_v = hsv_max;
let hsv_d = hsv_max - hsv_min;
hsv_s = hsv_max == 0 ? 0 : hsv_d / hsv_max;
if (hsv_max == hsv_min) hsv_h = 0;
else {
switch (hsv_max) {
case hsv_red:
hsv_h = (hsv_green - hsv_blue) / hsv_d + (hsv_green < hsv_blue ? 6 : 0);
break;
case hsv_green:
hsv_h = (hsv_blue - hsv_red) / hsv_d + 2;
break;
case hsv_blue:
hsv_h = (hsv_red - hsv_green) / hsv_d + 4;
break;
}
hsv_h /= 6;
}
return {
h: (hsv_h * 360).toFixed(),
s: (hsv_s * 100).toFixed(),
v: (hsv_v * 100).toFixed()
}
},
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
RoomLightControler 微信小程序上位机实现 (111个子文件)
02add20b581be471b8d17f887b8e8337070546 194B
051c86e402c553998177c933cbbcf4e8583824 168B
06546e0c7f0de2ecbf4e80bcfc9185b08dc559 76B
08fe6d5555889b55fde48711950033f3127856 1.29MB
18c24c36dcfcc9cc963d52584d06159377ab23 77B
1cb51cbe8906fd8f62a2e1bdcca1a3d1fcd1ed 4KB
1e902a6a83837b983df9aae5da135c82216b2c 371B
1f62021d5dd0f0599f48326c6576e38677a898 487B
302792d9469c2e6e461c4ea78b67279c7936a8 302B
3605bd44ce6e4081734535c4567163fd30c173 1KB
373b24c12053441db9826382622c7c9bf8d9d7 137B
374b47b8207d8bb737e59f531a08d435c472cf 75B
3f8b9a380a80a3a5a0091f9c2ceeb2cb535916 240KB
44fe11c76141704de81ffb98e90e7f24a468bf 9KB
557b6fbf90340432ebc18458ba6a715675a421 123B
57ddcd97063126f5ea6612f9200fce72bd1fa7 993B
587a006c6f80a4c8e674485414aad626bbb192 86B
59319121176d4fdf0bcbd1570f7c51f88c727f 338B
59f3c1d6bb128641a40f8a42e215acf0e76c13 897B
5cc02b049fd21c82bc61a7200f51fcec66e528 334B
640e0dc44a0e9b160f85b9124714ea071ae7b6 39B
6702a29533e046b598b12360525e7dd3694182 2KB
6b6456f7ac8b92181e8aff296890fd7d3d86a3 159B
731b7380de01a8c3543c5f41aae852049f300a 171B
76ae3a00f34cbffdd9b7bdefd04253dab6cb54 2KB
7894ebd7c965d6441fc973da6ab9c7331a0e33 271B
7dd749f34c971215aabad1454517d082911847 469B
8dc9f4e8fd8371d1a2b60623e976a98937e790 611B
90d8ec439601707f98906ff15d99678ed99577 4KB
986114b6de4352f34532043917fb01b9fc90fa 142B
9b1f4239333a3e8328683e575b64ca581d2b18 84B
9d0b0d54096714369de1abcef3791c14e250d8 91B
a2e193b6a580c5012ad41f7bd3bd13ddddc425 262B
a7b4d5ba2e7f9078598d76f6e390c1db9c55cd 112B
adf706ace7bdf36cdf065e605ec0a475298690 309B
bc4b1038420ea5beb6202822e60aa23a30296f 593B
c43d3e3ad544e1d94cbc45fe2e4e1cda268eb6 6KB
c4f4ad8b95f4e74a18ce53b1d698480ce4ab2f 136B
c6fc9ce35b7d02e031b1e8f4636147321dedc1 161B
cb449036209c6261cf413c59c43320b30173fa 898B
cd122c346ee6176a4846d0d1ba75f3f1d80601 2KB
cf46781eab16ec8ccefab4cc3e89b5e57bf659 189B
cfaaf80c404eb97d3cf8b6277ec15f37e6905e 54B
cfb222ba9edef104b1ed76504c5c657fde88fa 237B
config 130B
d464358e7ceb69e98c578b385d8feb39e79147 993B
d4b88a27dcea1fbaa6da8fc19c6a8821983924 102B
daa45b412b39430f3fd8f99b1e32d7740cc809 301B
dbb6aa07a2a0c4eda8fb18992863ea2889e42b 292B
description 73B
df88508c7a5e6e57cc1d7af83caef0e864a94f 292B
e5cdcaf6eec90d61c445c7587212b57a112fe1 135B
e60c854cd7aca1ca94b2291b6745419d35800e 163B
e76c183c748834923c80f78292e46d739d556e 92B
e784e0415c898ddbf753ee79bc221bb6f4d33f 333B
e8a7c2184d368b77b68da8f6bfd0c8e474bd2f 57B
ea590c816e52f41801770b5ef0be21624f726e 148B
edd87b3be31dc51bc6d680dcb712747b688dc3 10KB
eeaa5bcad593e2fd2a6cf054b63aa047165eab 2KB
exclude 113B
f2b2d1f693a69d6301d08586551857ea4651ba 88B
f7a78e4cc81f825a4a1347f8eb47b5c3795c08 192B
.gitignore 159B
HEAD 325B
HEAD 23B
index 4KB
color-picker.js 5KB
color-picker.js 5KB
SliderVertical.js 1KB
.eslintrc.js 587B
project.config.json 667B
tsconfig.json 654B
project.private.config.json 364B
app.json 281B
package.json 256B
sitemap.json 191B
index.json 153B
logs.json 77B
SliderVertical.json 48B
color-picker.json 23B
color-picker.json 23B
master 325B
master 41B
SmilingPunpkins2022_ZH-CN6763384812_UHD.png 1.29MB
README.sample 177B
lib.wx.api.d.ts 1.22MB
lib.wx.event.d.ts 42KB
lib.wx.component.d.ts 31KB
lib.wx.cloud.d.ts 29KB
lib.wx.page.d.ts 11KB
lib.wx.app.d.ts 10KB
index.d.ts 5KB
index.ts 3KB
lib.wx.behavior.d.ts 3KB
util.ts 474B
logs.ts 362B
index.d.ts 204B
app.ts 68B
index.d.ts 41B
index.wxml 2KB
共 111 条
- 1
- 2
资源评论
love范德萨
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功