重构第一版 智控助手小程序
This commit is contained in:
629
pages/basics/FacialDeviceBinding/FacialDeviceBinding.js
Normal file
629
pages/basics/FacialDeviceBinding/FacialDeviceBinding.js
Normal file
@@ -0,0 +1,629 @@
|
||||
// pages/FacialDeviceBinding/FacialDeviceBinding.js
|
||||
// 人脸设备绑定页面逻辑
|
||||
const app = getApp()
|
||||
// 导入请求中心
|
||||
import {
|
||||
GetHostsInfo,
|
||||
GetFaceSN,
|
||||
GetFaceCode,
|
||||
CheckFaceSNAutho,
|
||||
CheckFaceSN,
|
||||
OpenDoorTest
|
||||
} from '../../../lib/RequestingCenter';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
autho:null,
|
||||
RoomIndex: 0, // 当前选中房间索引
|
||||
Hotelinfo: null, // 酒店信息
|
||||
HostsData: null, // 原始设备数据
|
||||
HostsDataFilters: [], // 过滤后的设备数据
|
||||
onlineFaceDevices: 0, // 在线人脸设备数量
|
||||
inputValue: "", // 搜索输入值
|
||||
scrollHeight: 0, // 滚动区域高度
|
||||
toView: '', // 滚动位置
|
||||
modal: '', // 弹窗状态
|
||||
selHosts: null, // 当前选中的房间
|
||||
faceSNCode: '', // 人脸设备SN输入
|
||||
bdHosts: [], // 已绑定的主机列表
|
||||
Help: false, // 帮助状态
|
||||
islogs: false, // 操作记录状态
|
||||
showinfo: 0, // 显示信息类型
|
||||
faceAddress: '', // 人脸设备地址
|
||||
input: 0, // 输入类型
|
||||
ISLoopDebugging: 0, // 回路调试状态
|
||||
message: [], // 弹窗信息
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
|
||||
onLoad:async function(options) {
|
||||
|
||||
if (!options.HotelId || app.globalData.autho == null) {
|
||||
app.toast(2, "无酒店信息~")
|
||||
return;
|
||||
}
|
||||
|
||||
this.setData({
|
||||
autho: app.globalData.autho ,
|
||||
HotelId:options.HotelId
|
||||
})
|
||||
try {
|
||||
this.data.autho.forEach((element, index) => {
|
||||
element.Hotels.forEach((elements, indexs) => {
|
||||
if (elements.HotelId == options.HotelId) {
|
||||
this.setData({
|
||||
Hotelinfo: elements
|
||||
})
|
||||
throw new Error();
|
||||
}
|
||||
})
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("已经找到,无需循环~")
|
||||
}
|
||||
// 计算滚动区域高度
|
||||
this.calcScrollHeight();
|
||||
// 获取人脸设备数据
|
||||
this.GetHostsInfo();
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
// 页面显示时重新获取数据
|
||||
this.GetHostsInfo();
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
this.GetHostsInfo();
|
||||
wx.stopPullDownRefresh();
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
},
|
||||
|
||||
// 返回上一页
|
||||
back: function () {
|
||||
wx.navigateBack({
|
||||
delta: 1
|
||||
});
|
||||
},
|
||||
|
||||
// 计算滚动区域高度
|
||||
calcScrollHeight: function () {
|
||||
|
||||
// 1. 拿到屏幕可用高度(px)
|
||||
const sys = wx.getSystemInfoSync();
|
||||
const screenHeight = sys.windowHeight; // px
|
||||
|
||||
// 2. 拿到 scroll-view 的 top(px)
|
||||
wx.createSelectorQuery()
|
||||
.in(this)
|
||||
.select('#myScroll')
|
||||
.boundingClientRect(rect => {
|
||||
if (rect) {
|
||||
const topPx = rect.top; // px
|
||||
const bottomPx = 10 / 2; // 10rpx → 5px(2倍屏)
|
||||
const heightPx = screenHeight - topPx - bottomPx;
|
||||
|
||||
// 3. 转 rpx 并写入
|
||||
this.setData({
|
||||
scrollHeight: heightPx * 2 // px→rpx
|
||||
});
|
||||
}
|
||||
})
|
||||
.exec();
|
||||
|
||||
|
||||
|
||||
},
|
||||
|
||||
// 获取人脸设备数据
|
||||
GetHostsInfo: function () {
|
||||
const that = this;
|
||||
// 显示加载提示
|
||||
wx.showLoading({
|
||||
title: '加载中...',
|
||||
});
|
||||
|
||||
// 调用获取主机信息接口
|
||||
GetHostsInfo({
|
||||
HotelID: that.data.HotelId
|
||||
}).then(res => {
|
||||
// 隐藏加载提示
|
||||
wx.hideLoading();
|
||||
|
||||
if (res.Status == 200) {
|
||||
// 处理数据
|
||||
const HostsData = res.Data;
|
||||
const HostsDataFilters = HostsData;
|
||||
|
||||
// 统计在线人脸设备数量
|
||||
let onlineFaceDevices = 0;
|
||||
for (let i = 0; i < HostsDataFilters.length; i++) {
|
||||
if (HostsDataFilters[i].FaceStatus) {
|
||||
onlineFaceDevices++;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
that.setData({
|
||||
HostsData: HostsData,
|
||||
HostsDataFilters: HostsDataFilters,
|
||||
onlineFaceDevices: onlineFaceDevices,
|
||||
RoomIndex: 0
|
||||
});
|
||||
|
||||
// 获取位置信息
|
||||
that.GetLOC();
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '获取数据失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
}).catch(err => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '网络异常',
|
||||
icon: 'none'
|
||||
});
|
||||
console.error('获取主机信息失败:', err);
|
||||
});
|
||||
},
|
||||
|
||||
// 获取位置信息
|
||||
GetLOC: function () {
|
||||
const that = this;
|
||||
// 调用微信获取位置接口
|
||||
wx.getFuzzyLocation({
|
||||
type: 'wgs84',
|
||||
success(res) {
|
||||
const latitude = res.latitude;
|
||||
const longitude = res.longitude;
|
||||
const address = `${latitude},${longitude}`;
|
||||
that.setData({
|
||||
faceAddress: address
|
||||
});
|
||||
},
|
||||
fail(err) {
|
||||
console.error('获取位置信息失败:', err);
|
||||
// 位置信息获取失败不影响主流程
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 搜索输入
|
||||
inputSearchForHotels: function (e) {
|
||||
this.setData({
|
||||
inputValue: e.detail.value
|
||||
});
|
||||
},
|
||||
|
||||
// 搜索房间
|
||||
SearchForHotels: function () {
|
||||
const that = this;
|
||||
const inputValue = that.data.inputValue;
|
||||
const HostsData = that.data.HostsData;
|
||||
|
||||
if (inputValue === '') {
|
||||
// 搜索条件为空,显示所有数据
|
||||
that.setData({
|
||||
HostsDataFilters: HostsData
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据房号搜索
|
||||
const filters = HostsData.filter(item => {
|
||||
return item.RoomNumber.indexOf(inputValue) !== -1;
|
||||
});
|
||||
|
||||
that.setData({
|
||||
HostsDataFilters: filters
|
||||
});
|
||||
},
|
||||
|
||||
// 刷新房间数据
|
||||
RefreshTheRoom: function () {
|
||||
this.GetHostsInfo();
|
||||
},
|
||||
|
||||
// 跳转到人脸设备详情或直接扫码绑定
|
||||
goFaceDetail: function (e) {
|
||||
const index = e.currentTarget.id.split('-')[1];
|
||||
const HostsDataFilters = this.data.HostsDataFilters;
|
||||
const selHosts = HostsDataFilters[index];
|
||||
selHosts.index = index;
|
||||
|
||||
this.setData({
|
||||
RoomIndex: index,
|
||||
selHosts: selHosts
|
||||
});
|
||||
|
||||
// 判断条件:离线且未绑定
|
||||
if (!selHosts.FaceStatus && (!selHosts.FaceSN || selHosts.FaceSN === '')) {
|
||||
|
||||
// 直接调用摄像头扫码绑定
|
||||
this.GetFaceCode();
|
||||
} else {
|
||||
// 设置消息数据
|
||||
this.setData({
|
||||
message: [selHosts.FaceSN, selHosts.RoomNumber],
|
||||
// 显示设备详情
|
||||
modal: -1
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 关闭弹窗
|
||||
GetHide: function () {
|
||||
this.setData({
|
||||
modal: ''
|
||||
});
|
||||
},
|
||||
|
||||
// 反馈错误
|
||||
ErrorInfo: function () {
|
||||
wx.showToast({
|
||||
title: '反馈功能开发中',
|
||||
icon: 'none'
|
||||
});
|
||||
},
|
||||
|
||||
// 人脸设备解绑
|
||||
JbSn: function (params) {
|
||||
let jbjd = null;
|
||||
let faceSN = null;
|
||||
let that = this;
|
||||
let index = -1;
|
||||
|
||||
// 检查是否从SN已绑定弹窗点击解绑按钮
|
||||
if (typeof params.currentTarget.dataset['index'] != 'undefined') {
|
||||
faceSN = this.data.faceSNCode;
|
||||
index = params.currentTarget.dataset['index'];
|
||||
// 解绑的房间
|
||||
jbjd = this.data.bdHosts[index];
|
||||
} else {
|
||||
jbjd = this.data.selHosts;
|
||||
faceSN = this.data.selHosts.FaceSN;
|
||||
}
|
||||
|
||||
wx.showModal({
|
||||
title: '解绑确认',
|
||||
content: `确定要解除${jbjd.RoomNumber}房间的人脸设备绑定吗?`,
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
// 调用解绑接口
|
||||
GetFaceSN({
|
||||
faceSN: faceSN,
|
||||
roomID: jbjd.Id,
|
||||
roomNumber: jbjd.RoomNumber,
|
||||
faceAddress: that.data.faceAddress,
|
||||
HotelID: jbjd.HotelID,
|
||||
isjb: true
|
||||
}).then(res => {
|
||||
if (res.Status == 200) {
|
||||
wx.showToast({
|
||||
title: '解绑成功',
|
||||
icon: 'success'
|
||||
});
|
||||
|
||||
// 如果是从SN已绑定弹窗解绑,需要更新bdHosts数据
|
||||
if (index > -1) {
|
||||
let databdHosts = that.data.bdHosts;
|
||||
databdHosts.splice(index, 1);
|
||||
that.setData({
|
||||
bdHosts: databdHosts
|
||||
});
|
||||
|
||||
// 如果bdHosts为空,继续执行绑定
|
||||
if (databdHosts.length <= 0) {
|
||||
that.GetFaceSNend();
|
||||
}
|
||||
}
|
||||
|
||||
// 重新获取数据
|
||||
that.GetHostsInfo();
|
||||
// 关闭弹窗
|
||||
that.GetHide();
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '解绑失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
}).catch(err => {
|
||||
wx.showToast({
|
||||
title: '网络异常',
|
||||
icon: 'none'
|
||||
});
|
||||
console.error('解绑失败:', err);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 扫码绑定人脸设备
|
||||
GetFaceCode: function () {
|
||||
const that = this;
|
||||
|
||||
// 检查权限
|
||||
if (!that.CheckFaceSNAutho()) {
|
||||
wx.showToast({
|
||||
title: '您没有权限绑定人脸设备',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用微信扫码接口
|
||||
wx.scanCode({
|
||||
success: (res) => {
|
||||
const code = res.result;
|
||||
that.setData({
|
||||
faceSNCode: code
|
||||
});
|
||||
debugger
|
||||
that.GetFaceSNOK();
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('扫码失败:', err);
|
||||
wx.showToast({
|
||||
title: '扫码失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 手动输入人脸设备SN
|
||||
ShowInputsn: function () {
|
||||
// 检查权限
|
||||
if (!this.CheckFaceSNAutho()) {
|
||||
wx.showToast({
|
||||
title: '您没有权限绑定人脸设备',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.setData({
|
||||
modal: 'showBindConfirm'
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
GetFaceSNOK:function(){
|
||||
let that = this;
|
||||
if (!this.CheckFaceMAC(that.data.faceSNCode)) {
|
||||
this.setData({
|
||||
modal: 520
|
||||
})
|
||||
return;
|
||||
};
|
||||
if (that.data.selHosts.FaceSN == that.data.faceSNCode) {
|
||||
app.toast(2, "条码一致,无需更改~")
|
||||
return;
|
||||
}
|
||||
this.CheckFaceMACWL()
|
||||
},
|
||||
CheckFaceMACWL(){
|
||||
let that = this;
|
||||
CheckFaceSN({faceSN:this.data.faceSNCode}).then(
|
||||
res => {
|
||||
if (res.Status == 200) {
|
||||
if(res.Data<=0){
|
||||
that.setData({
|
||||
modal:-521,
|
||||
})
|
||||
}else{
|
||||
let remove = [];
|
||||
let bdHosts = res.Data;
|
||||
try {
|
||||
//记录已经分配酒店但是未分配房间 且酒店是当前酒店 那就判断为没有绑定
|
||||
that.data.autho.forEach((element, index) => {
|
||||
element.Hotels.forEach((elements, indexs) => {
|
||||
for (let index = 0; index < bdHosts.length; index++) {
|
||||
if (elements.HotelId == bdHosts[index].HotelID) {
|
||||
if(bdHosts[index].HotelID == that.data.Hotelinfo.HotelId && bdHosts[index].Id==0){
|
||||
remove.push(index);
|
||||
}
|
||||
elements.Auth.forEach (Auth=>{
|
||||
if(Auth.AuthorityId == 21 && Auth.AuthotypeId == 3){
|
||||
//有权限
|
||||
bdHosts[index].qx = 0;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
remove.forEach (x=>{
|
||||
bdHosts.splice(x, 1);
|
||||
})
|
||||
let modalval = -200;
|
||||
if(bdHosts.length<=0){
|
||||
modalval = -521;
|
||||
}
|
||||
that.setData({
|
||||
modal:modalval,
|
||||
bdHosts:bdHosts
|
||||
})
|
||||
// app.toast(2, "已经被绑定")
|
||||
}
|
||||
}else{
|
||||
app.toast(2, "网络繁忙")
|
||||
}
|
||||
},
|
||||
err => {
|
||||
console.log(err)
|
||||
app.toast(2, "网络繁忙")
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
app.toast(2, "网络繁忙")
|
||||
});
|
||||
},
|
||||
CheckFaceMAC:function(vlues){
|
||||
return true;
|
||||
console.log(vlues.length != 16)
|
||||
return vlues.length == 16;
|
||||
},
|
||||
// 完成人脸设备绑定
|
||||
GetFaceSNend: function () {
|
||||
const that = this;
|
||||
const selHosts = that.data.selHosts;
|
||||
const faceSNCode = that.data.faceSNCode;
|
||||
|
||||
// 显示加载提示
|
||||
wx.showLoading({
|
||||
title: '绑定中...',
|
||||
});
|
||||
|
||||
// 调用绑定接口
|
||||
GetFaceSN({
|
||||
faceSN: faceSNCode,
|
||||
roomID: selHosts.Id,
|
||||
roomNumber: selHosts.RoomNumber,
|
||||
faceAddress: that.data.faceAddress,
|
||||
HotelID: selHosts.HotelID,
|
||||
isjb: false
|
||||
}).then(res => {
|
||||
// 隐藏加载提示
|
||||
wx.hideLoading();
|
||||
|
||||
if (res.Status == 200) {
|
||||
wx.showToast({
|
||||
title: '绑定成功',
|
||||
icon: 'success'
|
||||
});
|
||||
// 重新获取数据
|
||||
that.GetHostsInfo();
|
||||
// 关闭弹窗
|
||||
that.GetHide();
|
||||
} else if (res.Status == 400) {
|
||||
// 设备已被绑定
|
||||
that.setData({
|
||||
bdHosts: res.Data,
|
||||
code: faceSNCode,
|
||||
modal: -200
|
||||
});
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '绑定失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
}).catch(err => {
|
||||
// 隐藏加载提示
|
||||
wx.hideLoading();
|
||||
|
||||
wx.showToast({
|
||||
title: '网络异常',
|
||||
icon: 'none'
|
||||
});
|
||||
console.error('绑定失败:', err);
|
||||
});
|
||||
},
|
||||
|
||||
// 检查人脸设备绑定权限
|
||||
CheckFaceSNAutho: function () {
|
||||
let res = false;
|
||||
this.data.Hotelinfo.Auth.forEach(x => {
|
||||
if (x.AuthorityId == 21 && x.AuthotypeId == 3) {
|
||||
res = true;
|
||||
}
|
||||
});
|
||||
return res;
|
||||
},
|
||||
|
||||
// 设置操作
|
||||
testinfo: function (e) {
|
||||
var jbjd = this.data.selHosts;
|
||||
wx.navigateTo({
|
||||
url: '/pages/test/test?Hotelinfo=' + e.currentTarget.id + '&RoomID=' + jbjd.Id + '&faceadd=' + this.data.faceAddress
|
||||
});
|
||||
},
|
||||
|
||||
// 开门操作
|
||||
OpenDoor: function (e) {
|
||||
const sn = e.currentTarget.id.split('_');
|
||||
OpenDoorTest({faceSN:sn[2],isjb:true}).then(
|
||||
res=>{
|
||||
if (res.Status == 200) {
|
||||
wx.showToast({
|
||||
title: res.Message,
|
||||
icon: 'none'
|
||||
})
|
||||
}else{
|
||||
wx.showToast({
|
||||
title: res.Message,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},rej=>{
|
||||
wx.showToast({
|
||||
title: "网络繁忙",
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
// 切换显示信息
|
||||
GetshowinfoClick: function (e) {
|
||||
const index = e.currentTarget.dataset.index;
|
||||
this.setData({
|
||||
showinfo: index
|
||||
});
|
||||
},
|
||||
|
||||
// 切换显示信息(刷新)
|
||||
GetshowinfoClick1: function () {
|
||||
this.GetHostsInfo();
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user