实训代码调整

This commit is contained in:
dong 2022-08-23 17:42:44 +08:00
parent 86c0b72802
commit 5443e46708
4 changed files with 126 additions and 27 deletions

View File

@ -27,7 +27,7 @@ export function createTraining(data) {
/** 更新当前用户的某个实训草稿 */ /** 更新当前用户的某个实训草稿 */
export function updateTraining(data) { export function updateTraining(data) {
return request({ return request({
url: `/api/v2/draft/training`, url: `/api/v2/draft/training/update/info`,
method: 'post', method: 'post',
data data
}); });

View File

@ -1,6 +1,30 @@
<template> <template>
<el-dialog :title="title" :visible.sync="dialogVisible" width="500px" :modal="false" :before-close="doClose" center> <el-dialog :title="title" :visible.sync="dialogVisible" width="500px" :modal="false" :before-close="doClose" center>
<data-form ref="dataform" :form="form" :form-model="formModel" :rules="rules" /> <data-form ref="dataform" :form="form" :form-model="formModel" :rules="rules" />
<el-form ref="form" :model="tagForm" label-width="60px">
<el-form-item label="标签">
<el-tag
v-for="tag in tagForm.dynamicTags"
:key="tag"
closable
:disable-transitions="false"
@close="handleClose(tag)"
>
{{ tag }}
</el-tag>
<el-input
v-if="inputVisible"
ref="saveTagInput"
v-model="inputValue"
autofocus
class="input-new-tag"
size="small"
@keyup.enter.native="handleInputConfirm"
@blur="handleInputConfirm"
/>
<el-button v-else class="button-new-tag" size="small" @click="showInput">+ New Tag</el-button>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button type="primary" @click="doCreate">{{ $t('global.confirm') }}</el-button> <el-button type="primary" @click="doCreate">{{ $t('global.confirm') }}</el-button>
<el-button @click="doClose">{{ $t('global.cancel') }}</el-button> <el-button @click="doClose">{{ $t('global.cancel') }}</el-button>
@ -23,8 +47,13 @@ export default {
name: '', name: '',
mapId: '', mapId: '',
description:'', description:'',
type: '', type: ''
labelJson: '' // labelJson: ''
},
inputVisible: false,
inputValue: '',
tagForm: {
dynamicTags: []
} }
}; };
}, },
@ -42,8 +71,8 @@ export default {
items: [ items: [
{ prop: 'name', label: '名称', type: 'text' }, { prop: 'name', label: '名称', type: 'text' },
{ prop: 'description', label: '描述', type: 'textarea' }, { prop: 'description', label: '描述', type: 'textarea' },
{ prop: 'type', label: '类型', type: 'select', options: ConstConfig.ConstSelect.trainingType }, { prop: 'type', label: '类型', type: 'select', options: ConstConfig.ConstSelect.trainingType }
{ prop: 'labelJson', label: '标签', type: 'text' } // { prop: 'labelJson', label: '', type: 'text', placeholder: '' }
] ]
}; };
@ -65,6 +94,20 @@ export default {
} }
}, },
methods: { methods: {
handleClose(tag) {
this.tagForm.dynamicTags.splice(this.tagForm.dynamicTags.indexOf(tag), 1);
},
showInput() {
this.inputVisible = true;
},
handleInputConfirm() {
const inputValue = this.inputValue;
if (inputValue) {
this.tagForm.dynamicTags.push(inputValue);
}
this.inputVisible = false;
this.inputValue = '';
},
validateName(rule, value, callback) { validateName(rule, value, callback) {
if (value.trim().length == 0) { if (value.trim().length == 0) {
this.formModel.name = this.formModel.name.replace(/\s/g, ''); this.formModel.name = this.formModel.name.replace(/\s/g, '');
@ -85,24 +128,31 @@ export default {
if (data) { if (data) {
this.isCreate = false; this.isCreate = false;
this.formModel = {...data}; this.formModel = {...data};
Object.keys(this.formModel).forEach(key => {
this.formModel[key] = data[key];
});
this.tagForm.dynamicTags = data.labelJson ? JSON.parse(data.labelJson) : [];
} else { } else {
this.isCreate = true; this.isCreate = true;
this.formModel = { this.formModel = {
name: '', name: '',
mapId: this.$route.query.mapId, mapId: this.$route.query.mapId,
description:'', description:'',
type: '', type: ''
labelJson: '' // labelJson: ''
}; };
this.tagForm.dynamicTags = [];
} }
this.dialogVisible = true; this.dialogVisible = true;
}, },
doCreate() { doCreate() {
this.$refs.dataform.validateForm(async() => { this.$refs.dataform.validateForm(async() => {
const cpData = Object.assign({}, this.formModel);
cpData.labelJson = JSON.stringify(this.tagForm.dynamicTags);
if (this.isCreate) { if (this.isCreate) {
await createTraining(this.formModel); await createTraining(cpData);
} else { } else {
await updateTraining(this.formModel); await updateTraining(cpData);
} }
this.$emit('edit'); this.$emit('edit');
this.doClose(); this.doClose();
@ -119,4 +169,19 @@ export default {
/deep/ .el-dialog--center .el-dialog__body{ /deep/ .el-dialog--center .el-dialog__body{
padding: 25px 65px 30px 10px; padding: 25px 65px 30px 10px;
} }
.el-tag + .el-tag {
margin-left: 10px;
}
.button-new-tag {
margin-left: 10px;
height: 32px;
line-height: 30px;
padding-top: 0;
padding-bottom: 0;
}
.input-new-tag {
width: 90px;
margin-left: 10px;
vertical-align: bottom;
}
</style> </style>

View File

@ -133,9 +133,14 @@ export default {
}, },
methods: { methods: {
addStep() { addStep() {
const lastIndex = this.queryList.data.length - 1;
let mId = '';
if (this.queryList.data[lastIndex]) {
mId = this.queryList.data[lastIndex].memberId || '';
}
const obj = { const obj = {
id: this.queryList.data.length + 1 + '', id: lastIndex + 2 + '',
memberId: '', memberId: mId,
description: '' description: ''
// triggerCondition: [], // triggerCondition: [],
// completionCondition:[], // completionCondition:[],
@ -146,7 +151,13 @@ export default {
}, },
handleDelete(index, row) { handleDelete(index, row) {
console.log('删除', index, row); console.log('删除', index, row);
this.queryList.data.splice(index, 1); this.$confirm('确定删除该条步骤数据?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.queryList.data.splice(index, 1);
}).catch(e => {});
}, },
minisize() { minisize() {
this.dialogVisible = true; this.dialogVisible = true;
@ -167,10 +178,12 @@ export default {
list.push(obj); list.push(obj);
}); });
updateTrainingStep(this.editData.id, list).then(res => { updateTrainingStep(this.editData.id, list).then(res => {
console.log('更新大数据成功', res); console.log('保存步骤成功!', res);
this.$message.success('保存步骤成功!');
this.doClose(); this.doClose();
}).catch(err => { }).catch(err => {
console.log('更新大数据错误', err); console.log('保存步骤失败', err);
this.$message.error('保存步骤失败');
}); });
}, },
doClose() { doClose() {
@ -204,21 +217,24 @@ export default {
}); });
}, },
updateMapLocation() { updateMapLocation() {
console.log('更新地图定位');
const data = Vue.prototype.$jlmap.$options; const data = Vue.prototype.$jlmap.$options;
const params = {scale: data.scaleRate, x: data.offsetX, y: data.offsetY}; const params = {scale: data.scaleRate, x: data.offsetX, y: data.offsetY};
updateTrainingMaplocation({id: this.editData.id, mapLocationJson: JSON.stringify(params)}).then(res => { updateTrainingMaplocation({id: this.editData.id, mapLocationJson: JSON.stringify(params)}).then(res => {
console.log('保存背景', res); console.log('保存地图定位成功!', res);
this.$message.success('保存地图定位成功!');
this.formModel.mapLocationJson = JSON.stringify(params); this.formModel.mapLocationJson = JSON.stringify(params);
}).catch(err => { }).catch(err => {
console.log('保存背景失败', err); console.log('保存地图定位失败', err);
this.$message.error('保存地图定位失败');
}); });
}, },
saveScenesStage() { saveScenesStage() {
updateTrainingBackgroud({id: this.editData.id, groupId: this.group}).then(res => { updateTrainingBackgroud({id: this.editData.id, groupId: this.group}).then(res => {
console.log('保存背景', res); console.log('保存背景', res);
this.$message.success('保存背景成功!');
}).catch(err => { }).catch(err => {
console.log('保存背景失败', err); console.log('保存背景失败', err);
this.$message.error('保存背景失败');
}); });
} }
} }

View File

@ -53,6 +53,7 @@ export default {
}, },
{ {
title: this.$t('trainingManage.type'), title: this.$t('trainingManage.type'),
width: '70',
prop: 'type', prop: 'type',
type: 'tag', type: 'tag',
columnValue: (row) => { return this.covertData(row); }, columnValue: (row) => { return this.covertData(row); },
@ -60,12 +61,16 @@ export default {
}, },
{ {
title: this.$t('trainingManage.labelJson'), title: this.$t('trainingManage.labelJson'),
prop: 'labelJson' width: '200',
prop: 'labelJson',
type: 'tagMore',
columnValue: (row) => { return this.labelJsonData(row); },
tagType: (row) => { return ''; }
}, },
{ {
type: 'button', type: 'button',
title: this.$t('trainingManage.operate'), title: this.$t('trainingManage.operate'),
width: '450', width: '360',
buttons: [ buttons: [
{ {
name: this.$t('trainingManage.record'), name: this.$t('trainingManage.record'),
@ -139,6 +144,11 @@ export default {
} }
return lastData.type; return lastData.type;
}, },
labelJsonData(row) {
const sList = row.labelJson ? JSON.parse(row.labelJson) : [];
const list = Object.prototype.toString.call(sList) === '[object Array]' ? sList : [sList];
return list;
},
drawUp(index, row) { drawUp(index, row) {
console.log('编辑', index, row); console.log('编辑', index, row);
this.$emit('updateDetails', row); this.$emit('updateDetails', row);
@ -151,22 +161,30 @@ export default {
}, },
deleteScript(index, row) { deleteScript(index, row) {
console.log('删除', index, row); console.log('删除', index, row);
if (!row.id) { return; } this.$confirm('确定删除该条实训数据?', '警告', {
deleteTraining([row.id]).then(res => { confirmButtonText: '确定',
console.log('删除实训成功', res); cancelButtonText: '取消',
this.getListData(); type: 'warning'
}).catch(err => { }).then(() => {
console.log('删除实训失败', err); if (!row.id) { return; }
this.getListData(); deleteTraining([row.id]).then(res => {
}); console.log('删除实训成功', res);
this.getListData();
}).catch(err => {
console.log('删除实训失败', err);
this.getListData();
});
}).catch(e => {});
}, },
publishScript(index, row) { publishScript(index, row) {
console.log('发布', index, row); console.log('发布', index, row);
if (!row.id) { return; } if (!row.id) { return; }
publishTraining({draftId: row.id}).then(res => { publishTraining({draftId: row.id}).then(res => {
console.log('发布实训成功', res); console.log('发布实训成功', res);
this.$message.success('发布实训成功!');
}).catch(err => { }).catch(err => {
console.log('发布实训失败', err); console.log('发布实训失败', err);
this.$message.error('发布实训失败');
}); });
}, },
previewScript(index, row) { previewScript(index, row) {