🐳 chore(eslint): 修正所有文件的eslint 错误❌
This commit is contained in:
+40
-41
@@ -69,8 +69,10 @@ const stateObj: stateStype = {
|
||||
// 取色仪主动返回的数据
|
||||
deviceLab: null,
|
||||
}
|
||||
|
||||
export default (props) => {
|
||||
interface PropsType {
|
||||
children?: React.ReactNode
|
||||
}
|
||||
const BlueToothCopy = (props: PropsType) => {
|
||||
const refStatus = useRef(stateObj)
|
||||
const [state, setState] = useState(refStatus.current)
|
||||
|
||||
@@ -78,6 +80,31 @@ export default (props) => {
|
||||
refStatus.current = { ...refStatus.current, ...obj }
|
||||
setState({ ...refStatus.current })
|
||||
}
|
||||
/** 打开蓝牙适配器 */
|
||||
const openAdapter = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
Taro.openBluetoothAdapter({
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
})
|
||||
})
|
||||
}
|
||||
const subscribe = (cb) => {
|
||||
if (cb) {
|
||||
changeStatus({
|
||||
listeners: refStatus.current.listeners.add(cb),
|
||||
})
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 推送事件
|
||||
* @param {{type: string; data: any}} event
|
||||
*/
|
||||
const emit = (event) => {
|
||||
refStatus.current.listeners.forEach((cb) => {
|
||||
cb && cb(event)
|
||||
})
|
||||
}
|
||||
|
||||
const init = async() => {
|
||||
try {
|
||||
@@ -123,34 +150,6 @@ export default (props) => {
|
||||
})
|
||||
}
|
||||
|
||||
/** 打开蓝牙适配器 */
|
||||
const openAdapter = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
Taro.openBluetoothAdapter({
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送事件
|
||||
* @param {{type: string; data: any}} event
|
||||
*/
|
||||
const emit = (event) => {
|
||||
refStatus.current.listeners.forEach((cb) => {
|
||||
cb && cb(event)
|
||||
})
|
||||
}
|
||||
|
||||
const subscribe = (cb) => {
|
||||
if (cb) {
|
||||
changeStatus({
|
||||
listeners: refStatus.current.listeners.add(cb),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取蓝牙适配器状态
|
||||
* @returns {Promise<{discovering: boolean; available: boolean}>}
|
||||
@@ -164,6 +163,15 @@ export default (props) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 获取搜索到的设备
|
||||
const getDevices = (res) => {
|
||||
res.devices.forEach((device) => {
|
||||
// 排除掉已搜索到的设备和名称不合法的设备, 将新发现的设备添加到列表中
|
||||
if (/^CM/.test(device.name) && !refStatus.current.devices.find(i => i.deviceId === device.deviceId)) {
|
||||
changeStatus({ devices: [...refStatus.current.devices, device] })
|
||||
}
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 启动设备扫描
|
||||
* @param {(res: { devices: { name: string, deviceId: string, RSSI: number }[] }) => void} cb
|
||||
@@ -189,17 +197,6 @@ export default (props) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 获取搜索到的设备
|
||||
const getDevices = (res) => {
|
||||
res.devices.forEach((device) => {
|
||||
// 排除掉已搜索到的设备和名称不合法的设备, 将新发现的设备添加到列表中
|
||||
if (/^CM/.test(device.name) && !refStatus.current.devices.find(i => i.deviceId === device.deviceId)) {
|
||||
changeStatus({ devices: [...refStatus.current.devices, device] })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接设备
|
||||
* @param {{ name: string, deviceId: string, RSSI: number }} device
|
||||
@@ -354,6 +351,7 @@ export default (props) => {
|
||||
* @returns {Promise<Uint8Array>}
|
||||
*/
|
||||
function exec(command) {
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
return new Promise(async(resolve, reject) => {
|
||||
if (refStatus.current.command) {
|
||||
reject(new Error('正在执行其他命令'))
|
||||
@@ -478,6 +476,7 @@ export default (props) => {
|
||||
/>
|
||||
)
|
||||
}
|
||||
export default BlueToothCopy
|
||||
|
||||
export const useBluetoothTwo = () => {
|
||||
const res = React.useContext<any>(Context)
|
||||
|
||||
@@ -69,8 +69,7 @@ const stateObj: BluetoothStateType = {
|
||||
// 取色仪主动返回的数据
|
||||
deviceLab: null,
|
||||
}
|
||||
|
||||
export default (props) => {
|
||||
const ContextBlueTooth = (props) => {
|
||||
const refStatus = useRef(stateObj)
|
||||
const [state, setState] = useState(refStatus.current)
|
||||
|
||||
@@ -79,50 +78,6 @@ export default (props) => {
|
||||
setState({ ...refStatus.current })
|
||||
}
|
||||
|
||||
const init = async() => {
|
||||
try {
|
||||
await openAdapter()
|
||||
}
|
||||
catch (e) {
|
||||
changeStatus({ available: false })
|
||||
}
|
||||
|
||||
// 绑定事件通知
|
||||
Taro.onBluetoothAdapterStateChange((res) => {
|
||||
emit({ type: 'stateUpdate', detail: res })
|
||||
})
|
||||
Taro.onBLEConnectionStateChange((res) => {
|
||||
emit({ type: res.connected ? 'connected' : 'disconnect', detail: res })
|
||||
})
|
||||
Taro.onBLECharacteristicValueChange(({ value }) => notifySubscriber(value))
|
||||
subscribe(async(ev) => {
|
||||
if (ev.type === 'stateUpdate') {
|
||||
// 蓝牙状态发生的变化
|
||||
changeStatus({ discovering: ev.detail.discovering, available: ev.detail.available })
|
||||
}
|
||||
else if (ev.type === 'disconnect' && refStatus.current.connected && refStatus.current.connected.deviceId === ev.detail.deviceId) {
|
||||
// 断开连接
|
||||
changeStatus({
|
||||
connected: null,
|
||||
serviceId: null,
|
||||
characteristicId: null,
|
||||
deviceLab: null,
|
||||
devices: [],
|
||||
})
|
||||
Taro.showToast({ icon: 'none', title: '蓝牙连接已断开' })
|
||||
}
|
||||
else if (ev.type === 'connected' && refStatus.current.connecting) {
|
||||
// 连接成功
|
||||
changeStatus({ connected: refStatus.current.connecting, connecting: null })
|
||||
Taro.showToast({ title: '蓝牙已连接' })
|
||||
}
|
||||
else if (ev.type === 'measure') {
|
||||
// 监听取色仪主动推送lab
|
||||
await measureAndGetLab()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** 打开蓝牙适配器 */
|
||||
const openAdapter = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -151,6 +106,50 @@ export default (props) => {
|
||||
}
|
||||
}
|
||||
|
||||
const init = async() => {
|
||||
try {
|
||||
await openAdapter()
|
||||
}
|
||||
catch (e) {
|
||||
changeStatus({ available: false })
|
||||
}
|
||||
|
||||
// 绑定事件通知
|
||||
Taro.onBluetoothAdapterStateChange((res) => {
|
||||
emit({ type: 'stateUpdate', detail: res })
|
||||
})
|
||||
Taro.onBLEConnectionStateChange((res) => {
|
||||
emit({ type: res.connected ? 'connected' : 'disconnect', detail: res })
|
||||
})
|
||||
Taro.onBLECharacteristicValueChange(({ value }) => notifySubscriber(value))
|
||||
subscribe(async(ev) => {
|
||||
if (ev.type === 'stateUpdate') {
|
||||
// 蓝牙状态发生的变化
|
||||
changeStatus({ discovering: ev.detail.discovering, available: ev.detail.available })
|
||||
}
|
||||
else if (ev.type === 'disconnect' && refStatus.current.connected && refStatus.current.connected.deviceId === ev.detail.deviceId) {
|
||||
// 断开连接
|
||||
changeStatus({
|
||||
connected: null,
|
||||
serviceId: null,
|
||||
characteristicId: null,
|
||||
deviceLab: null,
|
||||
devices: [],
|
||||
})
|
||||
Taro.showToast({ icon: 'none', title: '蓝牙连接已断开' })
|
||||
}
|
||||
else if (ev.type === 'connected' && refStatus.current.connecting) {
|
||||
// 连接成功
|
||||
changeStatus({ connected: refStatus.current.connecting, connecting: null })
|
||||
Taro.showToast({ title: '蓝牙已连接' })
|
||||
}
|
||||
else if (ev.type === 'measure') {
|
||||
// 监听取色仪主动推送lab
|
||||
await measureAndGetLab()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取蓝牙适配器状态
|
||||
* @returns {Promise<{discovering: boolean; available: boolean}>}
|
||||
@@ -164,6 +163,15 @@ export default (props) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 获取搜索到的设备
|
||||
const getDevices = (res) => {
|
||||
res.devices.forEach((device) => {
|
||||
// 排除掉已搜索到的设备和名称不合法的设备, 将新发现的设备添加到列表中
|
||||
if (/^CM/.test(device.name) && !refStatus.current.devices.find(i => i.deviceId === device.deviceId)) {
|
||||
changeStatus({ devices: [...refStatus.current.devices, device] })
|
||||
}
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 启动设备扫描
|
||||
* @param {(res: { devices: { name: string, deviceId: string, RSSI: number }[] }) => void} cb
|
||||
@@ -189,17 +197,6 @@ export default (props) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 获取搜索到的设备
|
||||
const getDevices = (res) => {
|
||||
res.devices.forEach((device) => {
|
||||
// 排除掉已搜索到的设备和名称不合法的设备, 将新发现的设备添加到列表中
|
||||
if (/^CM/.test(device.name) && !refStatus.current.devices.find(i => i.deviceId === device.deviceId)) {
|
||||
changeStatus({ devices: [...refStatus.current.devices, device] })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接设备
|
||||
* @param {{ name: string, deviceId: string, RSSI: number }} device
|
||||
@@ -212,7 +209,7 @@ export default (props) => {
|
||||
await discoverService(device.deviceId)
|
||||
await discoverCharacteristic(device.deviceId)
|
||||
await notifyCharacteristicValueChange(device.deviceId)
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
changeStatus({ connecting: null })
|
||||
Taro.showToast({ icon: 'none', title: '蓝牙连接失败' })
|
||||
@@ -273,7 +270,7 @@ export default (props) => {
|
||||
const service = services.find(i => refStatus.current.serviceRule.test(i.uuid))
|
||||
if (!service) {
|
||||
reject(new Error('服务不可用'))
|
||||
}
|
||||
}
|
||||
else {
|
||||
changeStatus({ serviceId: service.uuid })
|
||||
resolve(service)
|
||||
@@ -294,7 +291,7 @@ export default (props) => {
|
||||
const characteristic = characteristics.find(i => refStatus.current.characteristicRule.test(i.uuid))
|
||||
if (!characteristic) {
|
||||
reject(new Error('特征不可用'))
|
||||
}
|
||||
}
|
||||
else {
|
||||
changeStatus({ characteristicId: characteristic.uuid })
|
||||
resolve(characteristic)
|
||||
@@ -332,13 +329,13 @@ export default (props) => {
|
||||
if (refStatus.current.command.isComplete) {
|
||||
if (refStatus.current.command.isValid && refStatus.current.responseResolve) {
|
||||
refStatus.current.responseResolve(refStatus.current.command.response)
|
||||
}
|
||||
}
|
||||
else if (!refStatus.current.command.isValid) {
|
||||
refStatus.current.responseReject(new Error('无效数据'))
|
||||
}
|
||||
resetCommand()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const uint8Array = new Uint8Array(buffer)
|
||||
if (uint8Array[0] === 0xBB && uint8Array[1] === 1 && uint8Array[3] === 0) {
|
||||
@@ -354,10 +351,11 @@ export default (props) => {
|
||||
* @returns {Promise<Uint8Array>}
|
||||
*/
|
||||
function exec(command) {
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
return new Promise(async(resolve, reject) => {
|
||||
if (refStatus.current.command) {
|
||||
reject(new Error('正在执行其他命令'))
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
refStatus.current.command = command
|
||||
@@ -369,7 +367,7 @@ export default (props) => {
|
||||
if (command.responseSize <= 0) {
|
||||
resolve(true)
|
||||
resetCommand()
|
||||
}
|
||||
}
|
||||
else {
|
||||
refStatus.current.responseReject = reject
|
||||
refStatus.current.responseResolve = resolve
|
||||
@@ -378,7 +376,7 @@ export default (props) => {
|
||||
resetCommand()
|
||||
}, command.timeout)
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
@@ -478,12 +476,13 @@ export default (props) => {
|
||||
/>
|
||||
)
|
||||
}
|
||||
export default ContextBlueTooth
|
||||
|
||||
export const useBluetooth = () => {
|
||||
const res = React.useContext<any>(Context)
|
||||
if (res) {
|
||||
return { ...res }
|
||||
}
|
||||
}
|
||||
else {
|
||||
return {}
|
||||
}
|
||||
|
||||
@@ -23,32 +23,34 @@ interface Param {
|
||||
export default ({ scope, msg }: Param) => {
|
||||
// 这个hook微信授权检查授权
|
||||
const check = useCallback(() => {
|
||||
return new Promise((reslove, reject) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
Taro.getSetting({
|
||||
success: (res) => {
|
||||
if (res.authSetting[scope]) {
|
||||
reslove(true)
|
||||
}
|
||||
resolve(true)
|
||||
}
|
||||
else if (res.authSetting[scope] === undefined) {
|
||||
Taro.authorize({
|
||||
scope,
|
||||
success() {
|
||||
reslove(true)
|
||||
resolve(true)
|
||||
},
|
||||
fail() {
|
||||
alert.none(msg)
|
||||
// eslint-disable-next-line prefer-promise-reject-errors
|
||||
reject(false)
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
else {
|
||||
Taro.openSetting({
|
||||
success(res) {
|
||||
if (res.authSetting[scope]) {
|
||||
reslove(true)
|
||||
}
|
||||
resolve(true)
|
||||
}
|
||||
else {
|
||||
alert.none(msg)
|
||||
// eslint-disable-next-line prefer-promise-reject-errors
|
||||
reject(false)
|
||||
}
|
||||
},
|
||||
|
||||
+17
-16
@@ -1,6 +1,6 @@
|
||||
import { useRouter } from '@tarojs/taro'
|
||||
import dayjs from 'dayjs'
|
||||
import type { SetStateAction } from 'react'
|
||||
import type { SetStateAction } from 'react'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useSelector } from '@/reducers/hooks'
|
||||
|
||||
@@ -15,21 +15,6 @@ export const useTimeCountDown = () => {
|
||||
const [timeStatus, setTimeStatus] = useState<0 | 1 | 2>(0) // 倒计时状体 0:倒计时未开始 1:倒计时中, 2:倒计时已结束
|
||||
const timeObj: any = useRef()
|
||||
const endTime = useRef('')
|
||||
const onStart = (val = '') => {
|
||||
// console.log('time:::', val)
|
||||
endTime.current = val
|
||||
if (endTime.current) {
|
||||
clearInterval(timeObj.current)
|
||||
timeObj.current = setInterval(() => {
|
||||
count_down()
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
clearInterval(timeObj.current)
|
||||
}
|
||||
}, [])
|
||||
const count_down = () => {
|
||||
const startData = dayjs()
|
||||
const endDate = dayjs(endTime.current)
|
||||
@@ -56,6 +41,22 @@ export const useTimeCountDown = () => {
|
||||
// console.log('endTime::', `${DD}-${HH}-${MM}-${SS}`)
|
||||
setShowTime(e => ({ ...e, DD, HH, MM, SS }))
|
||||
}
|
||||
const onStart = (val = '') => {
|
||||
// console.log('time:::', val)
|
||||
endTime.current = val
|
||||
if (endTime.current) {
|
||||
clearInterval(timeObj.current)
|
||||
timeObj.current = setInterval(() => {
|
||||
count_down()
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
clearInterval(timeObj.current)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return {
|
||||
showTime,
|
||||
onStart,
|
||||
|
||||
+29
-31
@@ -10,11 +10,21 @@ import { IMG_CND_Prefix } from '@/common/constant'
|
||||
|
||||
export default () => {
|
||||
const { setUserInfo, setAdminUserInfo, setSortCode, userInfo } = useUserInfo()
|
||||
// 获取分享码(右上角分享码)
|
||||
const { SharePage } = SHARE_SCENE
|
||||
const { fetchData: fetchDataShortCode } = GetShortCodeApi()
|
||||
const getShortCode = async(user_id) => {
|
||||
const { data: resPage } = await fetchDataShortCode({ share_user_id: user_id, type: SharePage.value })
|
||||
setSortCode({ ...userInfo.sort_code, shareShortPage: { title: '打造面料爆品 专注客户服务', code: resPage.md5_key, img: `${IMG_CND_Prefix}/mall/share_img_01.png` } })
|
||||
}
|
||||
|
||||
useDidShow(() => {
|
||||
checkLogin()
|
||||
})
|
||||
|
||||
// 获取用户信息
|
||||
const { fetchData: FetchData } = GetAdminUserInfoApi()
|
||||
const getAdminUserInfo = async() => {
|
||||
const res = await FetchData()
|
||||
setAdminUserInfo({ ...res.data })
|
||||
getShortCode(res.data.user_id)
|
||||
}
|
||||
// 登录请求
|
||||
const { login } = useLoginRequest()
|
||||
// const {fetchData:login} = LoginApi()
|
||||
@@ -28,31 +38,24 @@ export default () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
const { fetchData: useFetchData } = GetAdminUserInfoApi()
|
||||
const getAdminUserInfo = async() => {
|
||||
const res = await useFetchData()
|
||||
setAdminUserInfo({ ...res.data })
|
||||
getShortCode(res.data.user_id)
|
||||
}
|
||||
|
||||
// 登录加checkLogin检查
|
||||
const checkLogin = () => {
|
||||
return new Promise(async(reslove) => {
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
return new Promise(async(resolve) => {
|
||||
if (!userInfo.token) {
|
||||
await wxLogin()
|
||||
reslove(true)
|
||||
resolve(true)
|
||||
}
|
||||
else {
|
||||
// 这个东西不要打开,checkSession有调用频率问题
|
||||
// Taro.checkSession({
|
||||
// success: async () => {
|
||||
// reslove(true)
|
||||
// resolve(true)
|
||||
// if(!userInfo.adminUserInfo) getAdminUserInfo()
|
||||
// },
|
||||
// fail: async () => {
|
||||
// await wxLogin()
|
||||
// reslove(true)
|
||||
// resolve(true)
|
||||
// }
|
||||
// })
|
||||
}
|
||||
@@ -62,9 +65,9 @@ export default () => {
|
||||
// 获取用户头像等信息数据
|
||||
const { fetchData: fetchDataUserInfo } = GetWxUserInfoApi()
|
||||
const getSelfUserInfo = async() => {
|
||||
return new Promise((reslove, reject) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (userInfo.adminUserInfo?.is_authorize_name) {
|
||||
reslove(true)
|
||||
resolve(true)
|
||||
return true
|
||||
}
|
||||
Taro.getUserProfile({
|
||||
@@ -83,7 +86,7 @@ export default () => {
|
||||
if (user_res.success) {
|
||||
setUserInfo({ ...user_res.data })
|
||||
getAdminUserInfo()
|
||||
reslove(true)
|
||||
resolve(true)
|
||||
}
|
||||
else {
|
||||
reject(user_res.msg)
|
||||
@@ -101,9 +104,10 @@ export default () => {
|
||||
const { fetchData: fetchDataUserPhone } = GetPhoneNumberApi()
|
||||
const { fetchData: fetchBindingCompany } = BindingCompanyApi()
|
||||
const getPhoneNumber = (code) => {
|
||||
return new Promise(async(reslove, reject) => {
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
return new Promise(async(resolve, reject) => {
|
||||
if (userInfo.adminUserInfo?.is_authorize_phone) {
|
||||
reslove(true)
|
||||
resolve(true)
|
||||
return true
|
||||
}
|
||||
const res = await fetchDataUserPhone({ code })
|
||||
@@ -111,22 +115,16 @@ export default () => {
|
||||
setUserInfo({ ...userInfo.userInfo, phone: res.data.phone_number })
|
||||
await fetchBindingCompany()
|
||||
getAdminUserInfo()
|
||||
reslove(res.data)
|
||||
resolve(res.data)
|
||||
}
|
||||
else {
|
||||
reject(res.msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 获取分享码(右上角分享码)
|
||||
const { SharePage } = SHARE_SCENE
|
||||
const { fetchData: fetchDataShortCode } = GetShortCodeApi()
|
||||
const getShortCode = async(user_id) => {
|
||||
const { data: resPage } = await fetchDataShortCode({ share_user_id: user_id, type: SharePage.value })
|
||||
setSortCode({ ...userInfo.sort_code, shareShortPage: { title: '打造面料爆品 专注客户服务', code: resPage.md5_key, img: `${IMG_CND_Prefix}/mall/share_img_01.png` } })
|
||||
}
|
||||
|
||||
useDidShow(() => {
|
||||
checkLogin()
|
||||
})
|
||||
return {
|
||||
checkLogin,
|
||||
wxLogin,
|
||||
|
||||
Reference in New Issue
Block a user