92 lines
4.2 KiB
React
Raw Normal View History

2025-04-19 18:21:33 +08:00
import { View, Image } from '@tarojs/components'
import './index.less'
import ColorPicker from "@/components/color-picker";
import { useEffect, useState } from 'react';
import history from "../../assets/history.png";
2025-04-21 18:27:42 +08:00
import Taro from '@tarojs/taro';
import { hex, strInsert } from '@/utils/sendOrder';
import BLESDK from '@/utils/ble'
import router from '@/baseRouter/index'
2025-04-19 18:21:33 +08:00
export default function Index() {
2025-04-21 18:27:42 +08:00
const [list, setList] = useState(["255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255", "255, 255, 255"])
2025-04-19 18:21:33 +08:00
const [open, setOpen] = useState(false)
2025-04-21 18:27:42 +08:00
const [curColor, setCurColor] = useState({
hex: '#ff0000',
rgba: '255, 0, 0'
})
const toPage = () => {
router.navigate('/pages/history/index').then((data) => {
setList([...data])
})
}
2025-04-19 18:21:33 +08:00
const handleColorPicker = (e) => {
2025-04-21 18:27:42 +08:00
if (e) {
setCurColor(e)
}
2025-04-19 18:21:33 +08:00
setOpen(false)
}
2025-04-21 18:27:42 +08:00
const addColor = (index) => {
setList((state) => {
state[index] = curColor.rgba
return [...state]
})
}
const submit = () => {
let str = '7B55EA10B2'
for (let i = 0; i < list.length; i++) {
const item = list[i].split(',')
str += hex(item[0])
str += hex(item[1])
str += hex(item[2])
str += hex(1)
}
BLESDK.writeBleValue(new Uint8Array(strInsert(str)).buffer)
2025-04-22 11:57:57 +08:00
setTimeout(() => {
router.back()
}, 800)
2025-04-21 18:27:42 +08:00
}
const saveTemplate = () => {
let historyList = Taro.getStorageSync('colorList') || []
if (historyList.length > 10) {
historyList[0] = list
} else {
historyList.unshift(list)
}
Taro.setStorageSync('colorList', historyList)
Taro.showToast({
title: '保存成功',
icon: "none",
})
}
2025-04-19 18:21:33 +08:00
2025-04-25 17:19:37 +08:00
BLESDK.onBLECharacteristicValueChange((bytes) => {
if (bytes[0] == 0x7A && bytes[4] == 0xB3) {
Taro.showToast({ title: '操作成功', icon: 'none' })
}
})
2025-04-19 18:21:33 +08:00
return (
<View className="index">
<View className='head'>
<View className='head-left'>像素跳动</View>
2025-04-22 11:57:57 +08:00
<View className='head-right' onClick={toPage}> <Image className='icon' src={history} />模板列表</View>
2025-04-19 18:21:33 +08:00
</View>
<View className="grid">
2025-04-21 18:27:42 +08:00
{list.map((item, index) => <View className="grid-item" style={{ backgroundColor: `rgb(${item})` }} key={index} onClick={() => addColor(index)}></View>)}
2025-04-19 18:21:33 +08:00
</View >
<View className='colorbox'>
<View className='colorbox-icon' onClick={() => setOpen(true)}></View>
2025-04-21 18:27:42 +08:00
<View className='colorbox-btn' style={{ backgroundColor: curColor.hex }} onClick={() => setOpen(true)}>{curColor.hex}</View>
2025-04-19 18:21:33 +08:00
</View>
<View className='hint'>*请选取喜欢的颜色再点击小方格填入颜色</View>
2025-04-22 11:57:57 +08:00
<View className='btns'>
<View className='btn' onClick={saveTemplate}>保存模板</View>
<View className='btn' onClick={submit}>传输到音响屏幕</View>
</View>
2025-04-21 18:27:42 +08:00
<ColorPicker open={open} onChange={handleColorPicker} />
2025-04-19 18:21:33 +08:00
</View >
)
}