@ -1,6 +1,22 @@
< template >
< view class = "content" >
< uni-nav-bar :border = "false" @clickLeft ="prevPage" fixed = "true" statusBar = "true" background -color = " # 121212 "
color = "#FFFFFF" :title = "Status.navbar.title" >
< template v -slot : left >
< view >
< uni-icons type = "left" size = "24" color = "#FFFFFF" > < / uni-icons >
< / view >
< / template >
< block slot = "right" >
< view class = "navbarRight center" >
< image @click.stop ="handleRightClick(index,item)" v-for = "item,index in Status.navbar.icons"
class = "img" :src = "item.src" mode = "aspectFit" > < / image >
< / view >
< / block >
< / uni-nav-bar >
< view class = "topStatric" >
@ -10,6 +26,9 @@
< / view >
< view class = "lblTitle" >
< view > 添加 : { { type . typeName } } 设备数量 : { { devicesCnt } } < / view >
< view class = "btn" style = "color: #FFFFFF;" @click ="ReSearch()" > 刷新 < / view >
< / view >
< view class = "lblTitle" >
@ -69,15 +88,13 @@
< / view >
< view class = "name lbl" >
设备名 :
< text class = "green" > { { item . device _name } } < / text >
< text class = "green" > { { item . device _name } } < / text >
< / view >
< / view >
< view class = "rightIco " :class = "item.isUpload?'bggreen':'bgred'" >
<!-- < image :src = "isItemLink(item,index,'upload')" class = "img" mode = "aspectFit" >
< / image > -- >
@ -87,6 +104,8 @@
< / view >
< / view >
< global-loading ref = "loading" / >
< MsgBox ref = "msgPop" / >
< / view >
< / template >
@ -98,19 +117,41 @@
hideLoading ,
updateLoading
} from '@/utils/loading.js'
import common from '@/utils/Common.js'
import common from '@/utils/Common.js'
const pagePath = "pages/common/addBLE/addEquip" ;
import {
MsgSuccess ,
MsgError ,
MsgClose ,
MsgWarning ,
showPop ,
MsgClear
} from '@/utils/MsgPops.js' ;
import MQTT from '@/utils/MqHelper.js' ;
var ble = null ;
var these = null ;
var eventChannel = null ;
var time = null ;
var time1 = null ;
// var serv = null;
var mq = null ;
export default {
data ( ) {
return {
Status : {
intval : null ,
pcAuthori : false ,
navbar : {
icons : [
{
src : '/static/images/common/scane.png'
}
] ,
title : '添加设备' ,
showBack : true ,
height : 90
}
} ,
search : '' ,
groupid : '' ,
@ -120,7 +161,8 @@
EquipMents : [ ] , //搜索出来的设备
devices : [ ] ,
devicesCnt : 0 ,
privateNetUrl : ''
privateNetUrl : '' ,
scanKey : ''
}
} ,
@ -137,18 +179,30 @@
} ,
onUnload ( ) {
ble . StopSearch ( ) . then ( res => {
conso le. log ( "停止搜索成功" )
} ) . catch ( ex => {
console . error ( "停止搜索成功" , ex ) ;
} ) ;
ble . removeAllCallback ( pagePath ) ;
ble . disconnectDevice ( ) ;
if ( ble ) {
b le. StopSearch ( ) . then ( res => {
console . log ( "停止搜索成功" )
} ) . catch ( ex => {
console . error ( "停止搜索成功" , ex ) ;
} ) ;
ble . removeAllCallback ( pagePath ) ;
ble . disconnectDevice ( ) ;
}
if ( mq ) {
mq . disconnect ( ) ;
}
} ,
onLoad ( ) {
these = this ;
mq = MQTT . getMqTool ( ) ;
mq . init ( ) ;
this . groupid = common . DateFormat ( new Date ( ) , 'yyyy-MM-dd HH:mm:ss' ) ;
these = this ;
ble = bleTool . getBleTool ( ) ;
// serv = serTool.serverInit();
@ -356,12 +410,13 @@
if ( ! arr [ i ] . name ) {
continue ;
}
arr [ i ] . name = arr [ i ] . name . replace ( /\r\n/g , '' ) . replace ( /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g , '' ) ;
arr [ i ] . name = arr [ i ] . name . replace ( /\r\n/g , '' ) . replace ( /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g ,
'' ) ;
let f = these . EquipMents . find ( function ( v , index ) {
if ( v . deviceId == arr [ i ] . deviceId ) {
these . $set ( these . EquipMents [ index ] , "RSSI" , arr [ i ] . RSSI ) ;
@ -381,7 +436,7 @@
}
}
these . sendEquipToMq ( ) ;
// console.log("equip=", these.EquipMents)
} , pagePath ) ;
// console.log("addEquip")
@ -403,6 +458,7 @@
console . log ( "111111" ) ;
}
if ( f . imei ) {
f . imei = f . imei . replace ( /\u0000/g , '' ) ;
item = this . EquipMents . find ( ( v , index ) => {
if ( v . deviceId == f . deviceId ) {
v . imei = f . imei ;
@ -474,7 +530,7 @@
let callback = ( ) => {
these . getTypeDeviceCnt ( ) . then ( res => {
console . error ( "设备数量:" , res ) ;
console . error ( "设备数量:" , res ) ;
these . devicesCnt = res ;
if ( res > 0 && res <= 10000 ) {
these . getAlltypeDevices ( ) . then ( devs => {
@ -490,10 +546,28 @@
} ) ;
}
callback ( ) ;
} ) ;
setTimeout ( ( ) => {
MsgSuccess ( "如需要在PC上查看此数据,请复制链接后在PC端打开, 然后点右上角扫码授权" , "复制链接" , these , ( ) => {
uni . setClipboardData ( {
data : 'https://static-mp-5b7c35fc-f6fe-4100-a2e1-3669e4d4bfc9.next.bspapp.com/AppTools/views/index.html' ,
success ( ) {
uni . showToast ( {
title : '已复制链接'
} ) ;
}
} ) ;
} ) ;
} , 500 ) ;
} ,
onShow : function ( ) {
@ -503,65 +577,87 @@
} ,
methods : {
prevPage ( ) {
uni . navigateBack ( {
} ) ;
} ,
handleRightClick : function ( s , e ) {
this . scan ( ) ;
} ,
initWatch ( ) {
this . $watch ( "devicesCnt" , ( newVal , oldVal ) => {
const phone = uni . getStorageSync ( 'phone' ) ;
mq . sendData ( 'pc/' + phone , JSON . stringify ( {
devicesCnt : this . devicesCnt
} ) , false ) ;
} ) ;
} ,
//获取某个类型下的所有设备
getAlltypeDevices ( ) {
return new Promise ( ( succ , err ) => {
let json = {
"tenant_id" : this . type . tenantId ,
"deviceType" : this . type . deviceTypeId
} ;
request ( {
url : "/app/xinghan/device/getEquipAllByType" ,
method : 'POST' ,
data : json ,
} ) . then ( res => {
if ( res && res . code == 200 ) {
succ ( res . data ) ;
return ;
}
err ( res ) ;
} ) . catch ( ex => {
console . error ( "ex=" , ex ) ;
err ( ex ) ;
} ) ;
let json = {
"tenant_id" : this . type . tenantId ,
"deviceType" : this . type . deviceTypeId
} ;
request ( {
url : "/app/xinghan/device/getEquipAllByType" ,
method : 'POST' ,
data : json ,
} ) . then ( res => {
if ( res && res . code == 200 ) {
succ ( res . data ) ;
return ;
}
err ( res ) ;
} ) . catch ( ex => {
console . error ( "ex=" , ex ) ;
err ( ex ) ;
} ) ;
} ) ;
} ,
//获取类型下的设备数量
getTypeDeviceCnt ( ) {
return new Promise ( ( resolve , reject ) => {
let json = {
"tenant_id" : this . type . tenantId ,
"deviceType" : this . type . deviceTypeId
} ;
console . error ( "json=" , json ) ;
request ( {
url : "/app/xinghan/device/getEquipCountByType" ,
method : 'POST' ,
data : json ,
} ) . then ( res => {
console . error ( "getEquipCountByType res.data=" , res . data )
if ( res && res . code == 200 ) {
resolve ( res . data ) ;
return ;
}
reject ( res ) ;
} ) . catch ( ex => {
console . error ( "ex=" , ex ) ;
reject ( ex ) ;
} ) ;
let json = {
"tenant_id" : this . type . tenantId ,
"deviceType" : this . type . deviceTypeId
} ;
console . error ( "json=" , json ) ;
request ( {
url : "/app/xinghan/device/getEquipCountByType" ,
method : 'POST' ,
data : json ,
} ) . then ( res => {
console . error ( "getEquipCountByType res.data=" , res . data )
if ( res && res . code == 200 ) {
resolve ( res . data ) ;
return ;
}
reject ( res ) ;
} ) . catch ( ex => {
console . error ( "ex=" , ex ) ;
reject ( ex ) ;
} ) ;
} ) ;
} ,
getDevice ( item ) {
@ -581,37 +677,40 @@
if ( this . devicesCnt > 0 ) {
if ( this . devices && this . devices . length > 0 ) {
let eqp = this . devices . find ( v => {
let flag = v . bluetooth _name . replace ( /\r\n/g , '' ) . replace ( /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g , '' ) == item . name ;
let flag = v . bluetooth _name . replace ( /\r\n/g , '' ) . replace (
/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g , '' ) == item . name ;
return flag ;
} ) ;
if ( eqp ) {
these . $set ( these . EquipMents [ fIndex ] , "isUpload" ,
true ) ;
these . $set ( these . EquipMents [ fIndex ] , "remark" ,
"校验完成,设备已入库" ) ;
these . $set ( these . EquipMents [ fIndex ] , "macAddress" ,
eqp . device _mac ) ;
these . $set ( these . EquipMents [ fIndex ] , "device_name" , eqp . device _name ) ;
console . log ( "从缓存中找到了设备" , eqp ) ;
these . $set ( these . EquipMents [ fIndex ] , "device_name" , eqp . device _name ) ;
console . log ( "从缓存中找到了设备" , eqp ) ;
resolve ( eqp ) ;
return ;
}
}
console. error ( "缓存中找不到此设备22222222", this . devices ) ;
// console.error( "缓存中找不到此设备22222222", this.devices);
these . $set ( these . EquipMents [ fIndex ] , "remark" ,
"校验完成,设备未入库" ) ;
reject ( null ) ;
these . sendEquipToMq ( ) ;
return ;
}
let succCallback = ( data ) => {
if ( data ) {
let succCallback = ( data ) => {
if ( data ) {
these . $set ( these . EquipMents [ fIndex ] , "isUpload" ,
true ) ;
these . $set ( these . EquipMents [ fIndex ] , "remark" ,
@ -620,77 +719,176 @@
data . device _mac ) ;
these . $set ( these . EquipMents [ fIndex ] , "imei" , data
. device _imei ) ;
these . $set ( these . EquipMents [ fIndex ] , "device_name" , data . device _name ) ;
}
else {
console . error ( "设备未入库111111" , data )
these . $set ( these . EquipMents [ fIndex ] , "device_name" , data . device _name ) ;
} else {
console . error ( "设备未入库111111" , data )
these . $set ( these . EquipMents [ fIndex ] , "remark" ,
"校验完成,设备未入库" ) ;
}
these . sendEquipToMq ( ) ;
}
let errCallback = ( ) => {
let errCallback = ( ) => {
these . $set ( these . EquipMents [ fIndex ] , "remark" ,
"校验出现异常" ) ;
these . sendEquipToMq ( ) ;
}
let p2 = new Promise ( ( resolve , reject ) => {
let p2 = new Promise ( ( resolve , reject ) => {
let json = {
"tenant_id" : this . type . tenantId ,
"deviceType" : this . type . deviceTypeId ,
"deviceName" : item . name
} ;
request ( {
url : '/app/xinghan/device/GetDeviceByName' ,
data : json ,
url : '/app/xinghan/device/GetDeviceByName' ,
data : json ,
method : 'POST'
} ) . then ( res => {
if ( res && res . code == 200 ) {
resolve ( res . data ) ;
return ;
} ) . then ( res => {
if ( res && res . code == 200 ) {
resolve ( res . data ) ;
return ;
}
reject ( res ) ;
} ) . catch ( ex => {
} ) . catch ( ex => {
reject ( ex ) ;
} ) ;
} )
Promise . any ( [ p2 ] ) . then ( res => {
Promise . any ( [ p2 ] ) . then ( res => {
succCallback ( res ) ;
} ) . catch ( ex => {
} ) . catch ( ex => {
errCallback ( ex ) ;
} ) . finally ( ( ) => {
} ) ;
} ) ;
} ,
scan ( ) {
uni . scanCode ( {
success : ( res ) => {
console . log ( '条码内容:' + res . result ) ;
let getUrlParams = ( url ) => {
var p = { } ,
s = ( url . indexOf ( '?' ) > - 1 ? url . split ( '?' ) [ 1 ] : '' ) . split ( '&' ) ;
for ( var i = 0 ; i < s . length ; i ++ ) {
if ( ! s [ i ] ) continue ;
var kv = s [ i ] . split ( '=' ) ;
p [ decodeURIComponent ( kv [ 0 ] ) ] = kv [ 1 ] ? decodeURIComponent ( kv [ 1 ] . replace (
/\+/g , ' ' ) ) : '' ;
}
return p ;
}
let json = getUrlParams ( res . result ) ;
if ( ! json . key ) {
uni . showModal ( {
title : '错误' ,
content : "无效的二维码"
} )
return ;
}
this . scanKey = json . key ;
let msg = {
scanResult : '已扫码' ,
scanCode : 200
} ;
mq . sendData ( 'pc/' + json . key , JSON . stringify ( msg ) , false ) ;
uni . showModal ( {
title : '授权申请' ,
content : 'pc端授权登陆' ,
confirmText : '同意' ,
cancelText : '拒绝' ,
showCancel : true ,
success ( res ) {
if ( res . confirm ) {
these . pcAuthori ( json ) ;
return ;
}
if ( res . cancel ) {
msg . scanResult = "用户拒绝授权" ;
msg . scanCode = 500 ;
mq . sendData ( 'pc/' + json . key , JSON . stringify ( msg ) , false ) ;
}
} ,
} )
} ,
fail : ( err ) => {
console . log ( '扫码失败' , err ) ;
uni . showToast ( {
title : '扫码失败' ,
icon : 'none'
} ) ;
}
} ) ;
} ,
pcAuthori ( ) { //同意授权
const token = 'Bearer ' + uni . getStorageSync ( 'token' ) ;
const clientid = uni . getStorageSync ( 'clientID' ) ;
const phone = uni . getStorageSync ( 'phone' ) ;
let msg = {
scanResult : '用户同意授权' ,
scanUsr : phone ,
scanCode : 0 ,
Authorization : token ,
clientid : clientid ,
} ;
console . log ( "同意授权" , msg ) ;
this . Status . pcAuthori = true ;
mq . sendData ( 'pc/' + this . scanKey , JSON . stringify ( msg ) , false ) ;
these . sendEquipToMq ( ) ;
} ,
sendEquipToMq ( ) {
if ( mq && this . scanKey ) {
const phone = uni . getStorageSync ( 'phone' ) ;
setTimeout ( ( ) => {
mq . sendData ( 'pc/' + phone , JSON . stringify ( {
EquipMents : this . EquipMents
} ) , false ) ;
} , 500 ) ;
}
} ,
ReSearch ( ) {
if ( ! ble ) {
return ;
}
ble . disconnectDevice ( ) . finally ( dis => {
ble . StopSearch ( ) . finally ( res => {
this . EquipMents = [ ] ;
this . PairEquip = [ ] ;
ble . StartSearch ( ) . then ( result => {
} ) . catch ( err => {
console . error ( "err=" , err ) ;
MsgError ( "出现错误:" + err . msg , '' , these ) ;
} ) ;
} ) . catch ( ex => {
console . error ( "ex=" , ex ) ;
MsgError ( "出现错误:" + ex . msg , '' , these ) ;
} ) ;
} ) ;
@ -727,7 +925,7 @@
this . devices . push ( {
bluetooth _name : item . name ,
device _mac : item . macAddress ,
device _name : item . name
device _name : item . name
} ) ;
this . devicesCnt = this . devices . length ;
@ -742,63 +940,31 @@
if ( v . deviceId == item . deviceId ) {
this . $set ( this . EquipMents [ index ] , "isUpload" , false ) ;
this . $set ( this . EquipMents [ index ] , "remark" , res . msg ) ;
this . devices . find ( ( d , i ) => {
if ( d . device _mac == item . macAddress ) {
this . $set ( this . EquipMents [ index ] , "device_name" , d . device _name ) ;
this . devices . find ( ( d , i ) => {
if ( d . device _mac == item . macAddress ) {
this . $set ( this . EquipMents [ index ] , "device_name" , d
. device _name ) ;
return true ;
}
} ) ;
return true ;
}
return false ;
} ) ;
}
} )
} ) . catch ( ex => { } ) . finally ( ( ) => {
these . sendEquipToMq ( ) ;
} ) ;
}
time = setTimeout ( exec , 100 )
} ,
isItemLink : function ( item , index , type ) {
let src = '/static/images/BLEAdd/noLink.png' ;
if ( ! item ) {
return src ;
}
if ( type == 'link' ) {
if ( this . PairEquip && this . PairEquip . length ) {
if ( this . PairEquip . length > 0 ) {
let f = this . PairEquip . find ( function ( v ) {
return v . deviceId == item . deviceId ;
} ) ;
if ( f ) {
src = '/static/images/BLEAdd/linked.png' ;
}
}
}
} else if ( type == 'mac' ) {
if ( item . macAddress ) {
src = '/static/images/BLEAdd/linked.png' ;
}
} else if ( type == 'imei' ) {
if ( item . imei ) {
src = '/static/images/BLEAdd/linked.png' ;
}
} else if ( type == 'upload' ) {
if ( item . isUpload ) {
src = '/static/images/BLEAdd/linked.png' ;
}
}
return src ;
} ,
Link : function ( item ) {
let exec = ( ) => {
@ -865,6 +1031,8 @@
execLink ( ) . then ( ( res ) => {
linkCallback ( res ) ;
these . sendEquipToMq ( ) ;
} ) . catch ( ex => {
console . log ( "ex=" , ex )
uni . showModal ( {
@ -1042,6 +1210,7 @@
width : 100 % ;
height : calc ( 100 % - 186 rpx ) ;
overflow - y : scroll ;
margin - top : 120 rpx ;
}
. list . item {
@ -1253,6 +1422,16 @@
animation : rotateClockwise 3 s linear infinite ;
}
. topStatric {
width : 100 % ;
box - sizing : border - box ;
padding : 30 rpx ;
position : fixed ;
top : 0 rpx ;
z - index : 99 ;
background - color : # 121212 ;
}
/* #ifdef H5 */
. topStatric {
@ -1274,17 +1453,13 @@
margin - top : 240 rpx ;
}
. topStatric {
top : 90 rpx
}
/* #endif */
. topStatric {
width : 100 % ;
box - sizing : border - box ;
padding : 30 rpx ;
position : fixed ;
top : 0 rpx ;
z - index : 99 ;
background - color : # 121212 ;
}
. uni - mt - 5 {
background - color : # 000000 ;
@ -1293,4 +1468,22 @@
. uni - easyinput _ _content {
background - color : # 121212 ! important ;
}
. navbarRight . img {
width : 35 rpx ;
height : 35 rpx ;
margin - right : 20 rpx ;
}
. uni - navbar -- fixed {
top : 0 rpx ;
}
/ deep / . uni - navbar -- fixed {
top : 0 px ;
}
/ deep / . uni - navbar _ _placeholder {
display : none ! important ;
}
< / style >