From 1668bfbc0d57a8370221fe62790a4bb82dc21041 Mon Sep 17 00:00:00 2001 From: xiaoheiiskinder <11674173+xiaohei102908@user.noreply.gitee.com> Date: Tue, 7 Nov 2023 11:11:32 +0800 Subject: [PATCH] =?UTF-8?q?1107=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86WiFi?= =?UTF-8?q?=E4=BA=BA=E8=84=B8=E9=94=81=E6=B3=A8=E5=86=8C=E5=80=92=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/index.html | 2 +- src/api/allFun.js | 18 +- src/store/index.js | 4 +- src/views/doorLock.vue | 1533 ++++++++++++++++++++++++------------------------ 4 files changed, 798 insertions(+), 759 deletions(-) diff --git a/dist/index.html b/dist/index.html index d205770..b543887 100644 --- a/dist/index.html +++ b/dist/index.html @@ -1 +1 @@ -智慧公寓管理系统
\ No newline at end of file +智慧公寓管理系统
\ No newline at end of file diff --git a/src/api/allFun.js b/src/api/allFun.js index 2de8e88..d7c4a70 100644 --- a/src/api/allFun.js +++ b/src/api/allFun.js @@ -169,7 +169,23 @@ export default class RequestSet { httpPost(str, api.registerDeviceAll).then(res => { callback(res) }); - } else { + } else if(data.manufactureId == 1241){ + let str = { + data: { + deviceNum: data.deviceNum, + imei:data.imei, + order: 5101, + platformId: data.platformId, + manufactureId: data.manufactureId, + }, + code: "/lwj/registerDevice", + enterpriseId: data.enterpriseId, + key: data.deviceNum + } + httpPost(str, api.sendCommand).then(res => { + callback(res) + }); + } else { var str = { data: { deviceNum: data.deviceNum, diff --git a/src/store/index.js b/src/store/index.js index b807ac4..fc15114 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -19,8 +19,8 @@ import moment from "moment" const store = new Vuex.Store({ state: { treeList:[], - // tenantId: '1200', - tenantId: '100', + tenantId: '1200', + // tenantId: '100', selectoption: [], tagsList: [], cardList: [], diff --git a/src/views/doorLock.vue b/src/views/doorLock.vue index ffc2bdb..ab95972 100644 --- a/src/views/doorLock.vue +++ b/src/views/doorLock.vue @@ -374,13 +374,19 @@ -
+
+ + + + + + @@ -2787,7 +2793,7 @@ export default { if (this.checkNodeId1 == '') { this.$message.error("请选择房间"); } else { - if (this.form.manufacturer == 101 || this.form.manufacturer == 1201) { + if (this.form.manufacturer == 101 || this.form.manufacturer == 1201 || this.form.manufacturer == 1241) { if ( this.form.deviceNum == "" || this.form.v == "" || @@ -2815,798 +2821,816 @@ export default { if (res.success) { this.$message.success("绑定成功"); this.editVisible = false - this.getdevice(); + if (this.form.manufacturer == 1241) { + let data3 = { + code: "lwj/registerSupperAdmin", + data:{ + lockerId: this.form.deviceNum, + lockerSuperAdminId: this.form.TockerSuperAdminId, + bluetoothMac: this.form.LockMac + } + } + httpPost(data3, this.$api.sendCommand).then(res => { + console.log(res); + if(res.success) { + this.$message.success('注册成功') + }else{ + this.$message.error('注册失败,请稍后再试') + } + }) + } } + this.getdevice(); }).catch((error) => { this.$message.error(`绑定失败`); }); - this.$message.success(res.data.msg); - this.editVisible = false; - this.getdevice(); - } else { - this.$message.error(callback.data.msg) - } - }) - } - } else if (this.form.manufacturer == 201 || this.form.manufacturer == 221) { - var data = { - lockerId: this.form.lockerId, - imei: this.form.imei, - customerCode: this.form.customerCode, - lockerSuperAdminId: this.form.lockerSuperAdminId, - authKey: this.form.authKey, - type: this.form.type, - manufactureId: this.form.manufacturer, - enterpriseId: this.userInfo.enterpriseId, - order: 5101, - }; - RequestSet.RegisterDevice(data, (callback) => { - if (callback.data.success && callback.success) { - var data = [{ - siteId: this.checkNodeId1, - deviceId: callback.data.id, - }]; - httpPost(data, this.$api.bindDeviceSite) - .then((res) => { - if (res.success) { - this.$message.success("绑定成功"); - - this.editVisible = falsethis.editVisible = false - this.getdevice(); - } - }) - .catch((error) => { - this.$message.error(`绑定失败`); - }); - this.$message.success("添加成功"); - this.editVisible = false; - this.getdevice(); - } else { - this.$message.error(callback.data.msg); - } - }) - } else if (this.form.manufacturer == 701) { - var data = { - deviceNum: this.form.deviceNum, - validateCode: this.form.validateCode, - manufactureId: this.form.manufacturer, - enterpriseId: this.userInfo.enterpriseId, - } - RequestSet.RegisterDevice(data, (callback) => { - if (callback.data.success && callback.success) { - var data = [{ - siteId: this.checkNodeId1, - deviceId: callback.data.id, - }]; - httpPost(data, this.$api.bindDeviceSite) - .then((res) => { - if (res.success) { - this.$message.success("绑定成功"); - this.editVisible = false - this.getdevice(); - } - }) - .catch((error) => { - this.$message.error(`绑定失败`); - }); - this.$message.success("添加成功"); - this.editVisible = false; - this.getdevice(); - } else { - this.$message.error(callback.data.msg); - } - }) - } else if (this.form.manufacturer == 1241) { - if (this.form.deviceNum == "") { - this.$message.error("请填写完整信息") + this.$message.success(res.data.msg); + this.editVisible = false; + this.getdevice(); } else { - var data = { - deviceNum: this.form.deviceNum, - imei: "", - imsi: "", - platformId: 9, - manufactureId: 1241 - } - RequestSet.RegisterDevice(data, (callback) => { - if (callback.data.success && callback.success) { - console.log(callback); - var data = [{ - siteId: this.checkNodeId1, - deviceId: callback.data.id - }] - httpPost(data, this.$api.bindDeviceSite).then(res => { - console.log(res); - if (res.success) { - this.$message.success("绑定成功") - this.editVisible = false - this.getdevice() - } - }).catch(error => { - this.$message.error("绑定失败", error) - }) - // this.$message.success(res.data.msg) - // this.editVisible = false - // this.getdevice(); - } else { - this.$message.error(callback.data.msg) - } - }) - } + this.$message.error(callback.data.msg) } - } - }, - // 选择绑定房间 - onClick: function (evt, treeId, treeNode) { - // 点击事件 - this.treedata = treeNode; - }, - // 获取绑定所有房间 - getalllist() { - var data = {}; - httpGet(data, this.$api.getTree).then((res) => { - var array = uniqueArray(res.data, "id"); - this.zNodes = ztreeToElementTree(array, {}); - }); - }, - // 获取设备 - getdevice() { - var q = { - isOnline: this.search.isOnline, - roomName: this.search.roomname, - roomIds: this.checkNodeId, - startBattery: this.search.startBattery, - endBattery: this.search.endBattery, - lockType: 1, - unBind: this.search.unBind, - firmwareVersion: this.search.firmwareVersion, - isUsed: this.search.isUsed, - iccid: this.search.iccid, - rssiStart: this.search.rssiStart, - rssiEnd: this.search.rssiEnd, - createStart: this.search.createStart, - createEnd: this.search.createEnd, - isAppBind: this.search.isAppBind - }; - if (q.isOnline == 2) { - delete q.isOnline - } - let qObject = utils.validObject(q) - var data = { - q: JSON.stringify(qObject), - pageNum: 1, - pageSize: 10 - }; - httpPost(data, this.$api.getDeviceItems).then((res) => { - var online = 0, - unonline = 0, - devIds = ""; - res.data.list.map((li) => { - if (li.isOnline == 1) { - online++; - } else if (li.isOnline == 0) { - unonline++; - } - let accessPlatform = this.accessPlatform.show.filter(item => item.code == li.accessPlatform)[0] - if (accessPlatform) { - li['accessPlatformText'] = accessPlatform.desc - } else { - li['accessPlatformText'] = '' - } - let deviceType = this.accessPlatform.deviceType.filter(item => item.code == li.manufactureId)[0] - if (deviceType) { - li['manufactureIdText'] = deviceType.desc - } else { - li['manufactureIdText'] = '' + }) + } + } else if(this.form.manufacturer == 201 || this.form.manufacturer == 221) { + var data = { + lockerId: this.form.lockerId, + imei: this.form.imei, + customerCode: this.form.customerCode, + lockerSuperAdminId: this.form.lockerSuperAdminId, + authKey: this.form.authKey, + type: this.form.type, + manufactureId: this.form.manufacturer, + enterpriseId: this.userInfo.enterpriseId, + order: 5101, + }; + RequestSet.RegisterDevice(data, (callback) => { + if (callback.data.success && callback.success) { + var data = [{ + siteId: this.checkNodeId1, + deviceId: callback.data.id, + }]; + httpPost(data, this.$api.bindDeviceSite) + .then((res) => { + if (res.success) { + this.$message.success("绑定成功"); + + this.editVisible = falsethis.editVisible = false + this.getdevice(); } - li.createAt = moment(li.createAt).format("YYYY-MM-DD HH:mm:ss"); - if (li.lastReportAt) { - li.lastReportAt = moment(li.lastReportAt).format("YYYY-MM-DD HH:mm:ss"); - } else { - li['lastReportAt'] = '' + }) + .catch((error) => { + this.$message.error(`绑定失败`); + }); + this.$message.success("添加成功"); + this.editVisible = false; + this.getdevice(); + } else { + this.$message.error(callback.data.msg); + } + }) +} else if (this.form.manufacturer == 701) { + var data = { + deviceNum: this.form.deviceNum, + validateCode: this.form.validateCode, + manufactureId: this.form.manufacturer, + enterpriseId: this.userInfo.enterpriseId, + } + RequestSet.RegisterDevice(data, (callback) => { + if (callback.data.success && callback.success) { + var data = [{ + siteId: this.checkNodeId1, + deviceId: callback.data.id, + }]; + httpPost(data, this.$api.bindDeviceSite) + .then((res) => { + if (res.success) { + this.$message.success("绑定成功"); + this.editVisible = false + this.getdevice(); } - devIds += li.deviceNum + ","; + }) + .catch((error) => { + this.$message.error(`绑定失败`); }); - var newArr = uniqueArray(res.data.list, "id"); - this.tableData = newArr; - this.currentPage4 = 1; - this.pageTotal = res.data.total; - }); - }, - timestampToTime(cjsj) { - var date = new Date(cjsj); //时间戳为10位需*1000,时间戳为13位的话不需乘1000 - var Y = date.getFullYear() + "-"; - var M = - (date.getMonth() + 1 < 10 ? - "0" + (date.getMonth() + 1) : - date.getMonth() + 1) + "-"; - var D = date.getDate() + " "; - var h = date.getHours() + ":"; - var m = date.getMinutes() + ":"; - var s = date.getSeconds(); - return Y + M + D + h + m + s; - }, - handleChange(value) { - console.log(value); - }, - restSearch() { - this.search = { - name: "", - deviceNum: "", - roomname: '', - imei: "", - isOnline: "", - unBind: '', - startBattery: '', - endBattery: '', - firmwareVersion: '', - operationStatus: '' + this.$message.success("添加成功"); + this.editVisible = false; + this.getdevice(); + } else { + this.$message.error(callback.data.msg); + } + }) +} else if (this.form.manufacturer == 1241) { + if (this.form.deviceNum == "") { + this.$message.error("请填写完整信息") + } else { + var data = { + deviceNum: this.form.deviceNum, + imei: "", + imsi: "", + platformId: 9, + manufactureId: 1241 + } + RequestSet.RegisterDevice(data, (callback) => { + if (callback.data.success && callback.success) { + console.log(callback); + var data = [{ + siteId: this.checkNodeId1, + deviceId: callback.data.id + }] + httpPost(data, this.$api.bindDeviceSite).then(res => { + console.log(res); + if (res.success) { + this.$message.success("绑定成功") + this.editVisible = false + this.getdevice() + } + }).catch(error => { + this.$message.error("绑定失败", error) + }) + // this.$message.success(res.data.msg) + // this.editVisible = false + // this.getdevice(); + } else { + this.$message.error(callback.data.msg) + } + }) + } +} } - this.checkNodeId = '' - this.searchRoom = '' - this.handleSearch() - }, - // 设备状态统计筛选 - screenStatisticsItemsMethods(data) { - httpPost(data, this.$api.screenStatisticsItems).then(res => { - console.log(res); - if (res.code == 200) { - var sumpageTotal = 0, online = 0, unonline = 0, abnormal = 0 - res.data.map(li => { - if (li.isAppBind == 1) { - abnormal++ - } - if (li.isOnline == '0') { - unonline++ - } - if (li.isOnline == '1') { - online++ - } - }) - this.sumpageTotal = res.data.length - this.online = online - this.unonline = unonline - this.abnormal = abnormal - } - }) }, - // 触发搜索按钮 - handleSearch() { - var deviceNum = this.search.deviceNum.replace(/\s*/g, ""); - var imei = this.search.imei.replace(/\s*/g, ""); - if (this.search.isOnline == 2) { - this.search.isAppBind = 1 +// 选择绑定房间 +onClick: function (evt, treeId, treeNode) { + // 点击事件 + this.treedata = treeNode; +}, +// 获取绑定所有房间 +getalllist() { + var data = {}; + httpGet(data, this.$api.getTree).then((res) => { + var array = uniqueArray(res.data, "id"); + this.zNodes = ztreeToElementTree(array, {}); + }); +}, +// 获取设备 +getdevice() { + var q = { + isOnline: this.search.isOnline, + roomName: this.search.roomname, + roomIds: this.checkNodeId, + startBattery: this.search.startBattery, + endBattery: this.search.endBattery, + lockType: 1, + unBind: this.search.unBind, + firmwareVersion: this.search.firmwareVersion, + isUsed: this.search.isUsed, + iccid: this.search.iccid, + rssiStart: this.search.rssiStart, + rssiEnd: this.search.rssiEnd, + createStart: this.search.createStart, + createEnd: this.search.createEnd, + isAppBind: this.search.isAppBind + }; + if (q.isOnline == 2) { + delete q.isOnline + } + let qObject = utils.validObject(q) + var data = { + q: JSON.stringify(qObject), + pageNum: 1, + pageSize: 10 + }; + httpPost(data, this.$api.getDeviceItems).then((res) => { + var online = 0, + unonline = 0, + devIds = ""; + res.data.list.map((li) => { + if (li.isOnline == 1) { + online++; + } else if (li.isOnline == 0) { + unonline++; + } + let accessPlatform = this.accessPlatform.show.filter(item => item.code == li.accessPlatform)[0] + if (accessPlatform) { + li['accessPlatformText'] = accessPlatform.desc } else { - this.search.isAppBind = '' + li['accessPlatformText'] = '' } - var q = { - deviceNum: deviceNum, - imei: imei, - isOnline: this.search.isOnline, - roomName: this.search.roomname, - roomIds: this.checkNodeId, - startBattery: this.search.startBattery, - endBattery: this.search.endBattery, - lockType: 1, - unBind: this.search.unBind, - firmwareVersion: this.search.firmwareVersion, - isUsed: this.search.isUsed, - iccid: this.search.iccid, - rssiStart: this.search.rssiStart, - rssiEnd: this.search.rssiEnd, - createStart: this.search.createStart, - createEnd: this.search.createEnd, - isAppBind: this.search.isAppBind - }; - if (q.isOnline == 2) { - delete q.isOnline + let deviceType = this.accessPlatform.deviceType.filter(item => item.code == li.manufactureId)[0] + if (deviceType) { + li['manufactureIdText'] = deviceType.desc + } else { + li['manufactureIdText'] = '' } - let qObject = utils.validObject(q) - let data = { - q: JSON.stringify(qObject), - pageNum: 1, - pageSize: this.pageSize, - }; - this.screenStatisticsItemsMethods(data) - httpPost(data, this.$api.getDeviceItems).then((res) => { - if (res.data.list.length > 0) { - res.data.list.map((li) => { - var accessPlatform = this.accessPlatform.show.filter(item => item.code == li.accessPlatform)[0] - if (accessPlatform) { - li['accessPlatformText'] = accessPlatform.desc - } else { - li['accessPlatformText'] = '' - } - let deviceType = this.accessPlatform.deviceType.filter(item => item.code == li.manufactureId)[0] - if (deviceType) { - li['manufactureIdText'] = deviceType.desc - } else { - li['manufactureIdText'] = '' - } - li.createAt = moment(li.createAt).format("YYYY-MM-DD HH:mm:ss"); - if (li.lastReportAt) { - li.lastReportAt = moment(li.lastReportAt).format("YYYY-MM-DD HH:mm:ss"); + li.createAt = moment(li.createAt).format("YYYY-MM-DD HH:mm:ss"); + if (li.lastReportAt) { + li.lastReportAt = moment(li.lastReportAt).format("YYYY-MM-DD HH:mm:ss"); + } else { + li['lastReportAt'] = '' + } + devIds += li.deviceNum + ","; + }); + var newArr = uniqueArray(res.data.list, "id"); + this.tableData = newArr; + this.currentPage4 = 1; + this.pageTotal = res.data.total; + }); +}, +timestampToTime(cjsj) { + var date = new Date(cjsj); //时间戳为10位需*1000,时间戳为13位的话不需乘1000 + var Y = date.getFullYear() + "-"; + var M = + (date.getMonth() + 1 < 10 ? + "0" + (date.getMonth() + 1) : + date.getMonth() + 1) + "-"; + var D = date.getDate() + " "; + var h = date.getHours() + ":"; + var m = date.getMinutes() + ":"; + var s = date.getSeconds(); + return Y + M + D + h + m + s; +}, +handleChange(value) { + console.log(value); +}, +restSearch() { + this.search = { + name: "", + deviceNum: "", + roomname: '', + imei: "", + isOnline: "", + unBind: '', + startBattery: '', + endBattery: '', + firmwareVersion: '', + operationStatus: '' + } + this.checkNodeId = '' + this.searchRoom = '' + this.handleSearch() +}, +// 设备状态统计筛选 +screenStatisticsItemsMethods(data) { + httpPost(data, this.$api.screenStatisticsItems).then(res => { + console.log(res); + if (res.code == 200) { + var sumpageTotal = 0, online = 0, unonline = 0, abnormal = 0 + res.data.map(li => { + if (li.isAppBind == 1) { + abnormal++ + } + if (li.isOnline == '0') { + unonline++ + } + if (li.isOnline == '1') { + online++ + } + }) + this.sumpageTotal = res.data.length + this.online = online + this.unonline = unonline + this.abnormal = abnormal + } + }) +}, +// 触发搜索按钮 +handleSearch() { + var deviceNum = this.search.deviceNum.replace(/\s*/g, ""); + var imei = this.search.imei.replace(/\s*/g, ""); + if (this.search.isOnline == 2) { + this.search.isAppBind = 1 + } else { + this.search.isAppBind = '' + } + var q = { + deviceNum: deviceNum, + imei: imei, + isOnline: this.search.isOnline, + roomName: this.search.roomname, + roomIds: this.checkNodeId, + startBattery: this.search.startBattery, + endBattery: this.search.endBattery, + lockType: 1, + unBind: this.search.unBind, + firmwareVersion: this.search.firmwareVersion, + isUsed: this.search.isUsed, + iccid: this.search.iccid, + rssiStart: this.search.rssiStart, + rssiEnd: this.search.rssiEnd, + createStart: this.search.createStart, + createEnd: this.search.createEnd, + isAppBind: this.search.isAppBind + }; + if (q.isOnline == 2) { + delete q.isOnline + } + let qObject = utils.validObject(q) + let data = { + q: JSON.stringify(qObject), + pageNum: 1, + pageSize: this.pageSize, + }; + this.screenStatisticsItemsMethods(data) + httpPost(data, this.$api.getDeviceItems).then((res) => { + if (res.data.list.length > 0) { + res.data.list.map((li) => { + var accessPlatform = this.accessPlatform.show.filter(item => item.code == li.accessPlatform)[0] + if (accessPlatform) { + li['accessPlatformText'] = accessPlatform.desc + } else { + li['accessPlatformText'] = '' + } + let deviceType = this.accessPlatform.deviceType.filter(item => item.code == li.manufactureId)[0] + if (deviceType) { + li['manufactureIdText'] = deviceType.desc + } else { + li['manufactureIdText'] = '' + } + li.createAt = moment(li.createAt).format("YYYY-MM-DD HH:mm:ss"); + if (li.lastReportAt) { + li.lastReportAt = moment(li.lastReportAt).format("YYYY-MM-DD HH:mm:ss"); + } else { + li['lastReportAt'] = '' + } + }); + var newArr = uniqueArray(res.data.list, "id"); + this.pageTotal = res.data.total + this.tableData = newArr; + } else { + this.tableData = []; + this.pageTotal = 0 + } + this.currentPage4 = 1; + this.$store.commit("increment", 1); + }); + // this.$set(this.query, "pageIndex", 1); +}, +// 删除操作 +handleDelete(index) { + // 二次确认删除 + this.$confirm("确定要删除吗?", "提示", { + type: "warning", + }) + .then(() => { + this.$message.success("删除成功"); + this.tableData.splice(index, 1); + }) + .catch(() => { }); +}, +// 多选操作 +handleSelectionChange(val) { + this.multipleSelection = val; +}, +// 批量远程开锁 +batchRemoteUnlocking() { + this.$confirm("确定要批量远程开锁吗?", "提示", { + type: "warning", + }) + .then(() => { + this.multipleSelection.map(li => { + if (li.manufactureId == 101) { + var str2 = { + imei: li.imei, + openLockType: 2, + is: true, + roomName: li.roomName, + roomId: li.roomId, + cardName: this.userInfo.username + }; + httpPost(str2, this.$api.openLock).then((res3) => { + if (res3.success) { + this.$message.success("开锁成功!"); } else { - li['lastReportAt'] = '' + this.$message.error("开锁失败!"); } }); - var newArr = uniqueArray(res.data.list, "id"); - this.pageTotal = res.data.total - this.tableData = newArr; - } else { - this.tableData = []; - this.pageTotal = 0 } - this.currentPage4 = 1; - this.$store.commit("increment", 1); - }); - // this.$set(this.query, "pageIndex", 1); - }, - // 删除操作 - handleDelete(index) { - // 二次确认删除 - this.$confirm("确定要删除吗?", "提示", { - type: "warning", - }) - .then(() => { - this.$message.success("删除成功"); - this.tableData.splice(index, 1); - }) - .catch(() => { }); - }, - // 多选操作 - handleSelectionChange(val) { - this.multipleSelection = val; - }, - // 批量远程开锁 - batchRemoteUnlocking() { - this.$confirm("确定要批量远程开锁吗?", "提示", { - type: "warning", }) - .then(() => { - this.multipleSelection.map(li => { - if (li.manufactureId == 101) { - var str2 = { - imei: li.imei, - openLockType: 2, - is: true, - roomName: li.roomName, - roomId: li.roomId, - cardName: this.userInfo.username - }; - httpPost(str2, this.$api.openLock).then((res3) => { - if (res3.success) { - this.$message.success("开锁成功!"); - } else { - this.$message.error("开锁失败!"); - } + }) +}, +delAllSelection() { + const length = this.multipleSelection.length; + let str = ""; + this.delList = this.delList.concat(this.multipleSelection); + for (let i = 0; i < length; i++) { + str += this.multipleSelection[i].name + " "; + } + this.$message.error(`删除了${str}`); + this.multipleSelection = []; +}, +// 删除设备 +deleteLock(index, row) { + this.$confirm("确定要删除吗?", "提示", { + type: "warning", + }) + .then(() => { + // if (row.manufactureId == 101) { + if (row.roomId) { + var q = { + id: row.roomId, + }; + var tenant = { + q: JSON.stringify(q), + }; + httpGet(tenant, this.$api.getSiteTenant).then((res) => { + Promise.all( + res.data.list.map((element) => { + return new Promise(function (resolve, reject) { + resolve(element.cardId); }); + }) + ).then((allId) => { + var str = [] + allId.map((li) => { + var obj = { + siteId: row.roomId, + cardId: li, + } + str.push(obj) + }); + if (str.length > 0) { + httpPost(str, this.$api.unbindCard).then((res) => { }); } - }) - }) - }, - delAllSelection() { - const length = this.multipleSelection.length; - let str = ""; - this.delList = this.delList.concat(this.multipleSelection); - for (let i = 0; i < length; i++) { - str += this.multipleSelection[i].name + " "; - } - this.$message.error(`删除了${str}`); - this.multipleSelection = []; - }, - // 删除设备 - deleteLock(index, row) { - this.$confirm("确定要删除吗?", "提示", { - type: "warning", - }) - .then(() => { - // if (row.manufactureId == 101) { - if (row.roomId) { - var q = { - id: row.roomId, - }; - var tenant = { - q: JSON.stringify(q), - }; - httpGet(tenant, this.$api.getSiteTenant).then((res) => { - Promise.all( - res.data.list.map((element) => { - return new Promise(function (resolve, reject) { - resolve(element.cardId); - }); - }) - ).then((allId) => { - var str = [] - allId.map((li) => { - var obj = { - siteId: row.roomId, - cardId: li, - } - str.push(obj) - }); - if (str.length > 0) { - httpPost(str, this.$api.unbindCard).then((res) => { }); + var data1 = [{ + siteId: row.roomId, + deviceId: row.id, + }]; + httpPost(data1, this.$api.unbindDeviceSite).then((res) => { + if (res.success) { + this.$message.success("解绑成功"); + var data = { + deviceNum: row.deviceNum, + imei: row.imei, + order: 5102 } - var data1 = [{ - siteId: row.roomId, - deviceId: row.id, - }]; - httpPost(data1, this.$api.unbindDeviceSite).then((res) => { - if (res.success) { - this.$message.success("解绑成功"); - var data = { - deviceNum: row.deviceNum, - imei: row.imei, - order: 5102 - } - RequestSet.DeleteDevic(data, row.manufactureId, (callback => { - if (callback.success) { - this.getdevice(); - this.$message.success('删除成功'); - } else { - this.getdevice(); - this.$message.error(callback.msg); - } - })) + RequestSet.DeleteDevic(data, row.manufactureId, (callback => { + if (callback.success) { + this.getdevice(); + this.$message.success('删除成功'); } else { this.getdevice(); - this.$message.error(`解绑失败`); + this.$message.error(callback.msg); } - }); - }) - }) - } else { - var data = { - deviceNum: row.deviceNum, - imei: row.imei, - order: 5102, - }; - RequestSet.DeleteDevic(data, row.manufactureId, (callback) => { - if (callback.success) { - this.$message.success("删除成功"); - this.getdevice(); + })) } else { this.getdevice(); - this.$message.error(callback.msg); + this.$message.error(`解绑失败`); } - }) - } - }).catch((err) => { - this.getdevice(); - this.$message.error(err.msg); - }); - }, - // 绑定房间 - bindRoom(index, row) { - this.bromm = row; - this.roomVisible = true; - this.$refs.tree.setCheckedKeys([]); - }, - // 确定绑定 - bindsave() { - var treedata = this.treedata; - this.roomVisible = false; - var data = [{ - siteId: treedata.id, - deviceId: this.bromm.id, - },]; - httpPost(data, this.$api.bindDeviceSite) - .then((res) => { - if (res.success) { - this.$message.success("绑定成功"); + }); + }) + }) + } else { + var data = { + deviceNum: row.deviceNum, + imei: row.imei, + order: 5102, + }; + RequestSet.DeleteDevic(data, row.manufactureId, (callback) => { + if (callback.success) { + this.$message.success("删除成功"); + this.getdevice(); + } else { this.getdevice(); + this.$message.error(callback.msg); } }) - .catch((error) => { - this.$message.error(`绑定失败`); - }); - }, - unbindsave(index, row) { - var data = [{ - siteId: row.roomId, - deviceId: row.id, - },]; - var q = { - id: row.roomId, - }; - var tenant = { - q: JSON.stringify(q), - }; - // 二次确认解绑 - this.$confirm("确定要解绑吗?", "提示", { - type: "warning", - }) - .then(() => { - // this.Reset(index, row) - httpGet(tenant, this.$api.getSiteTenant).then((res) => { - Promise.all( - res.data.list.map((element) => { - return new Promise(function (resolve, reject) { - resolve(element.cardId); - }); - }) - ).then((allId) => { - allId.map((li) => { - var str = [{ - siteId: row.roomId, - cardId: li, - },]; - httpPost(str, this.$api.unbindCard).then((res) => { }); - }); - httpPost(data, this.$api.unbindDeviceSite).then((res) => { - if (res.success) { - this.$message.success("解绑成功"); - this.getdevice(); - } else { - this.$message.error(`解绑失败`); - } - }); + } + }).catch((err) => { + this.getdevice(); + this.$message.error(err.msg); + }); +}, +// 绑定房间 +bindRoom(index, row) { + this.bromm = row; + this.roomVisible = true; + this.$refs.tree.setCheckedKeys([]); +}, +// 确定绑定 +bindsave() { + var treedata = this.treedata; + this.roomVisible = false; + var data = [{ + siteId: treedata.id, + deviceId: this.bromm.id, + },]; + httpPost(data, this.$api.bindDeviceSite) + .then((res) => { + if (res.success) { + this.$message.success("绑定成功"); + this.getdevice(); + } + }) + .catch((error) => { + this.$message.error(`绑定失败`); + }); +}, +unbindsave(index, row) { + var data = [{ + siteId: row.roomId, + deviceId: row.id, + },]; + var q = { + id: row.roomId, + }; + var tenant = { + q: JSON.stringify(q), + }; + // 二次确认解绑 + this.$confirm("确定要解绑吗?", "提示", { + type: "warning", + }) + .then(() => { + // this.Reset(index, row) + httpGet(tenant, this.$api.getSiteTenant).then((res) => { + Promise.all( + res.data.list.map((element) => { + return new Promise(function (resolve, reject) { + resolve(element.cardId); }); + }) + ).then((allId) => { + allId.map((li) => { + var str = [{ + siteId: row.roomId, + cardId: li, + },]; + httpPost(str, this.$api.unbindCard).then((res) => { }); + }); + httpPost(data, this.$api.unbindDeviceSite).then((res) => { + if (res.success) { + this.$message.success("解绑成功"); + this.getdevice(); + } else { + this.$message.error(`解绑失败`); + } }); - }) - .catch(() => { }); - }, - addequipment() { - this.form.customerCode = this.$store.state.customerCode; - this.editVisible = true; - }, - // 编辑操作 - handleEdit(index, row) { - this.idx = index; - this.form = row; - this.editVisible = true; - }, - // 保存编辑 - saveEdit() { - this.editVisible = false; - }, - handleSizeChange(val) { - console.log(`每页 ${val} 条`); - this.$router.replace({ - path: this.$route.path, - query: { - page: this.$route.query.page ? this.$route.query.page : 1, - pageSize: val, - }, - }); - this.pageSize = val - this.getlistNum(0, val); - }, - getlistNum(val, size) { - var deviceNum = this.search.deviceNum.replace(/\s*/g, ""); - var imei = this.search.imei.replace(/\s*/g, ""); - var q = { - deviceNum: deviceNum, - imei: imei, - isOnline: this.search.isOnline, - roomName: this.search.roomname, - roomIds: this.checkNodeId, - startBattery: this.search.startBattery, - endBattery: this.search.endBattery, - lockType: 1, - unBind: this.search.unBind, - firmwareVersion: this.search.firmwareVersion, - isUsed: this.search.isUsed, - iccid: this.search.iccid, - rssiStart: this.search.rssiStart, - rssiEnd: this.search.rssiEnd, - createStart: this.search.createStart, - createEnd: this.search.createEnd, - isAppBind: this.search.isAppBind - }; - if (q.isOnline == 2) { - delete q.isOnline - } - var qObject = utils.validObject(q) - var data = { - q: JSON.stringify(qObject), - pageNum: val, - pageSize: size, - }; - httpPost(data, this.$api.getDeviceItems).then((res) => { - res.data.list.map((li) => { - var accessPlatform = this.accessPlatform.show.filter(item => item.code == li.accessPlatform)[0] - if (accessPlatform) { - li['accessPlatformText'] = accessPlatform.desc - } else { - li['accessPlatformText'] = '' - } - let deviceType = this.accessPlatform.deviceType.filter(item => item.code == li.manufactureId)[0] - if (deviceType) { - li['manufactureIdText'] = deviceType.desc - } else { - li['manufactureIdText'] = '' - } - li.createAt = moment(li.createAt).format("YYYY-MM-DD HH:mm:ss"); - if (li.lastReportAt) { - li.lastReportAt = moment(li.lastReportAt).format("YYYY-MM-DD HH:mm:ss"); - } else { - li['lastReportAt'] = '' - } }); - var newArr = uniqueArray(res.data.list, "id"); - this.tableData = newArr; - this.pageTotal = res.data.total; }); - }, - // 分页导航 - handlePageChange(val) { - // this.$router.replace({ - // path: this.$route.path, - // query: { - // page: this.$route.query.page ? this.$route.query.page : 1, - // pageSize: val, - // }, - // }); - this.pageNum = val - this.$store.commit("increment", val); - var q = { - deviceNum: this.search.deviceNum, - imei: this.search.imei, - isOnline: this.search.isOnline, - roomName: this.search.roomname, - roomIds: this.checkNodeId, - startBattery: this.search.startBattery, - endBattery: this.search.endBattery, - lockType: 1, - unBind: this.search.unBind, - firmwareVersion: this.search.firmwareVersion, - isUsed: this.search.isUsed, - iccid: this.search.iccid, - rssiStart: this.search.rssiStart, - rssiEnd: this.search.rssiEnd, - createStart: this.search.createStart, - createEnd: this.search.createEnd, - isAppBind: this.search.isAppBind - }; - if (q.isOnline == 2) { - delete q.isOnline + }) + .catch(() => { }); +}, +addequipment() { + this.form.customerCode = this.$store.state.customerCode; + this.editVisible = true; +}, +// 编辑操作 +handleEdit(index, row) { + this.idx = index; + this.form = row; + this.editVisible = true; +}, +// 保存编辑 +saveEdit() { + this.editVisible = false; +}, +handleSizeChange(val) { + console.log(`每页 ${val} 条`); + this.$router.replace({ + path: this.$route.path, + query: { + page: this.$route.query.page ? this.$route.query.page : 1, + pageSize: val, + }, + }); + this.pageSize = val + this.getlistNum(0, val); +}, +getlistNum(val, size) { + var deviceNum = this.search.deviceNum.replace(/\s*/g, ""); + var imei = this.search.imei.replace(/\s*/g, ""); + var q = { + deviceNum: deviceNum, + imei: imei, + isOnline: this.search.isOnline, + roomName: this.search.roomname, + roomIds: this.checkNodeId, + startBattery: this.search.startBattery, + endBattery: this.search.endBattery, + lockType: 1, + unBind: this.search.unBind, + firmwareVersion: this.search.firmwareVersion, + isUsed: this.search.isUsed, + iccid: this.search.iccid, + rssiStart: this.search.rssiStart, + rssiEnd: this.search.rssiEnd, + createStart: this.search.createStart, + createEnd: this.search.createEnd, + isAppBind: this.search.isAppBind + }; + if (q.isOnline == 2) { + delete q.isOnline + } + var qObject = utils.validObject(q) + var data = { + q: JSON.stringify(qObject), + pageNum: val, + pageSize: size, + }; + httpPost(data, this.$api.getDeviceItems).then((res) => { + res.data.list.map((li) => { + var accessPlatform = this.accessPlatform.show.filter(item => item.code == li.accessPlatform)[0] + if (accessPlatform) { + li['accessPlatformText'] = accessPlatform.desc + } else { + li['accessPlatformText'] = '' } - var qObject = utils.validObject(q) - var data = { - q: JSON.stringify(qObject), - pageNum: val, - pageSize: this.pageSize, - }; - httpPost(data, this.$api.getDeviceItems).then((res) => { - res.data.list.map((li) => { - var accessPlatform = this.accessPlatform.show.filter(item => item.code == li.accessPlatform)[0] - if (accessPlatform) { - li['accessPlatformText'] = accessPlatform.desc - } else { - li['accessPlatformText'] = '' - } - let deviceType = this.accessPlatform.deviceType.filter(item => item.code == li.manufactureId)[0] - if (deviceType) { - li['manufactureIdText'] = deviceType.desc - } else { - li['manufactureIdText'] = '' - } - li.createAt = moment(li.createAt).format("YYYY-MM-DD HH:mm:ss"); - if (li.createAt) { } - if (li.lastReportAt) { - li.lastReportAt = moment(li.lastReportAt).format("YYYY-MM-DD HH:mm:ss"); - } else { - li['lastReportAt'] = '' - } - }); - var newArr = uniqueArray(res.data.list, "id"); - this.tableData = newArr; - this.pageTotal = res.data.total; - }); - }, - btnClick() { - document.querySelector(".input-file").click(); - }, - exportBtn() { - this.exportExcel() - }, - exportExcel() { - let sheet1data = [ - ['设备号', 'mac地址', 'sn', 'imei', 'app绑定号', '生产写入号'] - ] - var sheet1 = XLSX.utils.json_to_sheet(sheet1data, { - skipHeader: true, - }) - // 创建一个新的空的workbook - var wb = XLSX.utils.book_new() - XLSX.utils.book_append_sheet(wb, sheet1, '设备导入模板') - // XLSX.utils.book_append_sheet(wb, sheet2, '行政部') - // XLSX.utils.book_append_sheet(wb, sheet3, '前端部') - const workbookBlob = this.workbook2blob(wb) - this.openDownloadDialog(workbookBlob, '设备导入模板.xlsx') - }, - // 下载模板 - workbook2blob(workbook) { - // 生成excel的配置项 - var wopts = { - // 要生成的文件类型 - bookType: 'xlsx', - // // 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性 - bookSST: false, - type: 'binary' + let deviceType = this.accessPlatform.deviceType.filter(item => item.code == li.manufactureId)[0] + if (deviceType) { + li['manufactureIdText'] = deviceType.desc + } else { + li['manufactureIdText'] = '' } - var wbout = XLSX.write(workbook, wopts) - // 将字符串转ArrayBuffer - function s2ab(s) { - var buf = new ArrayBuffer(s.length) - var view = new Uint8Array(buf) - for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xff - return buf + li.createAt = moment(li.createAt).format("YYYY-MM-DD HH:mm:ss"); + if (li.lastReportAt) { + li.lastReportAt = moment(li.lastReportAt).format("YYYY-MM-DD HH:mm:ss"); + } else { + li['lastReportAt'] = '' } - let buf = s2ab(wbout) - var blob = new Blob([buf], { - type: 'application/octet-stream' - }) - return blob - }, - // 将blob对象 创建bloburl,然后用a标签实现弹出下载框 - openDownloadDialog(blob, fileName) { - if (typeof blob === 'object' && blob instanceof Blob) { - blob = URL.createObjectURL(blob) // 创建blob地址 + }); + var newArr = uniqueArray(res.data.list, "id"); + this.tableData = newArr; + this.pageTotal = res.data.total; + }); +}, +// 分页导航 +handlePageChange(val) { + // this.$router.replace({ + // path: this.$route.path, + // query: { + // page: this.$route.query.page ? this.$route.query.page : 1, + // pageSize: val, + // }, + // }); + this.pageNum = val + this.$store.commit("increment", val); + var q = { + deviceNum: this.search.deviceNum, + imei: this.search.imei, + isOnline: this.search.isOnline, + roomName: this.search.roomname, + roomIds: this.checkNodeId, + startBattery: this.search.startBattery, + endBattery: this.search.endBattery, + lockType: 1, + unBind: this.search.unBind, + firmwareVersion: this.search.firmwareVersion, + isUsed: this.search.isUsed, + iccid: this.search.iccid, + rssiStart: this.search.rssiStart, + rssiEnd: this.search.rssiEnd, + createStart: this.search.createStart, + createEnd: this.search.createEnd, + isAppBind: this.search.isAppBind + }; + if (q.isOnline == 2) { + delete q.isOnline + } + var qObject = utils.validObject(q) + var data = { + q: JSON.stringify(qObject), + pageNum: val, + pageSize: this.pageSize, + }; + httpPost(data, this.$api.getDeviceItems).then((res) => { + res.data.list.map((li) => { + var accessPlatform = this.accessPlatform.show.filter(item => item.code == li.accessPlatform)[0] + if (accessPlatform) { + li['accessPlatformText'] = accessPlatform.desc + } else { + li['accessPlatformText'] = '' } - var aLink = document.createElement('a') - aLink.href = blob - // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,有时候 file:///模式下不会生效 - aLink.download = fileName || '' - var event - if (window.MouseEvent) event = new MouseEvent('click') - // 移动端 - else { - event = document.createEvent('MouseEvents') - event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) + let deviceType = this.accessPlatform.deviceType.filter(item => item.code == li.manufactureId)[0] + if (deviceType) { + li['manufactureIdText'] = deviceType.desc + } else { + li['manufactureIdText'] = '' } - aLink.dispatchEvent(event) - }, - exportData(event) { - if (!event.currentTarget.files.length) { - return; + li.createAt = moment(li.createAt).format("YYYY-MM-DD HH:mm:ss"); + if (li.createAt) { } + if (li.lastReportAt) { + li.lastReportAt = moment(li.lastReportAt).format("YYYY-MM-DD HH:mm:ss"); + } else { + li['lastReportAt'] = '' } - const that = this; - // 拿取文件对象 - var f = event.currentTarget.files[0]; - // 用FileReader来读取 - var reader = new FileReader(); - // 重写FileReader上的readAsBinaryString方法 - FileReader.prototype.readAsBinaryString = function (f) { - var binary = ""; - var wb; // 读取完成的数据 - var outdata; // 你需要的数据 - var reader = new FileReader(); - reader.onload = function (e) { - // 读取成Uint8Array,再转换为Unicode编码(Unicode占两个字节) - var bytes = new Uint8Array(reader.result); - var length = bytes.byteLength; - for (var i = 0; i < length; i++) { - binary += String.fromCharCode(bytes[i]); - } - // 接下来就是xlsx了,具体可看api - wb = XLSX.read(binary, { - type: "binary", - }); - outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); - // 自定义方法向父组件传递数据 - let arr1 = []; - outdata.map((li, index) => { - var str = {}; - str.deviceNum = li["设备号"]; - str.mac = li["mac地址"]; - str.imei = li["imei"]; - str.app = li["app绑定号"]; - str.write = li["生产写入号"]; - arr1.push(str); - }); - // this.tableData=arr - that.userlist1statu = false; - that.$nextTick(() => { - that.userlist2 = arr1; - that.userlist1statu = true; - }); - }; - reader.readAsArrayBuffer(f); - }; - reader.readAsBinaryString(f); - }, + }); + var newArr = uniqueArray(res.data.list, "id"); + this.tableData = newArr; + this.pageTotal = res.data.total; + }); +}, +btnClick() { + document.querySelector(".input-file").click(); +}, +exportBtn() { + this.exportExcel() +}, +exportExcel() { + let sheet1data = [ + ['设备号', 'mac地址', 'sn', 'imei', 'app绑定号', '生产写入号'] + ] + var sheet1 = XLSX.utils.json_to_sheet(sheet1data, { + skipHeader: true, + }) + // 创建一个新的空的workbook + var wb = XLSX.utils.book_new() + XLSX.utils.book_append_sheet(wb, sheet1, '设备导入模板') + // XLSX.utils.book_append_sheet(wb, sheet2, '行政部') + // XLSX.utils.book_append_sheet(wb, sheet3, '前端部') + const workbookBlob = this.workbook2blob(wb) + this.openDownloadDialog(workbookBlob, '设备导入模板.xlsx') +}, +// 下载模板 +workbook2blob(workbook) { + // 生成excel的配置项 + var wopts = { + // 要生成的文件类型 + bookType: 'xlsx', + // // 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性 + bookSST: false, + type: 'binary' + } + var wbout = XLSX.write(workbook, wopts) + // 将字符串转ArrayBuffer + function s2ab(s) { + var buf = new ArrayBuffer(s.length) + var view = new Uint8Array(buf) + for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xff + return buf + } + let buf = s2ab(wbout) + var blob = new Blob([buf], { + type: 'application/octet-stream' + }) + return blob +}, +// 将blob对象 创建bloburl,然后用a标签实现弹出下载框 +openDownloadDialog(blob, fileName) { + if (typeof blob === 'object' && blob instanceof Blob) { + blob = URL.createObjectURL(blob) // 创建blob地址 + } + var aLink = document.createElement('a') + aLink.href = blob + // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,有时候 file:///模式下不会生效 + aLink.download = fileName || '' + var event + if (window.MouseEvent) event = new MouseEvent('click') + // 移动端 + else { + event = document.createEvent('MouseEvents') + event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) + } + aLink.dispatchEvent(event) +}, +exportData(event) { + if (!event.currentTarget.files.length) { + return; + } + const that = this; + // 拿取文件对象 + var f = event.currentTarget.files[0]; + // 用FileReader来读取 + var reader = new FileReader(); + // 重写FileReader上的readAsBinaryString方法 + FileReader.prototype.readAsBinaryString = function (f) { + var binary = ""; + var wb; // 读取完成的数据 + var outdata; // 你需要的数据 + var reader = new FileReader(); + reader.onload = function (e) { + // 读取成Uint8Array,再转换为Unicode编码(Unicode占两个字节) + var bytes = new Uint8Array(reader.result); + var length = bytes.byteLength; + for (var i = 0; i < length; i++) { + binary += String.fromCharCode(bytes[i]); + } + // 接下来就是xlsx了,具体可看api + wb = XLSX.read(binary, { + type: "binary", + }); + outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); + // 自定义方法向父组件传递数据 + let arr1 = []; + outdata.map((li, index) => { + var str = {}; + str.deviceNum = li["设备号"]; + str.mac = li["mac地址"]; + str.imei = li["imei"]; + str.app = li["app绑定号"]; + str.write = li["生产写入号"]; + arr1.push(str); + }); + // this.tableData=arr + that.userlist1statu = false; + that.$nextTick(() => { + that.userlist2 = arr1; + that.userlist1statu = true; + }); + }; + reader.readAsArrayBuffer(f); + }; + reader.readAsBinaryString(f); +}, }, }; @@ -4011,5 +4035,4 @@ export default { .demo-form-inline .el-form-item { width: 100%; } -} - +}