🌈 style(eslint): 新增eslint规则

This commit is contained in:
xuan
2022-12-02 18:59:29 +08:00
parent c3cb46a5a7
commit d49314aa5b
217 changed files with 19491 additions and 19187 deletions
+81 -81
View File
@@ -1,93 +1,93 @@
import { View } from "@tarojs/components";
import { memo, useEffect, useMemo, useState } from "react";
import Taro, { useDidShow } from "@tarojs/taro";
import {useBluetooth} from "@/use/contextBlueTooth"
import SearchInput from "@/components/searchInput";
import Popup from "@/components/bluetooth/Popup"
import classnames from "classnames";
import styles from "./css/linkBlueTooth.module.scss"
import useCheckAuthorize from "@/use/useCheckAuthorize";
import { View } from '@tarojs/components'
import Taro, { useDidShow } from '@tarojs/taro'
import { memo, useEffect, useMemo, useState } from 'react'
import classnames from 'classnames'
import styles from './css/linkBlueTooth.module.scss'
import { useBluetooth } from '@/use/contextBlueTooth'
import SearchInput from '@/components/searchInput'
import Popup from '@/components/bluetooth/Popup'
import useCheckAuthorize from '@/use/useCheckAuthorize'
export default memo(() => {
const {state, init, startScan, connect, disconnect} = useBluetooth()
const { state, init, startScan, connect, disconnect } = useBluetooth()
const {check} = useCheckAuthorize({scope:'scope.bluetooth', msg:'请开启小程序蓝牙权限'})
const { check } = useCheckAuthorize({ scope: 'scope.bluetooth', msg: '请开启小程序蓝牙权限' })
useEffect(() => {
init()
}, [])
useEffect(() => {
init()
}, [])
const [linkStatus, setLinkStatus] = useState(1)
useEffect(() => {
if(!state.available) {
setLinkStatus(1)
} else if(state.available&&state.connected?.name) {
setLinkStatus(3)
} else {
setLinkStatus(2)
}
}, [state.available, state.connected])
const linkName = useMemo(() => {
return state.connected?.localName||''
}, [state.connected])
//链接设备
const onLinkListen = (item) => {
if(!state.connected&&!state.connecting)
connect(item)
const [linkStatus, setLinkStatus] = useState(1)
useEffect(() => {
if (!state.available) {
setLinkStatus(1)
}
else if (state.available && state.connected?.name) {
setLinkStatus(3)
}
else {
setLinkStatus(2)
}
}, [state.available, state.connected])
const [popupShow, setPopupShow] = useState(false)
//显示设备列表
const onFindDevice = () => {
check().then(res => {
if(linkStatus == 1) {
Taro.showToast({
title:'请打开手机蓝牙',
icon:'none'
})
} else {
setPopupShow(true)
onFindEven()
}
const linkName = useMemo(() => {
return state.connected?.localName || ''
}, [state.connected])
// 链接设备
const onLinkListen = (item) => {
if (!state.connected && !state.connecting) { connect(item) }
}
const [popupShow, setPopupShow] = useState(false)
// 显示设备列表
const onFindDevice = () => {
check().then((res) => {
if (linkStatus == 1) {
Taro.showToast({
title: '请打开手机蓝牙',
icon: 'none',
})
}
const onFindEven = () => {
if(!state.discovering&&!state.connected&&!state.connecting)
startScan()
}
}
else {
setPopupShow(true)
onFindEven()
}
})
}
const onFindEven = () => {
if (!state.discovering && !state.connected && !state.connecting) { startScan() }
}
//断开链接
const onDisconnect = () => {
disconnect()
setPopupShow(false)
}
// 断开链接
const onDisconnect = () => {
disconnect()
setPopupShow(false)
}
return (
<>
<View className={styles.main}>
<SearchInput title="蓝牙设备" showIcon={true}>
<View className={styles.bluetooth_link} onClick={onFindDevice}>
<View className={classnames(styles.link_status, linkStatus == 3 &&styles.link_statused, linkStatus == 2&&styles.link_statused_no)}></View>
{
linkStatus == 1&&<View className={classnames(styles.link_name, styles.link_name_no)}>请开启蓝牙</View>||
linkStatus == 2&&<View className={classnames(styles.link_name,styles.link_name_no_link) }>未连接设备</View>||
linkStatus == 3&&<View className={classnames(styles.link_name)}>{linkName}</View>
}
</View>
</SearchInput>
<Popup
state={state}
show={popupShow}
onClose={() => setPopupShow(false)}
onLink={item => onLinkListen(item)}
onOff={onDisconnect}
onFind={onFindEven}
/>
</View>
</>
);
return (
<>
<View className={styles.main}>
<SearchInput title="蓝牙设备" showIcon>
<View className={styles.bluetooth_link} onClick={onFindDevice}>
<View className={classnames(styles.link_status, linkStatus == 3 && styles.link_statused, linkStatus == 2 && styles.link_statused_no)}></View>
{
linkStatus == 1 && <View className={classnames(styles.link_name, styles.link_name_no)}>请开启蓝牙</View>
|| linkStatus == 2 && <View className={classnames(styles.link_name, styles.link_name_no_link)}>未连接设备</View>
|| linkStatus == 3 && <View className={classnames(styles.link_name)}>{linkName}</View>
}
</View>
</SearchInput>
<Popup
state={state}
show={popupShow}
onClose={() => setPopupShow(false)}
onLink={item => onLinkListen(item)}
onOff={onDisconnect}
onFind={onFindEven}
/>
</View>
</>
)
})
+66 -66
View File
@@ -1,73 +1,73 @@
import { ScrollView, View } from "@tarojs/components"
import { memo, useEffect, useState } from "react"
import Loading from "@/components/loading"
import style from "./css/popup.module.scss"
import { ScrollView, View } from '@tarojs/components'
import { memo, useEffect, useState } from 'react'
import style from './css/popup.module.scss'
import Loading from '@/components/loading'
interface params {
state: any,
show: Boolean,
onClose: (Boolean) => void,
onLink: (any) => void,
children?: React.ReactNode
onOff: () => void,
onFind: () => void,
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>
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.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>
(!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.mask} onClick={onCloseListener}></View>
</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>
}
</>
)
})