2022-04-18 18:47:22 +08:00

73 lines
3.7 KiB
TypeScript

import { ScrollView, View } from "@tarojs/components"
import { memo, useEffect, useState } from "react"
import Loading from "@/components/loading"
import style from "./css/popup.module.scss"
interface params {
state: any,
show: Boolean,
onClose: (Boolean) => void,
onLink: (any) => void,
children?: React.ReactNode
onOff: () => void,
onFind: () => void,
}
export default memo(({state, show=false, onClose, onLink, onOff, onFind}:params) => {
const [popupShow, setPopupShow] = useState(show)
useEffect(() => {
setPopupShow(show)
}, [show])
const onCloseListener = () => {
onClose(false)
}
return (
<>
{
popupShow&&<View className={style.popup}>
<View className={style.content}>
<View className={style.title}></View>
<View className={style.list}>
<ScrollView scrollY className={style.scroll}>
{
(state.devices&&state.devices.length > 0)&&state?.devices.map(item => {
return (
<View className={style.item} onClick={() => onLink(item)}>
<View>{item.name}</View>
{
(!state.connecting&&!state.connected)&&<View ></View>||
(state.connecting&&item.deviceId == state.connecting.deviceId)&&<View className={style.link_ing}>...</View>||
(state.connected&&item.deviceId == state.connected.deviceId)&&<View className={style.link_success}></View>
}
</View>
)
})||
<View className={style.noDevice}>
{
(!state.discovering)&& <>
<View>,</View>
<View className={style.n_item}>1.</View>
<View className={style.n_item}>2.</View>
<View className={style.n_item}>3.</View>
</>||
<View></View>
}
</View>
}
</ScrollView>
</View>
{
state.connected&&<View className={`${style.footer} ${style.footer_off}`} onClick={onOff}></View>||
(!state.connected&&state.discovering)&&<View className={`${style.footer} ${style.finding}`}><Loading width={30} color='orange'/></View>||
<View className={style.footer} onClick={onFind}></View>
}
</View>
<View className={style.mask} onClick={onCloseListener}></View>
</View>
}
</>
)
})