Merge branch 'feature/feature-20250331-h5' into uat
This commit is contained in:
25
src/App.vue
25
src/App.vue
@@ -1,18 +1,23 @@
|
|||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { RouterView } from 'vue-router';
|
||||||
import AndroidBackHandler from '@/components/AndroidBackHandler.vue';
|
import { onMounted } from 'vue';
|
||||||
|
import appBridge from '@/assets/js/appBridge';
|
||||||
|
import utils from '@/assets/js/common';
|
||||||
|
|
||||||
export default defineComponent({
|
onMounted(async () => {
|
||||||
name: 'App',
|
if (utils.getParameter('digitalYiliToken')) {
|
||||||
components: {
|
// 隐藏/显示 header
|
||||||
AndroidBackHandler
|
appBridge.setHeaderShown(false);
|
||||||
|
// 设置系统状态栏明暗主题
|
||||||
|
appBridge.setStatusBarStyle('light');
|
||||||
|
// 设置禁止原生返回
|
||||||
|
appBridge.takeOverAndroidBack();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div id="app">
|
<div>
|
||||||
<AndroidBackHandler />
|
<RouterView />
|
||||||
<router-view></router-view>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -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>
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<div class="common-layout">
|
<div class="common-layout">
|
||||||
<!-- title 标题和搜索栏 -->
|
<!-- title 标题和搜索栏 -->
|
||||||
<header class="header">
|
<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" />
|
<van-search shape="round" class="header-search" placeholder="请输入搜索关键词" background="#6fb937" />
|
||||||
</header>
|
</header>
|
||||||
<!-- content -->
|
<!-- content -->
|
||||||
|
|||||||
19
src/main.ts
19
src/main.ts
@@ -23,19 +23,26 @@ declare global {
|
|||||||
appBridge?: any;
|
appBridge?: any;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 隐藏/显示 header
|
// 定义路由是否可以返回的判断
|
||||||
appBridge.setHeaderShown(true);
|
const routerCanGoBack = () => {
|
||||||
// 设置系统状态栏明暗主题
|
const position = router.options.history.state?.position;
|
||||||
appBridge.setStatusBarStyle('light');
|
return typeof position === 'number' && position > 0;
|
||||||
|
};
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
if (to.query.digitalYiliToken) {
|
if (to.query.digitalYiliToken) {
|
||||||
utils.setSessionStorage('xToken', to.query.digitalYiliToken);
|
utils.setSessionStorage('xToken', to.query.digitalYiliToken);
|
||||||
}
|
}
|
||||||
// 设置 header 标题
|
|
||||||
appBridge.setTitle(to.meta.title as string);
|
appBridge.setTitle(to.meta.title as string);
|
||||||
|
// 添加 Android 返回按钮监听方法
|
||||||
|
window.onAndroidBack = () => {
|
||||||
|
if (routerCanGoBack()) {
|
||||||
|
router.go(-1);
|
||||||
|
} else {
|
||||||
|
appBridge.navigateBack();
|
||||||
|
}
|
||||||
|
};
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(createPinia());
|
app.use(createPinia());
|
||||||
app.use(router);
|
app.use(router);
|
||||||
app.mount('#app');
|
app.mount('#app');
|
||||||
Reference in New Issue
Block a user