Files
APP/pages/common/send/index.vue

347 lines
7.4 KiB
Vue
Raw Normal View History

2025-07-05 14:49:26 +08:00
<template>
<view class="container">
<!-- 设备列表 -->
<scroll-view class="device-list" scroll-y>
<view class="device-card" v-for="(item, index) in deviceList" :key="index" @click="toggleSelect(index)">
<!-- 复选框 -->
<view class="checkbox" :class="{ checked: item.checked }">
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
</view>
<!-- 设备信息 -->
<view class="device-content">
<view class="device-header">
<view class="deviceIMG">
2025-07-16 11:33:26 +08:00
<image :src="item.devicePic" mode="" class="IMG"></image>
2025-07-05 14:49:26 +08:00
</view>
<view class="device-name">
2025-07-16 11:33:26 +08:00
<view>设备:{{item.deviceName}}</view>
2025-07-16 16:43:22 +08:00
<view class="ID">
<view class="ID" v-if="item.communicationMode==0">ID:{{item.deviceImei}}
</view>
<view class="ID" v-else>ID:{{item.deviceMac}}</view>
<!-- <view class="onlines" v-if="item.communicationMode==0">在线</view> -->
<view class="unlines" v-if="item.communicationMode==0">离线</view>
<view>电量90%</view>
</view>
2025-07-05 14:49:26 +08:00
</view>
</view>
2025-07-16 11:33:26 +08:00
<view class="" v-if="item.communicationMode==1">
<view class="device-status online">已连接</view>
<view class="device-status unline">未连接</view>
</view>
2025-07-05 14:49:26 +08:00
</view>
</view>
2025-07-24 10:05:17 +08:00
<view class="editInfmation">
2025-07-05 14:49:26 +08:00
<view class="ql-editor">编辑信息</view>
<view class="ql-input">
2025-07-22 17:47:38 +08:00
<textarea placeholder-style="color:rgba(255, 255, 255, 0.4)" placeholder="请输入内容" class="textarea"
v-model="messageToSend" />
2025-07-05 14:49:26 +08:00
</view>
2025-07-22 17:47:38 +08:00
<button class="login-btn" @click="sendTextMessage">发送</button>
2025-07-05 14:49:26 +08:00
</view>
</scroll-view>
2025-07-22 17:47:38 +08:00
<!-- 成功提示弹框 -->
2025-07-24 10:05:17 +08:00
<CustomPopup :show="showPopupFlag" :title="popupTitle" :message="popupMessage" icon="/static/images/sendSucc.png"
:confirm-text="popupConfirmText" :show-cancel="false" @confirm="onPopupConfirm" />
2025-07-05 14:49:26 +08:00
</view>
</template>
<script>
2025-07-24 10:05:17 +08:00
import CustomPopup from '@/components/CustomPopup/CustomPopup.vue'
2025-07-16 11:33:26 +08:00
import {
deviceInfo,
} from '@/api/common/index.js'
2025-07-22 17:47:38 +08:00
import {
deviceSendMessage
} from '@/api/6170/deviceControl.js'
2025-07-05 14:49:26 +08:00
export default {
2025-07-24 10:05:17 +08:00
components: {
CustomPopup
},
2025-07-05 14:49:26 +08:00
data() {
return {
2025-07-16 16:43:22 +08:00
deviceList: [],
2025-07-22 17:47:38 +08:00
messageToSend: '', //发送信息
2025-07-24 10:05:17 +08:00
showPopupFlag: false,
popupTitle: '',
popupMessage: '信息发送成功!',
popupConfirmText: '确认'
2025-07-05 14:49:26 +08:00
}
},
methods: {
toggleSelect(index) {
this.deviceList[index].checked = !this.deviceList[index].checked
this.$forceUpdate()
},
2025-07-16 11:33:26 +08:00
// 获取设备列表
getData(deviceType) {
this.loading = true;
let data = {
pageNum: 1,
2025-07-16 16:43:22 +08:00
pageSize: 20,
deviceType: deviceType
2025-07-16 11:33:26 +08:00
}
deviceInfo(data).then((res) => {
if (res.code == 200) {
const newDevices = res.rows.map(device => ({
...device,
showConfirm: false,
2025-07-16 16:43:22 +08:00
checked: false
2025-07-16 11:33:26 +08:00
}));
this.total = res.total;
2025-07-16 16:43:22 +08:00
this.deviceList = newDevices
2025-07-16 11:33:26 +08:00
}
}).finally(() => {
this.loading = false;
});
},
2025-07-22 17:47:38 +08:00
// 发送文本消息
sendTextMessage() {
const selectedDevices = this.deviceList.filter(item => item.checked)
const deviceIds = selectedDevices.map(item => item.id);
2025-07-24 10:05:17 +08:00
if (selectedDevices.length === 0) {
uni.showToast({
title: '请选择一个设备',
icon: 'none'
});
return;
}
2025-07-22 17:47:38 +08:00
if (!this.messageToSend) {
uni.showToast({
title: '请输入要发送的内容',
icon: 'none'
});
return;
}
let data = {
sendMsg: this.messageToSend,
deviceIds: deviceIds
}
deviceSendMessage(data).then((res) => {
if (res.code == 200) {
2025-07-24 10:05:17 +08:00
this.showPopupFlag = true
2025-07-22 17:47:38 +08:00
} else {
uni.showToast({
title: res.msg,
icon: 'none'
});
}
})
},
2025-07-24 10:05:17 +08:00
onPopupConfirm() {
this.showPopupFlag = false
uni.navigateBack()
console.log('用户点击了确定')
// 处理确认逻辑
},
2025-07-16 11:33:26 +08:00
},
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', {})
},
2025-07-05 14:49:26 +08:00
}
</script>
<style scoped>
.container {
min-height: 100vh;
background-color: rgb(18, 18, 18);
2025-07-24 10:05:17 +08:00
box-sizing: border-box;
overflow-x: hidden;
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
}
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
.device-list {
flex: 1;
padding: 0 20rpx;
2025-07-24 10:05:17 +08:00
2025-07-05 14:49:26 +08:00
}
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
.device-card {
position: relative;
display: flex;
align-items: center;
2025-07-16 16:43:22 +08:00
width: 95%;
2025-07-05 14:49:26 +08:00
}
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
.checkbox {
width: 40rpx;
height: 40rpx;
border: 2rpx solid rgba(255, 255, 255, 0.5);
margin-right: 20rpx;
border-radius: 4rpx;
display: flex;
align-items: center;
justify-content: center;
}
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
.checkbox.checked {
background-color: rgb(187, 230, 0);
border-color: rgb(187, 230, 0);
}
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
.device-content {
background-color: rgb(26, 26, 26);
border-radius: 16rpx;
position: relative;
/* display: flex; */
align-items: center;
padding: 20rpx;
2025-07-16 16:43:22 +08:00
width: 95%;
2025-07-05 14:49:26 +08:00
}
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
.device-header {
display: flex;
align-items: center;
margin-bottom: 15rpx;
}
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
.device-name {
font-size: 32rpx;
color: rgba(255, 255, 255, 0.87);
2025-07-16 16:43:22 +08:00
margin-left: 12rpx;
2025-07-05 14:49:26 +08:00
line-height: 50rpx;
2025-07-16 16:43:22 +08:00
width: 83%;
white-space: nowrap;
2025-07-05 14:49:26 +08:00
}
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
.ID {
color: rgba(255, 255, 255, 0.6);
font-size: 26rpx;
2025-07-16 16:43:22 +08:00
display: flex;
justify-content: space-between;
position: relative;
2025-07-05 14:49:26 +08:00
}
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
.device-status {
width: 122rpx;
height: 52rpx;
font-size: 26rpx;
border-radius: 0px 8px 0px 8px;
background-color: rgb(42, 42, 42);
position: absolute;
top: 0rpx;
right: 0rpx;
text-align: center;
line-height: 52rpx;
}
.online {
color: rgb(187, 230, 0);
}
2025-07-16 16:43:22 +08:00
.unline {
2025-07-16 11:33:26 +08:00
color: rgba(255, 255, 255, 0.4);
}
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
.device-info {
display: flex;
justify-content: space-evenly;
2025-07-16 16:43:22 +08:00
font-size: 26rpx;
2025-07-05 14:49:26 +08:00
color: rgba(255, 255, 255, 0.87);
padding-top: 10rpx;
2025-07-16 16:43:22 +08:00
position: relative;
2025-07-05 14:49:26 +08:00
}
.deviceIMG {
width: 100rpx;
height: 100rpx;
border-radius: 16rpx;
position: relative;
background-color: rgba(42, 42, 42, 0.6);
display: flex;
align-items: center;
}
.IMG {
width: 68rpx;
height: 50rpx;
margin-left: 17%;
}
2025-07-16 16:43:22 +08:00
.onlines {
position: relative;
}
2025-07-05 14:49:26 +08:00
.onlines::before {
content: '';
position: absolute;
width: 15rpx;
height: 15rpx;
background: rgb(0, 171, 103);
border-radius: 50%;
2025-07-16 16:43:22 +08:00
top: 20rpx;
left: -20rpx
}
.unlines {
position: relative;
}
.unlines::before {
content: '';
position: absolute;
width: 15rpx;
height: 15rpx;
background: rgba(255, 255, 255, 0.4);
border-radius: 50%;
top: 20rpx;
left: -20rpx
2025-07-05 14:49:26 +08:00
}
.line {
width: 2rpx;
height: 24rpx;
background: linear-gradient(90deg,
rgba(0, 0, 0, 0) 0%,
rgb(255, 255, 255) 50%,
rgba(255, 255, 255, 0) 100%);
margin-top: 12rpx;
}
.ql-editor {
color: rgba(255, 255, 255, 0.6);
2025-07-16 16:43:22 +08:00
font-size: 30rpx;
2025-07-05 14:49:26 +08:00
}
.ql-input {
2025-07-16 16:43:22 +08:00
width: 95.9%;
2025-07-05 14:49:26 +08:00
height: 200rpx;
margin-top: 30rpx;
box-sizing: border-box;
padding: 30rpx;
2025-07-16 16:43:22 +08:00
border-radius: 16rpx;
2025-07-05 14:49:26 +08:00
background: rgb(26, 26, 26);
}
2025-07-16 16:43:22 +08:00
.textarea {
2025-07-05 14:49:26 +08:00
color: rgba(255, 255, 255, 0.8);
2025-07-24 10:05:17 +08:00
background: rgba(42, 42, 42, 1);
border-radius: 16rpx;
padding: 10rpx;
height: 150rpx;
}
.editInfmation {
padding: 20rpx;
border-radius: 40rpx 40rpx 0px 0px;
background: rgba(28, 28, 28, 1);
position: fixed;
bottom: 50rpx;
box-sizing: border-box;
2025-07-05 14:49:26 +08:00
}
2025-07-16 16:43:22 +08:00
2025-07-05 14:49:26 +08:00
.login-btn {
2025-07-16 16:43:22 +08:00
margin-top: 30rpx;
2025-07-05 14:49:26 +08:00
background-color: rgb(187, 230, 0);
color: rgb(35, 35, 35);
border-radius: 50rpx;
2025-07-16 16:43:22 +08:00
width: 90%;
2025-07-22 17:47:38 +08:00
}
2025-07-05 14:49:26 +08:00
</style>