This commit is contained in:
Haiyi
2022-06-28 14:04:59 +08:00
parent 18c9ef9b0c
commit 2de447402e
3 changed files with 522 additions and 9 deletions
@@ -94,6 +94,7 @@ page {
font-family: Microsoft YaHei, Microsoft YaHei-Regular;
font-weight: 400;
color: #707070;
}
}
@@ -101,6 +102,13 @@ page {
.color_bock {
width: 290px;
height: 290px;
border-radius: 50%;
}
.color_bocktwo {
width: 290px;
height: 290px;
border-radius: 50%;
}
.nameColor {
+37 -9
View File
@@ -3,6 +3,7 @@ import { Image, Text, Textarea, View } from "@tarojs/components"
import Taro, { useDidShow, usePullDownRefresh, useRouter } from "@tarojs/taro";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useBluetooth } from "@/use/contextBlueTooth"
import { useBluetoothTwo } from "@/use/BlueToothCopy"
import classnames from "classnames";
import LinkBlueTooth from "./compoents/bluetooth/LinkBlueTooth";
import { toRgb } from '@/common/bluetooth/color/colorSpace'
@@ -21,10 +22,22 @@ export default () => {
product_kind_id: '',
component: ''
})
const [colorList, setColorList] = useState({
one: [],
two: []
})
const { state: colorState, measureAndGetLab } = useBluetooth()
const getLab = () => {
const getLab = async (val) => {
if (colorState.connected) {
measureAndGetLab()
let res = await measureAndGetLab()
if (val === 1) {
setColorList({ ...colorList, one: res })
} else {
setColorList({ ...colorList, two: res })
console.log('colorList',colorList)
}
} else {
Taro.showToast({
title: '请链接设备',
@@ -32,15 +45,24 @@ export default () => {
})
}
}
//监听lab数据变化
const [blueToothColor, setBlueToothColor] = useState('')
const [blueToothColorTwo, setBlueToothColorTwo] = useState('')
useEffect(() => {
if (colorState.deviceLab) {
const rgb = toRgb([colorState.deviceLab.L, colorState.deviceLab.a, colorState.deviceLab.b])
setBlueToothColor(`rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`)
setSearchField({ ...searchField, l: rgb[0], a: rgb[1], b: rgb[2], size: 10 })
console.log(colorList, 'colorList.one.lengthcolorList.one.length')
if (colorList.one?.constructor === Object) {
setBlueToothColor(`rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`)
console.log(blueToothColor, 'blueToothColorblueToothColor')
}
if (colorList.two?.constructor === Object) {
setBlueToothColorTwo(`rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`)
}
// setSearchField({ ...searchField, l: rgb[0], a: rgb[1], b: rgb[2], size: 10 })
}
}, [colorState.deviceLab])
}, [colorList])
return (
<View className={styles.body}>
{/* <View className={styles.topBox}>
@@ -58,7 +80,7 @@ export default () => {
<View className={styles.firstLeftName} >对比样品</View>
{
blueToothColor === '' &&
<View className={styles.firstLeftbox} onClick={() => getLab()}>
<View className={styles.firstLeftbox} onClick={() => getLab(1)}>
<View className={styles.clickFont} >点击取色</View>
</View>
}
@@ -69,9 +91,15 @@ export default () => {
</View>
<View className={styles.firstBox}>
<View className={styles.firstLeftName}>对比样品</View>
<View className={styles.firstLeftbox}>
<View className={styles.clickFont} onClick={() => getLab()}>点击取色</View>
</View>
{
blueToothColorTwo === '' &&
<View className={styles.firstLeftbox} onClick={() => getLab(2)}>
<View className={styles.clickFont} >点击取色</View>
</View>
}
{blueToothColorTwo && <View className={classnames(styles.color_bocktwo)} style={{ background: blueToothColorTwo }}></View>
}
<View className={styles.nameColor}>--</View>
</View>
</View>