This commit is contained in:
微微一笑
2025-07-16 11:35:14 +08:00
4 changed files with 85 additions and 28 deletions

View File

@ -13,8 +13,7 @@
</view>
</view>
</scroll-view>
<view class="sendFlex">
<view class="sendFlex" v-if="activeTab && activeTab.id !== ''">
<view class="callpolice">报警</view>
<view class="Sendmessage" @click="location">位置</view>
<view class="Sendmessage" @click="handleSend">发送信息</view>
@ -46,7 +45,6 @@
<view class="device-status online">已连接</view>
<view class="device-status unline">未连接</view>
</view>
</view>
<image src="/static/images/cires.png" class="circle"></image>
</uni-swipe-action-item>
@ -177,7 +175,7 @@
getTab() {
deviceTypeList({}).then((res) => {
if (res.code == 200) {
console.log("deviceTypeList=" + JSON.stringify(res.data));
//console.log("deviceTypeList=" + JSON.stringify(res.data));
this.tabs = [{
id: '',
name: '全部设备',
@ -353,8 +351,19 @@
},
// 发生短信
handleSend() {
const currentTab = this.tabs[this.activeTab];
const deviceType = currentTab.id || 'all';
console.log(`跳转到发送信息页面\n当前设备类型: ${deviceType}\n设备类型名称: ${currentTab.typeName}`);
uni.navigateTo({
url: '/pages/common/send/index'
url: '/pages/common/send/index',
events: {
ack: function(data) {}
},
success: (res) => {
res.eventChannel.emit('deviceSend', {
data: deviceType
});
}
})
},
// 位置
@ -402,13 +411,21 @@
onIntall() {
this.page = 1;
this.finished = false;
this.getData(); // 重新加载第一页数据
this.getData(this.deviceType); // 重新加载第一页数据
},
},
onShow() {
onLoad() {
this.getTab()
this.onIntall()
}
// 绑定页面做了监听,新增成功,刷新页面
uni.$on('refreshDeviceList', () => {
this.getTab() // 刷新数据
});
},
beforeDestroy() {
// 组件销毁前移除监听器
uni.$off('refreshDeviceList');
},
}
</script>

View File

@ -146,6 +146,7 @@
tenantId: '894078' //租户ID
})
if (res.code == 200) {
console.log(res,'ressss');
uni.hideLoading()
uni.setStorageSync('token', res.data.access_token) // 缓存token
uni.setStorageSync('clientID', res.data.client_id) // 缓存token

View File

@ -35,18 +35,21 @@
return {
deviceId: '',
isConnecting: false, // 是否正在连接
isConnected: false ,// 是否连接成功
isConnectNo:false,
isSuccess:false
isConnected: false, // 是否连接成功
isConnectNo: false,
isSuccess: false
}
},
methods: {
async handleConnect() {
if (this.isConnecting) {
// 绑定成功,确认按钮跳转到首页并通知刷新数据
uni.$emit('refreshDeviceList'); // 发出刷新事件
// 绑定成功,确认按钮跳转到首页
uni.switchTab({
url: '/pages/common/index/index'
})
} else {
// 开始连接逻辑
uni.showLoading({
@ -54,7 +57,7 @@
title: '加载中....'
})
this.isConnecting = true;
this.isConnectNo=true
this.isConnectNo = true
try {
// 调用绑定设备接口
const res = await deviceBind({
@ -62,10 +65,10 @@
deviceMac: '',
communicationMode: '0', //0是4g,1是蓝牙
})
console.log(this.deviceId,'deerer ere');
console.log(this.deviceId, 'deerer ere');
if (res.code == 200) {
this.isConnectNo=false
this.isSuccess =true
this.isConnectNo = false
this.isSuccess = true
uni.hideLoading()
uni.showToast({
title: res.data,
@ -73,7 +76,7 @@
});
this.isConnecting = true;
} else {
this.isConnectNo=false
this.isConnectNo = false
uni.showToast({
title: res.msg,
});

View File

@ -11,14 +11,17 @@
<view class="device-content">
<view class="device-header">
<view class="deviceIMG">
<image src="/static/images/device.png" mode="" class="IMG"></image>
<image :src="item.devicePic" mode="" class="IMG"></image>
</view>
<view class="device-name">
<view>设备:001-00</view>
<view class="ID">ID:{{ item.id }}</view>
<view>设备:{{item.deviceName}}</view>
<view class="ID">ID:{{ item.deviceImei }}</view>
</view>
</view>
<view class="device-status online">已连接</view>
<view class="" v-if="item.communicationMode==1">
<view class="device-status online">已连接</view>
<view class="device-status unline">未连接</view>
</view>
<view class="device-info">
<text class="onlines">在线</text>
<text class="line"></text>
@ -39,14 +42,13 @@
</template>
<script>
import {
deviceInfo,
} from '@/api/common/index.js'
export default {
data() {
return {
deviceList: Array(6).fill().map((_, i) => ({
id: `1321615${i}`,
checked: false,
showConfirm: false
})),
deviceList:[],
}
},
methods: {
@ -61,8 +63,40 @@
title: `已发送到${selectedDevices.length}台设备`,
icon: 'success'
})
}
}
},
// 获取设备列表
getData(deviceType) {
this.loading = true;
let data = {
pageNum: 1,
pageSize: 50,
deviceType:deviceType
}
deviceInfo(data).then((res) => {
if (res.code == 200) {
const newDevices = res.rows.map(device => ({
...device,
showConfirm: false,
checked:false
}));
this.total = res.total;
this.deviceList =newDevices
}
}).finally(() => {
this.loading = false;
});
},
},
onLoad(options) {
const eventChannel = this.getOpenerEventChannel();
// 监听 'deviceSend' 事件,获取传过来的数据
eventChannel.on('deviceSend', (data) => {
console.log('Received detail data:', data);
this.getData(data.data)
});
// 如果需要向调用页面返回数据,可以触发 'ack' 事件
eventChannel.emit('ack', {})
},
}
</script>
@ -146,7 +180,9 @@
.online {
color: rgb(187, 230, 0);
}
.unline {
color: rgba(255, 255, 255, 0.4);
}
.device-info {
display: flex;
justify-content: space-evenly;