Ver código fonte

Merge branch 'dev_v3_lqw' into dev_v3

ext.liuqiwen3 1 mês atrás
pai
commit
f1cab01a2f
3 arquivos alterados com 30 adições e 22 exclusões
  1. 2 1
      pages.json
  2. 23 7
      pages/index/index.vue
  3. 5 14
      pages/order_addcart/order_addcart.vue

+ 2 - 1
pages.json

@@ -14,7 +14,8 @@
         "navigationBarTitleText": "首页",
         "navigationBarBackgroundColor": "#ffe079",
         "navigationBarTextStyle": "black",
-        "navigationStyle": "custom"
+        "navigationStyle": "custom",
+        "enablePullDownRefresh": true
       }
     },
     {

+ 23 - 7
pages/index/index.vue

@@ -23,6 +23,7 @@
       :showBackTop="showBackTop" 
       @backTop="scrollToTop"
     />
+
     <!-- <view class="page-index" :class="{ bgf: navIndex > 0 }"> -->
     <view class="page-index">
       <view class="top-box jianbianBG">
@@ -178,7 +179,7 @@
 <script setup>
 // 获取实时金价
 import useRealGoldPrice from "@/hooks/useRealGoldPrice";
-import { onLoad, onShow, onReachBottom,onPageScroll } from "@dcloudio/uni-app";
+import { onLoad, onShow, onReachBottom,onPageScroll,onPullDownRefresh } from "@dcloudio/uni-app";
 import {ref, onMounted, reactive, computed, getCurrentInstance, watch, nextTick} from "vue";
 import { getIndexData, getCoupons, setCouponReceive, getMerchantBannerList } from "@/api/api.js";
 import {
@@ -273,7 +274,6 @@ const calculatedProducts = computed(() => {
   });
 });
 onLoad(async (options) => {
-  console.log('onLOAD')
   const params = await getSceneInfo(options,'index');
   // 2. 设置商户ID
   const isLogin = appStore.isLogin;
@@ -300,27 +300,26 @@ onLoad(async (options) => {
 onShow(async () => {
   // 隐藏原生 tabBar,使用自定义 tabBar
   uni.hideTabBar();
-  console.log('appStore.userInfo',appStore.userInfo)
   const isLogin = appStore.isLogin;
   if(isLogin){
     rightsStore.getUserBenefits(appStore.userInfo?.userId);
     getUserBenefits();
   }
   if (appStore.merchantId && appStore.merchantId !== '') {
-    console.log('111111111')
     merchantId.value = appStore.merchantId;
     if (!isLogin) {
       toLogin();
       return; // 登录后页面会刷新,避免继续执行
     }
   }else if(appStore?.userInfo?.lastVisitedMerchantId){
-    console.log('2222222222222222')
     merchantId.value = appStore?.userInfo?.lastVisitedMerchantId;
+    if(!merchantInfo.merchantName){
+      initPageData();
+    }
   } else if (appStore?.userInfo?.merchant?.id) {
-    console.log('333333333333333')
     merchantId.value = appStore.userInfo.merchant.id;
     if(!merchantInfo.merchantName){
-      getSbmerchantInfoFn()
+      initPageData();
     }
   } else {
     merchantId.value = '';
@@ -333,6 +332,19 @@ onShow(async () => {
 
 
 });
+const onRefresh = () => {
+  refreshing.value = true;
+
+  Promise.allSettled([
+    initPageData()
+  ]).finally(() => {
+    // 添加一个短暂延迟,确保 DOM 更新完成
+    setTimeout(() => {
+      refreshing.value = false;
+      uni.hideLoading();
+    }, 50);
+  });
+};
 const initPageData = async () => {
   try {
     loading.value = true;
@@ -556,6 +568,10 @@ onPageScroll((e) => {
     showBackTop.value = false;
   }
 })
+onPullDownRefresh(async () => {
+  await initPageData();
+  uni.stopPullDownRefresh();
+})
 
 // 回到顶部
 const scrollToTop = () => {

+ 5 - 14
pages/order_addcart/order_addcart.vue

@@ -1,10 +1,5 @@
 <template>
 <!--  <view style="min-height: 100%;">-->
-    <up-pull-refresh
-        :refreshing="refreshing"
-        :threshold="60"
-        @refresh="onRefresh"
-    >
     <view class="shoppingCart copy-data">
       <view class="borRadius14">
           <view
@@ -293,7 +288,6 @@
         </view>
       </view>
     </view>
-    </up-pull-refresh>
     <view
       class="footer acea-row row-between-wrapper"
       v-if="cartList.valid.length > 0"
@@ -425,7 +419,6 @@ const isLogin = computed(()=>appStore.isLogin);
 // 添加全选的值控制
 const allCheckboxValue = ref([]);
 
-const refreshing = ref(false);
 
 // 监听isAllSelect的变化,同步到allCheckboxValue
 watch(isAllSelect, (newVal) => {
@@ -463,15 +456,11 @@ onShow(() => {
   // 隐藏原生 tabBar
   uni.hideTabBar();
 });
-
-const onRefresh = () => {
-  console.log('refresj=========')
-  refreshing.value = true;
+onPullDownRefresh(async () => {
   canShow.value = false;
   if (isLogin.value) {
     // 重置所有状态
     resetAllState();
-    console.log('+++++++++++++=========')
     Promise.allSettled([
       getCartListFn(),
       getInvalidList(),
@@ -480,12 +469,14 @@ const onRefresh = () => {
       // 添加一个短暂延迟,确保 DOM 更新完成
       setTimeout(() => {
         canShow.value = true;
-        refreshing.value = false;
+        uni.stopPullDownRefresh();
         uni.hideLoading();
       }, 50);
     });
   }
-};
+
+})
+
 function resetAllState() {
   footerswitch.value = true;
   goodsHidden.value = false;