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"; import Taro from '@tarojs/taro'; import { hex, strInsert } from '@/utils/sendOrder'; import BLESDK from '@/utils/ble' import router from '@/baseRouter/index' export default function Index() { 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"]) const [open, setOpen] = useState(false) const [curColor, setCurColor] = useState({ hex: '#ff0000', rgba: '255, 0, 0' }) const toPage = () => { router.navigate('/pages/history/index').then((data) => { setList([...data]) }) } const handleColorPicker = (e) => { console.log(e); if (e) { setCurColor(e) } setOpen(false) } 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) setTimeout(() => { router.back() }, 800) } 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", }) } return ( 像素跳动 模板列表 {list.map((item, index) => addColor(index)}>)} setOpen(true)}> setOpen(true)}>{curColor.hex} *请选取喜欢的颜色,再点击小方格填入颜色; 保存模板 传输到音响屏幕 ) }