feat: 引入事件总线,解决iframe刷新问题

This commit is contained in:
liulujian 2026-06-16 00:19:40 +08:00
parent e46e4f942c
commit 121e6ea55c
5 changed files with 24 additions and 1 deletions

View File

@ -166,6 +166,7 @@ export default {
'/txqsc': 'fwsc', '/txqsc': 'fwsc',
'/tjrsc': 'fwsc', '/tjrsc': 'fwsc',
'/tsjsc': 'fwsc', '/tsjsc': 'fwsc',
'/tsjlbc': 'fwsc',
'/yhzx': 'yhzx', '/yhzx': 'yhzx',
'/gxnlpt': 'gxnlpt', '/gxnlpt': 'gxnlpt',
'/qych': 'qych', '/qych': 'qych',

View File

@ -65,6 +65,11 @@ const router = new VueRouter({
}); });
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
// 禁止跳转到与当前完全相同的路由
if (from.name && to.fullPath === from.fullPath) {
next(false);
return;
}
// 路由切换时清掉全局 figma 视觉高度 clamp 变量, // 路由切换时清掉全局 figma 视觉高度 clamp 变量,
// 避免旧页面残留的 --home-figma-visual-height 把新页面裁切掉。 // 避免旧页面残留的 --home-figma-visual-height 把新页面裁切掉。
// 新页面的 portal-figma-scale-mixin 会在 mounted/activated 时基于真实高度重新写入。 // 新页面的 portal-figma-scale-mixin 会在 mounted/activated 时基于真实高度重新写入。

View File

@ -0,0 +1,3 @@
import Vue from 'vue';
export const iframeReloadBus = new Vue();

View File

@ -62,6 +62,7 @@ import {
// 线 $showComingSoon Vue // 线 $showComingSoon Vue
import "@/pages/index/utils/coming-soon-dialog.js"; import "@/pages/index/utils/coming-soon-dialog.js";
import { comingSoonBus } from "@/pages/index/utils/coming-soon-dialog.js"; import { comingSoonBus } from "@/pages/index/utils/coming-soon-dialog.js";
import { iframeReloadBus } from "@/pages/index/utils/iframe-reload-bus.js";
export default { export default {
name: "Main", name: "Main",
@ -245,6 +246,11 @@ export default {
window.location.href = `/view/mhzc/login`; window.location.href = `/view/mhzc/login`;
return; return;
} }
const currentPage = this.$route.query.page;
if (this.$route.path === '/tzzx' && currentPage === iframeUrl) {
iframeReloadBus.$emit('reload');
return;
}
this.$router.push({ this.$router.push({
path: `/tzzx?page=${iframeUrl}`, path: `/tzzx?page=${iframeUrl}`,
}); });

View File

@ -4,6 +4,7 @@
<template v-else-if="iframeUrl"> <template v-else-if="iframeUrl">
<iframe <iframe
ref="tzzxIframe" ref="tzzxIframe"
:key="iframeKey"
:src="iframeUrl" :src="iframeUrl"
class="tzzx-iframe" class="tzzx-iframe"
frameborder="0" frameborder="0"
@ -20,6 +21,7 @@
import { import {
isAllowedIframeMessageOrigin, isAllowedIframeMessageOrigin,
} from '@/pages/index/utils/tzzx-iframe'; } from '@/pages/index/utils/tzzx-iframe';
import { iframeReloadBus } from '@/pages/index/utils/iframe-reload-bus.js';
// 使 CSS --page-offset-top main.vue // 使 CSS --page-offset-top main.vue
@ -28,6 +30,7 @@ export default {
data() { data() {
return { return {
iframeUrl: '', iframeUrl: '',
iframeKey: 0,
loading: true, loading: true,
iframeHeight: 0, iframeHeight: 0,
heightMode: 'default', heightMode: 'default',
@ -59,12 +62,17 @@ export default {
}, },
mounted() { mounted() {
this.fetchPage(); this.fetchPage();
this.$watch(() => this.$route.query.page, () => this.fetchPage()); this.$watch('$route.fullPath', () => this.fetchPage());
this._iframeReloadHandler = () => {
this.iframeKey += 1;
};
iframeReloadBus.$on('reload', this._iframeReloadHandler);
}, },
activated() { activated() {
this.fetchPage(); this.fetchPage();
}, },
beforeDestroy() { beforeDestroy() {
iframeReloadBus.$off('reload', this._iframeReloadHandler);
this.cleanup(); this.cleanup();
}, },
deactivated() { deactivated() {