unknown há 2 anos atrás
pai
commit
2285732ee2

+ 31 - 0
.eslintrc.js

@@ -0,0 +1,31 @@
+/*
+ * Eslint config file
+ * Documentation: https://eslint.org/docs/user-guide/configuring/
+ * Install the Eslint extension before using this feature.
+ */
+module.exports = {
+  env: {
+    es6: true,
+    browser: true,
+    node: true,
+  },
+  ecmaFeatures: {
+    modules: true,
+  },
+  parserOptions: {
+    ecmaVersion: 2018,
+    sourceType: 'module',
+  },
+  globals: {
+    wx: true,
+    App: true,
+    Page: true,
+    getCurrentPages: true,
+    getApp: true,
+    Component: true,
+    requirePlugin: true,
+    requireMiniProgram: true,
+  },
+  // extends: 'eslint:recommended',
+  rules: {},
+}

+ 0 - 14
app.js

@@ -5,20 +5,6 @@ App({
     const logs = wx.getStorageSync('logs') || []
     logs.unshift(Date.now())
     wx.setStorageSync('logs', logs)
-    // 登录
-    let token = wx.getStorageSync('token')
-    let time = wx.getStorageSync('time')//登录时间
-    let Time = new Date()//当前时间
-    //console.log('时间差为' + parseInt(Time - time)/1000)
-    let currentTime = wx.getStorageSync('currentTime')//过期时间
-    if(token != ''){
-      if(parseInt(Time - time)/1000 < currentTime){
-        wx.switchTab({url: 'pages/scene/scene'})
-      }
-      else{
-        
-      }
-    }
     wx.login({
       success: res => {
         // 发送 res.code 到后台换取 openId, sessionKey, unionId

+ 3 - 1
https/intell.js

@@ -4,7 +4,9 @@ module.exports = {
     let fullUrl = `${baseUrl}${url}`
     return new Promise((resolve,reject)=>{
       wx.request({url: fullUrl,method:type,data,header: {"api-key":key},
-        success(res){resolve(res)},
+        success(res){
+          resolve(res)
+        },
         fail(){
           wx.showToast({
             title: '接口请求错误',

+ 16 - 2
https/request.js

@@ -2,10 +2,24 @@ const { baseUrl } = require('./env').prod
 module.exports = {
     request : function(url, type , data = {}){
     let fullUrl = `${baseUrl}${url}`
-    var token = wx.getStorageSync('token')
+    var token = wx.getStorageSync('token') || ''
     return new Promise((resolve,reject)=>{
       wx.request({url: fullUrl,method:type,data,header: {'content-type': 'application/json','Authorization': token},
-        success(res){resolve(res)},
+        success(res){
+          if(res.data.code == 0){
+            resolve(res)
+          }else if(res.data.code == 401){
+              wx.navigateTo({
+                url: '/pages/sign/sign',
+              })
+          }else{
+            wx.showModal({
+              title: '错误',
+              content: res.data.msg,
+              showCancel:false
+            })
+          }
+        },
         fail(){
           wx.showToast({
             title: '接口请求错误',

+ 22 - 2
pages/control/control.js

@@ -61,6 +61,11 @@ Page({
   },
   //回路开
   Open(e) {
+    wx.showToast({
+      title: '发送指令中',
+      icon: 'loading',
+      duration: 2500
+    })
     var that = this
     var play = that.data.play
     var id = that.data.id
@@ -345,7 +350,7 @@ Page({
             })
           }, 500)
         }
-      }, 3000)
+      }, 2000)
     } else {
       wx.showModal({
         title: '提示',
@@ -356,6 +361,11 @@ Page({
   },
   //回路关
   Shut(e) {
+    wx.showToast({
+      title: '发送指令中',
+      icon: 'loading',
+      duration: 2500
+    })
     var that = this
     var play = that.data.play
     var id = that.data.id
@@ -637,7 +647,7 @@ Page({
             })
           }, 500)
         }
-      }, 3000)
+      }, 2000)
     } else {
       wx.showModal({
         title: '提示',
@@ -1341,6 +1351,11 @@ Page({
   },
   //全开
   Fullopen: function () {
+    wx.showToast({
+      title: '发送指令中',
+      icon: 'loading',
+      duration: 2500
+    })
     var that = this
     //获取设备的在线状态
     getBasic(that.data.deviceId,that.data.deviceKey).then(res => {
@@ -1448,6 +1463,11 @@ Page({
   },
   //全关
   Allclosed: function () {
+    wx.showToast({
+      title: '发送指令中',
+      icon: 'loading',
+      duration: 2500
+    })
     var that = this
     getBasic(that.data.deviceId,that.data.deviceKey).then(res => {
       if(res.data.errno == 0){

+ 48 - 0
pages/index/index.js

@@ -0,0 +1,48 @@
+// index.js
+// 获取应用实例
+const app = getApp()
+
+Page({
+  data: {
+    motto: 'Hello World',
+    userInfo: {},
+    hasUserInfo: false,
+    canIUse: wx.canIUse('button.open-type.getUserInfo'),
+    canIUseGetUserProfile: false,
+    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
+  },
+  // 事件处理函数
+  bindViewTap() {
+    wx.navigateTo({
+      url: '../logs/logs'
+    })
+  },
+  onLoad() {
+    if (wx.getUserProfile) {
+      this.setData({
+        canIUseGetUserProfile: true
+      })
+    }
+  },
+  getUserProfile(e) {
+    // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
+    wx.getUserProfile({
+      desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
+      success: (res) => {
+        console.log(res)
+        this.setData({
+          userInfo: res.userInfo,
+          hasUserInfo: true
+        })
+      }
+    })
+  },
+  getUserInfo(e) {
+    // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
+    console.log(e)
+    this.setData({
+      userInfo: e.detail.userInfo,
+      hasUserInfo: true
+    })
+  }
+})

+ 3 - 0
pages/index/index.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 23 - 0
pages/index/index.wxml

@@ -0,0 +1,23 @@
+<!--index.wxml-->
+<view class="container">
+  <view class="userinfo">
+    <block wx:if="{{canIUseOpenData}}">
+      <view class="userinfo-avatar" bindtap="bindViewTap">
+        <open-data type="userAvatarUrl"></open-data>
+      </view>
+      <open-data type="userNickName"></open-data>
+    </block>
+    <block wx:elif="{{!hasUserInfo}}">
+      <button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button>
+      <button wx:elif="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
+      <view wx:else> 请使用1.4.4及以上版本基础库 </view>
+    </block>
+    <block wx:else>
+      <image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
+      <text class="userinfo-nickname">{{userInfo.nickName}}</text>
+    </block>
+  </view>
+  <view class="usermotto">
+    <text class="user-motto">{{motto}}</text>
+  </view>
+</view>

+ 19 - 0
pages/index/index.wxss

@@ -0,0 +1,19 @@
+/**index.wxss**/
+.userinfo {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  color: #aaa;
+}
+
+.userinfo-avatar {
+  overflow: hidden;
+  width: 128rpx;
+  height: 128rpx;
+  margin: 20rpx;
+  border-radius: 50%;
+}
+
+.usermotto {
+  margin-top: 200px;
+}

+ 18 - 0
pages/logs/logs.js

@@ -0,0 +1,18 @@
+// logs.js
+const util = require('../../utils/util.js')
+
+Page({
+  data: {
+    logs: []
+  },
+  onLoad() {
+    this.setData({
+      logs: (wx.getStorageSync('logs') || []).map(log => {
+        return {
+          date: util.formatTime(new Date(log)),
+          timeStamp: log
+        }
+      })
+    })
+  }
+})

+ 4 - 0
pages/logs/logs.json

@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "查看启动日志",
+  "usingComponents": {}
+}

+ 6 - 0
pages/logs/logs.wxml

@@ -0,0 +1,6 @@
+<!--logs.wxml-->
+<view class="container log-list">
+  <block wx:for="{{logs}}" wx:key="timeStamp" wx:for-item="log">
+    <text class="log-item">{{index + 1}}. {{log.date}}</text>
+  </block>
+</view>

+ 8 - 0
pages/logs/logs.wxss

@@ -0,0 +1,8 @@
+.log-list {
+  display: flex;
+  flex-direction: column;
+  padding: 40rpx;
+}
+.log-item {
+  margin: 10rpx;
+}

+ 41 - 150
pages/scene/scene.js

@@ -28,7 +28,7 @@ Page({
   //刷新列表
   Refreshlist:function(){
     wx.showToast({
-      title:'刷新中',
+      title:'获取数据中',
       icon:'loading',
       duration: 2000
     })
@@ -51,14 +51,6 @@ Page({
                       else{
                         data[i].devices[j].status = '离线'
                       }
-                      wx.setStorageSync('group',data)
-                      let tgroups = wx.getStorageSync('group')
-                      for(let i = 0;i < tgroups.length;i++){
-                        if(tgroups[i].groupName.length > 10){
-                          tgroups[i].groupName = tgroups[i].groupName.slice(0,9) + '....'
-                        }
-                      }
-                      that.setData({array:tgroups})
                     }
                     else{
                       wx.showModal({
@@ -79,14 +71,6 @@ Page({
                       data[i].devices[j].status = '在线'
                     break
                   }
-                  wx.setStorageSync('group',data)
-                  let tgroups = wx.getStorageSync('group')
-                  for(let i = 0;i < tgroups.length;i++){
-                    if(tgroups[i].groupName.length > 10){
-                      tgroups[i].groupName = tgroups[i].groupName.slice(0,9) + '....'
-                    }
-                  }
-                  that.setData({array:tgroups})
                 }
               }
             }
@@ -102,6 +86,11 @@ Page({
             }
           }
         }
+        setTimeout(function(){
+          wx.setStorageSync('group',data)
+          let tgroups = wx.getStorageSync('group')
+          that.nameRestriction(tgroups)  
+        },1500)
       }
       else{
         wx.showModal({
@@ -150,12 +139,7 @@ Page({
                   wx.setStorageSync('group', b)
                 }
                 var group = wx.getStorageSync('group')
-                for(let i = 0;i < group.length;i++){
-                  if(group[i].groupName.length > 10){
-                    group[i].groupName = group[i].groupName.slice(0,9) + '....'
-                  }
-                }
-                that.setData({array:group})
+                that.nameRestriction(group)
               }
               else{
                 wx.showModal({
@@ -191,12 +175,7 @@ Page({
               deleteid.splice(index,1)
               wx.setStorageSync('group', deleteid)
               var Group = wx.getStorageSync('group')
-              for(let i = 0;i < Group.length;i++){
-                if(Group[i].groupName.length > 10){
-                  Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
-                  }
-              }
-              that.setData({array: Group})
+              that.nameRestriction(Group)
             }
             else{
               wx.showModal({
@@ -246,12 +225,7 @@ Page({
                 group[index].groupName = res.content
                 wx.setStorageSync('group',group)
                 var Group = wx.getStorageSync('group')
-                for(let i = 0;i < Group.length;i++){
-                  if(Group[i].groupName.length > 10){
-                    Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
-                  }
-                }
-                that.setData({array:Group})
+                that.nameRestriction(Group)
               }
               else{
                 wx.showModal({
@@ -303,12 +277,7 @@ Page({
                 }
                 wx.setStorageSync('group', group)
                 var Group = wx.getStorageSync('group')
-                for(let i = 0;i < Group.length;i++){
-                  if(Group[i].groupName.length > 10){
-                    Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
-                  }
-                }
-                that.setData({array: Group})
+                that.nameRestriction(Group)
               })
             }
             else{
@@ -330,7 +299,6 @@ Page({
               //查询设备
               getDevice(add.data.data.id,Idindex).then(get =>{
                 var Get = get.data.data
-                console.log(Get)
                 switch(Get.status){
                   case 0:
                     Get.status = '离线'
@@ -348,12 +316,7 @@ Page({
                 }
                 wx.setStorageSync('group', group)
                 var Group = wx.getStorageSync('group')
-                for(let i = 0;i < Group.length;i++){
-                  if(Group[i].groupName.length > 10){
-                    Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
-                  }
-                }
-                that.setData({array: Group})
+                that.nameRestriction(Group)
               })
             }
             else{
@@ -432,12 +395,7 @@ Page({
                   }
                   wx.setStorageSync('group', group)
                   var Group = wx.getStorageSync('group')
-                  for(let i = 0;i < Group.length;i++){
-                    if(Group[i].groupName.length > 10){
-                      Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
-                    }
-                  }
-                  that.setData({array: Group})
+                  that.nameRestriction(Group)
                 }
                 else{
                   wx.showModal({
@@ -507,12 +465,7 @@ Page({
                 group[key[0]].devices[key[1]].deviceName = res.content
                 wx.setStorageSync('group', group)
                 var Group = wx.getStorageSync('group')
-                for(let i = 0;i < Group.length;i++){
-                  if(Group[i].groupName.length > 10){
-                    Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
-                  }
-                }
-                that.setData({array: Group})
+                that.nameRestriction(Group)
               }
               else{
                 wx.showModal({
@@ -545,12 +498,7 @@ Page({
               group[key[0]].devices.splice(key[1],1)
               wx.setStorageSync('group', group)
               var Group = wx.getStorageSync('group')
-                for(let i = 0;i < Group.length;i++){
-                  if(Group[i].groupName.length > 10){
-                    Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
-                  }
-                }
-                that.setData({array: Group})
+              that.nameRestriction(Group)
               if(groupName == wx.getStorageSync('groupName') && deviceName == wx.getStorageSync('deviceName')){
                 wx.setStorageSync('deviceName','')
               }
@@ -586,94 +534,31 @@ Page({
       array:array
     })
   },
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad(options) {
-    wx.showToast({
-      title:'获取数据中',
-      icon:'loading',
-      duration: 2000
-    })
+  //分组和设备名称的显示限制
+  nameRestriction:function(Group){
     var that = this
-    getGroup().then(res => {
-      if(res.data.code == 0){
-        var data = res.data.data
-        if(data != null){
-          for(let i = 0;i <data.length;i++){
-            if(data[i].devices != null){
-              for(let j = 0;j < data[i].devices.length;j++){
-                if(data[i].devices[j].module == 0){
-                  let id = data[i].devices[j].deviceId
-                  let key = data[i].devices[j].deviceKey
-                  getBasic(id,key).then(ever =>{
-                    if(ever.data.errno == 0){
-                      if(ever.data.data.online == true){
-                        data[i].devices[j].status = '在线'
-                      }
-                      else{
-                        data[i].devices[j].status = '离线'
-                      }
-                      wx.setStorageSync('group',data)
-                      let tgroups = wx.getStorageSync('group')
-                      for(let i = 0;i < tgroups.length;i++){
-                        if(tgroups[i].groupName.length > 10){
-                          tgroups[i].groupName = tgroups[i].groupName.slice(0,9) + '....'
-                        }
-                      }
-                      that.setData({array:tgroups})
-                    }
-                    else{
-                      wx.showModal({
-                        title:'错误',
-                        content:ever.data.error,
-                        showCancel:false
-                      })
-                    }
-                  })
-                }
-                else{
-                  let status = data[i].devices[j].status
-                  switch(status){
-                    case 0:
-                      data[i].devices[j].status = '离线'
-                    break;
-                    case 1:
-                      data[i].devices[j].status = '在线'
-                    break
-                  }
-                  wx.setStorageSync('group',data)
-                  let tgroups = wx.getStorageSync('group')
-                  for(let i = 0;i < tgroups.length;i++){
-                    if(tgroups[i].groupName.length > 10){
-                      tgroups[i].groupName = tgroups[i].groupName.slice(0,9) + '....'
-                    }
-                  }
-                  that.setData({array:tgroups})
-                }
-              }
-            }
-            else{
-              wx.setStorageSync('group',data)
-              let group = wx.getStorageSync('group')
-              for(let i = 0;i < group.length;i++){
-                if(group[i].groupName.length > 10){
-                  group[i].groupName = group[i].groupName.slice(0,9) + '....'
-                }
-              }
-              that.setData({array:group})
-            }
+    for(let i = 0;i < Group.length;i++){
+      if(Group[i].groupName.length > 10){
+        Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
+      }
+      if(Group[i].devices != null){
+        for(let j = 0;j < Group[i].devices.length;j++){
+          if(Group[i].devices[j].deviceName.length > 10){
+            Group[i].devices[j].deviceName = Group[i].devices[j].deviceName.substr(-4)
+          }
+          if(Group[i].devices[j].deviceSn.length > 10){
+            Group[i].devices[j].deviceSn = Group[i].devices[j].deviceSn.substr(-4)
           }
         }
       }
-      else{
-        wx.showModal({
-          title:'错误',
-          content:res.data.msg,
-          showCancel:false
-        })
-      }
-    })
+    }
+    that.setData({array: Group})
+  },
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad(options) {
+    this.Refreshlist()
   },
 
   /**
@@ -686,6 +571,12 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
+    var that = this
+    setTimeout(function(){
+      if(that.data.array.length == 0){
+        that.Refreshlist()
+      }
+    },1000)
   },
 
   /**

+ 6 - 4
pages/scene/scene.wxml

@@ -13,10 +13,12 @@
       <image src="{{displaypicture}}" class="develop" bindtap="Develop" data-indexdel="{{child}}"></image>
       <image src="https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/delete.png" class="engineering-image-2" bindtap="removeapption" data-indexdel="{{child}}"></image>
     </view>
-    <view wx:for="{{item.devices}}" wx:key="id" class="develops"  wx:for-item="devices" hidden="{{item.insert?'true':''}}">
-      <text class="develops-1">{{devices.deviceSn}}</text>
-      <text class="develops-2">{{devices.deviceName}}</text>
-      <text class="develops-3">{{devices.status}}</text>
+    <view wx:for="{{item.devices}}" wx:key="id" class="develops"  wx:for-item="devices" hidden="{{item.insert?'':'true'}}">
+      <view class="develops-1">
+        {{devices.deviceSn}}
+      </view>
+      <view class="develops-2">{{devices.deviceName}}</view>
+      <view class="develops-3">{{devices.status}}</view>
       <image src="https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/set.png" style="right: 9%;" bindtap="modifyequipmentname" data-indexdel="{{[child,index]}}"></image>
       <image src="https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/delete.png" style="right: 2%;width:calc(100vw * 15/375);height: calc(100vw * 28/375);" bindtap="Deletedevice" data-indexdel="{{[child,index]}}"></image>
     </view>

+ 10 - 4
pages/scene/scene.wxss

@@ -109,15 +109,21 @@ page{
 
 .develops-1{
   position: absolute;
-  left: 5%;
-  top: 20%;
+  width: 30%;
+  height: 50%;
+  left: 2%;
+  top: 15%;
   font-size: calc(100vw * 14/375);
+  overflow: hidden;
 }
 
 .develops-2{
   position: absolute;
-  left: 50%;
-  top: 20%;
+  width: 30%;
+  height: 50%;
+  overflow: hidden;
+  left: 35%;
+  top: 15%;
   font-size: calc(100vw * 14/375);
 }
 

+ 0 - 3
pages/sign/sign.js

@@ -30,9 +30,6 @@ Page({
           header:{"Content-Type": "application/json"},
           success:function(res){
             if(res.data.code == 0){
-              let time = new Date()
-              wx.setStorageSync('time',time) //登录时间
-              wx.setStorageSync('currentTime', res.data.data.expires_in)//过期时间
               wx.setStorageSync('token', res.data.data.access_token)
               wx.switchTab({
                 url: '/pages/scene/scene',

+ 1 - 1
project.config.json

@@ -6,7 +6,7 @@
   },
   "setting": {
     "ignoreDevUnusedFiles": false,
-    "ignoreUploadUnusedFiles": false,
+    "ignoreUploadUnusedFiles": true,
     "bundle": false,
     "userConfirmedBundleSwitch": false,
     "urlCheck": true,

+ 14 - 1
project.private.config.json

@@ -6,5 +6,18 @@
     "urlCheck": true
   },
   "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
-  "libVersion": "2.19.6"
+  "libVersion": "2.19.6",
+  "condition": {
+    "miniprogram": {
+      "list": [
+        {
+          "name": "",
+          "pathName": "pages/control/control",
+          "query": "",
+          "launchMode": "default",
+          "scene": null
+        }
+      ]
+    }
+  }
 }

+ 19 - 0
utils/util.js

@@ -0,0 +1,19 @@
+const formatTime = date => {
+  const year = date.getFullYear()
+  const month = date.getMonth() + 1
+  const day = date.getDate()
+  const hour = date.getHours()
+  const minute = date.getMinutes()
+  const second = date.getSeconds()
+
+  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
+}
+
+const formatNumber = n => {
+  n = n.toString()
+  return n[1] ? n : `0${n}`
+}
+
+module.exports = {
+  formatTime
+}