feat: 引入事件总线,解决iframe刷新问题
This commit is contained in:
parent
e46e4f942c
commit
121e6ea55c
@ -166,6 +166,7 @@ export default {
|
||||
'/txqsc': 'fwsc',
|
||||
'/tjrsc': 'fwsc',
|
||||
'/tsjsc': 'fwsc',
|
||||
'/tsjlbc': 'fwsc',
|
||||
'/yhzx': 'yhzx',
|
||||
'/gxnlpt': 'gxnlpt',
|
||||
'/qych': 'qych',
|
||||
|
||||
@ -65,6 +65,11 @@ const router = new VueRouter({
|
||||
});
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 禁止跳转到与当前完全相同的路由
|
||||
if (from.name && to.fullPath === from.fullPath) {
|
||||
next(false);
|
||||
return;
|
||||
}
|
||||
// 路由切换时清掉全局 figma 视觉高度 clamp 变量,
|
||||
// 避免旧页面残留的 --home-figma-visual-height 把新页面裁切掉。
|
||||
// 新页面的 portal-figma-scale-mixin 会在 mounted/activated 时基于真实高度重新写入。
|
||||
|
||||
3
txw-mhzc-web/src/pages/index/utils/iframe-reload-bus.js
Normal file
3
txw-mhzc-web/src/pages/index/utils/iframe-reload-bus.js
Normal file
@ -0,0 +1,3 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
export const iframeReloadBus = new Vue();
|
||||
@ -62,6 +62,7 @@ import {
|
||||
// 引入全局总线(同时把 $showComingSoon 注册到 Vue 原型上)
|
||||
import "@/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 {
|
||||
name: "Main",
|
||||
@ -245,6 +246,11 @@ export default {
|
||||
window.location.href = `/view/mhzc/login`;
|
||||
return;
|
||||
}
|
||||
const currentPage = this.$route.query.page;
|
||||
if (this.$route.path === '/tzzx' && currentPage === iframeUrl) {
|
||||
iframeReloadBus.$emit('reload');
|
||||
return;
|
||||
}
|
||||
this.$router.push({
|
||||
path: `/tzzx?page=${iframeUrl}`,
|
||||
});
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
<template v-else-if="iframeUrl">
|
||||
<iframe
|
||||
ref="tzzxIframe"
|
||||
:key="iframeKey"
|
||||
:src="iframeUrl"
|
||||
class="tzzx-iframe"
|
||||
frameborder="0"
|
||||
@ -20,6 +21,7 @@
|
||||
import {
|
||||
isAllowedIframeMessageOrigin,
|
||||
} from '@/pages/index/utils/tzzx-iframe';
|
||||
import { iframeReloadBus } from '@/pages/index/utils/iframe-reload-bus.js';
|
||||
|
||||
// 视口降级时高度使用 CSS 变量 --page-offset-top(与 main.vue 顶部固定栏保持一致)
|
||||
|
||||
@ -28,6 +30,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
iframeUrl: '',
|
||||
iframeKey: 0,
|
||||
loading: true,
|
||||
iframeHeight: 0,
|
||||
heightMode: 'default',
|
||||
@ -59,12 +62,17 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
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() {
|
||||
this.fetchPage();
|
||||
},
|
||||
beforeDestroy() {
|
||||
iframeReloadBus.$off('reload', this._iframeReloadHandler);
|
||||
this.cleanup();
|
||||
},
|
||||
deactivated() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user