fast(监控大屏): 监听大屏添加iframe监听方法,封装跳转方法,设备列表添加url参数识别,解决重复操作导航报错问题

This commit is contained in:
fhysy 2024-12-25 17:01:46 +08:00
parent 14126d0793
commit 5eaf34ed1b
3 changed files with 53 additions and 6 deletions

View File

@ -2,7 +2,14 @@ import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
const RouterPush = Router.prototype.push
Router.prototype.push = function push (to) {
return RouterPush.call(this, to).catch(err => err)
}
const RouterReplace = Router.prototype.replace
Router.prototype.replace = function replace (to) {
return RouterReplace.call(this, to).catch(err => err)
}
/* Layout */
import Layout from '@/layout'
import ParentView from '@/components/ParentView';
@ -305,5 +312,6 @@ export const constantRoutes = [
export default new Router({
mode: 'history', // 去掉url中的#
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
routes: constantRoutes,
ignoreDuplicates: true
})

View File

@ -5,6 +5,7 @@
</template>
<script>
import { debounce } from 'debounce'
export default {
name: "bigScreenIframe",
data() {
@ -12,7 +13,8 @@ export default {
src: "https://goview.drgyen.cn/#/chart/preview/202409060982078",
loading: true,
token: "",
iframeRef: null
iframeRef: null,
userType: "",
};
},
computed: {
@ -28,6 +30,7 @@ export default {
},
created() {
this.token = this.getCookie("Admin-Token");
this.userType = this.$store.getters.userType;
// this.src = process.env.VUE_APP_BIGSCREEN_PLATFORM_URL + "?token=" + this.token;
// document.getElementById('bigIframe').onload = function () {
@ -37,10 +40,10 @@ export default {
},
mounted() {
this.iframeRef = this.$refs.iframeRef;
// window.addEventListener('message', this.receiveMsg, false);
window.addEventListener('message',this.receiveMsg, false);
},
beforeMount() {
// window.removeEventListener('message', this.receiveMsg, false);
window.removeEventListener('message', this.receiveMsg, false);
},
methods: {
getCookie(name) {
@ -71,7 +74,40 @@ export default {
// },10000)
},
receiveMsg(e) {
console.log("父页面-接收消息",e)
// e.data
// {type:'path',url:'/project/project?id=1'}
// {type:'pathType',typeName:'',query: { id: 123 }}
if (e.data.type === 'path') {
if(e.data.url){
this.$router.push(e.data.url);
}
}else if (e.data.type === 'pathType') {
if(e.data.typeName === '设备'){
if(this.userType === 'SYSTEM'){
this.$router.push({
path: '/device/device',
query: e.data.query
});
}else{
this.$router.push({
path: '/device_tenant/device_tenant',
query: e.data.query
});
}
}else if(e.data.typeName === '项目'){
if(this.userType === 'SYSTEM'){
this.$router.push({
path: '/project/project',
query: e.data.query
});
}else{
this.$router.push({
path: '/project_tenant/project_tenant',
query: e.data.query
});
}
}
}
},
onIframeError() {
this.loading = false;

View File

@ -763,6 +763,9 @@ export default {
},
created() {
console.log(this.$route);
if (this.$route.query.deviceState){
this.queryParams.deviceState = this.$route.query.deviceState;
}
this.init();
this.getInProjectList();
},