添加消息推送云函数、消息处理为后续的消息通知做准备
This commit is contained in:
229
pages/common/addDevice/TypeList.vue
Normal file
229
pages/common/addDevice/TypeList.vue
Normal file
@ -0,0 +1,229 @@
|
||||
<template>
|
||||
<view class="content contentBg">
|
||||
<view class="topStatric">
|
||||
<uni-easyinput :styles="{color:'#ffffff'}" :clearable="true" class="uni-mt-5" :trim="'both'"
|
||||
prefixIcon="search" v-model="search" placeholder="名称筛选"></uni-easyinput>
|
||||
</view>
|
||||
|
||||
<view class="mainContent">
|
||||
<view class="item " :class="{'displayNone':item.typeName.toLowerCase().indexOf(search.toLowerCase())===-1}"
|
||||
v-for="item,index in list" v-on:click.stop="gotoAdd(item)">
|
||||
<view class="itemLine">
|
||||
<view class="imgContent">
|
||||
<image class="img" :src="item.devicePic?item.devicePic:'/static/images/path3.png'" mode="aspectFit"></image>
|
||||
|
||||
|
||||
</view>
|
||||
|
||||
<text class="typeName">{{item['typeName']}}</text>
|
||||
<text class="netName">
|
||||
({{(item['communicationMode']=='0' || item['communicationMode']===0)?'4G':(item['communicationMode']===1|| item['communicationMode']==='1')?'蓝牙':'蓝牙&4G'}})
|
||||
</text>
|
||||
</view>
|
||||
<uni-icons type="forward" size="18" color="#FFFFFFde"></uni-icons>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import request from '@/utils/request';
|
||||
var these = null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
v: '',
|
||||
search: '',
|
||||
list: []
|
||||
}
|
||||
},
|
||||
onLoad: function(op) {
|
||||
these = this;
|
||||
|
||||
this.getDevList();
|
||||
let time = null;
|
||||
let channel = this.getOpenerEventChannel();
|
||||
channel.on('checkTypes', function(data) {
|
||||
these.v = data;
|
||||
})
|
||||
|
||||
},
|
||||
methods: {
|
||||
getDevList() {
|
||||
let arr = [
|
||||
|
||||
];
|
||||
request({
|
||||
url: '/app/xinghan/device/typeAll',
|
||||
method: 'get'
|
||||
}).then(res => {
|
||||
if (res && res.code == 200) {
|
||||
console.log("获取到类型", res.data);
|
||||
arr = res.data;
|
||||
}
|
||||
|
||||
this.list = arr;
|
||||
}).catch(ex => {
|
||||
uni.showModal({
|
||||
content: "获取类型列表失败"
|
||||
})
|
||||
})
|
||||
},
|
||||
gotoAdd(item, index) {
|
||||
debugger;
|
||||
if (this.v) {
|
||||
let eventChannel = this.getOpenerEventChannel();
|
||||
eventChannel.emit('checkType', item);
|
||||
uni.navigateBack();
|
||||
return;
|
||||
}
|
||||
let url = '';
|
||||
|
||||
let goto = () => {
|
||||
uni.navigateTo({
|
||||
url: url,
|
||||
success(res) {
|
||||
res.eventChannel.emit('addType', {
|
||||
data: item
|
||||
})
|
||||
},
|
||||
fail(ex) {
|
||||
console.log("页面跳转失败了", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (item.communicationMode === 1 || item.communicationMode === '1') { //蓝牙添加
|
||||
url = '/pages/common/addDevice/addBle';
|
||||
} else if (item.communicationMode === 0 || item.communicationMode === '0') { //扫码或输入IMEI添加
|
||||
url = '/pages/common/addDevice/addImei?type=imei';
|
||||
} else {
|
||||
uni.showActionSheet({
|
||||
title: '添加方式',
|
||||
itemColor: '#aed600',
|
||||
itemList: ["扫一扫添加", "蓝牙添加"],
|
||||
success: function(res) {
|
||||
switch (res.tapIndex) {
|
||||
case 0:
|
||||
url = '/pages/common/addDevice/addImei?type=blueAndImei';
|
||||
break;
|
||||
case 1:
|
||||
url = '/pages/common/addDevice/addBle';
|
||||
break;
|
||||
}
|
||||
|
||||
goto();
|
||||
}
|
||||
})
|
||||
}
|
||||
goto();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.content {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 100vh;
|
||||
height: auto;
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.item {
|
||||
margin-bottom: 20rpx;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
border-bottom: 1rpx dashed #FFFFFF3d;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
.itemLine {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.netName {
|
||||
color: #838282;
|
||||
font-size: 26rpx;
|
||||
margin-left: 10rpx;
|
||||
}
|
||||
|
||||
.typeName {
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
.topStatric {
|
||||
width: calc(100% - 60rpx);
|
||||
box-sizing: border-box;
|
||||
|
||||
position: fixed;
|
||||
top: 0rpx;
|
||||
z-index: 99;
|
||||
background-color: #121212;
|
||||
}
|
||||
|
||||
/* #ifdef H5 */
|
||||
.topStatric {
|
||||
top: 44px;
|
||||
}
|
||||
|
||||
.mainContent {
|
||||
margin-top: 60rpx;
|
||||
}
|
||||
|
||||
|
||||
/* #endif */
|
||||
|
||||
/* #ifdef APP */
|
||||
.mainContent {
|
||||
|
||||
margin-top: 60rpx;
|
||||
}
|
||||
|
||||
/* #endif */
|
||||
.uni-mt-5 {
|
||||
background-color: #000000;
|
||||
}
|
||||
|
||||
.uni-easyinput__content {
|
||||
background-color: #121212 !important;
|
||||
}
|
||||
|
||||
.imgContent {
|
||||
width: 70rpx;
|
||||
height: 70rpx;
|
||||
border: 1px solid #838282;
|
||||
border-radius: 10rpx;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-right: 20rpx;
|
||||
box-sizing: border-box;
|
||||
padding: 10rpx;
|
||||
}
|
||||
|
||||
.img {
|
||||
width: 60rpx;
|
||||
height: 60rpx;
|
||||
|
||||
|
||||
}
|
||||
</style>
|
||||
1296
pages/common/addDevice/addBle.vue
Normal file
1296
pages/common/addDevice/addBle.vue
Normal file
File diff suppressed because it is too large
Load Diff
507
pages/common/addDevice/addImei.vue
Normal file
507
pages/common/addDevice/addImei.vue
Normal file
@ -0,0 +1,507 @@
|
||||
<template>
|
||||
<view class="content contentBg">
|
||||
|
||||
<uni-nav-bar class="nvbar" leftIcon="left" @clickLeft="navigatorBack">
|
||||
<view slot="left">
|
||||
<uni-icons type="back" size="23" color="#FFFFFF"></uni-icons>
|
||||
</view>
|
||||
<view slot="default" class="center uninavebartext">
|
||||
{{Status.navbar.title}}
|
||||
</view>
|
||||
<view slot="right">
|
||||
<view class="navbarRight center">
|
||||
<view class="imgContent" :class="{'visibilityHidden':Status.apiType!=item.apiType}"
|
||||
@click.stop="handleRightClick(item,index)" v-for="item,index in Status.navbar.icons">
|
||||
<image class="img" :src="item.src" mode="aspectFit"></image>
|
||||
<view class="baber" v-if="item.math">{{item.math>9?'9+':item.math}}</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
|
||||
</view>
|
||||
|
||||
</uni-nav-bar>
|
||||
|
||||
|
||||
|
||||
<view class="ul">
|
||||
<view class="red">扫码或输入IMEI,以添加设备</view>
|
||||
<text>IMEI列表:</text>
|
||||
<view class="li" v-for="item,index in imeis">
|
||||
<view>
|
||||
<view class="txt">IMEI:{{item.imei}}</view>
|
||||
<view class="txt">Mac:{{item.mac}}</view>
|
||||
<view class="remark" :class="item.isUpload?'green':'red'">状态:{{item.msg}}</view>
|
||||
</view>
|
||||
|
||||
<image :src="isItemLink(item,index,'upload')" class="img" mode="aspectFit">
|
||||
</image>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="footer">
|
||||
<view class="row">
|
||||
|
||||
|
||||
<view class="inputContent">
|
||||
|
||||
<uni-easyinput v-model="input" placeholder="请输入IMEI"></uni-easyinput>
|
||||
|
||||
</view>
|
||||
<view class="btn" @click="addImei(null)">
|
||||
确定
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Common from '@/utils/Common';
|
||||
import request from '@/utils/request';
|
||||
import MqHelper from '@/utils/MqHelper';
|
||||
|
||||
var eventChannel = null;
|
||||
var these = null;
|
||||
var mq = null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
Status:{
|
||||
navbar: {
|
||||
icons: [{
|
||||
src: '/static/images/common/scane.png',
|
||||
callback: this.scan
|
||||
|
||||
}],
|
||||
title: '添加IMEI'
|
||||
|
||||
}
|
||||
},
|
||||
groupid: '',
|
||||
type: {
|
||||
|
||||
|
||||
},
|
||||
input: '',
|
||||
imeis: [],
|
||||
topic: ""
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
if (mq) {
|
||||
mq.unSubscribes();
|
||||
mq.disconnect();
|
||||
mq = null;
|
||||
}
|
||||
},
|
||||
onLoad(opt) {
|
||||
this.groupid = Common.DateFormat(new Date(), 'yyyy-MM-dd HH:mm:ss');
|
||||
these = this;
|
||||
eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
|
||||
eventChannel.on('addType', function(rec) {
|
||||
console.log("接收到父页面的参数:", rec);
|
||||
these.type = rec.data;
|
||||
these.Status.navbar.title="添加" + rec.data.typeName;
|
||||
|
||||
|
||||
let typeName = these.type.typeName.replace(/-/g, '').replace(/_/g, '').replace(
|
||||
/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '').toUpperCase();
|
||||
these.topic = 'regis/equip/' + typeName;
|
||||
mq = MqHelper.getMqTool();
|
||||
mq.init().then(res => {
|
||||
let arr = [{
|
||||
topic: these.topic,
|
||||
callback: these.mqReceive
|
||||
}];
|
||||
mq.subscribes(arr).catch(ex => {
|
||||
console.error("出现错误", ex);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
methods: {
|
||||
handleRightClick(item, s) {
|
||||
if (item && item.callback) {
|
||||
item.callback(item, s);
|
||||
} else {
|
||||
uni.showModal({
|
||||
content: '敬请期待'
|
||||
})
|
||||
|
||||
}
|
||||
},
|
||||
navigatorBack() {
|
||||
uni.navigateBack();
|
||||
},
|
||||
//收到上报消息时的处理方法
|
||||
mqReceive(receive) {
|
||||
console.log("收到主题消息:", receive);
|
||||
|
||||
let task = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
let json = JSON.parse(receive.payload);
|
||||
let imei = "";
|
||||
if (json.imei) {
|
||||
imei = json.imei;
|
||||
}
|
||||
|
||||
let f = this.imeis.find(v => {
|
||||
return v.imei === imei
|
||||
});
|
||||
|
||||
let mac = "";
|
||||
if (json.mac) {
|
||||
if (!json.mac.includes(':')) {
|
||||
mac = json.mac.replace(/(.{2})/g, '$1:').slice(0, -1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let dev = {
|
||||
imei: imei,
|
||||
mac: mac,
|
||||
isUpload: false,
|
||||
msg: '正在上传'
|
||||
};
|
||||
if (!f) {
|
||||
this.imeis.unshift(dev);
|
||||
}
|
||||
|
||||
|
||||
this.uploadItem(dev).then(res => {
|
||||
this.sendSuccNotice(imei);
|
||||
resolve(true);
|
||||
}).catch(ex => {
|
||||
console.error("ex=", ex);
|
||||
reject(ex);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("出现错误:", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
task();
|
||||
},
|
||||
//发送成功的通知
|
||||
sendSuccNotice(imei) {
|
||||
let json = JSON.stringify({
|
||||
code: 200
|
||||
});
|
||||
mq.sendData("regis/" + imei, json, false);
|
||||
},
|
||||
isItemLink: function(item, index, type) {
|
||||
console.log("item=", item);
|
||||
let src = '/static/images/BLEAdd/noLink.png';
|
||||
if (!item) {
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
if (type == 'upload') {
|
||||
if (item.isUpload) {
|
||||
src = '/static/images/BLEAdd/linked.png';
|
||||
}
|
||||
}
|
||||
|
||||
return src;
|
||||
},
|
||||
//扫码
|
||||
scan() {
|
||||
let systemInfo = uni.getSystemInfoSync();
|
||||
if (systemInfo.uniPlatform == 'web') {
|
||||
uni.showModal({
|
||||
content:"Web平台不支持此功能,请手工录入或设备开机上报"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
uni.scanCode({
|
||||
onlyFromCamera: false,
|
||||
scanType: ['qrCode'],
|
||||
autoDecodeCharset: true,
|
||||
autoZoom: true,
|
||||
barCodeInput: true,
|
||||
hideAlbum: false,
|
||||
success: (res) => {
|
||||
|
||||
if (res.result) {
|
||||
|
||||
console.log("扫码成功,", res);
|
||||
this.input = res.res
|
||||
this.addImei(res.result);
|
||||
}
|
||||
},
|
||||
fail: (ex) => {
|
||||
console.log("扫码失败,", ex);
|
||||
}
|
||||
});
|
||||
},
|
||||
//手动输入
|
||||
addImei(txt) {
|
||||
debugger;
|
||||
if (!txt) {
|
||||
txt = this.input
|
||||
}
|
||||
let imei = "";
|
||||
let mac = "";
|
||||
console.log("txt=", txt);
|
||||
try {
|
||||
let json = JSON.parse(txt);
|
||||
if ('blue' in json) {
|
||||
mac = json.blue;
|
||||
if (mac) {
|
||||
if (!mac.includes(':')) {
|
||||
mac = mac.replace(/(.{2})/g, '$1:').slice(0, -1)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ('imei' in json) {
|
||||
imei = json.imei;
|
||||
console.log("imei=", imei)
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error("出现异常:", error);
|
||||
imei = txt;
|
||||
}
|
||||
|
||||
let f = this.imeis.find(v => {
|
||||
return v.imei === imei
|
||||
});
|
||||
|
||||
if (!f) {
|
||||
let dev = {
|
||||
imei: imei,
|
||||
mac: mac,
|
||||
isUpload: false,
|
||||
msg: '正在上传'
|
||||
};
|
||||
this.imeis.unshift(dev);
|
||||
|
||||
this.uploadItem(dev).then(res => {
|
||||
|
||||
}).catch(ex => {
|
||||
console.error("ex=", ex);
|
||||
});
|
||||
|
||||
} else {
|
||||
uni.showModal({
|
||||
content: "IMEI重复了"
|
||||
})
|
||||
}
|
||||
},
|
||||
//上报设备至服务器
|
||||
uploadItem(item) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log("item=", this.type);
|
||||
let json = {
|
||||
"deviceType": this.type.id,
|
||||
"deviceName": this.type.typeName,
|
||||
"deviceImei": item.imei,
|
||||
"remark": this.groupid,
|
||||
"deviceMac": item.mac,
|
||||
"bluetoothName": this.type.typeName,
|
||||
}
|
||||
console.log("111111", json)
|
||||
request({
|
||||
url: '/app/xinghan/device/add',
|
||||
method: 'post',
|
||||
data: json
|
||||
}).then(res => {
|
||||
|
||||
if (res && res.code) {
|
||||
|
||||
|
||||
this.imeis.find((v, index) => {
|
||||
if (v.imei == item.imei) {
|
||||
this.$set(this.imeis[index], "isUpload", (res && res.code ==
|
||||
200));
|
||||
this.$set(this.imeis[index], "msg", res.msg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
this.input = "";
|
||||
if (res.code == 200) {
|
||||
console.log("成功了,", res);
|
||||
resolve(true);
|
||||
return;
|
||||
} else if (res.code == 500) {
|
||||
if (res.msg.indexOf('已存在') > -1) {
|
||||
resolve(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
console.log("出现错误,", res);
|
||||
reject(res);
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.content {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 100vh;
|
||||
height: auto;
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.li {
|
||||
width: 100%;
|
||||
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
background: #1A1A1A;
|
||||
box-sizing: border-box;
|
||||
padding: 20rpx;
|
||||
border-radius: 16rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.txt {
|
||||
font-size: 34rpx;
|
||||
font-weight: 400;
|
||||
|
||||
}
|
||||
|
||||
.remark {
|
||||
font-size: 26rpx;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.img {
|
||||
width: 50rpx;
|
||||
height: 50rpx;
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
bottom: 0rpx;
|
||||
left: 0rpx;
|
||||
}
|
||||
|
||||
.footer .row {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
box-sizing: border-box;
|
||||
padding: 20rpx;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.inputContent {
|
||||
width: calc(100% - 110rpx);
|
||||
}
|
||||
|
||||
.footer .btn {
|
||||
width: 100rpx;
|
||||
text-align: center;
|
||||
background-color: #09a0f7;
|
||||
color: #fff;
|
||||
border-radius: 16rpx;
|
||||
height: 70rpx;
|
||||
line-height: 70rpx;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.navbarRight {
|
||||
width: 40px;
|
||||
height: 100%;
|
||||
|
||||
}
|
||||
|
||||
.navbarRight .imgContent {
|
||||
width: 36rpx;
|
||||
height: 36rpx;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.navbarRight .imgContent:first-child {
|
||||
|
||||
width: 38rpx !important;
|
||||
height: 38rpx !important;
|
||||
margin-top: -2rpx;
|
||||
}
|
||||
|
||||
.navbarRight .imgContent .baber {
|
||||
position: absolute;
|
||||
z-index: 100;
|
||||
width: 30rpx;
|
||||
height: 30rpx;
|
||||
line-height: 30rpx;
|
||||
right: -15rpx;
|
||||
top: -15rpx;
|
||||
border-radius: 50%;
|
||||
background: #f12828;
|
||||
color: #ffffff;
|
||||
font-family: 'PingFang SC';
|
||||
font-style: Regular;
|
||||
font-size: 20rpx;
|
||||
font-weight: 400;
|
||||
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
|
||||
}
|
||||
|
||||
.navbarRight .imgContent .img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.navbarRight .imgContent .img:last-child {
|
||||
padding: 1rpx;
|
||||
}
|
||||
|
||||
.nvbar {
|
||||
top: 0px;
|
||||
}
|
||||
|
||||
/deep/ .uni-navbar--fixed {
|
||||
top: 0px;
|
||||
}
|
||||
|
||||
.uninavebartext {
|
||||
width: 100%;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user