Merge branch 'feature/feature-20250331-h5' into uat

This commit is contained in:
LHY\18810
2025-03-15 00:04:20 +08:00
4 changed files with 30 additions and 76 deletions

View File

@@ -1,18 +1,23 @@
<script lang="ts">
import { defineComponent } from 'vue';
import AndroidBackHandler from '@/components/AndroidBackHandler.vue';
<script setup lang="ts">
import { RouterView } from 'vue-router';
import { onMounted } from 'vue';
import appBridge from '@/assets/js/appBridge';
import utils from '@/assets/js/common';
export default defineComponent({
name: 'App',
components: {
AndroidBackHandler
onMounted(async () => {
if (utils.getParameter('digitalYiliToken')) {
// 隐藏/显示 header
appBridge.setHeaderShown(false);
// 设置系统状态栏明暗主题
appBridge.setStatusBarStyle('light');
// 设置禁止原生返回
appBridge.takeOverAndroidBack();
}
});
</script>
<template>
<div id="app">
<AndroidBackHandler />
<router-view></router-view>
<div>
<RouterView />
</div>
</template>

View File

@@ -1,58 +0,0 @@
<template>
<div></div>
</template>
<script lang="ts">
import { defineComponent, onMounted, onUnmounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import appBridge from '@/assets/js/appBridge';
export default defineComponent({
name: 'AndroidBackHandler',
setup() {
const router = useRouter();
const route = useRoute();
// 检查是否可以返回
const canGoBack = () => {
// 检查是否有历史记录
if (window.history.length > 1) {
return true;
}
// 检查路由状态
const position = router.options.history.state?.position;
return typeof position === 'number' && position > 0;
};
// 检查是否是首页
const isHomePage = () => {
// 根据实际路由配置修改这里的判断逻辑
return route.path === '/' || route.path === '/home';
};
// 处理返回按钮事件
const handleBack = () => {
// 如果有历史记录,说明是从其他页面进入的
if (canGoBack()) {
router.go(-1);
return false;
} else {
appBridge.navigateBack();
}
};
onMounted(() => {
// 设置禁止原生返回
appBridge.takeOverAndroidBack();
// 添加返回按钮监听
window.onAndroidBack = handleBack;
});
onUnmounted(() => {
// 移除返回按钮监听
window.onAndroidBack = null;
});
return {};
}
});
</script>

View File

@@ -2,7 +2,7 @@
<div class="common-layout">
<!-- title 标题和搜索栏 -->
<header class="header">
<van-nav-bar class="header-nav" :title="$route.meta.title" left-arrow @click-left="$route.go(-1)" />
<van-nav-bar class="header-nav" :title="$route.meta.title" left-arrow @click-left="$router.go(-1)" />
<van-search shape="round" class="header-search" placeholder="请输入搜索关键词" background="#6fb937" />
</header>
<!-- content -->

View File

@@ -23,19 +23,26 @@ declare global {
appBridge?: any;
}
}
// 隐藏/显示 header
appBridge.setHeaderShown(true);
// 设置系统状态栏明暗主题
appBridge.setStatusBarStyle('light');
// 定义路由是否可以返回的判断
const routerCanGoBack = () => {
const position = router.options.history.state?.position;
return typeof position === 'number' && position > 0;
};
router.beforeEach((to, from, next) => {
if (to.query.digitalYiliToken) {
utils.setSessionStorage('xToken', to.query.digitalYiliToken);
}
// 设置 header 标题
appBridge.setTitle(to.meta.title as string);
// 添加 Android 返回按钮监听方法
window.onAndroidBack = () => {
if (routerCanGoBack()) {
router.go(-1);
} else {
appBridge.navigateBack();
}
};
next();
});
app.use(createPinia());
app.use(router);
app.mount('#app');
app.mount('#app');