代码调整

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,5 @@
import SessionStorage from 'sessionstorage'; import SessionStorage from 'sessionstorage';
import store from '@/store/index';
const TokenKey = 'Admin-Token'; const TokenKey = 'Admin-Token';
@ -23,3 +24,22 @@ export function setSessionStorage(key, value) {
export function removeSessionStorage(key) { export function removeSessionStorage(key) {
return SessionStorage.removeItem(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)) { } else if (!(obj2 instanceof Object)) {
return false; return false;
} }
const arr1 = Object.keys(obj1); // 仅过滤值为null的项
const arr2 = Object.keys(obj2); 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) { if (arr1.length !== arr2.length) {
return false; 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="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="pauseScript">暂停</el-button>
<el-button v-if="isPause && record" size="small" type="primary" @click="executePlayScript">恢复</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 type="primary" size="small" @click="back">返回</el-button>
</el-button-group> </el-button-group>
</div> </div>
@ -19,7 +17,7 @@
</template> </template>
<script> <script>
import { clearSimulation, executeScriptNew, simulationPause, exitRunPlan } from '@/api/simulation'; 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 TrainingJlmap from './trainingJlmap';
import MenuDemon from '@/views/trainingManage/demonMenu.vue'; import MenuDemon from '@/views/trainingManage/demonMenu.vue';
import TrainingTip from './trainingTip'; import TrainingTip from './trainingTip';
@ -140,31 +138,14 @@ export default {
await clearSimulation(this.$route.query.group); 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() { nextStep() {
const stepList = JSON.parse(this.$store.state.trainingNew.trainingDetail.stepJson); 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 => { endTrainingStep(this.group, step.id).then(resp => {
}).catch(() => { }).catch(() => {
this.$message.error('进入下一步实训失败!'); 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('trainingNew/trainingEnd');
this.$store.dispatch('socket/clearTrainingStepTip'); this.$store.dispatch('socket/clearTrainingStepTip');
this.$store.dispatch('trainingNew/clearStepOrder'); this.$store.dispatch('trainingNew/clearStepOrder');
this.$store.dispatch('trainingNew/clearOperateOrder');
this.$store.dispatch('trainingNew/setTrainingScore', resp.data); this.$store.dispatch('trainingNew/setTrainingScore', resp.data);
}).catch(() => { }).catch(() => {
this.$message.error('结束实训失败!'); this.$message.error('结束实训失败!');