Pārlūkot izejas kodu

Merge branch 'master' of ssh://gogs.zfire.top:2222/zfire-front/recycle-mobile

* 'master' of ssh://gogs.zfire.top:2222/zfire-front/recycle-mobile:
  feat:修改数据类型
  feat: 修改休息未读角标
  feat: 修改数据
  feat: 减少环境下不必要的执行
Moss 1 gadu atpakaļ
vecāks
revīzija
cdcd9a90ca
5 mainītis faili ar 126 papildinājumiem un 109 dzēšanām
  1. 13 9
      src/App.vue
  2. 45 54
      src/common/utils/navPag.js
  3. 48 43
      src/common/utils/util.js
  4. 15 1
      src/pages/goods/order.vue
  5. 5 2
      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>

+ 45 - 54
src/common/utils/navPag.js

@@ -90,20 +90,7 @@ export const navToPage = (function() {
   }
 })()
 
-// var curRouteH5 = {}
-// var curRouteMini = {}
-
 export function webViewHref(url, pam = {}, crossPagePam = {}) {
-
-
-  // if(crossPagePam.crossPageTs){
-  //   var funs = Object.keys(JSON.parse(decodeURIComponent(crossPagePam.crossPageTs)))
-  //   var H5 = Object.keys(curRouteH5).find(_url=>!!~url.indexOf(_url))
-  //   var Mini = Object.keys(curRouteMini).find(_url=>!!~url.indexOf(_url))
-  // }else{
-
-  // }
-
   var defaultPam = {
     ...pam,
     ...crossPagePam,
@@ -126,8 +113,6 @@ export function webViewHref(url, pam = {}, crossPagePam = {}) {
   }
 }
 
-
-
 export const crossPage = (function() {
   var funs = {}
   var tiemIdIs = {}
@@ -164,6 +149,7 @@ export const crossPage = (function() {
 
   var funco = {
     $emit(name, data) {
+      // 同个环境下可以触发
       if (funs[name]) {
         Object.keys(funs[name]).map(key => {
           funs[name][key](data)
@@ -171,21 +157,34 @@ export const crossPage = (function() {
       }
 
       // #ifndef H5
+      // 用于小程序触发更新H5页面
       datacd.push([name, data])
       delaydeparture()
       // #endif
 
       // #ifdef H5
-      var postMessage = (window.uniWebview && window.uniWebview.postMessage) || (window.postMessage)
-      if (postMessage) {
-        postMessage({
-          data: {
-            type: "crossPageTs",
-            name,
-            data
+      // h5在小程序环境下通过定时器传送
+      wx.miniProgram.getEnv(res => {
+        if (res.miniprogram) {
+          var postMessage = (window.uniWebview && window.uniWebview.postMessage) || (window.postMessage)
+          if (postMessage) {
+            postMessage({
+              data: {
+                type: "crossPageTs",
+                name,
+                data
+              }
+            })
           }
-        })
-      }
+          if (tiemIdIs[name]) {
+            clearTimeout(tiemIdIs[name])
+          }
+          uni.setStorageSync(name, data);
+          tiemIdIs[name] = setTimeout(function() {
+            uni.removeStorageSync(name)
+          }, 350)
+        }
+      })
       // #endif
     },
 
@@ -193,40 +192,11 @@ export const crossPage = (function() {
       if (!funs[name]) {
         funs[name] = {}
       }
-      let funcName = md5(fun.toString())
-      funs[name][funcName] = fun;
+      funs[name][md5(fun.toString())] = fun
 
       // #ifdef H5
       delaydepartFun()
       // #endif
-
-      // -----------------------------------
-      // (function getrouter() {
-      //   let routes = getCurrentPages();
-      //   if (routes.length) {
-      //     let curRoute = routes[routes.length - 1].route
-      //     wx.miniProgram.getEnv(res => {
-      //       if (res.miniprogram) {
-      //         if (!curRouteMini[curRoute]) {
-      //           curRouteMini[curRoute] = []
-      //         }
-      //         if (!!~curRouteMini[curRoute].indexOf(name)) {
-      //           curRouteMini[curRoute].push(name)
-      //         }
-      //       } else {
-      //         if (!curRouteH5[curRoute]) {
-      //           curRouteH5[curRoute] = []
-      //         }
-      //         if (!!~curRouteH5[curRoute].indexOf(name)) {
-      //           curRouteH5[curRoute].push(name)
-      //         }
-      //       }
-      //     })
-
-      //   } else {
-      //     setTimeout(getrouter, 300)
-      //   }
-      // })();
     },
 
     $off(name, fun) {
@@ -256,5 +226,26 @@ export const crossPage = (function() {
     },
     // #endif
   };
+
+  // #ifdef H5
+  wx.miniProgram.getEnv(res => {
+    if (res.miniprogram) {
+      (function tiemID() {
+        Object.keys(funs).map(name => {
+          if (funs[name]) {
+            var data = uni.getStorageSync(name);
+            if (data) {
+              Object.keys(funs[name]).map(key => {
+                funs[name][key](data)
+              })
+            }
+          }
+        })
+        setTimeout(tiemID, 200)
+      })()
+    }
+  })
+  // #endif
+
   return funco
 })()

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

@@ -11,6 +11,11 @@ export const getUserInfo = () => {
         const {
           data
         } = response;
+        // tab数字角标
+        uni.setTabBarBadge({
+          index: 2,
+          text: data.unread + ""
+        })
         uni.setStorageSync('recycle_mobile_user', data);
         resolve(data);
       })
@@ -35,49 +40,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) {

+ 15 - 1
src/pages/goods/order.vue

@@ -61,6 +61,7 @@
     onLoad(pam) {
       this.pam = pam
       this.getGoods()
+      this.getAddList()
       uni.$on("chooseAddress", (data) => {
         this.hasAddress = true
         this.addressInfo = data
@@ -73,6 +74,19 @@
 
     },
     methods: {
+      getAddList() {
+        this.$api.get('/user/address/list', {
+          pageNum: 1,
+          pageSize: -1,
+          userId: this.$store.state.user.userId
+        }).then(res => {
+          var data = res.data.records.find(item => item.defaultAddr)
+          if (data) {
+            this.hasAddress = true
+            this.addressInfo = data
+          }
+        })
+      },
       submitOrder() {
         if (!this.btnBool) {
           return
@@ -327,4 +341,4 @@
       margin: 0;
     }
   }
-</style>
+</style>

+ 5 - 2
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()