实训的导入和导出

This commit is contained in:
dong 2023-05-29 18:42:34 +08:00
parent 80007a7521
commit 9d193dcd66
2 changed files with 79 additions and 2 deletions

View File

@ -166,3 +166,19 @@ export function clearDesignTraining(trainingId, group) {
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 { superAdmin, admin } from '@/router/index';
import { getAllPublishTrainingList, getManageTrainingListInOrg, publishTrainingPutOn, publishTrainingPutOff, publishTrainingDelete } from '@/api/jmap/training';
import { exportTrainingData, importTrainingData } from '@/api/trainingManage';
export default {
name:'TrainingManage',
components: {
@ -56,7 +57,9 @@ export default {
},
queryList:{
query: this.queryFunction,
selectCheckShow: false,
selectCheckShow: this.hasTeachingDataManage(),
selectCheckClass: 'hiddenCheckBtn',
onSelectionChange: this.onSelectionChange,
// paginationHiden: true,
indexShow: true,
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: {
@ -164,6 +172,54 @@ export default {
});
},
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() {
this.queryList.reload();
},
@ -270,3 +326,8 @@ export default {
}
};
</script>
<style>
.hiddenCheckBtn {
display: none;
}
</style>