2025年04月18日18:40:29

This commit is contained in:
luojiayi 2025-04-18 18:40:31 +08:00
parent f9e437ce29
commit 11606b87ad
3 changed files with 23 additions and 19 deletions

View File

@ -5,7 +5,7 @@ import { useEffect, useState } from 'react'
import Taro from '@tarojs/taro' import Taro from '@tarojs/taro'
export default function Index({ open, handleColorPicker }) { export default function Index({ open, handleColorPicker }) {
const [data, setData] = useState({ let [data, setData] = useState({
boundaryData: [], // boundaryData: [], //
gradient: '', gradient: '',
hex: '#000000', hex: '#000000',
@ -42,23 +42,26 @@ export default function Index({ open, handleColorPicker }) {
state.hex = '#' + rgbToHex(data.rgba) state.hex = '#' + rgbToHex(data.rgba)
return { ...state } return { ...state }
}) })
wx.nextTick(() => {
getBoundaryData();
})
}, []) }, [])
useEffect(() => {
if (open) {
setTimeout(() => {
getBoundaryData();
}, 200)
}
}, [open])
// //
const getBoundaryData = () => { const getBoundaryData = () => {
Taro.createSelectorQuery().selectAll('.range-box').boundingClientRect((data) => { Taro.createSelectorQuery().selectAll('.range-box').boundingClientRect((res) => {
if (!data || data.length === 0) { if (!res || res.length === 0) {
setTimeout(() => getBoundaryData(), 20) setTimeout(() => getBoundaryData(), 20)
return return
} }
setData((state) => { data.boundaryData = res
state.boundaryData = data console.log(res);
return { ...state }
}) setData({ ...data })
}).exec() }).exec()
} }
@ -72,7 +75,6 @@ export default function Index({ open, handleColorPicker }) {
const touchstart = (e) => { const touchstart = (e) => {
const index = e.currentTarget.dataset.index; const index = e.currentTarget.dataset.index;
const { const {
pageX, pageX,
pageY pageY
@ -86,7 +88,6 @@ export default function Index({ open, handleColorPicker }) {
pageX, pageX,
pageY pageY
} = e.touches[0]; } = e.touches[0];
console.log(pageX, pageY, index);
setPointAndColor(pageX, pageY, index); setPointAndColor(pageX, pageY, index);
} }

View File

@ -26,11 +26,12 @@ export default function Index() {
</View > </View >
<View className='colorbox'> <View className='colorbox'>
<View className='colorbox-icon'></View> <View className='colorbox-icon' onClick={() => setOpen(true)}></View>
<View className='colorbox-btn'>#EDEDED</View> <View className='colorbox-btn' onClick={() => setOpen(true)}>#EDEDED</View>
</View> </View>
<View className='btn' onClick={() => setOpen(true)}>传输画面到音响屏幕</View> <View className='hint'>*请选取喜欢的颜色再点击小方格填入颜色</View>
<View className='hint'>*点击上方小格子并选取颜色</View>
<View className='btn' >传输画面到音响屏幕</View>
<ColorPicker open={open} handleColorPicker={handleColorPicker} /> <ColorPicker open={open} handleColorPicker={handleColorPicker} />
</View > </View >

View File

@ -70,7 +70,8 @@
.hint { .hint {
color: #999999; color: #999999;
font-size: 26rpx; font-size: 26rpx;
margin: 24rpx; margin: 32rpx 0 64rpx;
margin-left: 48rpx;
} }
.colorbox { .colorbox {
@ -83,6 +84,7 @@
height: 54rpx; height: 54rpx;
background: url('../../assets/chromaticCircle.png') no-repeat; background: url('../../assets/chromaticCircle.png') no-repeat;
background-size: 100% 100%; background-size: 100% 100%;
margin-right: 16rpx;
} }
.colorbox-btn { .colorbox-btn {
@ -107,7 +109,7 @@
line-height: 80rpx; line-height: 80rpx;
color: #FFFFFF; color: #FFFFFF;
font-size: 30rpx; font-size: 30rpx;
margin: 24rpx auto; margin: 0 auto;
} }