Sfoglia il codice sorgente

增加webview异常通知;首页底部空间增加填充逻辑

yangguanjin 1 settimana fa
parent
commit
b419a2c724
2 ha cambiato i file con 43 aggiunte e 3 eliminazioni
  1. 31 2
      src/pages/home/index.vue
  2. 12 1
      src/pages/loading/index.vue

+ 31 - 2
src/pages/home/index.vue

@@ -16,6 +16,7 @@
 <template>
   <view class="home-container">
     <scroll-view class="scroll-view" scroll-y>
+      <view class="scroll-content">
       <!-- 状态栏占位 -->
       <view class="status-bar-placeholder" :style="{ height: statusBarHeight + 'px' }"></view>
 
@@ -74,6 +75,10 @@
           </view>
         </view>
       </view>
+      </view>
+
+      <!-- 底部留白占位:内容超出屏幕时补充底部间距 -->
+      <view v-if="bottomSpacerHeight > 0" :style="{ height: bottomSpacerHeight + 'px' }"></view>
     </scroll-view>
 
     <!-- 网络状态提示 -->
@@ -108,7 +113,7 @@
 </template>
 
 <script lang="ts" setup>
-import { ref, reactive, computed, onMounted, onUnmounted } from 'vue'
+import { ref, reactive, computed, onMounted, onUnmounted, nextTick } from 'vue'
 import { onShow, onLoad } from '@dcloudio/uni-app'
 import { useUserStore } from '@/store/user'
 import { useConfigStore } from '@/store/config'
@@ -132,8 +137,10 @@ const refresh = ref(false)
 const userId = ref('')
 const cardItemRef = reactive<Record<string, any>>({})
 const windowWidth = ref(0)
+const windowHeight = ref(0)
 const statusBarHeight = ref(20)
 const networkStatus = ref(true)
+const bottomSpacerHeight = ref(0)
 
 const userStore = useUserStore()
 const userInfo = computed(() => userStore.userInfo)
@@ -185,13 +192,34 @@ onShow(() => {
   refreshAllCards()
 })
 
-// 获取屏幕宽度
+// 获取屏幕信息
 const getWindowWidth = () => {
   const systemInfo = uni.getSystemInfoSync()
   windowWidth.value = systemInfo.windowWidth || 375
+  windowHeight.value = systemInfo.windowHeight || 667
   statusBarHeight.value = systemInfo.statusBarHeight || 20
 }
 
+// 计算底部留白占位高度
+const calcBottomSpacer = () => {
+  nextTick(() => {
+    const query = uni.createSelectorQuery()
+    query.select('.scroll-content').boundingClientRect()
+    query.exec((res) => {
+      if (res && res[0]) {
+        const contentHeight = (res[0] as UniApp.NodeInfo).height || 0
+        const minBottomSpace = 40
+        // 内容超出可视区域时,补充底部间距
+        if (contentHeight > windowHeight.value - minBottomSpace) {
+          bottomSpacerHeight.value = minBottomSpace * 1.5
+        } else {
+          bottomSpacerHeight.value = 0
+        }
+      }
+    })
+  })
+}
+
 // 监听网络状态
 const onNetworkStatusChange = (res: any) => {
   networkStatus.value = res.isConnected
@@ -223,6 +251,7 @@ onMounted(() => {
   getWindowWidth()
   getUserId()
   checkNetworkStatus()
+  calcBottomSpacer()
 
   // 监听网络状态变化
   uni.onNetworkStatusChange(onNetworkStatusChange)

+ 12 - 1
src/pages/loading/index.vue

@@ -163,7 +163,7 @@ const doLogin = async (
 
     if (!loginRes || loginRes.code !== 0 || !loginData) {
       statusText.value = '加载失败: ' + (loginRes?.msg || '未知错误')
-      uni.showToast({ title: statusText.value, icon: 'none' })
+      tellRNLoadingError(statusText.value)
       return
     }
 
@@ -187,6 +187,7 @@ const doLogin = async (
   } catch (error) {
     console.error('[LoadingPage] 加载失败:', error)
     statusText.value = '加载失败,请重试'
+    tellRNLoadingError(statusText.value)
   } finally {
     if (fromType.value !== 'APP') {
       uni.hideLoading()
@@ -194,6 +195,15 @@ const doLogin = async (
   }
 }
 
+const tellRNLoadingError = (message: string) => {
+  if (window.ReactNativeWebView) {
+    window.ReactNativeWebView.postMessage(JSON.stringify({
+      type: 'loadingError',
+      message: message,
+    }))
+  }
+}
+
 // 获取用户信息
 const fetchUserInfo = async (userId: string, overrideUsername?: string) => {
   try {
@@ -215,6 +225,7 @@ const fetchUserInfo = async (userId: string, overrideUsername?: string) => {
     }
   } catch (error) {
     console.error('[LoadingPage] 加载页面失败:', error)
+    tellRNLoadingError(statusText.value)
   }
 }