fix修复重置问题

This commit is contained in:
Haiyi 2022-06-29 20:09:30 +08:00
parent 8c6392c90e
commit 349d41c62d

View File

@ -18,11 +18,11 @@ export default () => {
a2: '', a2: '',
b2: '', b2: '',
}) })
type ColorList = {
const [colorList, setColorList] = useState({ one?: any,
one: null, two?: any
two: null }
}) const [colorList, setColorList] = useState<ColorList>()
const { state: colorState, measureAndGetLab } = useBluetooth() const { state: colorState, measureAndGetLab } = useBluetooth()
const getLab = async (val) => { const getLab = async (val) => {
@ -57,25 +57,28 @@ export default () => {
useEffect(() => { useEffect(() => {
if (colorState.deviceLab) { if (colorState.deviceLab) {
if (colorList.one?.constructor === Object) { if ((colorList as any).one?.constructor === Object) {
const rgb = toRgb([colorList.one.L, colorList.one.a, colorList.one.b]) const rgb = toRgb([(colorList as any).one.L, (colorList as any).one.a, (colorList as any).one.b])
setBlueToothColor(`rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`) setBlueToothColor(`rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`)
setTime(getNowTime()) setTime(getNowTime())
setSearchField({ ...searchField, l1: rgb[0], a1: rgb[1], b1: rgb[2] }) setSearchField({ ...searchField, l1: rgb[0], a1: rgb[1], b1: rgb[2] })
} }
if (colorList.two?.constructor === Object) { if ((colorList as any).two?.constructor === Object) {
const rgb = toRgb([colorList.two.L, colorList.two.a, colorList.two.b])
const rgb = toRgb([(colorList as any).two.L, (colorList as any).two.a, (colorList as any).two.b])
setBlueToothColorTwo(`rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`) setBlueToothColorTwo(`rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`)
setTimeTwo(getNowTime()) setTimeTwo(getNowTime())
setSearchField({ ...searchField, l2: rgb[0], a2: rgb[1], b2: rgb[2] }) setSearchField({ ...searchField, l2: rgb[0], a2: rgb[1], b2: rgb[2] })
} }
} }
}, [colorList]) }, [colorList])
const reset = () => { const reset = () => {
setColorList({})
setBlueToothColor('') setBlueToothColor('')
setBlueToothColorTwo('') setBlueToothColorTwo('')
setTime('') setTime('')
setTime('') setTimeTwo('')
setData('') setData('')
setResult('') setResult('')
} }