Pārlūkot izejas kodu

enh: 优化消息系统(前端)

joe 4 gadi atpakaļ
vecāks
revīzija
289f1a404d

+ 1 - 1
view/xcx/api/message.js

@@ -7,7 +7,7 @@ import request from "./../utils/request.js";
 /**
  * 获取列表
 */
-export function getMessages(page, limit = 20) {
+export function getMessages(page, limit = 30) {
   return request.get("user/messages", {page: page, limit: limit});
 }
 

+ 6 - 3
view/xcx/pages/goods_details/index.js

@@ -207,7 +207,6 @@ Page({
         'sharePacket.isState': isState,
         uid: res.data.uid
       });
-      app.globalData.unread = res.data.notice
     });
   },
   /**
@@ -327,10 +326,14 @@ Page({
       //记录推广人uid
       if (value.pid) app.globalData.spid = value.pid;
     }
-    if (!options.id) return app.Tips({ title: '缺少参数无法查看商品' }, { tab: 3, url: 1 });
+    if (!options.id) {
+      return app.Tips({ title: '缺少参数无法查看商品' }, { tab: 3, url: 1 });
+    }
     this.setData({ id: options.id });
     //记录推广人uid
-    if (options.spid) app.globalData.spid = options.spid;
+    if (options.spid) {
+      app.globalData.spid = options.spid;
+    }
     this.getGoodsDetails();
     this.getList();
   },

+ 9 - 20
view/xcx/pages/message/index.js

@@ -3,8 +3,6 @@ import { getProductHot } from '../../api/store.js';
 import { getMessages, readMessages } from "../../api/message"
 import { tsToString } from "../../utils/util"
 
-var base64 = require("../../utils/base64")
-
 const app = getApp();
 
 Page({
@@ -22,7 +20,6 @@ Page({
     host_product:[],
     iShidden: false,
     page: 0,
-    unread: 0,
     messages: []
   },
 
@@ -30,7 +27,9 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    if (app.globalData.token) this.setData({ iShidden:true});
+    if (app.globalData.token) {
+      this.setData({ iShidden:true});
+    }
   },
 
   /**
@@ -41,7 +40,6 @@ Page({
 
   onLoadFun: function() {
     this.pullMessageList();
-    this.get_host_product();
   },
 
   /**
@@ -50,12 +48,12 @@ Page({
   onShow: function () {
     if (app.globalData.isLog) {
       this.data.page = 1;
-      this.get_host_product();
       this.pullMessageList();
       this.setData({
         iShidden: true
       });
     }
+    app.setUnread(app.globalData.unread); // 从详情页面返回,更新已读
   },
 
   /**
@@ -83,23 +81,19 @@ Page({
   pullMessageList() {
     var that = this;
     getMessages(that.data.page).then(res=>{
-      var unread = 0;
       res.data.forEach(function(row){
         row.ts = tsToString(row.ts)
         row.read = row.read == null ? false : true
-        if (!row.read){
-          unread += 1
-        }
       })
-
-      app.setUnread(unread)
       
       that.setData({
         messages: res.data,
-        unread: unread
       });
-    }, err=> {
 
+      if (!this.message || this.messages.length <= 0) {
+        this.get_host_product();
+      }
+    }, err=> {
     });
   },
 
@@ -107,13 +101,8 @@ Page({
     if (!e.currentTarget.dataset.items.read) {
       var that = this
       readMessages([e.currentTarget.dataset.items.id]).then(res=>{
-        that.setData({
-          unread: that.data.unread-1,
-        })
-        // app.globalData.unread = res.data.unread
-        app.setUnread(res.data.unread)
+        app.globalData.unread -= 1;
       })
-      
     }
     wx.navigateTo({
       url: '/pages/message_details/index?data=' + encodeURIComponent(JSON.stringify(e.currentTarget.dataset.items)),

+ 2 - 2
view/xcx/pages/message/index.wxml

@@ -12,9 +12,9 @@
         <image src="{{item.icon}}"></image>
       </view>
       <view class="content">
-        <view class="title">{{item.subject}}</view>
+        <view class="title {{item.read?'color_read':''}}">{{item.subject}}</view>
         <view class="header">
-          <view class="from">来自 {{item.from}}</view>
+          <view class="from">来自{{item.from}}</view>
           <view class="time">{{ item.ts }}</view>
         </view>
       </view>

+ 3 - 2
view/xcx/pages/message/index.wxss

@@ -9,5 +9,6 @@
 .message .list .item .content { margin-left: 20rpx; width: 82%; }
 .message .list .item .content .header {display: flex; margin: 20rpx 0;}
 .message .list .item .content .title { font-size: 32rpx; width: 50%; text-align: left; }
-.message .list .item .content .header .time { font-size: 28rpx; color: #a1a1a1; width: 50%; text-align: right; margin-right: 20rpx; }
-.message .list .item .content .header .from { font-size: 28rpx; color: #a1a1a1; text-align: left; }
+.message .list .item .content .color_read { color: #a1a1a1;}
+.message .list .item .content .header .time { font-size: 26rpx; color: #a1a1a1; width: 50%; text-align: right; margin-right: 20rpx; }
+.message .list .item .content .header .from { font-size: 26rpx; color: #a1a1a1; text-align: left; }

+ 1 - 1
view/xcx/pages/message_details/index.wxml

@@ -2,7 +2,7 @@
 <view class="message_details">
   <!-- <view class="title">{{title}}</view> -->
   <view class="header">
-    <view class="from">来自:{{from}}</view>
+    <view class="from">来自{{from}}</view>
     <view class="date">{{date}}</view>
   </view>
   <view class="content">

+ 3 - 3
view/xcx/pages/message_details/index.wxss

@@ -2,9 +2,9 @@
 .message_details { margin: auto; }
 .message_details .title { width: 100%; text-align: center; font-size: 36rpx; font-weight: bold; padding: 20rpx; background-color: #fff; }
 .message_details .header{ display: flex; width: 100%; background-color: #fff; padding: 30rpx; margin-bottom: 20rpx; }
-.message_details .header .from { color: gray; width: 50%; text-align: left; }
-.message_details .header .date { color: gray; width: 50%; text-align: right; }
-.message_details .content { background-color: #fff; padding: 30rpx; }
+.message_details .header .from {font-size: 26rpx; color: gray; width: 50%; text-align: left; }
+.message_details .header .date {font-size: 26rpx; color: gray; width: 50%; text-align: right; }
+.message_details .content { font-size: 32rpx; background-color: #fff; padding: 30rpx; }
 .message_details .bottom { position: fixed; bottom: 30rpx; text-align: center; width: 100%; }
 .message_details .bottom button { width: 90%; background-color: red; border-radius: 20rpx; color: #fff; height: 80rpx; line-height: 80rpx; margin: auto; }