123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- // pages/scene/scene.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- remove:true,//删除工程
- Modify:true,//修改工程名称
- array:[],//分组
- brray:[],
- keyid:[],
- inputVal:[],
- getName:[],//发送往服务器的工程名称参数
- subscript:0,
- Id:[],
- key:[],
- developline:[],
- status:0,
- Status:"",
- },
- //添加分组
- apption:function(){
- var that = this
- wx.showModal({
- title:'添加工程',
- editable:true,
- placeholderText:'请输入名称',
- success:function(ever){
- if(ever.confirm){
- if (ever.content == '') {
- wx.showModal({
- title:'提示',
- content:'请输入工程名',
- showCancel:false
- })
- }
- else{
- let token = wx.getStorageSync('token')
- wx.request({
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/groups',
- method:'POST',
- header:{'Content-Type': 'application/json',
- 'Authorization': token},
- data:{
- groupName:ever.content
- },
- success:res => {
- console.log(res)
- if(res.data.code == 200){
- if(wx.getStorageSync('group') == ''){
- wx.setStorageSync('group', [])
- var a = wx.getStorageSync('group')
- a.push({id:res.data.data.id,name:ever.content,device:[]})
- wx.setStorageSync('group', a)
- }
- else{
- var b = wx.getStorageSync('group')
- b.push({id:res.data.data.id,name:ever.content,device:[]})
- wx.setStorageSync('group', b)
- }
- that.setData({
- array:wx.getStorageSync('group'),
- })
- console.log(wx.getStorageSync('group'))
- }
- else{
- console.log("添加分组失败")
- }
- }
- })
- }
- }
- }
- })
- },
- //删除分组
- removeapption:function(e){
- var that = this
- wx.showModal({
- title:'提示',
- content:'确定删除该工程',
- success:function(res){
- if (res.confirm) {
- var index = e.currentTarget.dataset.indexdel//获取对应下标
- var Idindex = that.data.array[index].id
- var token = wx.getStorageSync('token')
- wx.request({
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/groups?id=' + Idindex,//
- method:'DELETE',
- header:{'Content-Type': 'application/json',
- 'Authorization': token},
- success:res => {
- if(res.data.code == 200){
- if(wx.getStorageSync('group') != ''){
- var deleteid = wx.getStorageSync('group')
- deleteid.splice(index,1)
- wx.setStorageSync('group', deleteid)
- that.setData({
- array:wx.getStorageSync('group'),
- })
- }
- }
- else{
- console.log('删除分组失败')
- }
- }
- })
- }
- }
- })
- },
- //修改分组名称
- ShowChanges:function(e){
- var that = this
- wx.showModal({
- title:'修改工程名称',
- editable:true,
- placeholderText:'请输入名称',
- success:res =>{
- console.log(res)
- if (res.confirm) {
- var index = e.currentTarget.dataset.indexdel//获取对应下标
- var Idindex = that.data.array[index].id//获取对应下标的id值
- if (res.content == '') {
- wx.showModal({
- title:'提示',
- content:'请输入工程名',
- showCancel:false
- })
- }
- else{
- var token = wx.getStorageSync('token')
- wx.request({
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/groups',
- method:'PUT',
- header:{
- 'Content-Type': 'application/json',
- 'Authorization': token
- },
- data:{
- groupName:res.content,
- id:Idindex
- },
- success:ever =>{
- console.log(ever)
- if (ever.data.code == 200) {
- let group = wx.getStorageSync('group')
- group[index].name = res.content
- wx.setStorageSync('group',group)
- that.setData({
- array:wx.getStorageSync('group')
- })
- }
- else{
- console.log('修改分组名称失败')
- }
- }
- })
- }
- }
- }
- })
- },
- //扫码(添加设备)
- scanCodeEvent: function(e){
- var that = this
- var index = e.currentTarget.dataset.indexdel//获取对应下标
- var Idindex = that.data.array[index].id//分组Id
- Idindex = parseInt(Idindex)
- //获取设备
- wx.scanCode({
- success(res){
- var arr = res.result.split(' ');
- var a = arr[0]//设备id
- var b = arr[1]//设备key
- //获取该设备的在线状态和编码
- wx.request({
- url: 'https://api.heclouds.com/devices/' + a,
- method:'GET',
- header:{
- 'api-key':b,
- },
- success(ever){
- var online = ever.data.data.online//设备在线状态
- switch (online) {
- case true:
- that.setData({status:1})
- that.setData({Status:"在线"})
- break;
- default:
- that.setData({status:0})
- that.setData({Status:"离线"})
- break;
- }
- var title = ever.data.data.title//设备编码
- let token = wx.getStorageSync('token')
- wx.request({
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/devices',
- method:'POST',
- header:{'Content-Type': 'application/json',
- 'Authorization': token},
- data:{
- groupId:Idindex,//分组id
- deviceSn:title,//设备编码
- deviceName:title,//设备名称
- deviceId:a,//设备id
- deviceKey:b,//设备key
- status:that.data.status//设备在线状态
- },
- success:su =>{
- if (su.data.code == 200){
- //将设备的信息储存至本地
- let group = wx.getStorageSync('group')
- group[index].device.push({id:su.data.data.id,deviceSn:title,deviceName:title,status:that.data.Status,deviceId:a,
- deviceKey:b})
- wx.setStorageSync('group', group)
- that.setData({
- array:wx.getStorageSync('group')
- })
- console.log(that.data.array)
- }
- else{
- console.log('添加设备失败')
- }
- }
- })
- }
- })
- }
- })
- },
- //修改设备名称
- modifyequipmentname:function(e){
- var that = this
- var key = e.currentTarget.dataset.indexdel
- var group = wx.getStorageSync('group')
- var deviceId = group[key[0]].device[key[1]].id
- var token = wx.getStorageSync('token')
- wx.showModal({
- title:'修改设备名称',
- editable:true,
- placeholderText:'请输入名称',
- success:res =>{
- if (res.confirm) {
- if (res.content == '') {
- wx.showModal({
- title:'提示',
- showCancel:false,
- content:'请输入名称'
- })
- }
- else{
- wx.request({
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/devices',
- method:'PUT',
- header:{'Content-Type': 'application/json','Authorization': token},
- data:{
- deviceName:res.content,
- id:deviceId
- },
- success:ever =>{
- console.log(ever)
- if(ever.data.code == 200){
- group[key[0]].device[key[1]].deviceName = res.content
- wx.setStorageSync('group', group)
- that.setData({
- array:wx.getStorageSync('group')
- })
- }
- else{
- console.log('修改设备名称失败')
- }
- }
- })
- }
- }
- }
- })
- },
- //删除设备
- Deletedevice:function(e){
- var that = this
- var token = wx.getStorageSync('token')
- wx.showModal({
- title:'删除设备',
- content:'确定删除该设备吗?',
- success:function(res){
- if(res.confirm){
- let key = e.currentTarget.dataset.indexdel//获得分组和设备的下标值([分组下标,设备下标])
- let group = wx.getStorageSync('group')
- let subscript = group[key[0]].device[key[1]].id//设备对应的id
- wx.request({
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/devices?id=' + subscript,
- method:'DELETE',
- header:{'Content-Type': 'application/json','Authorization': token},
- success:nrg => {
- console.log(nrg)
- if (nrg.data.code == 200) {
- group[key[0]].device.splice(key[1],1)
- wx.setStorageSync('group', group)
- that.setData({
- array:wx.getStorageSync('group')
- })
- }
- else{
- console.log('删除列表失败')
- }
- }
- })
- }
- }
- })
- },
- Refresh:function(){
-
- },
- //展开设备
- develops:function(){
-
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- var that = this
- let token = wx.getStorageSync('token')
- // wx.request({
- // url:'http://110.40.223.170:8120/api/minigrogram/lightcontrol/groups',
- // method:'GET',
- // header:{'Content-Type': 'application/json','Authorization': token},
- // success:tp => {
- // console.log(tp)
- // }
- // })
- // wx.request({
- // url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/devices?id=' + '5',
- // method:'DELETE',
- // header:{'Content-Type': 'application/json','Authorization': token},
- // success:nrg => {
- // console.log(nrg)
- // }
- // })
- console.log(wx.getStorageSync('group'))
- // that.data.array = []
- // wx.setStorageSync('information', )
- // console.log(wx.getStorageSync('information'))
- // wx.setStorageSync('id', [])
- // wx.setStorageSync('values', [])
- that.setData({
- array:wx.getStorageSync('group'),
- })
- console.log(that.data.array)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|