优化mqtt协议代码
This commit is contained in:
@ -6,7 +6,7 @@ const config = {
|
|||||||
API_PREFIX: '',
|
API_PREFIX: '',
|
||||||
// MQTT 配置
|
// MQTT 配置
|
||||||
MQTT_HOST: '47.120.79.150',
|
MQTT_HOST: '47.120.79.150',
|
||||||
MQTT_PORT: 8083,
|
MQTT_PORT: 9083,
|
||||||
MQTT_USERNAME: 'admin',
|
MQTT_USERNAME: 'admin',
|
||||||
MQTT_PASSWORD: '#YtvpSfCNG'
|
MQTT_PASSWORD: '#YtvpSfCNG'
|
||||||
},
|
},
|
||||||
@ -16,7 +16,7 @@ const config = {
|
|||||||
API_PREFIX: '',
|
API_PREFIX: '',
|
||||||
// MQTT 配置
|
// MQTT 配置
|
||||||
MQTT_HOST: '47.120.79.150',
|
MQTT_HOST: '47.120.79.150',
|
||||||
MQTT_PORT: 8083,
|
MQTT_PORT: 9083,
|
||||||
MQTT_USERNAME: 'admin',
|
MQTT_USERNAME: 'admin',
|
||||||
MQTT_PASSWORD: '#YtvpSfCNG'
|
MQTT_PASSWORD: '#YtvpSfCNG'
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,8 @@
|
|||||||
{
|
{
|
||||||
"path": "pages/common/send/index",
|
"path": "pages/common/send/index",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "发送信息"
|
"navigationBarTitleText": "发送信息",
|
||||||
|
"enablePullDownRefresh": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -66,7 +67,8 @@
|
|||||||
{
|
{
|
||||||
"path": "pages/6170/callPolice/index",
|
"path": "pages/6170/callPolice/index",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "报警"
|
"navigationBarTitleText": "报警",
|
||||||
|
"enablePullDownRefresh": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
<!-- 设备列表 -->
|
<!-- 设备列表 -->
|
||||||
<view class="allSelect" @click="selectAll"> 全选</view>
|
<view class="allSelect" @click="selectAll"> 全选</view>
|
||||||
<scroll-view class="device-list" scroll-y>
|
<scroll-view class="device-list" scroll-y>
|
||||||
<view class="device-card" v-for="(item, index) in deviceList" :key="index" @click="toggleSelect(index)">
|
<view class="device-card" v-for="(item, index) in deviceList" :key="index" @click="item.onlineStatus === 1 ? toggleSelect(index) : null">
|
||||||
<!-- 复选框 -->
|
<!-- 复选框 -->
|
||||||
<view class="checkbox" :class="{ checked: item.checked }">
|
<view class="checkbox" :class="{ checked: item.checked,disabled: item.onlineStatus !== 1 }">
|
||||||
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
|
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
|
||||||
</view>
|
</view>
|
||||||
<!-- 设备信息 -->
|
<!-- 设备信息 -->
|
||||||
@ -81,45 +81,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/**
|
|
||||||
* 获取设备状态(带自动轮询)
|
|
||||||
* @param {number} val - 功能模式
|
|
||||||
* @param {string} batchId - 批次ID
|
|
||||||
* @param {number} [interval=1000] - 轮询间隔(毫秒)
|
|
||||||
*/
|
|
||||||
async getdeviceSTatus(val, batchId, interval = 800) {
|
|
||||||
let retries = 0;
|
|
||||||
const checkStatus = async () => {
|
|
||||||
try {
|
|
||||||
const data = {
|
|
||||||
functionMode: val, //批量的传2
|
|
||||||
batchId: batchId,
|
|
||||||
typeName: this.sendInfo.typeName,
|
|
||||||
deviceImei: this.sendInfo.deviceImei
|
|
||||||
};
|
|
||||||
const res = await deviceRealTimeStatus(data);
|
|
||||||
if (res.code !== 200) {
|
|
||||||
throw new Error(res.msg || '请求失败');
|
|
||||||
}
|
|
||||||
switch (res.data.functionAccess) {
|
|
||||||
case 'OK':
|
|
||||||
return res; // 成功完成
|
|
||||||
case 'ACTIVE':
|
|
||||||
await new Promise(r => setTimeout(r, interval));
|
|
||||||
return checkStatus(); // 继续轮询
|
|
||||||
case 'FAILED':
|
|
||||||
throw new Error('设备操作失败');
|
|
||||||
case 'TIMEOUT':
|
|
||||||
throw new Error('设备响应超时');
|
|
||||||
default:
|
|
||||||
throw new Error('未知状态');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return checkStatus();
|
|
||||||
},
|
|
||||||
onclosePopup() {
|
onclosePopup() {
|
||||||
this.showPopupFlag = false
|
this.showPopupFlag = false
|
||||||
},
|
},
|
||||||
@ -142,7 +103,7 @@
|
|||||||
this.loading = true;
|
this.loading = true;
|
||||||
let data = {
|
let data = {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 30,
|
pageSize: 50,
|
||||||
deviceType: deviceType
|
deviceType: deviceType
|
||||||
}
|
}
|
||||||
deviceInfo(data).then((res) => {
|
deviceInfo(data).then((res) => {
|
||||||
@ -195,33 +156,20 @@
|
|||||||
const selectedDevices = this.deviceList.filter(item => item.checked);
|
const selectedDevices = this.deviceList.filter(item => item.checked);
|
||||||
const deviceIds = selectedDevices.map(item => item.id);
|
const deviceIds = selectedDevices.map(item => item.id);
|
||||||
const deviceImeiList = selectedDevices.map(item => item.deviceImei);
|
const deviceImeiList = selectedDevices.map(item => item.deviceImei);
|
||||||
const isAlarming = this.pendingAlarmAction == 1;
|
const isAlarming = this.pendingAlarmAction == 1;
|
||||||
try {
|
try {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: isAlarming ? '设备报警中...' : '解除报警中...',
|
title: isAlarming ? '设备报警中...' : '解除报警中...',
|
||||||
mask: true
|
mask: true
|
||||||
});
|
});
|
||||||
// 2. 准备请求数据
|
|
||||||
const batchId = generateShortId();
|
|
||||||
const data = {
|
const data = {
|
||||||
deviceIds: deviceIds,
|
deviceIds: deviceIds,
|
||||||
batchId: batchId,
|
|
||||||
typeName: this.sendInfo.typeName,
|
typeName: this.sendInfo.typeName,
|
||||||
deviceImeiList: deviceImeiList,
|
deviceImeiList: deviceImeiList,
|
||||||
instructValue: this.pendingAlarmAction == 1 ? '1' : '0'
|
instructValue: this.pendingAlarmAction == 1 ? '1' : '0'
|
||||||
};
|
};
|
||||||
// 3.人员信息
|
|
||||||
const registerRes = await deviceSendAlarmMessage(data);
|
const registerRes = await deviceSendAlarmMessage(data);
|
||||||
if (registerRes.code !== 200) {
|
if (registerRes.code == 200) {
|
||||||
uni.showToast({
|
|
||||||
title: registerRes.msg,
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 4. 获取设备状态
|
|
||||||
const statusRes = await this.getdeviceSTatus(2, batchId);
|
|
||||||
if (statusRes.data.functionAccess === 'OK') {
|
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: statusRes.msg,
|
title: statusRes.msg,
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
@ -231,6 +179,11 @@
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.navigateBack()
|
uni.navigateBack()
|
||||||
}, 500)
|
}, 500)
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: registerRes.msg,
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -479,4 +432,14 @@
|
|||||||
border: 1px solid rgba(255, 255, 255, 0.87);
|
border: 1px solid rgba(255, 255, 255, 0.87);
|
||||||
background: rgba(18, 18, 18, 1);
|
background: rgba(18, 18, 18, 1);
|
||||||
}
|
}
|
||||||
|
.checkbox.disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
background-color: rgba(255, 255, 255, 0.1) !important;
|
||||||
|
border-color: rgba(255, 255, 255, 0.2) !important;
|
||||||
|
pointer-events: none; /* 阻止点击事件 */
|
||||||
|
}
|
||||||
|
/* 可选:离线设备的卡片整体置灰 */
|
||||||
|
.device-card[data-offline="true"] {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
File diff suppressed because it is too large
Load Diff
@ -2,9 +2,9 @@
|
|||||||
<view class="container">
|
<view class="container">
|
||||||
<!-- 设备列表 -->
|
<!-- 设备列表 -->
|
||||||
<scroll-view class="device-list" scroll-y>
|
<scroll-view class="device-list" scroll-y>
|
||||||
<view class="device-card" v-for="(item, index) in deviceList" :key="index" @click="toggleSelect(index)">
|
<view class="device-card" v-for="(item, index) in deviceList" :key="index" @click="item.onlineStatus === 1 ? toggleSelect(index) : null">
|
||||||
<!-- 复选框 -->
|
<!-- 复选框 -->
|
||||||
<view class="checkbox" :class="{ checked: item.checked }">
|
<view class="checkbox" :class="{ checked: item.checked,disabled: item.onlineStatus !== 1 }">
|
||||||
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
|
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
|
||||||
</view>
|
</view>
|
||||||
<!-- 设备信息 -->
|
<!-- 设备信息 -->
|
||||||
@ -71,6 +71,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
onPullDownRefresh() {
|
||||||
|
// 执行下拉刷新时的操作,比如重新获取数据
|
||||||
|
this.getData();
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* 获取设备状态(带自动轮询)
|
* 获取设备状态(带自动轮询)
|
||||||
* @param {number} val - 功能模式
|
* @param {number} val - 功能模式
|
||||||
@ -419,4 +423,14 @@
|
|||||||
border-radius: 50rpx;
|
border-radius: 50rpx;
|
||||||
width: 90%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
|
.checkbox.disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
background-color: rgba(255, 255, 255, 0.1) !important;
|
||||||
|
border-color: rgba(255, 255, 255, 0.2) !important;
|
||||||
|
pointer-events: none; /* 阻止点击事件 */
|
||||||
|
}
|
||||||
|
/* 可选:离线设备的卡片整体置灰 */
|
||||||
|
.device-card[data-offline="true"] {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
@ -6,7 +6,7 @@
|
|||||||
<image src="/static/images/common/logo.png" class="logo"></image>
|
<image src="/static/images/common/logo.png" class="logo"></image>
|
||||||
</view>
|
</view>
|
||||||
<view class="user-right">
|
<view class="user-right">
|
||||||
<view class="user-title">富源晟科技</view>
|
<view class="user-title">武汉研创</view>
|
||||||
<view class="ID">ID:123456</view>
|
<view class="ID">ID:123456</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import config from '../config/index.js';
|
import config from '../config/index.js';
|
||||||
const env = 'development'; //production development //开发of线上 改这里就行
|
const env = 'production'; //production development //开发of线上 改这里就行
|
||||||
const BASE = config[env];
|
const BASE = config[env];
|
||||||
const request = (options) => {
|
const request = (options) => {
|
||||||
console.log("options"+JSON.stringify(options),BASE.BASE_URL)
|
console.log("options"+JSON.stringify(options),BASE.BASE_URL)
|
||||||
@ -20,7 +20,7 @@ const request = (options) => {
|
|||||||
method: options.method || 'GET',
|
method: options.method || 'GET',
|
||||||
data: options.method !== 'GET' ? options.data : {},
|
data: options.method !== 'GET' ? options.data : {},
|
||||||
header: options.header || {},
|
header: options.header || {},
|
||||||
timeout: 10000,
|
timeout: 30000,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
resolve(res.data);
|
resolve(res.data);
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user