2024-08-21 18:36:55 +08:00
|
|
|
const app = getApp()
|
|
|
|
|
2024-08-22 18:30:58 +08:00
|
|
|
import {
|
|
|
|
getAllDeviceInfoByRoomIdRq,
|
|
|
|
getAllPanelInfoByRoomIdRq,
|
2024-08-22 18:38:57 +08:00
|
|
|
callApiByPanelIdRq,
|
2024-08-22 18:30:58 +08:00
|
|
|
callApiByDeviceIdRq,
|
|
|
|
getDeviceInfoRq
|
|
|
|
} from "../../../api/meeting/equipment.js"
|
|
|
|
|
2024-08-21 18:36:55 +08:00
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
IMG_NAME: app.IMG_NAME,
|
2024-08-22 18:30:58 +08:00
|
|
|
roomId: null,
|
|
|
|
roomName: '',
|
|
|
|
lockDoor: null,
|
2024-08-21 18:36:55 +08:00
|
|
|
sceneList: [{
|
|
|
|
name: '茶歇模式',
|
2024-08-22 18:30:58 +08:00
|
|
|
url: app.IMG_NAME + '/profile/static/shanghai_changyang/device/scene/' + 'chaxie1.png',
|
|
|
|
selectUrl: app.IMG_NAME + '/profile/static/shanghai_changyang/device/scene/' + 'chaxie0.png',
|
2024-08-21 19:36:59 +08:00
|
|
|
isSelect: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '开门模式',
|
2024-08-22 18:30:58 +08:00
|
|
|
url: app.IMG_NAME + '/profile/static/shanghai_changyang/device/scene/' + 'kaimen1.png',
|
|
|
|
selectUrl: app.IMG_NAME + '/profile/static/shanghai_changyang/device/scene/' + 'kaimen0.png',
|
2024-08-21 19:36:59 +08:00
|
|
|
isSelect: false
|
|
|
|
},
|
2024-08-22 18:30:58 +08:00
|
|
|
],
|
|
|
|
equipmentList: [], // 设备列表
|
2024-08-21 18:36:55 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad(options) {
|
|
|
|
let _this = this
|
2024-08-22 18:30:58 +08:00
|
|
|
_this.setData({
|
|
|
|
...options
|
|
|
|
})
|
2024-08-21 18:36:55 +08:00
|
|
|
|
2024-08-22 18:30:58 +08:00
|
|
|
// 查询所有设备列表
|
|
|
|
_this.queryDeviceList()
|
|
|
|
// 查询情景列表
|
|
|
|
_this.queryScene()
|
2024-08-21 18:36:55 +08:00
|
|
|
},
|
|
|
|
|
2024-08-22 18:30:58 +08:00
|
|
|
// 查询情景列表
|
|
|
|
queryScene() {
|
2024-08-21 18:36:55 +08:00
|
|
|
let _this = this
|
2024-08-22 18:30:58 +08:00
|
|
|
getAllPanelInfoByRoomIdRq(_this.data.roomId).then(res => {
|
|
|
|
console.log('getAllPanelInfoByRoomIdRq', res);
|
|
|
|
let sceneList = res.data.map(item => {
|
|
|
|
item.isSelect = false
|
|
|
|
item.img = app.IMG_NAME + item.img
|
|
|
|
item.imgOpen = app.IMG_NAME + item.imgOpen
|
|
|
|
return item
|
|
|
|
})
|
|
|
|
_this.setData({
|
|
|
|
sceneList
|
|
|
|
})
|
2024-08-21 18:36:55 +08:00
|
|
|
})
|
2024-08-22 18:30:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// 查询所有设备列表
|
|
|
|
queryDeviceList() {
|
|
|
|
let _this = this
|
|
|
|
getAllDeviceInfoByRoomIdRq(_this.data.roomId).then(res => {
|
|
|
|
console.log('getAllDeviceInfoByRoomIdRq', res);
|
|
|
|
let equipmentList = res.data.map(item => _this.formatDevice(item))
|
|
|
|
equipmentList = equipmentList.filter(item => item.type != '门锁')
|
|
|
|
let lockDoor = res.data.find(item => item.type == '门锁')
|
|
|
|
_this.setData({
|
|
|
|
lockDoor,
|
|
|
|
equipmentList
|
|
|
|
})
|
|
|
|
// 查询设备详情
|
|
|
|
_this.queryDeviceInfo()
|
2024-08-21 18:36:55 +08:00
|
|
|
})
|
|
|
|
},
|
2024-08-22 18:30:58 +08:00
|
|
|
// 格式化设备数据
|
|
|
|
formatDevice(item) {
|
|
|
|
if (item.type == '灯条') {
|
|
|
|
item.status = false
|
|
|
|
item.lampCloseUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'lamp-close.png'
|
|
|
|
item.lampOpenUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'lamp-open.png'
|
|
|
|
item.switchCloseUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'switch-close.png'
|
|
|
|
item.switchOpenUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'switch-open.png'
|
|
|
|
}
|
|
|
|
if (item.type == '雾化玻璃') {
|
|
|
|
item.status = false
|
|
|
|
item.glassImgUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/glass/glass-close.png'
|
|
|
|
item.glassImgActivityUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/glass/glass-open.png'
|
|
|
|
item.glassSwitchImgUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/glass/switch-close.png'
|
|
|
|
item.glassSwitchImgActivityUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/glass/switch-open.png'
|
|
|
|
}
|
|
|
|
if (item.type == '窗帘') {
|
|
|
|
item.subtype = 'curtain'
|
|
|
|
item.status = 'close_cover'
|
|
|
|
item.equipmentCurtainCurtainTopImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/curtainTop.png'
|
|
|
|
item.equipmentCurtainWindowImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/window.png'
|
|
|
|
item.equipmentCurtainCordFabricImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/cordFabric.png'
|
|
|
|
item.curtainSwitchOpenImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/switch-open.png'
|
|
|
|
item.curtainSwitchCloseImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/switch-close.png'
|
|
|
|
item.curtainStopImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/stop-black.png'
|
|
|
|
}
|
|
|
|
if (item.type == '插座') {
|
|
|
|
item.status = false
|
|
|
|
item.socketImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/socket/socket.png'
|
|
|
|
item.socketSwitchCloseImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/socket/switch-close.png'
|
|
|
|
item.socketSwitchOpenImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/socket/switch-open.png'
|
|
|
|
}
|
|
|
|
if (item.type == '调光灯') {
|
|
|
|
item.status = false
|
|
|
|
item.lampCloseUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'lamp-close.png'
|
|
|
|
item.lampOpenUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'lamp-open.png'
|
|
|
|
item.switchCloseUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'switch-close.png'
|
|
|
|
item.switchOpenUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'switch-open.png'
|
|
|
|
}
|
|
|
|
return item
|
|
|
|
},
|
|
|
|
|
|
|
|
// 查询设备详情
|
|
|
|
queryDeviceInfo() {
|
|
|
|
let _this = this
|
|
|
|
let equipmentList = _this.data.equipmentList
|
|
|
|
for (let i = 0; i < equipmentList.length; i++) {
|
|
|
|
let equipmentData = equipmentList[i];
|
|
|
|
if (equipmentData.type == '窗帘' || equipmentData.type == '门锁') {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
//
|
|
|
|
getDeviceInfoRq(equipmentData.id).then(res => {
|
|
|
|
console.log('getDeviceInfoRq', equipmentData.type, res);
|
|
|
|
if (equipmentData.type == '灯条') {
|
|
|
|
equipmentData.status = res.on
|
|
|
|
}
|
|
|
|
if (equipmentData.type == '雾化玻璃') {
|
|
|
|
equipmentData.status = res.on
|
|
|
|
}
|
|
|
|
if (equipmentData.type == '插座') {
|
|
|
|
equipmentData.status = res.on
|
|
|
|
}
|
|
|
|
if (equipmentData.type == '调光灯') {
|
|
|
|
equipmentData.status = res.on
|
|
|
|
}
|
|
|
|
_this.setData({
|
|
|
|
equipmentList
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-08-21 18:36:55 +08:00
|
|
|
|
|
|
|
// 选择情景
|
|
|
|
selectScene(e) {
|
|
|
|
console.log('selectScene', e);
|
|
|
|
let _this = this
|
|
|
|
let obj = e.currentTarget.dataset.obj
|
|
|
|
let sceneList = _this.data.sceneList
|
|
|
|
sceneList = sceneList.map(item => {
|
2024-08-22 18:30:58 +08:00
|
|
|
if (item.id == obj.id) {
|
2024-08-21 18:36:55 +08:00
|
|
|
item.isSelect = !item.isSelect
|
2024-08-22 18:38:57 +08:00
|
|
|
if (item.isSelect) {
|
|
|
|
callApiByPanelIdRq({
|
|
|
|
id: item.id
|
|
|
|
}).then(res => {
|
|
|
|
console.log('callApiByPanelIdRq', res);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-08-21 18:36:55 +08:00
|
|
|
} else {
|
|
|
|
item.isSelect = false
|
|
|
|
}
|
|
|
|
return item
|
|
|
|
})
|
|
|
|
_this.setData({
|
|
|
|
sceneList
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2024-08-22 18:30:58 +08:00
|
|
|
|
|
|
|
// 灯控
|
|
|
|
lampCall(e) {
|
|
|
|
console.log('lampCall', e);
|
|
|
|
let _this = this
|
|
|
|
let id = e.currentTarget.dataset.obj.id
|
|
|
|
let equipmentList = _this.data.equipmentList
|
|
|
|
let equipmentData = equipmentList.find(item => item.id == id)
|
|
|
|
equipmentData.status = !equipmentData.status
|
|
|
|
_this.setData({
|
|
|
|
equipmentList
|
|
|
|
})
|
|
|
|
// 调用设备接口
|
|
|
|
_this.callApiByDevice({
|
|
|
|
"deviceId": equipmentData.id,
|
|
|
|
"actionArg": equipmentData.status,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 窗帘
|
|
|
|
curtainSwitch(e) {
|
|
|
|
console.log('curtainSwitch', e);
|
|
|
|
let _this = this
|
|
|
|
let id = e.currentTarget.dataset.obj.id
|
|
|
|
let status = e.currentTarget.dataset.status
|
|
|
|
let equipmentList = _this.data.equipmentList
|
|
|
|
let equipmentData = equipmentList.find(item => item.id == id)
|
|
|
|
equipmentData.status = status
|
|
|
|
_this.setData({
|
|
|
|
equipmentList
|
|
|
|
})
|
|
|
|
|
|
|
|
// 调用设备接口
|
|
|
|
_this.callApiByDevice({
|
|
|
|
"deviceId": equipmentData.id,
|
|
|
|
"coverType": equipmentData.status,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
// 雾化玻璃
|
|
|
|
glassSwitch(e) {
|
|
|
|
console.log('glassSwitch', e);
|
|
|
|
let _this = this
|
|
|
|
let id = e.currentTarget.dataset.obj.id
|
|
|
|
let equipmentList = _this.data.equipmentList
|
|
|
|
let equipmentData = equipmentList.find(item => item.id == id)
|
|
|
|
equipmentData.status = !equipmentData.status
|
|
|
|
_this.setData({
|
|
|
|
equipmentList
|
|
|
|
})
|
|
|
|
|
|
|
|
// 调用设备接口
|
|
|
|
_this.callApiByDevice({
|
|
|
|
"deviceId": equipmentData.id,
|
|
|
|
"actionArg": equipmentData.status,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
// 调光灯
|
|
|
|
dimmingSwitch(e) {
|
|
|
|
console.log('dimmingSwitch', e);
|
|
|
|
let _this = this
|
|
|
|
let id = e.currentTarget.dataset.obj.id
|
|
|
|
let equipmentList = _this.data.equipmentList
|
|
|
|
let equipmentData = equipmentList.find(item => item.id == id)
|
|
|
|
equipmentData.status = !equipmentData.status
|
|
|
|
_this.setData({
|
|
|
|
equipmentList
|
|
|
|
})
|
|
|
|
|
|
|
|
// 调用设备接口
|
|
|
|
_this.callApiByDevice({
|
|
|
|
"deviceId": equipmentData.id,
|
|
|
|
"actionArg": equipmentData.status,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
// 插座开关
|
|
|
|
socketSwitch(e) {
|
|
|
|
console.log('socketSwitch', e);
|
|
|
|
let _this = this
|
|
|
|
let id = e.currentTarget.dataset.obj.id
|
|
|
|
let equipmentList = _this.data.equipmentList
|
|
|
|
let equipmentData = equipmentList.find(item => item.id == id)
|
|
|
|
equipmentData.status = !equipmentData.status
|
|
|
|
_this.setData({
|
|
|
|
equipmentList
|
|
|
|
})
|
|
|
|
// 调用设备接口
|
|
|
|
_this.callApiByDevice({
|
|
|
|
"deviceId": equipmentData.id,
|
|
|
|
"actionArg": equipmentData.status,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2024-08-22 18:48:42 +08:00
|
|
|
// 开门
|
|
|
|
openLockDoor() {
|
|
|
|
let _this = this
|
|
|
|
let lockDoor = _this.data.lockDoor
|
|
|
|
// 调用设备接口
|
|
|
|
_this.callApiByDevice({
|
|
|
|
"deviceId": lockDoor.id,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2024-08-22 18:30:58 +08:00
|
|
|
// 调用设备接口
|
|
|
|
callApiByDevice(data) {
|
|
|
|
callApiByDeviceIdRq(data).then(res => {
|
|
|
|
console.log('callApiByDeviceIdRq', res);
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2024-08-22 18:59:58 +08:00
|
|
|
// 初始化socket
|
|
|
|
initSocket() {
|
|
|
|
const ws = new WebSocket("ws:///222.184.49.22:8081/websocket-server");
|
|
|
|
ws.onopen = function () {
|
|
|
|
console.log('链接建立成功')
|
|
|
|
};
|
|
|
|
ws.onmessage = function (evt) {
|
|
|
|
console.log(evt.data)
|
|
|
|
};
|
|
|
|
ws.onclose = function () {
|
|
|
|
console.log('链接已经关闭')
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2024-08-21 18:36:55 +08:00
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
onReady() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow() {
|
2024-08-22 18:59:58 +08:00
|
|
|
let _this = this
|
|
|
|
// 初始化socket
|
|
|
|
_this.initSocket()
|
2024-08-21 18:36:55 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户点击右上角分享
|
|
|
|
*/
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|