Commit 1a95ffa9 by lirandong

fix

parent d5c7b72b
...@@ -8,6 +8,14 @@ export interface IUpdateWifi { ...@@ -8,6 +8,14 @@ export interface IUpdateWifi {
equipmentWifiType: string equipmentWifiType: string
} }
export interface IUpdateDeviceInfo {
equipmentId: string
equipmentName: string
equipmentUrl: string
equipmentResolution: string
equipmentStyle: 'CROSSWISE' | 'LENGTHWAYS'
}
class UsersApi extends ApiClient { class UsersApi extends ApiClient {
/** 过去模板列表数据 */ /** 过去模板列表数据 */
getTempList(page: number) { getTempList(page: number) {
...@@ -48,6 +56,7 @@ class UsersApi extends ApiClient { ...@@ -48,6 +56,7 @@ class UsersApi extends ApiClient {
getMyDeviceList(page: number) { getMyDeviceList(page: number) {
return this.request({ url: '/myequipment/get/list', data: { p: page, c: 10 } }) return this.request({ url: '/myequipment/get/list', data: { p: page, c: 10 } })
} }
/** 获取设备详情 */ /** 获取设备详情 */
getDeviceDetail(equipmentId: string) { getDeviceDetail(equipmentId: string) {
return this.request({ return this.request({
...@@ -56,6 +65,11 @@ class UsersApi extends ApiClient { ...@@ -56,6 +65,11 @@ class UsersApi extends ApiClient {
}) })
} }
/** 更新设备详情信息 */
updateDeviceInfo(data: IUpdateDeviceInfo) {
return this.request({ url: `/myequipment/update/myequipment`, data })
}
/** 添加新设备-PIN */ /** 添加新设备-PIN */
addDevicePIN(pin: string) { addDevicePIN(pin: string) {
return this.request({ method: 'GET', url: `/myequipment/add/equipment/num/info/${pin}` }) return this.request({ method: 'GET', url: `/myequipment/add/equipment/num/info/${pin}` })
......
...@@ -34,9 +34,9 @@ class App extends Component { ...@@ -34,9 +34,9 @@ class App extends Component {
*/ */
config: Config = { config: Config = {
pages: [ pages: [
'pages/home/tempaltes/index',
'pages/home/device/index', 'pages/home/device/index',
'pages/home/device/device_detail/index', 'pages/home/device/device_detail/index',
'pages/home/tempaltes/index',
'pages/system/wifi_list/index', 'pages/system/wifi_list/index',
'pages/home/device/device_bind/index', 'pages/home/device/device_bind/index',
'pages/home/user/index', 'pages/home/user/index',
......
/**
*
* @description 小程序、RN和H5 功能方法兼用文件
*
*/
import Taro from '@tarojs/taro' import Taro from '@tarojs/taro'
export function scanCode(OBJECT?: Taro.scanCode.Param) { export function scanCode(OBJECT?: Taro.scanCode.Param) {
......
import Taro, { arrayBuffer } from '@tarojs/taro'
import { bluetooth } from './adapter' import { bluetooth } from './adapter'
import Taro, { arrayBuffer } from '@tarojs/taro'
import { IWifiListItem } from '@/pages/home/device/device_list' import { IWifiListItem } from '@/pages/home/device/device_list'
import { import { strToAb, getAdverts, showMyToast, analysisPage } from './utils'
showMyToast,
getAdverts,
getBLEData,
strToAb,
ArrayBufferToString,
analysisPage
} from './utils'
import { import {
BLE_SERVICE_ID, BLE_SERVICE_ID,
WIFI_CHARACTERISTIC_ID,
POST_WIFI_PASS_ID,
DEVICE_TOKEN_ID, DEVICE_TOKEN_ID,
BLE_DEVICE_SERVICE_ID POST_WIFI_PASS_ID,
BLE_DEVICE_SERVICE_ID,
WIFI_CHARACTERISTIC_ID
} from '.' } from '.'
class Bluetooth { class Bluetooth {
// protected deviceId = '' /* 获取 WiFi 列表回调 */
protected advertisData = ''
/* 获取 WiFi 列表弧度回调 */
protected getWifiListCallBack: (wifiItem: IWifiListItem) => void protected getWifiListCallBack: (wifiItem: IWifiListItem) => void
/* 接收到蓝牙端的设备token回调 */
protected getDeviceTokenCallBack: (token: string) => void protected getDeviceTokenCallBack: (token: string) => void
/** 打开蓝牙 */ /** 打开蓝牙 */
...@@ -61,7 +53,6 @@ class Bluetooth { ...@@ -61,7 +53,6 @@ class Bluetooth {
console.error({ error }) console.error({ error })
bluetooth.stopBluetoothDevicesDiscovery() bluetooth.stopBluetoothDevicesDiscovery()
const { errCode } = error const { errCode } = error
console.log({ errCode })
if (errCode === 10001) { if (errCode === 10001) {
showMyToast({ title: '请打开手机蓝牙~' }) showMyToast({ title: '请打开手机蓝牙~' })
} else { } else {
...@@ -74,7 +65,6 @@ class Bluetooth { ...@@ -74,7 +65,6 @@ class Bluetooth {
async createBLEConnection(deviceId: string) { async createBLEConnection(deviceId: string) {
await bluetooth.createBLEConnection({ deviceId }) await bluetooth.createBLEConnection({ deviceId })
bluetooth.stopBluetoothDevicesDiscovery() bluetooth.stopBluetoothDevicesDiscovery()
// showMyToast({ title: '蓝牙连接成功~' })
bluetooth.onBLEConnectionStateChange(({ connected }) => { bluetooth.onBLEConnectionStateChange(({ connected }) => {
showMyToast({ title: connected ? '蓝牙已连接' : '蓝牙已断开' }) showMyToast({ title: connected ? '蓝牙已连接' : '蓝牙已断开' })
}) })
...@@ -91,11 +81,6 @@ class Bluetooth { ...@@ -91,11 +81,6 @@ class Bluetooth {
this.listenBleValueChange(deviceId) this.listenBleValueChange(deviceId)
} }
/** 设置监听获取WiFi列表的回调函数 */
// async setGetWiFiListCallBack(callBack: (wifiItem: IWifiListItem) => void) {
// this.getWifiListCallBack = callBack
// }
setCallBack({ getWiFiListCallBack, getDeviceTokenCallBack }) { setCallBack({ getWiFiListCallBack, getDeviceTokenCallBack }) {
this.getWifiListCallBack = getWiFiListCallBack this.getWifiListCallBack = getWiFiListCallBack
this.getDeviceTokenCallBack = getDeviceTokenCallBack this.getDeviceTokenCallBack = getDeviceTokenCallBack
...@@ -105,7 +90,6 @@ class Bluetooth { ...@@ -105,7 +90,6 @@ class Bluetooth {
listenBleValueChange(deviceId: string) { listenBleValueChange(deviceId: string) {
// 来自设备端的通知 // 来自设备端的通知
bluetooth.onBLECharacteristicValueChange(async ({ value, characteristicId }) => { bluetooth.onBLECharacteristicValueChange(async ({ value, characteristicId }) => {
console.log({ characteristicId })
switch (characteristicId) { switch (characteristicId) {
case WIFI_CHARACTERISTIC_ID: case WIFI_CHARACTERISTIC_ID:
// 获取 WiFi 列表 // 获取 WiFi 列表
...@@ -151,7 +135,6 @@ class Bluetooth { ...@@ -151,7 +135,6 @@ class Bluetooth {
} else { } else {
showMyToast({ title: '连接失败~' }) showMyToast({ title: '连接失败~' })
} }
// console.log('ArrayBufferToString', str)
} }
async formatToken(deviceId: string, value: arrayBuffer) { async formatToken(deviceId: string, value: arrayBuffer) {
......
@import '@styles/var.scss'; @import '@styles/var.scss';
.device-detail { .device-detail {
padding: 40px 40px 0; padding: 10px 40px 0;
@include eject(box-sizing, border-box); @include eject(box-sizing, border-box);
...@@ -10,8 +10,31 @@ ...@@ -10,8 +10,31 @@
flex-direction: column; flex-direction: column;
.item-text { .item-text {
padding: 20px 0; padding: 20px 0 10px;
color: $primary-text-color; color: $primary-text-color;
} }
.item-input {
padding: 10px 20px;
border-radius: 6px;
border: 1px solid $border-color;
}
.item-img-box {
width: 400px;
height: 220px;
border-radius: 6px;
padding: 4px 2.25px;
border: 1px solid $border-color;
.item-img {
width: 100%;
height: 100%;
}
}
}
.bottom-btn {
margin-top: 60px;
} }
} }
import api from '@/api/index' import api from '@/api/index'
import { ComponentClass } from 'react' import { ComponentClass } from 'react'
import { showMyToast } from '@/common/utils'
import Taro, { Component, Config } from '@tarojs/taro' import Taro, { Component, Config } from '@tarojs/taro'
import { View, Text, Input, Image, ScrollView, Button } from '@tarojs/components' import {
View,
Text,
Input,
Image,
ScrollView,
Button,
RadioGroup,
Radio,
Label
} from '@tarojs/components'
import './index.scss' import './index.scss'
...@@ -11,17 +22,6 @@ type PageDispatchProps = {} ...@@ -11,17 +22,6 @@ type PageDispatchProps = {}
type PageOwnProps = {} type PageOwnProps = {}
interface IInfo {
filmId?: any
filmName?: any
clientId: string
equipmentId: string
clientSecret: string
equipmentUrl: string
equipmentName: string
equipmentState: string
}
type PageState = { type PageState = {
filmId?: any filmId?: any
filmName?: any filmName?: any
...@@ -31,6 +31,8 @@ type PageState = { ...@@ -31,6 +31,8 @@ type PageState = {
equipmentUrl: string equipmentUrl: string
equipmentName: string equipmentName: string
equipmentState: string equipmentState: string
equipmentResolution: string
equipmentStyle: 'CROSSWISE' | 'LENGTHWAYS'
} }
type IProps = PageStateProps & PageDispatchProps & PageOwnProps type IProps = PageStateProps & PageDispatchProps & PageOwnProps
...@@ -49,16 +51,21 @@ class DeviceDetail extends Component { ...@@ -49,16 +51,21 @@ class DeviceDetail extends Component {
constructor(props: any) { constructor(props: any) {
super(props) super(props)
this.equipmentId = this.$router.params.equipmentId || 'd73cc4ec13394a8ab5de7b8ce7f99fac' this.equipmentId = this.$router.params.equipmentId
// console.log(this.equipmentId)
this.state = { this.state = {
clientId: '', clientId: '',
equipmentId: '', equipmentId: '',
clientSecret: '', clientSecret: '',
equipmentUrl: '', equipmentUrl: '',
equipmentName: '', equipmentName: '',
equipmentState: '' equipmentState: '',
equipmentResolution: '',
equipmentStyle: 'CROSSWISE'
} }
this.setDeviceName = this.setDeviceName.bind(this)
this.setResolution = this.setResolution.bind(this)
this.chengDirection = this.chengDirection.bind(this)
this.updateDeviceDetail = this.updateDeviceDetail.bind(this)
} }
componentWillMount() { componentWillMount() {
...@@ -74,7 +81,9 @@ class DeviceDetail extends Component { ...@@ -74,7 +81,9 @@ class DeviceDetail extends Component {
clientSecret, clientSecret,
equipmentUrl, equipmentUrl,
equipmentName, equipmentName,
equipmentState equipmentState,
equipmentStyle,
equipmentResolution
} = res } = res
this.setState({ this.setState({
clientId, clientId,
...@@ -82,7 +91,9 @@ class DeviceDetail extends Component { ...@@ -82,7 +91,9 @@ class DeviceDetail extends Component {
clientSecret, clientSecret,
equipmentUrl, equipmentUrl,
equipmentName, equipmentName,
equipmentState equipmentState,
equipmentResolution,
equipmentStyle: !equipmentStyle ? 'CROSSWISE' : equipmentStyle
}) })
console.log({ res }) console.log({ res })
} catch (error) { } catch (error) {
...@@ -90,28 +101,100 @@ class DeviceDetail extends Component { ...@@ -90,28 +101,100 @@ class DeviceDetail extends Component {
} }
} }
setDeviceName({ target }) {
const { value } = target
this.setState({ equipmentName: value })
}
setResolution({ target }) {
const { value } = target
this.setState({ equipmentResolution: value })
}
chengDirection({ currentTarget }: any) {
const { value } = currentTarget
if (value === 'horizontal') {
this.setState({ equipmentStyle: 'CROSSWISE' })
} else if (value === 'vertical') {
this.setState({ equipmentStyle: 'LENGTHWAYS' })
}
}
async updateDeviceDetail() {
const {
equipmentId,
equipmentUrl,
equipmentName,
equipmentStyle,
equipmentResolution
} = this.state
if (!equipmentName || !equipmentUrl) {
showMyToast({ title: '设备名称或设备图片不能为空~' })
return
}
try {
await api.common.updateDeviceInfo({
equipmentId,
equipmentName,
equipmentUrl,
equipmentResolution,
equipmentStyle
})
showMyToast({ title: '修改成功~' })
} catch (error) {
// console.error(error)
showMyToast({ result: error, title: '修改失败~' })
}
}
render() { render() {
const { equipmentName, equipmentUrl } = this.state const { equipmentName, equipmentUrl, equipmentResolution, equipmentStyle } = this.state
console.log({ equipmentStyle })
return ( return (
<ScrollView className="device-detail" scrollY> <ScrollView className="device-detail" scrollY>
{/* <Text>hello world</Text> */}
<View className="device-detail-item"> <View className="device-detail-item">
<Text className="item-text">设备名称</Text> <Text className="item-text">设备名称:</Text>
<Input value={equipmentName} placeholder="请输入设备名称" /> <Input
className="item-input"
value={equipmentName}
placeholder="请输入设备名称"
onInput={this.setDeviceName}
/>
</View> </View>
<View className="device-detail-item"> <View className="device-detail-item">
<Text className="item-text">设备图片</Text> <Text className="item-text">设备图片:</Text>
<Image src={equipmentUrl} /> <View className="item-img-box">
<Image className="item-img" src={equipmentUrl} />
</View>
</View> </View>
<View className="device-detail-item"> <View className="device-detail-item">
<Text className="item-text">屏幕板式</Text> <Text className="item-text">屏幕板式</Text>
{/* <Image src="" /> */} <RadioGroup onChange={this.chengDirection}>
<Label for="horizontal">
<Radio value="horizontal" checked={equipmentStyle === 'CROSSWISE'}>
横屏
</Radio>
</Label>
<Label for="vertical">
<Radio value="vertical" checked={equipmentStyle === 'LENGTHWAYS'}>
竖屏
</Radio>
</Label>
</RadioGroup>
</View> </View>
<View className="device-detail-item"> <View className="device-detail-item">
<Text className="item-text">屏幕分辨率</Text> <Text className="item-text">屏幕分辨率</Text>
<Input placeholder="宽 * 高" /> <Input
placeholder="宽x高"
className="item-input"
value={equipmentResolution}
onInput={this.setResolution}
/>
</View> </View>
<Button type="primary">确实</Button> <Button type="primary" className="bottom-btn" onClick={this.updateDeviceDetail}>
确定
</Button>
</ScrollView> </ScrollView>
) )
} }
......
...@@ -117,6 +117,7 @@ class WifiList extends Component { ...@@ -117,6 +117,7 @@ class WifiList extends Component {
equipmentWifiPassword: password equipmentWifiPassword: password
}) })
showMyToast({ title: '设备添加成功~' }) showMyToast({ title: '设备添加成功~' })
Taro.redirectTo({ url: `/pages/home/device/device_detail/index?equipmentId=${equipmentId}` })
} catch (error) { } catch (error) {
console.error(error) console.error(error)
} }
......
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