Commit fc9c18dc by hank

修改设备绑定

parent 9ed8ee85
import { pages } from './../constants/router'
import { createStore } from 'redux'
import { FilmListItem } from '@/conpoments/film_list_item'
import { ApiClient } from './client'
export interface IUpdateWifi {
......@@ -110,6 +108,13 @@ class UsersApi extends ApiClient {
url: `/myequipment/get/details/info/${equipmentId}`
})
}
/** 获取设备是否被使用 */
getDeviceUseState(token: string) {
return this.request({
method: 'GET',
url: `/equipment/get/state/${token}`
})
}
/** 更新影片数据 */
updateFilmInfo(data: IUpdateFilmInfo) {
return this.request({ url: `/template/update/film/info`, data })
......
......@@ -7,7 +7,8 @@ import {
DEVICE_TOKEN_ID,
POST_WIFI_PASS_ID,
BLE_DEVICE_SERVICE_ID,
WIFI_CHARACTERISTIC_ID
WIFI_CHARACTERISTIC_ID,
DEVICE_TOKEN_TOKEN
} from '.'
class Bluetooth {
/* 获取 WiFi 列表回调 */
......@@ -113,6 +114,7 @@ class Bluetooth {
/** 蓝牙的监听队列 */
listenBleValueChange(deviceId: string) {
console.log(deviceId, 'deviceId')
// 来自设备端的通知
bluetooth.onBLECharacteristicValueChange(async ({ value, characteristicId }) => {
switch (characteristicId) {
......@@ -128,6 +130,10 @@ class Bluetooth {
// 设备 token 信息回调
this.formatToken(deviceId, value)
break
case DEVICE_TOKEN_TOKEN:
// 设备 token 信息回调
this.formatDeviceToken(deviceId, value)
break
default:
break
}
......@@ -181,6 +187,18 @@ class Bluetooth {
})
page === 0 && this.getDeviceTokenCallBack && this.getDeviceTokenCallBack(token)
}
async formatDeviceToken(deviceId: string, value: arrayBuffer) {
console.log(value, 'formatDeviceToken')
const { page, advertisData: token } = await analysisPage(value)
console.log(await analysisPage(value), 'formatDeviceToken')
bluetooth.writeBLECharacteristicValue({
deviceId,
serviceId: BLE_DEVICE_SERVICE_ID,
characteristicId: DEVICE_TOKEN_ID,
value: new Uint8Array([page]).buffer
})
page === 0 && console.log(token)
}
/** 向设备端发送WiFi密码 */
async postWifiPassword(id: number, pass: string, deviceId: string) {
......
export const FETCH_TIME_OUT = 5000
export const BASE_URL = 'https://server.bdideal.com'
export const WEBVIEW_URL = 'https://visual.bdideal.com'
// export const BASE_URL = 'https://dev-server.bdideal.com'
// export const WEBVIEW_URL = 'https://dev-visual.bdideal.com'
// export const BASE_URL = 'https://server.bdideal.com'
// export const WEBVIEW_URL = 'https://visual.bdideal.com'
export const BASE_URL = 'https://dev-server.bdideal.com'
export const WEBVIEW_URL = 'https://dev-visual.bdideal.com'
/** 蓝牙的服务 uuid */
export const BLE_SERVICE_ID = '000088A0-0000-1000-8000-00805F9B34FB'
......@@ -18,3 +18,4 @@ export const POST_WIFI_PASS_ID = '000088A2-0000-1000-8000-00805F9B34FB'
/** 提交WiFi密码特征值 uuid */
export const DEVICE_TOKEN_ID = '0000888A-0000-1000-8000-00805F9B34FB'
export const DEVICE_TOKEN_TOKEN = '000088A3-0000-1000-8000-00805F9B34FB'
......@@ -3,6 +3,12 @@
@import '~taro-ui/dist/style/components/list.scss';
@import '~taro-ui/dist/style/components/radio.scss';
@import '~taro-ui/dist/style/components/icon.scss';
@import '~taro-ui/dist/style/components/modal.scss';
.overhidden {
height: 100vh;
overflow: hidden;
}
.device-bind {
width: 100%;
......@@ -118,6 +124,32 @@
}
}
.dialog-container {
position: absolute;
z-index: 1000;
height: calc(100vh - 190px);
width: 100vw;
top: 60px;
.dialog-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.3);
}
.dialog-content {
position: absolute;
top: 0;
width: 100%;
text-align: left;
height: 100%;
overflow: scroll;
}
}
.device-tab-container {
display: flex;
font-size: 38px;
......
......@@ -4,7 +4,7 @@ import { showMyToast } from '@/common/utils'
import DeviceItem from '@/conpoments/device_item'
import Taro, { Component, Config } from '@tarojs/taro'
import { View, Text, ScrollView, Button, Checkbox, Label, Input, Image } from '@tarojs/components'
import { AtDrawer } from 'taro-ui'
import { AtModal, AtModalContent, AtList, AtListItem } from 'taro-ui'
import './index.scss'
......@@ -182,7 +182,8 @@ class DeviceSelect extends Component {
this.setState(
{
activeIndex: index,
TabIndex: 0
TabIndex: 0,
showModal: false
},
() => {
this.getData(this.state.searchName)
......@@ -299,8 +300,8 @@ class DeviceSelect extends Component {
})
console.log(TabIndex, 'TabIndex')
return (
<View className="device-bind">
<View className="search-bar-container">
<View className={showModal ? 'device-bind overhidden' : 'device-bind'}>
<View className="search-bar-container" onClick={this.onClose}>
{/* <View className="search-bar-container-left" onClick={this.showModalView}>
<Text>{items[activeIndex]}</Text>
<Text className="triangle" />
......@@ -331,14 +332,38 @@ class DeviceSelect extends Component {
src="https://visual-clouds.oss-cn-beijing.aliyuncs.com/miniprogram/list-icon.png"
className="triangle"
onClick={this.showModalView}
onBlur={() => {
console.log('aaaa')
}}
/>
</View>
{showModal ? (
<View className="dialog-container">
<View className="dialog-overlay" onClick={this.onClose} />
<View className="dialog-content" onClick={this.onClose}>
<AtList>
{items.map((item, index) => {
return (
<AtListItem
title={item}
key={item}
onClick={() => {
this.onItemClick(index)
}}
/>
)
})}
</AtList>
</View>
</View>
) : null}
</View>
<View
className={
TabIndex === 0 ? 'device-tab-item' : 'device-tab-item device-tab-item-active'
}
onClick={() => {
this.onClose()
this.setState({ TabIndex: 1 })
}}
>
......@@ -404,7 +429,17 @@ class DeviceSelect extends Component {
完成
</Button>
</View>
<AtDrawer
{/* <AtModal isOpened={showModal}>
<AtModalContent>
<AtList>
{items.map(item => {
return <AtListItem title={item} key={item} />
})}
</AtList>
</AtModalContent>
</AtModal> */}
{/* <AtDrawer
show={showModal}
mask
onClose={() => {
......@@ -414,7 +449,7 @@ class DeviceSelect extends Component {
onItemClick={this.onItemClick}
>
aaa
</AtDrawer>
</AtDrawer> */}
</View>
)
}
......
......@@ -57,6 +57,7 @@ class WifiList extends Component {
}
protected deviceId = ''
protected deviceToken = ''
protected password = ''
protected advertisData = ''
protected bluetoothCode = ''
......@@ -122,6 +123,7 @@ class WifiList extends Component {
// 获取到设备token信息的回调
async getDeviceTokenCallBack(token: string) {
this.deviceToken = token
try {
const { equipmentId } = await api.common.addDeviceToken(token)
const { password, activeWLAN } = this
......@@ -134,7 +136,7 @@ class WifiList extends Component {
equipmentWifiIdentity: '',
equipmentWifiPassword: password
})
console.log(this.props.getFilmListData(1), this.props)
// console.log(this.props.getFilmListData(1), this.props)
showMyToast({ title: '设备添加成功~' })
Taro.navigateBack()
// Taro.redirectTo({ url: `/pages/home/device/device_detail/index?equipmentId=${equipmentId}` })
......@@ -155,7 +157,7 @@ class WifiList extends Component {
async onConfirm() {
const { id, type } = this.activeWLAN
const { password, deviceId } = this
const { password, deviceId, deviceToken } = this
const { mode } = this.$router.params
if (id === undefined || !deviceId) return
if (type !== 'OPEN' && password.length < 8) {
......@@ -165,6 +167,11 @@ class WifiList extends Component {
this.cancelModal()
try {
Taro.showLoading({ title: '连接中...' })
// 检查设备是否使用
if (deviceToken) {
const { data } = await api.common.getDeviceUseState(deviceToken)
console.log(data, deviceToken, '查看该设备是否被绑定')
}
await Ble.postWifiPassword(id, password, deviceId)
if (mode && mode === 'OWNRESET') {
setTimeout(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment