增加demo

This commit is contained in:
ival 2021-03-17 17:50:17 +08:00
parent 94bb1a0395
commit 520c95a00c
4 changed files with 171 additions and 2 deletions

View File

@ -4,7 +4,7 @@ import router from './router/index';
import {loginInfo} from '@/scripts/ProjectConfig';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import { getToken, removeToken, getSessionStorage } from '@/utils/auth';
import { setToken, getToken, removeToken, getSessionStorage } from '@/utils/auth';
import localStore from 'storejs';
const whiteList = ['/login', '/design/login', '/gzzbxy/relay', '/authorization', '/AUSline', '/AUStool']; // 不重定向白名单
@ -67,7 +67,15 @@ router.beforeEach((to, from, next) => {
document.title = loginInfo[project || 'login'].browserTitle || loginInfo[project || 'login'].title;
NProgress.start();
const loginPath = getRouteInfo(to);
if (getToken()) {
const token = to.query.token
if (/demoTraining/.test(to.path) && token) {
const header = { group: to.query.group, 'X-Token': token };
setToken(token);
store.commit('SET_TOKEN', token)
store.commit('SUBSCRIBE', { header, type: '' });
next();
} else if (getToken()) {
if (to.path === loginPath) {
// 登录页面不拦截
next();

View File

@ -147,6 +147,8 @@ const DraftLessonManage = () => import('@/views/teach/draftLessonManage');
const OrganizationManage = () => import('@/views/organization/index');
const RunPlanViewWindow = () => import('@/views/newMap/displayNew/demon/runPlanViewWindow');
const SecondaryHome = () => import('@/views/trainingPlatform/secondaryHome');
const Demo = () => import('@/views/demo');
const DemoTraining = () => import('@/views/newMap/displayNew/demoTraining');
// import { GenerateRouteProjectList } from '@/scripts/ProjectConfig';
// import { getSessionStorage } from '@/utils/auth';
@ -192,6 +194,16 @@ export const userTrainingPlatform = '016'; // 实训系统
// export const refereePlatform = '017'; // 裁判系统
export const constantRoutes = [
{
path: '/demo',
component: Demo,
hidden: true
},
{
path: '/demoTraining/:mode',
component: DemoTraining,
hidden: true
},
// 实训平台登录
{
path: '/login',

77
src/views/demo/index.vue Normal file
View File

@ -0,0 +1,77 @@
<template>
<div>
<div v-for="(el, i) in trainingList" :key="i" >
<el-button @click="doClick(el)">{{el.title}}</el-button>
</div>
<iframe class="dialog" :style="{display:show?'block': 'none'}" :src="src" width="100%" height="100%"/>
</div>
</template>
<script>
import { getToken } from '@/utils/auth';
export default {
data() {
return {
src: '',
show: false,
trainingList: [
{
title: '全站取消联锁自动触发',
id: '4994993'
},
{
title: '2222',
id: 1
},
{
title: '33333',
id: 1
}
]
};
},
mounted() {
window.addEventListener('message', (e) => {
// console.log(e, e.data) //e.data
// console.log(e.origin) //e.origin postMessage origin
// console.log(e.source) //e.source使origin
this.src = '';
this.show = false;
this.$nextTick(_ => {
const result = e.data;
if (result.type == 'DEMO_RESULT' && result.hasOwnProperty('score')) {
this.$confirm(`得分:${result.score}`, "结果", {
confirmButtonText: "确定",
type:'warning',
showCancelButton: false,
center: true
}).then(_ => {
}).catch(_ => {
});
}
})
})
},
destroyed() {
window.removeEventListener('message');
},
methods: {
doClick(el) {
this.show = true;
this.src = `http://localhost:9527/cbtc/demoTraining/teach?lessonId=101&mapId=49&lineCode=02&prdType=01&noPreLogout=true&trainingId=${el.id}&token=${getToken()}`;
}
}
};
</script>
<style scoped lang="scss">
.dialog {
background: #fff;
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
}
</style>

View File

@ -0,0 +1,72 @@
<template>
<div class="demo" v-loading="loading">
<lesson-training v-if="hasGroup"/>
</div>
</template>
<script>
import LessonTraining from '../index';
import { trainingNotifyNew } from '@/api/simulation';
import { EventBus } from '@/scripts/event-bus';
export default {
components: {
LessonTraining
},
data() {
return {
loading: false,
result: {
}
};
},
computed: {
hasGroup() {
return this.$route.query.group;
},
},
watch: {
'$route': function() {
this.loading = false;
}
},
async mounted() {
await this.createSimulation();
},
methods: {
async createSimulation() {
const lineCode = this.$route.query.lineCode;
const mapId = this.$route.query.mapId;
const prdType = this.$route.query.prdType;
const trainingId = this.$route.query.trainingId;
const lessonId = this.$route.query.lessonId;
const mode = this.$route.params.mode;
const goodsId = '';
this.loading = true;
const resp = await trainingNotifyNew({trainingId});
if (resp && resp.code == 200) {
const query = { lineCode, group: resp.data, prdType, mapId, lessonId, trainingId, goodsId, from: 'kzfmooc', project: 'login', try: '0'};
this.$store.dispatch('training/setPrdType', prdType);
this.$router.replace({ path: `/demoTraining/${mode}`, query: query });
EventBus.$on('demoResult', e => this.exitSimulation(e) );
} else if (resp.code == 10003) {
this.loading = false;
this.$messageBox(this.$t('error.createSimulationFailed') + ':您的仿真权限不足!');
} else {
this.loading = false;
this.$messageBox(this.$t('error.createSimulationFailed') + error.message);
};
},
exitSimulation(result={}) {
window.parent.postMessage(Object.assign(result, {type: 'DEMO_RESULT'}), 'http://localhost:9527/cbtc/demo')
}
}
};
</script>
<style lang="scss" scoped>
.demo {
width: 100%;
height: 100%;
}
</style>