Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
visualcloud
/
Vmatrix-client-taro
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ba80394d
authored
Dec 05, 2019
by
hank
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wifi 列表修改
parent
b9f1f275
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
26 deletions
+127
-26
src/api/common.ts
+10
-2
src/common/bluetooth.ts
+13
-6
src/pages/home/device/device_list/index.scss
+3
-0
src/pages/system/wifi_list/index.tsx
+101
-18
No files found.
src/api/common.ts
View file @
ba80394d
...
...
@@ -2,7 +2,7 @@ import { pages } from './../constants/router'
import
{
ApiClient
}
from
'./client'
export
interface
IUpdateWifi
{
equipmentId
:
string
equipmentId
?
:
string
equipmentWifiSsid
:
string
equipmentWifiPassword
:
string
equipmentWifiIdentity
:
string
...
...
@@ -137,10 +137,18 @@ class UsersApi extends ApiClient {
url
:
`/myequipment/add/equipment/token/info/
${
centerToken
}
`
})
}
/** 添加新设备
-token
*/
/** 添加新设备
更新WIFI
*/
updateMyequipmentWifi
(
data
:
IUpdateWifi
)
{
return
this
.
request
({
url
:
`/myequipment/update/myequipment/wifi`
,
data
})
}
/** 添加新设备更新WIFI */
addMyequipmentWifi
(
data
)
{
return
this
.
request
({
url
:
`/wifi/vindicate/info`
,
data
})
}
/** 添加新设备更新WIFI */
getWifiList
()
{
return
this
.
request
({
method
:
'GET'
,
url
:
`/wifi/get/list`
})
}
/** 删除设备 */
removeDevice
(
equipmentId
:
string
)
{
...
...
src/common/bluetooth.ts
View file @
ba80394d
...
...
@@ -17,6 +17,8 @@ class Bluetooth {
/* 接收到蓝牙端的设备token回调 */
protected
getDeviceTokenCallBack
:
(
token
:
string
)
=>
void
protected
getDeviceIdCallBack
:
(
token
:
string
)
=>
void
/** 打开蓝牙 */
async
openBle
(
bluetoothCode
:
string
):
Promise
<
any
>
{
try
{
...
...
@@ -119,9 +121,10 @@ class Bluetooth {
this
.
listenBleValueChange
(
deviceId
)
}
setCallBack
({
getWiFiListCallBack
,
getDeviceTokenCallBack
})
{
setCallBack
({
getWiFiListCallBack
,
getDeviceTokenCallBack
,
getDeviceIdCallBack
})
{
this
.
getWifiListCallBack
=
getWiFiListCallBack
this
.
getDeviceTokenCallBack
=
getDeviceTokenCallBack
this
.
getDeviceIdCallBack
=
getDeviceIdCallBack
}
/** 蓝牙的监听队列 */
...
...
@@ -160,7 +163,10 @@ class Bluetooth {
const
{
page
,
advertisData
}
=
await
analysisPage
(
value
)
if
(
page
===
0
)
{
// 数据传输完毕 :一条数据
this
.
getWifiListCallBack
&&
this
.
getWifiListCallBack
(
JSON
.
parse
(
advertisData
))
this
.
getWifiListCallBack
&&
JSON
.
parse
(
advertisData
).
ssid
&&
this
.
getWifiListCallBack
(
JSON
.
parse
(
advertisData
))
this
.
getDeviceIdCallBack
&&
this
.
getDeviceIdCallBack
(
JSON
.
parse
(
advertisData
).
DeviceId
)
}
bluetooth
.
writeBLECharacteristicValue
({
deviceId
,
...
...
@@ -190,7 +196,7 @@ class Bluetooth {
showMyToast
({
title
:
'连接失败~'
})
}
}
/** 整理设备token */
async
formatToken
(
deviceId
:
string
,
value
:
arrayBuffer
)
{
const
{
page
,
advertisData
:
token
}
=
await
analysisPage
(
value
)
bluetooth
.
writeBLECharacteristicValue
({
...
...
@@ -201,17 +207,18 @@ class Bluetooth {
})
page
===
0
&&
this
.
getDeviceTokenCallBack
&&
this
.
getDeviceTokenCallBack
(
token
)
}
/** 整理设备ID */
async
formatDeviceToken
(
deviceId
:
string
,
value
:
arrayBuffer
)
{
console
.
log
(
value
,
'formatDeviceToken'
)
const
{
page
,
advertisData
:
token
}
=
await
analysisPage
(
value
)
console
.
log
(
await
analysisPage
(
value
),
'formatDeviceToken'
)
console
.
log
(
page
,
'formatDeviceToken'
)
// console.log(await analysisPage(value), 'formatDeviceToken')
bluetooth
.
writeBLECharacteristicValue
({
deviceId
,
serviceId
:
BLE_SERVICE_ID
,
characteristicId
:
DEVICE_TOKEN_TOKEN
,
value
:
new
Uint8Array
([
page
]).
buffer
})
page
===
0
&&
console
.
log
(
token
)
page
===
0
&&
console
.
log
(
token
,
'formatDeviceToken'
)
}
/** 向设备端发送WiFi密码 */
...
...
src/pages/home/device/device_list/index.scss
View file @
ba80394d
...
...
@@ -24,6 +24,9 @@
}
&
-add-btn
{
position
:
absolute
;
top
:
130px
;
.bottom-btn-img
{
width
:
42px
;
height
:
42px
;
...
...
src/pages/system/wifi_list/index.tsx
View file @
ba80394d
...
...
@@ -31,6 +31,8 @@ type PageOwnProps = {}
type
PageState
=
{
openModal
:
boolean
wifiList
:
IWifiListItem
[]
recordList
:
IWifiListItem
[]
recordObj
:
any
}
type
IProps
=
PageStateProps
&
PageDispatchProps
&
PageOwnProps
...
...
@@ -57,6 +59,7 @@ class WifiList extends Component {
}
protected
deviceId
=
''
protected
deviceCpuId
=
''
protected
deviceToken
=
''
protected
password
=
''
protected
advertisData
=
''
...
...
@@ -66,6 +69,8 @@ class WifiList extends Component {
constructor
(
props
:
any
)
{
super
(
props
)
this
.
state
=
{
recordList
:
[],
recordObj
:
{},
wifiList
:
[
// {
// id: 11211,
...
...
@@ -82,12 +87,35 @@ class WifiList extends Component {
this
.
cancelModal
=
this
.
cancelModal
.
bind
(
this
)
this
.
setPasswprd
=
this
.
setPasswprd
.
bind
(
this
)
this
.
resetWifiList
=
this
.
resetWifiList
.
bind
(
this
)
this
.
connectWifi
=
this
.
connectWifi
.
bind
(
this
)
this
.
getWiFiListCallBack
=
this
.
getWiFiListCallBack
.
bind
(
this
)
this
.
getDeviceTokenCallBack
=
this
.
getDeviceTokenCallBack
.
bind
(
this
)
this
.
getDeviceIdCallBack
=
this
.
getDeviceIdCallBack
.
bind
(
this
)
}
componentDidMount
()
{
async
componentDidMount
()
{
this
.
getWifiList
()
await
this
.
getRecordList
()
}
async
getRecordList
()
{
api
.
common
.
getWifiList
().
then
(
res
=>
{
let
Obj
=
{}
res
.
map
(
item
=>
{
let
obj
=
{
id
:
item
.
wifiIdentity
,
rssi
:
-
10
,
ssid
:
item
.
wifiSsid
,
type
:
item
.
wifiType
,
password
:
item
.
wifiPassword
}
Obj
[
item
.
wifiSsid
]
=
obj
return
item
})
this
.
setState
({
recordObj
:
Obj
})
})
}
async
getWifiList
()
{
...
...
@@ -98,7 +126,8 @@ class WifiList extends Component {
// 设置回调函数
Ble
.
setCallBack
({
getWiFiListCallBack
:
this
.
getWiFiListCallBack
,
getDeviceTokenCallBack
:
this
.
getDeviceTokenCallBack
getDeviceTokenCallBack
:
this
.
getDeviceTokenCallBack
,
getDeviceIdCallBack
:
this
.
getDeviceIdCallBack
})
/** 打开蓝牙的监听 */
...
...
@@ -111,11 +140,11 @@ class WifiList extends Component {
// 过滤信号强度 0 到 -100 绝对值越小越好
filterRssi
(
rssi
:
number
)
{
if
(
rssi
>=
-
25
)
{
if
(
rssi
>=
-
50
)
{
return
'4-icon.png'
}
else
if
(
rssi
>=
-
50
)
{
}
else
if
(
rssi
>=
-
65
)
{
return
'3-icon.png'
}
else
if
(
rssi
>=
-
7
5
)
{
}
else
if
(
rssi
>=
-
8
5
)
{
return
'2-icon.png'
}
else
{
return
'1-icon.png'
...
...
@@ -124,24 +153,62 @@ class WifiList extends Component {
// wifi 列表信息更新回调
getWiFiListCallBack
(
wifiItem
:
IWifiListItem
)
{
const
{
recordObj
,
recordList
}
=
this
.
state
this
.
initLoading
&&
setTimeout
(()
=>
{
Taro
.
hideLoading
()
},
2000
)
this
.
initLoading
=
false
this
.
setState
({
wifiList
:
[...
this
.
state
.
wifiList
,
wifiItem
]
})
let
list
:
any
=
[]
let
myRecordList
:
any
=
[]
if
(
recordObj
[
wifiItem
.
ssid
])
{
myRecordList
=
[...
recordList
,
wifiItem
]
this
.
setState
({
recordList
:
myRecordList
})
}
else
{
list
=
[...
this
.
state
.
wifiList
,
wifiItem
]
this
.
setState
({
wifiList
:
list
})
}
}
getDeviceIdCallBack
(
token
:
string
)
{
this
.
deviceCpuId
=
token
console
.
log
(
'deviceId'
,
token
)
}
// 获取到设备token信息的回调
async
getDeviceTokenCallBack
(
token
:
string
)
{
this
.
deviceToken
=
token
try
{
Taro
.
showLoading
({
title
:
'绑定设备中'
})
// 检查设备是否使用
if
(
this
.
deviceCpuId
)
{
const
{
data
}
=
await
api
.
common
.
getDeviceUseState
(
this
.
deviceCpuId
)
if
(
data
===
'YES'
)
{
Taro
.
hideLoading
()
showMyToast
({
title
:
'设备已被绑定'
})
setTimeout
(()
=>
{
Taro
.
navigateBack
()
},
1000
)
return
}
}
const
{
equipmentId
}
=
await
api
.
common
.
addDeviceToken
(
token
)
const
{
password
,
activeWLAN
}
=
this
const
{
ssid
,
type
}
=
activeWLAN
await
api
.
common
.
addMyequipmentWifi
({
equipmentId
:
''
,
wifiType
:
type
,
wifiSsid
:
ssid
,
wifiIdentity
:
''
,
wifiPassword
:
password
})
await
api
.
common
.
updateMyequipmentWifi
({
equipmentId
,
equipmentWifiType
:
type
,
...
...
@@ -149,6 +216,7 @@ class WifiList extends Component {
equipmentWifiIdentity
:
''
,
equipmentWifiPassword
:
password
})
Taro
.
hideLoading
()
// console.log(this.props.getFilmListData(1), this.props)
showMyToast
({
title
:
'设备添加成功~'
})
Taro
.
navigateBack
()
...
...
@@ -168,9 +236,16 @@ class WifiList extends Component {
}
}
connectWifi
(
item
:
IWifiListItem
)
{
this
.
activeWLAN
=
item
console
.
log
(
this
.
state
.
recordObj
[
item
.
ssid
][
'password'
],
'pasword'
)
this
.
password
=
this
.
state
.
recordObj
[
item
.
ssid
][
'password'
]
this
.
onConfirm
()
}
async
onConfirm
()
{
const
{
id
,
type
}
=
this
.
activeWLAN
const
{
password
,
deviceId
,
deviceToken
}
=
this
const
{
password
,
deviceId
}
=
this
const
{
mode
}
=
this
.
$router
.
params
if
(
id
===
undefined
||
!
deviceId
)
return
if
(
type
!==
'OPEN'
&&
password
.
length
<
8
)
{
...
...
@@ -180,15 +255,10 @@ 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
(()
=>
{
Taro
.
navigateBack
()
//
Taro.navigateBack()
},
500
)
}
// Taro.hideLoading()
...
...
@@ -217,14 +287,27 @@ class WifiList extends Component {
}
render
()
{
const
{
wifiList
,
openModal
}
=
this
.
state
const
{
wifiList
,
recordList
,
openModal
}
=
this
.
state
let
url
=
'https://visual-clouds.oss-cn-beijing.aliyuncs.com/miniprogram/wifi'
return
(
<
View
className=
"wifi"
>
<
View
className=
"wifi-scroll"
>
<
ScrollView
className=
"wifi-scroll-view"
scrollY
>
<
View
className=
"wifi-content"
>
<
Text
className=
"wifi-title"
>
选取附近的WLAN
</
Text
>
{
recordList
.
length
?
<
Text
className=
"wifi-title"
>
缓存网络:
</
Text
>
:
null
}
{
recordList
.
map
(
item
=>
(
<
View
className=
"wifi-item"
key=
{
item
.
id
}
onClick=
{
()
=>
this
.
connectWifi
(
item
)
}
>
<
Text
className=
"wifi-item-name"
>
{
item
.
ssid
}
</
Text
>
{
item
.
type
!==
'OPEN'
&&
(
<
Image
className=
"lock"
src=
"https://visual-clouds.oss-cn-beijing.aliyuncs.com/miniprogram/lock-icon.png"
/>
)
}
<
Image
className=
"level"
src=
{
url
+
this
.
filterRssi
(
item
.
rssi
)
}
/>
</
View
>
))
}
<
Text
className=
"wifi-title"
>
其他网络:
</
Text
>
{
wifiList
.
map
(
item
=>
(
<
View
className=
"wifi-item"
key=
{
item
.
id
}
onClick=
{
()
=>
this
.
openModal
(
item
)
}
>
<
Text
className=
"wifi-item-name"
>
{
item
.
ssid
}
</
Text
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment