feat: 引入事件总线,解决iframe刷新问题
This commit is contained in:
parent
e46e4f942c
commit
121e6ea55c
@ -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',
|
||||||
|
|||||||
@ -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 时基于真实高度重新写入。
|
||||||
|
|||||||
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 原型上)
|
// 引入全局总线(同时把 $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}`,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -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() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user