rt-sim-training-client/src/views/display/menuDemon.vue

261 lines
7.0 KiB
Vue
Raw Normal View History

2019-07-26 13:32:43 +08:00
<template>
2019-08-02 10:36:17 +08:00
<div>
<div class="display-card" :style="{top: offset+'px'}">
<el-row>
<span v-if="countTime" class="display-score">{{ $t('display.demon.trialTime') }} {{ countTime }}</span>
2019-08-02 10:36:17 +08:00
</el-row>
2019-07-26 13:32:43 +08:00
</div>
2019-08-02 10:36:17 +08:00
<div class="display-draft">
<el-button-group>
<el-button v-if="isShowScheduling" type="primary" @click="jumpScheduling">{{ $t('display.demon.dispatchingPlan') }}</el-button>
2019-08-02 10:36:17 +08:00
<el-button type="jumpjlmap3d" @click="jumpjlmap3d">{{ jl3dname }}</el-button>
2019-08-30 09:00:36 +08:00
<template v-if="isShowQuest">
2019-10-28 19:12:31 +08:00
<!-- && !isDesignPlatform -->
<el-button v-if="!isDesignPlatform " type="danger" @click="handleQuitQuest">{{ $t('display.demon.exitScript') }}</el-button>
2019-08-02 10:36:17 +08:00
</template>
<template v-else>
<el-button type="success" :disabled="isDisable" @click="selectBeginTime">{{ $t('display.demon.drivingByPlan') }}</el-button>
<el-button type="danger" :disabled="!isDisable" @click="end">{{ $t('display.demon.exitPlan') }}</el-button>
2019-08-02 10:36:17 +08:00
</template>
<el-button type="primary" @click="back">{{ $t('display.demon.back') }}</el-button>
2019-08-02 10:36:17 +08:00
</el-button-group>
</div>
<set-time ref="setTime" @ConfirmSelectBeginTime="start" />
</div>
2019-07-26 13:32:43 +08:00
</template>
<!-- 单人仿真 -->
<script>
2019-08-02 10:36:17 +08:00
import SetTime from './demon/setTime';
import { Notification } from 'element-ui';
import { getGoodsTryUse } from '@/api/management/goods';
2019-08-06 10:11:32 +08:00
import { runDiagramStart, runDiagramOver, runDiagramGetTime } from '@/api/simulation';
import { PermissionType } from '@/scripts/ConstDic';
2019-08-02 10:36:17 +08:00
import { exitFullscreen } from '@/utils/screen';
import { getCountTime } from '@/utils/index';
2019-08-16 15:02:34 +08:00
import { runDiagramIsStart, quitScript } from '@/api/simulation';
2019-08-02 10:36:17 +08:00
import { timeFormat } from '@/utils/date';
import { EventBus } from '@/scripts/event-bus';
2019-07-26 13:32:43 +08:00
2019-08-02 10:36:17 +08:00
export default {
name: 'MenuDemon',
components: {
2019-08-19 10:31:11 +08:00
SetTime
2019-08-02 10:36:17 +08:00
},
props: {
group: {
type: String,
required: true
},
offset: {
type: Number,
required: true
},
questId: {
type: Number,
default() {
return 0;
}
}
},
data() {
return {
isDisable: false,
2019-08-30 09:00:36 +08:00
tryTime: 0, // 进入页面多少秒
timeNow: 0, // 进入页面 相对时间
time: null, // 定时器
countTime: 0, // 显示 倒计时
2019-08-02 10:36:17 +08:00
remainingTime: 0,
goodsId: this.$route.query.goodsId,
try: this.$route.query.try, // 是否是试用权限
training: {
id: '',
name: '',
remarks: ''
},
2019-09-11 15:33:00 +08:00
jl3dname: this.$t('display.demon.threeDimensionalView')
2019-08-02 10:36:17 +08:00
};
},
2019-08-30 09:00:36 +08:00
computed: {
isShowQuest() {
return this.questId;
2019-08-30 15:46:08 +08:00
},
isShowScheduling() {
return this.$route.query.prdType == '05';
2019-10-28 19:12:31 +08:00
},
isDesignPlatform(){
return this.$route.fullPath.includes('design/display/demon');
2019-08-30 09:00:36 +08:00
}
},
2019-08-02 10:36:17 +08:00
watch: {
'$store.state.training.subscribeCount': function () {
2019-08-06 10:11:32 +08:00
this.group && this.initLoadPage();
2019-08-02 10:36:17 +08:00
},
'$store.state.socket.tipOperateCount': function (val) {
this.$alert(this.$t('display.demon.taskOperateSuccess'), this.$t('global.tips'), {
2019-09-11 15:33:00 +08:00
confirmButtonText: this.$t('global.confirm'),
2019-08-02 10:36:17 +08:00
callback: action => {
}
});
}
},
beforeDestroy() {
if (this.time) {
this.setTryTime();
clearTimeout(this.time);
}
},
methods: {
2019-08-06 10:11:32 +08:00
async initLoadPage() {
2019-08-02 10:36:17 +08:00
try {
if (this.try != '0') {
this.loadInitData();
}
2019-07-26 13:32:43 +08:00
2019-08-02 10:36:17 +08:00
const resp = await runDiagramIsStart(this.group);
if (resp && resp.data) {
this.isDisable = true;
this.$store.dispatch('training/simulationStart');
} else {
this.isDisable = false;
this.$store.dispatch('training/over');
}
2019-07-26 13:32:43 +08:00
2019-08-02 10:36:17 +08:00
await this.loadSystemTime();
this.change3dname();
} catch (error) {
console.log(error);
}
},
loadInitData() {
const data = {
mapId: this.$route.query.mapId,
2019-08-30 19:19:48 +08:00
prdCode: this.$route.query.code,
permissionType: PermissionType.SIMULATION
2019-08-02 10:36:17 +08:00
};
getGoodsTryUse(data).then(res => {
this.remainingTime = res.data.tryTime;
this.timeNow = Date.parse(new Date()) / 1000 + this.remainingTime;
if (this.try) {
this.time = setInterval(() => {
this.tryTime += 1;
this.countTime = getCountTime(this.timeNow);
if (this.countTime == -1) {
this.back();
}
}, 1000);
}
}).catch(() => {
2019-09-11 15:33:00 +08:00
this.$messageBox(this.$t('display.demon.getTimeFail'));
2019-08-02 10:36:17 +08:00
});
},
selectBeginTime() {
this.$refs.setTime.doShow();
},
start(model) {
this.isDisable = true;
runDiagramStart(model, this.group).then(res => {
this.$store.dispatch('training/simulationStart').then(() => {
this.$store.dispatch('training/setInitTime', +new Date(`${new Date().getFullYear()} ${model.initTime}`));
});
}).catch(() => {
this.isDisable = false;
2019-09-11 15:33:00 +08:00
this.$messageBox(this.$t('display.demon.startSimulationFail'));
2019-08-02 10:36:17 +08:00
});
},
end() {
this.isDisable = false;
runDiagramOver(this.group).then(() => {
this.$store.dispatch('training/over').then(() => {
this.$store.dispatch('training/setMapDefaultState').then(() => {
this.$store.dispatch('map/clearJlmapTrainView');
this.$store.dispatch('map/setTrainWindowShow', false);
});
});
}).catch(() => {
this.isDisable = true;
2019-09-11 15:33:00 +08:00
this.$messageBox(this.$t('display.demon.endSimulationFail'));
2019-08-02 10:36:17 +08:00
});
},
handleQuitQuest() {
2019-08-19 10:31:11 +08:00
quitScript(this.group).then(resp => {
2019-08-02 10:36:17 +08:00
this.$emit('quitQuest');
}).catch(() => {
2019-09-11 15:33:00 +08:00
this.$messageBox(this.$t('display.demon.exitTaskFail'));
2019-08-02 10:36:17 +08:00
});
},
back() {
this.$store.dispatch('training/over').then(() => {
EventBus.$emit('runPlanStop');
EventBus.$emit('chatSubscribeStop');
history.go(-1);
Notification.closeAll();
exitFullscreen();
});
},
jumpjlmap3d() {
this.$emit('hidepanel');
},
2019-08-30 15:46:08 +08:00
jumpScheduling() {
this.$emit('showScheduling');
},
2019-08-02 10:36:17 +08:00
setTryTime() {
if (this.try) {
this.$emit('tryTime', { time: this.tryTime, goodsId: this.goodsId });
}
},
async loadSystemTime() {
const rest = await runDiagramGetTime(this.group);
if (rest && rest.code == 200) {
this.$store.dispatch('training/setInitTime', +new Date(`${new Date().getFullYear()} ${timeFormat(rest.data)}`));
}
},
change3dname() {
if (this.$route.query.prdType == '04') {
2019-09-11 15:33:00 +08:00
this.jl3dname = this.$t('display.demon.driverPerspective');
2019-08-02 10:36:17 +08:00
} else {
2019-09-11 15:33:00 +08:00
this.jl3dname = this.$t('display.demon.threeDimensionalView');
2019-08-02 10:36:17 +08:00
}
}
}
};
2019-07-26 13:32:43 +08:00
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.display-card {
z-index: 9;
2019-07-26 15:52:50 +08:00
display: inline-block;
2019-07-26 13:32:43 +08:00
position: absolute;
top: 17px;
left: 160px;
height: 32px;
}
.display-card .el-row {
line-height: 32px !important;
}
.display-score {
background-color: black;
display: -moz-inline-box;
display: inline-block;
text-align: left;
height: 32px;
line-height: 24px;
border-radius: 4px;
padding-left: 2px;
margin-left: 10px;
font-family: "Microsoft" !important;
font-size: 18px !important;
color: #fff;
}
.display-draft {
position: absolute;
float: right;
right: 20px;
bottom: 15px;
}
2019-08-02 10:36:17 +08:00
</style>