Commit 1a95ffa9 by lirandong

fix

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