ソースを参照

feat: 修改休息未读角标

linwenxin 1 年間 前
コミット
aead2c0b16
3 ファイル変更68 行追加55 行削除
  1. 13 9
      src/App.vue
  2. 49 43
      src/common/utils/util.js
  3. 6 3
      src/pages/message/index.vue

+ 13 - 9
src/App.vue

@@ -1,14 +1,12 @@
 <script>
   import Vue from 'vue';
+  import {
+    getUserInfo
+  } from "@/common/utils/util"
 
+  var getUserValTimeId = null
   export default {
-    onLaunch: function() {
-      
-      // tab数字角标
-      // uni.setTabBarBadge({
-      //   index: 2,
-      //   text: '2'
-      // })
+    onLaunch: function() {
 
       // #ifdef MP-WEIXIN
       // 小程序更新
@@ -70,7 +68,13 @@
     methods: {
       // #ifdef MP-WEIXIN
       async updateUserInfo() {
-
+        (function getUserVal() {
+          if (getUserValTimeId) {
+            clearTimeout(getUserValTimeId)
+          }
+          getUserInfo()
+          getUserValTimeId = setTimeout(getUserVal, 2000)
+        })()
       },
       // #endif
     },
@@ -82,4 +86,4 @@
   @import "uview-ui/index.scss";
 
   @import "styles/iconfont.css";
-</style>
+</style>

+ 49 - 43
src/common/utils/util.js

@@ -11,6 +11,12 @@ export const getUserInfo = () => {
         const {
           data
         } = response;
+
+        // tab数字角标
+        uni.setTabBarBadge({
+          index: 2,
+          text: data.unread
+        })
         uni.setStorageSync('recycle_mobile_user', data);
         resolve(data);
       })
@@ -35,49 +41,49 @@ const createName = function(name) {
 
 // 图片上传
 export const uploadImg = async function(file) {
-	console.log(file);
-	uni.showLoading({
-		mask: true,
-	})
-	
-	// 获取oss配置
-	const par = await axios({
-		url: '/common/oss/config',
-		method: 'get'
-	}).then(res=>{
-		return res.data;
-	}).catch(err=>{
-		uni.hideLoading();
-	})
-	
-	const fileKey = par.dir + createName(file.path);
-	
-	return new Promise((resolve, reject) => {
-		uni.uploadFile({
-			url: par.host,
-			// header: {
-			// 	"Content-Type": 'multipart/form-data',
-			// },
-			name: 'file',
-			formData:{
-				...par,
-				name: file.name,
-				key: fileKey
-			},
-			filePath: file.path,
-			success(res) {
-				resolve({
-					url: fileKey
-				})
-			},
-			fail(err) {
-				reject(err)
-			},
-			complete(res) {
-				uni.hideLoading();
-			}
-		})
-	})
+  console.log(file);
+  uni.showLoading({
+    mask: true,
+  })
+
+  // 获取oss配置
+  const par = await axios({
+    url: '/common/oss/config',
+    method: 'get'
+  }).then(res => {
+    return res.data;
+  }).catch(err => {
+    uni.hideLoading();
+  })
+
+  const fileKey = par.dir + createName(file.path);
+
+  return new Promise((resolve, reject) => {
+    uni.uploadFile({
+      url: par.host,
+      // header: {
+      // 	"Content-Type": 'multipart/form-data',
+      // },
+      name: 'file',
+      formData: {
+        ...par,
+        name: file.name,
+        key: fileKey
+      },
+      filePath: file.path,
+      success(res) {
+        resolve({
+          url: fileKey
+        })
+      },
+      fail(err) {
+        reject(err)
+      },
+      complete(res) {
+        uni.hideLoading();
+      }
+    })
+  })
 }
 
 export const getArea = function(str) {

+ 6 - 3
src/pages/message/index.vue

@@ -14,10 +14,12 @@
           <view class="message_user_a">
             <view class="message_user_info">
               <!-- 头像 -->
-              <view class="user_head">
+              <view class="user_head" style="position: relative;">
                 <image v-if="item.userPic" style="width: 100%; height: 100%;" mode="aspectFill"
                   :src="imageUrl + item.userPic"></image>
                 <image v-else style="width: 100%; height: 100%;" mode="aspectFill" src="@/static/common/logo.png">
+                </image>
+                <u-badge type="error" :value="item.unread" :absolute="true" :offset="[0,0]"></u-badge>
               </view>
               <view class="user_info">
                 <!-- 姓名 -->
@@ -56,6 +58,7 @@
       }
     },
     onShow() {
+      uni.$emit("updateUserInfo")
       var getList = () => {
         if (this.timeId) {
           clearTimeout(this.timeId)
@@ -66,7 +69,7 @@
           pageSize: -1
         }, false).then(res => {
           this.list = res.data.records
-          this.timeId = setTimeout(getList, 3000)
+          this.timeId = setTimeout(getList, 2000)
         })
       }
       getList()
@@ -298,4 +301,4 @@
       }
     }
   }
-</style>
+</style>