فهرست منبع

购物车数量和商城首页同步

skyblued 3 سال پیش
والد
کامیت
d484395b9a
3فایلهای تغییر یافته به همراه8 افزوده شده و 3 حذف شده
  1. 6 1
      src/views/shop-mall/index.tsx
  2. 1 1
      src/views/shop-mall/modal/add-goods-cart/index.tsx
  3. 1 1
      src/views/shop-mall/shop-mall.ts

+ 6 - 1
src/views/shop-mall/index.tsx

@@ -23,7 +23,7 @@ import { useRect } from '@vant/use'
 import { postMessage } from '@/helpers/native-message'
 import ColSearch from '@/components/col-search'
 import { browser } from '@/helpers/utils'
-import { cartCount } from './shop-mall'
+import { cartCount, getCartCount } from './shop-mall'
 
 export default defineComponent({
   name: 'shop-mall',
@@ -40,6 +40,11 @@ export default defineComponent({
   },
   mounted() {
     this.init()
+    document.addEventListener('visibilitychange', () => {
+      if (document.hidden){
+        getCartCount()
+      }
+    })
   },
   methods: {
     onSearch() {},

+ 1 - 1
src/views/shop-mall/modal/add-goods-cart/index.tsx

@@ -64,7 +64,7 @@ export default defineComponent({
       const radio = this.radio
       const select = this.skuStockList.find((n: any) => n.id == radio) as any
       if (select) {
-        let stock : number = select.stock - select.lockStock - select.cartNum
+        let stock : number = select.stock - select.lockStock //- select.cartNum
         return {
           ...select,
           stock

+ 1 - 1
src/views/shop-mall/shop-mall.ts

@@ -14,7 +14,7 @@ export const orderState = {
 export const cartCount = ref(0)
 export const getCartCount = async () => {
   try {
-    let {data: {count}} = await request.get('/api-mall-portal/home/content')
+    let {data: {count}} = await request.get('/api-mall-portal/home/content', {hideLoading: true})
     if (count) cartCount.value = count
   } catch (error) {