This commit is contained in:
fan 2023-05-30 10:21:21 +08:00
commit ac3457efbd
2 changed files with 79 additions and 2 deletions

View File

@ -166,3 +166,19 @@ export function clearDesignTraining(trainingId, group) {
method: 'delete' method: 'delete'
}); });
} }
/** 导出实训数据 */
export function exportTrainingData(data) {
return request({
url: `/api/v2/training/published/export`,
method: 'post',
data
});
}
/** 导入实训数据 */
export function importTrainingData(data) {
return request({
url: `/api/v2/training/published/import`,
method: 'post',
data
});
}

View File

@ -14,6 +14,7 @@ import { launchFullscreen } from '@/utils/screen';
import editTraining from './editTraining'; import editTraining from './editTraining';
import { superAdmin, admin } from '@/router/index'; import { superAdmin, admin } from '@/router/index';
import { getAllPublishTrainingList, getManageTrainingListInOrg, publishTrainingPutOn, publishTrainingPutOff, publishTrainingDelete } from '@/api/jmap/training'; import { getAllPublishTrainingList, getManageTrainingListInOrg, publishTrainingPutOn, publishTrainingPutOff, publishTrainingDelete } from '@/api/jmap/training';
import { exportTrainingData, importTrainingData } from '@/api/trainingManage';
export default { export default {
name:'TrainingManage', name:'TrainingManage',
components: { components: {
@ -56,7 +57,9 @@ export default {
}, },
queryList:{ queryList:{
query: this.queryFunction, query: this.queryFunction,
selectCheckShow: false, selectCheckShow: this.hasTeachingDataManage(),
selectCheckClass: 'hiddenCheckBtn',
onSelectionChange: this.onSelectionChange,
// paginationHiden: true, // paginationHiden: true,
indexShow: true, indexShow: true,
columns: [ columns: [
@ -133,8 +136,13 @@ export default {
} }
] ]
} }
],
actions: [
{ text: '导 入', fileType: 'file', handler: this.importTrainingData, show: this.hasTeachingDataManage() },
{ text: '导 出', handler: this.exportTrainingData, show: this.hasTeachingDataManage() }
] ]
} },
checkList: []
}; };
}, },
computed: { computed: {
@ -164,6 +172,54 @@ export default {
}); });
}, },
methods: { methods: {
onSelectionChange(val) {
this.checkList = val.map(item => {
return item.id;
});
},
importTrainingData() {
const loading = this.$loading({
lock: true,
text: '正在导入中...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
setTimeout(() => {
const obj = document.getElementById('queryFormFilesInput');
if (!obj.files) return;
const f = obj.files[0];
const reader = new FileReader();
const that = this;
reader.readAsText(f, 'utf-8');
reader.onload = function(e) {
const data = e.target.result;
importTrainingData(JSON.parse(data)).then(res => {
that.$message.success('导入成功!');
loading.close();
that.queryList.reload();
}).catch(error => {
loading.close();
that.$message.error('导入失败' + error.message);
});
obj.value = '';
};
});
},
exportTrainingData() {
if (!this.checkList.length) { return; }
exportTrainingData(this.checkList).then(res => {
const content = new Blob([JSON.stringify(res.data)]);
const urlObject = window.URL || window.webkitURL || window;
const url = urlObject.createObjectURL(content);
const el = document.createElement('a');
el.href = url;
el.download = `实训数据.json`;
el.click();
urlObject.revokeObjectURL(url);
}).catch(() => {
this.$message.error('导出失败');
});
},
editLabel() { editLabel() {
this.queryList.reload(); this.queryList.reload();
}, },
@ -270,3 +326,8 @@ export default {
} }
}; };
</script> </script>
<style>
.hiddenCheckBtn {
display: none;
}
</style>