Explorar el Código

bugfix:补全index

XieXing hace 4 meses
padre
commit
d5ba664066
Se han modificado 1 ficheros con 27 adiciones y 1 borrados
  1. 27 1
      shudao-vue-frontend/src/views/mobile/m-Index.vue

+ 27 - 1
shudao-vue-frontend/src/views/mobile/m-Index.vue

@@ -163,7 +163,7 @@
 </template>
 
 <script setup>
-import { ref, computed, onMounted, watch } from 'vue'
+import { ref, computed, onMounted, watch, onBeforeUnmount } from 'vue'
 import { useRouter } from 'vue-router'
 import FeedbackModal from '@/components/MobileFeedbackModal.vue'
 import { apis } from '@/request/apis.js'
@@ -436,6 +436,32 @@ onMounted(() => {
     username: username || '蜀道用户'
   }
   console.log('用户信息:', userInfo.value)
+
+  // 原生导航控制
+  try {
+    if (window.bridge && window.bridge.callNative) {
+      console.log('📱 初始化原生导航栏控制')
+      // 显示原生导航栏
+      window.bridge.callNative("showNativeNav", 1);
+      
+      // 注册返回回调
+      window.webGoBack = () => {
+        console.log('📱 原生返回按钮被点击,准备关闭页面');
+        window.bridge.callNative("finishPage");
+      };
+    }
+  } catch (e) {
+    console.error('❌ 原生交互初始化失败:', e);
+  }
+})
+
+onBeforeUnmount(() => {
+  // 离开主页时,将 webGoBack 重置为路由返回
+  // 这样在其他页面点击原生返回按钮时,会执行路由后退
+  window.webGoBack = () => {
+    console.log('📱 调用通用路由返回');
+    router.back();
+  };
 })
 </script>