瀏覽代碼

feature: 动态添加下午好标识

Damon 8 月之前
父節點
當前提交
a625c4b0cc
共有 4 個文件被更改,包括 71 次插入73 次删除
  1. 65 69
      pages/index/index.js
  2. 3 3
      pages/index/index.wxml
  3. 1 1
      pages/index/index.wxss
  4. 2 0
      pages/login/login.js

+ 65 - 69
pages/index/index.js

@@ -17,6 +17,8 @@ import route_constant from '../../utils/route_constant.js'
 
 Page({
   data: {
+    ///下午好
+    greeting: "",
     nvabarData: {
       showCapsule: 0, //是否显示左上角图标   1表示显示    0表示不显示
       title: 'OhPlay', //导航栏 中间的标题
@@ -46,55 +48,7 @@ Page({
     actionIndex: null,
     luoma: ["Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", " Ⅶ", "Ⅷ", "Ⅸ", "Ⅹ", "Ⅺ", "Ⅻ"],
     channelData: [],
-    deviceList: [{
-      "deviceId": "BLUFI_7cdfa1fcbb24",
-      "name": "BLUFI_7cdfa1fcbb24",
-      "state": "online",
-      "ProdModel": "MW-2AX(WIFI-N)",
-      "devName": "猫王小王子OTR-X"
-    }, {
-      "deviceId": "BLUFI_7cdfa1fcbb24",
-      "name": "BLUFI_7cdfa1fcbb24",
-      "state": "online",
-      "ProdModel": "MW-2AX(WIFI-N)",
-      "devName": "猫王小王子OTR-X"
-    }, {
-      "deviceId": "BLUFI_7cdfa1fcbb24",
-      "name": "BLUFI_7cdfa1fcbb24",
-      "state": "online",
-      "ProdModel": "MW-2AX(WIFI-N)",
-      "devName": "猫王小王子OTR-X"
-    }, {
-      "deviceId": "BLUFI_7cdfa1fcbb24",
-      "name": "BLUFI_7cdfa1fcbb24",
-      "state": "online",
-      "ProdModel": "MW-2AX(WIFI-N)",
-      "devName": "猫王小王子OTR-X"
-    }, {
-      "deviceId": "BLUFI_7cdfa1fcbb24",
-      "name": "BLUFI_7cdfa1fcbb24",
-      "state": "online",
-      "ProdModel": "MW-2AX(WIFI-N)",
-      "devName": "猫王小王子OTR-X"
-    }, {
-      "deviceId": "BLUFI_7cdfa1fcbb24",
-      "name": "BLUFI_7cdfa1fcbb24",
-      "state": "online",
-      "ProdModel": "MW-2AX(WIFI-N)",
-      "devName": "猫王小王子OTR-X"
-    }, {
-      "deviceId": "BLUFI_7cdfa1fcbb24",
-      "name": "BLUFI_7cdfa1fcbb24",
-      "state": "online",
-      "ProdModel": "MW-2AX(WIFI-N)",
-      "devName": "猫王小王子OTR-X"
-    }, {
-      "deviceId": "BLUFI_7cdfa1fcbb24",
-      "name": "BLUFI_7cdfa1fcbb24",
-      "state": "online",
-      "ProdModel": "MW-2AX(WIFI-N)",
-      "devName": "猫王小王子OTR-X"
-    }],
+    deviceList: [],
     deviceListIndex: null,
     showLogin: false,
     isOneLoading: true,
@@ -106,7 +60,7 @@ Page({
 
     ////我的界面
     loginStatus: true,
-    userName: "未登录",
+    nickname: "未登录",
     userPic: './../../img/head_pic.png',
     islogin: false,
   },
@@ -121,14 +75,30 @@ Page({
     var that = this;
     that.onHomeShow();
     that.onMeShow();
+    var nickname = that.data.nickname;
+    var greeting = that.updateGreeting();
+    if (nickname != "" && nickname != "未登录") {
+      greeting = greeting + ',' + nickname;;
+    }
+    console.log("gadfqwwerqewrqr===00==" + greeting);
+    console.log("gadfqwwerqewrqr===11==" + nickname);
+    that.setData({
+      greeting: greeting
+    });
+  },
 
-    getDevices({}).then((res) => {
-      console.log("gadfadfqwwerqewqr===" + JSON.stringify(res));
-      // wx.setStorage({
-      //   key: "channelData",
-      //   data: res
-      // });
-    })
+  updateGreeting() {
+    const now = new Date();
+    const hour = now.getHours();
+    let greeting;
+    if (hour >= 5 && hour < 12) {
+      greeting = '上午好';
+    } else if (hour >= 12 && hour < 18) {
+      greeting = '下午好';
+    } else {
+      greeting = '晚上好';
+    }
+    return greeting;
   },
 
   onHomeLoad() {
@@ -177,18 +147,30 @@ Page({
 
   onMeLoad() {
     // wx.getStorage("userInfo")
-    const _this = this;
+    var that = this;
     wx.getStorage({
       key: "userInfo",
       success(res) {
         if (!res.data.phone) {
           return;
         };
-        _this.setData({
-          userName: res.data.nickname || "",
+
+        var nickname = res.data.nickname || "";
+        console.log("gadfqwwerqewrqr===44==" + res.data.nickname);
+        var greeting = that.updateGreeting();
+        if (nickname != "" && nickname != "未登录") {
+          greeting = greeting + ',' + nickname;;
+        }
+
+        console.log("gadfqwwerqewrqr===22==" + greeting);
+        console.log("gadfqwwerqewrqr===33==" + nickname);
+        that.setData({
+          greeting: greeting,
+          nickname: nickname,
           userPic: res.data.headUrl || "",
           islogin: true,
-        })
+        });
+
       }
     })
   },
@@ -671,20 +653,26 @@ Page({
   },
 
   goMeLogin() {
-    const _this = this;
-    if (this.data.islogin) {
+    const that = this;
+    if (that.data.islogin) {
       // 退出登录
       wx.removeStorage({
         key: 'userInfo',
         success(res) {
-          _this.setData({
+          var nickname = "未登录";
+          var greeting = that.updateGreeting();
+          if (nickname != "" && nickname != "未登录") {
+            greeting = greeting + ',' + nickname;;
+          }
+          that.setData({
+            greeting: greeting,
             islogin: false,
-            userName: "未登录",
+            nickname: nickname,
             userPic: "./../../img/head_pic.png",
           });
-          wx.switchTab({
-            url: `./../index/index`
-          });
+          // wx.switchTab({
+          //   url: `./../index/index`
+          // });
         }
       });
       wx.removeStorage({
@@ -802,4 +790,12 @@ Page({
     });
   },
 
-})
+})
+
+// getDevices({}).then((res) => {
+//   console.log("gadfadfqwwerqewqr===" + JSON.stringify(res));
+//   // wx.setStorage({
+//   //   key: "channelData",
+//   //   data: res
+//   // });
+// })

+ 3 - 3
pages/index/index.wxml

@@ -6,7 +6,7 @@
 <view class="container">
   <view wx:if="{{indexPage==0}}" class="mair" style="height: calc(100vh - 120rpx - {{navBarHeight}}px);">
 
-    <view style="font-size: 32rpx; color: #333333; margin-top: 14rpx;">下午好,Demon</view>
+    <view style="font-size: 32rpx; color: #333333; margin-top: 14rpx;">{{greeting}}</view>
 
     <!-- banner-->
     <view wx:if="{{bannerList.length>0}}" class="banner_container">
@@ -28,7 +28,7 @@
 
       <view wx:if="{{deviceList}}">
         <block wx:key="key" wx:for-item="item" wx:for-index="index" wx:for="{{deviceList}}">
-          <view class="item_public" style="width: calc(100vw - 68rpx);border: {{item.state && item.state === 'online'&&deviceListIndex === index  ? '4rpx solid #6546A3' : item.state && item.state === 'online'?'2rpx solid #6546A3':'2rpx solid #F2F5F7'}};" data-item="{{item}}" bind:tap="{{item.state && item.state === 'online' ? 'onTapIem' : ''}}">
+          <view class="item_public" style="width: calc(100vw - 72rpx);border: {{item.state && item.state === 'online'&&deviceListIndex === index  ? '4rpx solid #6546A3' : item.state && item.state === 'online'?'2rpx solid #6546A3':'2rpx solid #F2F5F7'}}; margin-left: {{item.state && item.state === 'online'&&deviceListIndex === index  ?0:4}}rpx;" data-item="{{item}}" bind:tap="{{item.state && item.state === 'online' ? 'onTapIem' : ''}}">
             <image class="item_public_image" src="./../../img/min.png" style="opacity: {{item.state && item.state === 'online' ? '1' : '0.5'}};"></image>
             <view class="item_public_right" style="margin-right: 26rpx; opacity: {{item.state && item.state === 'online' ? '1' : '0.5'}};">
               <view style="height: 190rpx; margin-top: 37rpx; margin-left: 32rpx; flex-direction: column; display: flex;">
@@ -129,7 +129,7 @@
       <view wx:elif="{{indexPage==2}}" class="me" style="height: calc(100vh - 100rpx - {{navBarHeight}}px);">
         <view class="head-logo">
           <image mode="scaleToFill" src="{{userPic}}"></image>
-          <text class="userName" wx:if="{{userName}}">{{userName}}</text>
+          <text class="nickname" wx:if="{{nickname}}">{{nickname}}</text>
         </view>
         <view class="br"></view>
         <view class="list">

+ 1 - 1
pages/index/index.wxss

@@ -623,7 +623,7 @@
    color: #999;
  }
 
- .me .head-logo .userName {
+ .me .head-logo .nickname {
    color: #353535;
  }
 

+ 2 - 0
pages/login/login.js

@@ -96,6 +96,8 @@ Page({
         openid: app.globalData.userInfo.openid,
         code: e.detail.code,
       }).then((res) => {
+
+        console.log("gadfqwwerqewrqr===啊啊啊啊==" + JSON.stringify(res));
         wx.showToast({
           title: "登陆成功",
           icon: 'success',