123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509 |
- // pages/system/system.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- dates:"",//日期
- times:"",//时间
- Illuminance:"",//光照度
- Firealarmtext:"",//消防报警文字
- Firealarmcolor:"",//消防报警颜色
- longitude:"",//经度
- latitude:"",//纬度
- Sunrisetime:"",//日出时间
- Sunsettime:"",//日落时间
- array: ['0', '1', '2', '3','4','5','6','7','8','9','10',
- '11', '12', '13', '14','15','16','17','18','19','20'],//开关延时
- index: 0,
- longitudemodal:true,//经度弹窗显示隐藏
- latitudemodal:true,//纬度弹窗显示隐藏
- getLongitude:"",//获取文本框经度
- getLatitude:"",//获取文本框纬度
- Manualinput1:"00,00'",//经度显示
- Manualinput2:"00,00'",//纬度显示
- Title:"",
- statu:"false",
- status:"离线",
- loops:"",//记录回路数量
- Storage:[],//储存发送数据
- },
- bindPickerChange: function(e) {
- this.setData({
- index: e.detail.value,
- // Index: e.detail.value
- })
- },
- //扫码
- scanCodeEvent: function(){
- wx.scanCode({
- onlyFromCamera: true,// 只允许从相机扫码
- success(res){
- console.log("扫码成功:"+JSON.stringify(res))
- var arr = res.split(' ');
- var a = arr[0]
- var b = arr[1]
- wx.request({
- url: 'https://api.heclouds.com/devices/' + a,
- method:'GET',
- header:{
- 'api-key':b,
- },
- success(res){
- this.setData({
- Title:res.data.title,
- statu:res.data.online
- })
- if(this.data.statu == true){
- this.setData({
- status:"在线",
- })
- wx.request({
- url: 'https://api.heclouds.com/devices/' + '773359551' + '/datastreams',
- header: {"api-key": 'YhyMeWv90ODkHVsNrwdzlhrwV04='},
- method:'GET',
- success: (res) => {
- console.log(res.data)
- }
- })
- }
- else{
- this.setData({
- status:"离线"
- })
- }
- }
- })
- }
- })
- },
- //校准时间
- Calibrationtime:function(){
- var that = this
- wx.request({
- url: 'https://api.heclouds.com/devices/' + '773359551' + '/datastreams',
- header: {"api-key": 'YhyMeWv90ODkHVsNrwdzlhrwV04='},
- method:'GET',
- success: function(res){
- console.log(res.data)
- let {data} = res.data
- console.log(data[0].id)
- for(let i = 0; i < data.length; i++){
- if (data[i].id == "SysTime") {
- var times = data[i].current_value
- }
- }
- if(times.length == 5){
- var a = "0" + times.substring(0,1) + ':' + times.substring(1,3) + ':' + times.substring(3,5)
- }
- else if(times.length == 6){
- var a =times.substring(0,2) + ':' + times.substring(2,4) + ':' + times.substring(4,6)
- }
- else{
- a = times
- }
- that.setData({
- times:a,
- })
- }
- })
- },
- //经度弹窗
- simulation1:function(){
- this.setData({
- longitudemodal:false
- })
- },
- //获取经度
- GetLongitude:function(e){
- let a = e.detail.value
- this.setData({
- getLongitude:a
- })
- },
- //取消
- cancel1:function(){
- this.setData({
- longitudemodal:true
- })
- },
- //确认
- confirm1:function(){
- this.setData({
- longitudemodal:true,
- Manualinput1:this.data.getLongitude,
- })
- },
- //纬度弹窗
- simulation2:function(){
- this.setData({
- latitudemodal:false
- })
- },
- //取消
- cancel2:function(){
- this.setData({
- latitudemodal:true
- })
- },
- //确认
- confirm2:function(){
- this.setData({
- latitudemodal:true,
- Manualinput2:this.data.getLatitude
- })
- },
- //获取纬度
- GetLatitude:function(e){
- let b = e.detail.value
- this.setData({
- getLatitude:b
- })
- },
- //刷新页面
- RefreshPage:function(){
- var that = this
- var storage = that.data.Storage
- wx.request({
- url: 'https://api.heclouds.com/devices/' + '773359551' + '/datastreams',
- header: {"api-key": 'YhyMeWv90ODkHVsNrwdzlhrwV04='},
- method:'GET',
- success: function(res){
- let {data} = res.data
- for(let i = 0; i < data.length; i++){
- //时间
- if (data[i].id == "SysTime") {
- var times = data[i].current_value
- storage[0] = times
- }
- //日期
- else if(data[i].id == "SysDate"){
- var dates = data[i].current_value
- storage[1] = dates
- }
- //光照度
- else if(data[i].id == "lightLuxValue"){
- var Illuminance = data[i].current_value
- storage[2] = Illuminance
- }
- //日出时间
- else if(data[i].id == "RiseTime"){
- var Sunrisetime = data[i].current_value
- storage[3] = Sunrisetime
- }
- //日落时间
- else if(data[i].id == "SetTime"){
- var Sunsettime = data[i].current_value
- storage[4] = Sunsettime
- }
- //经度
- else if(data[i].id == "Longitude"){
- var longitude = data[i].current_value
- storage[5] = longitude
- }
- //纬度
- else if(data[i].id == "Latitude"){
- var latitude = data[i].current_value
- storage[6] = latitude
- }
- //消防报警
- else if(data[i].id == "AlarmState"){
- var Firealarm = data[i].current_value
- storage[7] = Firealarm
- }
- //回路数量
- else if(data[i].id == "RelayCount"){
- var loops = data[i].current_value
- storage[8] = loops
- }
- //开关延时
- else if (data[i].id == "DeviceID") {
- var device = data[i].current_value
- that.setData({index:device})
- }
- }
- //时间
- if(times.length == 5){
- var a = "0" + times.substring(0,1) + ':' + times.substring(1,3) + ':' + times.substring(3,5)
- }
- else if(times.length == 6){
- var a =times.substring(0,2) + ':' + times.substring(2,4) + ':' + times.substring(4,6)
- }
- else{
- a = times
- }
- //日期
- var b ='20' + dates.substring(0,2) + '-' + dates.substring(2,4) + '-' + dates.substring(4,6)
- //日出时间
- var c = Sunrisetime.substring(0,1) + ':' + Sunrisetime.substring(1,3)
- //日落时间
- var d = Sunsettime.substring(0,2) + ':' + Sunsettime.substring(2,4)
- //经度
- if (longitude.length == 5) {
- var e = longitude.substring(0,3) + "," + longitude.substring(3,5) + "'"
- }
- else{
- var e = longitude.substring(0,2) + "," + longitude.substring(3,4) + "'"
- }
- //纬度
- if (latitude.length == 5) {
- var f = latitude.substring(0,3) + "," + latitude.substring(2,5) + "'"
- }
- else{
- var f = latitude.substring(0,2) + "," + latitude.substring(2,4) + "'"
- }
- //光照度
- var g = Illuminance
- //消防报警
- if(Firealarm == "0"){
- that.setData({
- Firealarmtext:"正常",
- Firealarmcolor:"#5cfe03"
- })
- }
- else{
- that.setData({
- Firealarmtext:"异常",
- Firealarmcolor:"red"
- })
- }
- console.log(storage)
- that.setData({
- times:a,
- dates:b,
- Sunrisetime:c,
- Sunsettime:d,
- longitude:e,
- latitude:f,
- Illuminance:g,
- loops:loops,
- Storage:storage
- })
- }
- })
- },
- //存储数据
- Storedata: function(){
- var that = this
- var switchtime = that.data.array[that.data.index]
- console.log(switchtime)
- if(this.data.statu == true){
- wx.request({
- url: 'https://api.heclouds.com/cmds?device_id=' + '773359551',
- method:'POST',
- header:{"api-key":"YhyMeWv90ODkHVsNrwdzlhrwV04="},
- data:{
- "Reflash":0
- },
- success:function(res){
- console.log("发送成功")
- }
- })
- }
- else{
- wx.showModal({
- title:'提示',
- content:'存储数据失败,请检查设备是否在线或者刷新页面',
- showCancel:false,
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- // wx.showToast({
- // title: '加载中',
- // duration: 2000,
- // icon: 'loading',
- // mask: true
- // }
- var that = this
- wx.request({
- url: 'https://api.heclouds.com/devices/' + '773359551',
- method:'GET',
- header:{"api-key": 'YhyMeWv90ODkHVsNrwdzlhrwV04='},
- success:(res) =>{
- if (res.data.data.online == true) {
- that.setData({
- status:"在线"
- })
- }
- else{
- that.setData({
- status:"离线"
- })
- }
- }
- })
- var storage = that.data.Storage
- wx.request({
- url: 'https://api.heclouds.com/devices/' + '773359551' + '/datastreams',
- header: {"api-key": 'YhyMeWv90ODkHVsNrwdzlhrwV04='},
- method:'GET',
- success: function(res){
- let {data} = res.data
- for(let i = 0; i < data.length; i++){
- //时间
- if (data[i].id == "SysTime") {
- var times = data[i].current_value
- storage[0] = times
- }
- //日期
- else if(data[i].id == "SysDate"){
- var dates = data[i].current_value
- storage[1] = dates
- }
- //光照度
- else if(data[i].id == "lightLuxValue"){
- var Illuminance = data[i].current_value
- storage[2] = Illuminance
- }
- //日出时间
- else if(data[i].id == "RiseTime"){
- var Sunrisetime = data[i].current_value
- storage[3] = Sunrisetime
- }
- //日落时间
- else if(data[i].id == "SetTime"){
- var Sunsettime = data[i].current_value
- storage[4] = Sunsettime
- }
- //经度
- else if(data[i].id == "Longitude"){
- var longitude = data[i].current_value
- storage[5] = longitude
- }
- //纬度
- else if(data[i].id == "Latitude"){
- var latitude = data[i].current_value
- storage[6] = latitude
- }
- //消防报警
- else if(data[i].id == "AlarmState"){
- var Firealarm = data[i].current_value
- storage[7] = Firealarm
- }
- //回路数量
- else if(data[i].id == "RelayCount"){
- var loops = data[i].current_value
- storage[8] = loops
- }
- //开关延时
- else if (data[i].id == "DeviceID") {
- var device = data[i].current_value
- that.setData({index:device})
- }
- }
- //时间
- if(times.length == 5){
- var a = "0" + times.substring(0,1) + ':' + times.substring(1,3) + ':' + times.substring(3,5)
- }
- else if(times.length == 6){
- var a =times.substring(0,2) + ':' + times.substring(2,4) + ':' + times.substring(4,6)
- }
- else{
- a = times
- }
- //日期
- var b ='20' + dates.substring(0,2) + '-' + dates.substring(2,4) + '-' + dates.substring(4,6)
- //日出时间
- var c = Sunrisetime.substring(0,1) + ':' + Sunrisetime.substring(1,3)
- //日落时间
- var d = Sunsettime.substring(0,2) + ':' + Sunsettime.substring(2,4)
- //经度
- if (longitude.length == 5) {
- var e = longitude.substring(0,3) + "," + longitude.substring(3,5) + "'"
- }
- else{
- var e = longitude.substring(0,2) + "," + longitude.substring(3,4) + "'"
- }
- //纬度
- if (latitude.length == 5) {
- var f = latitude.substring(0,3) + "," + latitude.substring(2,5) + "'"
- }
- else{
- var f = latitude.substring(0,2) + "," + latitude.substring(2,4) + "'"
- }
- //光照度
- var g = Illuminance
- //消防报警
- if(Firealarm == "0"){
- that.setData({
- Firealarmtext:"正常",
- Firealarmcolor:"#5cfe03"
- })
- }
- else{
- that.setData({
- Firealarmtext:"异常",
- Firealarmcolor:"red"
- })
- }
- console.log(storage)
- that.setData({
- times:a,
- dates:b,
- Sunrisetime:c,
- Sunsettime:d,
- longitude:e,
- latitude:f,
- Illuminance:g,
- loops:loops,
- Storage:storage
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|