代码调整

This commit is contained in:
dong 2022-09-22 17:03:13 +08:00
parent 986fe7eada
commit c76ca2288c
8 changed files with 60 additions and 36 deletions

View File

@ -17,7 +17,7 @@
</template>
<script>
import { getToken } from '@/utils/auth';
import { getToken, getUserIdKey } from '@/utils/auth';
import { getSessionStorage } from '@/utils/auth';
import { loginInfo, ProjectIcon } from '@/scripts/ProjectConfig';
import DeomonTopic from '@/views/demonstration/deomonTopic';
@ -89,16 +89,19 @@ export default {
}
});
window.addEventListener('storage', e => {
if (e.key == getUserIdKey('setSceneOperate')) {
if (this.$route.path.includes('trainingDesign')) {
if (e.key == 'setTrainingOperate') {
const operate = JSON.parse(e.newValue);
this.$store.dispatch('trainingNew/setTrainingOperate', operate);
}
if (e.key == 'setSceneOperate') {
const operate = JSON.parse(e.newValue);
this.$store.dispatch('trainingNew/setSceneOperate', operate);
}
}
if (e.key == getUserIdKey('nextNew')) {
if (this.$route.path.includes('trainingDesign') || this.$route.path.includes('trainingPreview')) {
const operate = JSON.parse(e.newValue);
this.$store.dispatch('training/nextNew', operate);
}
}
});
this.$nextTick(() => {
openIndexedDB();

View File

@ -6,6 +6,7 @@ import { State2SimulationMap } from './Config.js';
import { sendTrainingNextStepNew } from '@/api/jmap/training';
import { getCmdList } from '@/api/management/dictionary';
import { OperationEvent } from '@/scripts/cmdPlugin/OperationHandler';
import { getLocalStorage } from '@/utils/auth';
class Handler {
constructor() {
@ -185,9 +186,17 @@ class Handler {
}
getNewTrainingOperation() {
try {
const stepList = JSON.parse(store.state.trainingNew.trainingDetail.stepJson);
const step = stepList[store.state.trainingNew.stepOrder - 1];
const stepOperation = step.operations[store.state.trainingNew.operateOrder];
let trainingDetail = getLocalStorage('trainingDetail') || `{}`;
trainingDetail = JSON.parse(trainingDetail);
const stepList = JSON.parse(trainingDetail.stepJson || `[]`);
let stepOrder = getLocalStorage('stepOrder') || `1`;
stepOrder = JSON.parse(stepOrder);
let operateOrder = getLocalStorage('operateOrder') || `1`;
operateOrder = JSON.parse(operateOrder);
const step = stepList[stepOrder - 1];
// const index = stepOrder - 1 >= 0 ? stepOrder - 1 : 0;
// const step = stepList[index];
const stepOperation = step.operations[operateOrder];
return stepOperation;
} catch (e) {
console.error(e);

View File

@ -6,6 +6,7 @@ import Handler from '@/scripts/cmdPlugin/Handler';
import { deepAssign } from '@/utils/index';
import store from '@/store/index';
import { ScriptMode } from '@/scripts/ConstDic';
import { setLocalStorage } from '@/utils/auth';
/**
* 实训状态数据
@ -430,6 +431,7 @@ const training = {
// 下一步
nextNew: ({ commit, state }, operate) => {
setLocalStorage('nextNew', JSON.stringify(operate));
return new Promise((resolve, reject) => {
commit('setOperate', operate);
if (!state.started && !state.mode) {

View File

@ -1,3 +1,4 @@
import { setLocalStorage } from '@/utils/auth';
const training = {
namespaced: true,
state: {
@ -44,6 +45,7 @@ const training = {
},
setTrainingDetail: (state, detail) => {
state.trainingDetail = detail;
setLocalStorage('trainingDetail', JSON.stringify(detail));
},
setTrainingSwitch: (state, flag) => {
state.trainingSwitch = flag;
@ -53,18 +55,22 @@ const training = {
},
stepOrderIncrease: (state) => {
state.stepOrder++;
setLocalStorage('stepOrder', JSON.stringify(state.stepOrder));
},
clearStepOrder: (state) => {
state.stepOrder = 0;
setLocalStorage('stepOrder', JSON.stringify(state.stepOrder));
},
operateOrderIncrease: (state) => {
state.operateOrder++;
setLocalStorage('operateOrder', JSON.stringify(state.operateOrder));
},
setSimulationPause: (state, value) => {
state.simulationPause = value;
},
clearOperateOrder: (state) => {
state.operateOrder = 0;
setLocalStorage('operateOrder', JSON.stringify(state.operateOrder));
},
stepOverCountChange: (state) => {
state.stepOverCount++;
@ -88,13 +94,14 @@ const training = {
},
trainingStart: ({commit}) => {
commit('setTrainingSwitch', true);
setLocalStorage('nextNew', null);
},
trainingEnd: ({commit}) => {
commit('setTrainingSwitch', false);
setLocalStorage('nextNew', null);
},
setTrainingOperate: ({commit, state}, trainingOperate) => {
commit('setTrainingOperate', trainingOperate);
window.localStorage.setItem('setTrainingOperate', JSON.stringify(trainingOperate));
},
stepOrderIncrease: ({commit}) => {
commit('stepOrderIncrease');
@ -119,7 +126,7 @@ const training = {
},
setSceneOperate: ({commit}, sceneOperate) => {
commit('setSceneOperate', sceneOperate);
window.localStorage.setItem('setSceneOperate', JSON.stringify(sceneOperate));
setLocalStorage('setSceneOperate', JSON.stringify(sceneOperate));
},
handleCheckNewTrainingResult:({commit, state}, valid) => {
const stepList = JSON.parse(state.trainingDetail.stepJson);

View File

@ -1,4 +1,5 @@
import SessionStorage from 'sessionstorage';
import store from '@/store/index';
const TokenKey = 'Admin-Token';
@ -23,3 +24,22 @@ export function setSessionStorage(key, value) {
export function removeSessionStorage(key) {
return SessionStorage.removeItem(key);
}
// 操作LocalStorage
export function getLocalStorage(key) {
const idKey = getUserIdKey(key);
return localStorage.getItem(idKey);
}
export function setLocalStorage(key, value) {
const idKey = getUserIdKey(key);
return localStorage.setItem(idKey, value);
}
export function removeLocalStorage(key) {
const idKey = getUserIdKey(key);
return localStorage.removeItem(idKey);
}
export function getUserIdKey(key) {
const id = store.state.user.id;
const idKey = `${id}_${key}`;
return idKey;
}

View File

@ -104,8 +104,9 @@ export function objectIsEqual(obj1, obj2) {
} else if (!(obj2 instanceof Object)) {
return false;
}
const arr1 = Object.keys(obj1);
const arr2 = Object.keys(obj2);
// 仅过滤值为null的项
const arr1 = Object.keys(obj1).filter(key => { return obj1[key] != null; });
const arr2 = Object.keys(obj2).filter(key => { return obj1[key] != null; });
if (arr1.length !== arr2.length) {
return false;
}

View File

@ -10,8 +10,6 @@
<el-button v-if="record" v-loading="loading" type="danger" :disabled="loading" size="small" @click="init">初始化</el-button>
<el-button v-if="!isPause && record" size="small" type="primary" @click="pauseScript">暂停</el-button>
<el-button v-if="isPause && record" size="small" type="primary" @click="executePlayScript">恢复</el-button>
<!-- <el-button v-if="!trainingSwitch && trainingDetail" type="success" size="small" @click="handlerStart">开始</el-button>-->
<!-- <el-button v-if="trainingSwitch" type="danger" size="small" @click="handlerEnd">结束</el-button>-->
<el-button type="primary" size="small" @click="back">返回</el-button>
</el-button-group>
</div>
@ -19,7 +17,7 @@
</template>
<script>
import { clearSimulation, executeScriptNew, simulationPause, exitRunPlan } from '@/api/simulation';
import { startTraining, endTraining, endTrainingStep } from '@/api/jmap/training';
import { endTrainingStep } from '@/api/jmap/training';
import TrainingJlmap from './trainingJlmap';
import MenuDemon from '@/views/trainingManage/demonMenu.vue';
import TrainingTip from './trainingTip';
@ -140,31 +138,14 @@ export default {
await clearSimulation(this.$route.query.group);
}
},
handlerStart() {
startTraining(this.group, {mode: this.teachMode}).then(() => {
this.$store.dispatch('trainingNew/changeTeachMode', this.teachMode);
this.$store.dispatch('trainingNew/trainingStart');
}).catch(() => {
this.$message.error('开始实训失败!');
});
},
nextStep() {
const stepList = JSON.parse(this.$store.state.trainingNew.trainingDetail.stepJson);
const step = stepList[this.$store.state.trainingNew.stepOrder - 1];
const index = this.$store.state.trainingNew.stepOrder - 1 >= 0 ? this.$store.state.trainingNew.stepOrder - 1 : 0;
const step = stepList[index];
endTrainingStep(this.group, step.id).then(resp => {
}).catch(() => {
this.$message.error('进入下一步实训失败!');
});
},
handlerEnd() {
endTraining(this.group).then(() => {
this.$store.dispatch('trainingNew/trainingEnd');
this.$store.dispatch('socket/clearTrainingStepTip');
this.$store.dispatch('trainingNew/clearStepOrder');
this.$store.dispatch('trainingNew/changeTeachMode', '');
}).catch(() => {
this.$message.error('结束实训失败!');
});
}
}
};

View File

@ -148,6 +148,7 @@ export default {
this.$store.dispatch('trainingNew/trainingEnd');
this.$store.dispatch('socket/clearTrainingStepTip');
this.$store.dispatch('trainingNew/clearStepOrder');
this.$store.dispatch('trainingNew/clearOperateOrder');
this.$store.dispatch('trainingNew/setTrainingScore', resp.data);
}).catch(() => {
this.$message.error('结束实训失败!');